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/metadata/cil-coff.h>
55 #include <mono/io-layer/io-layer.h>
56 #include <mono/utils/strtod.h>
57 #include <mono/utils/monobitset.h>
59 #if defined (PLATFORM_WIN32)
65 static MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
69 * We expect a pointer to a char, not a string
72 mono_double_ParseImpl (char *ptr)
80 result = bsd_strtod (ptr, &endptr);
82 if (!*ptr || (endptr && *endptr))
83 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib,
91 ves_icall_System_Double_AssertEndianity (double *value)
95 MONO_DOUBLE_ASSERT_ENDIANITY (value);
99 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
108 ao = (MonoArray *)this;
109 ac = (MonoClass *)ao->obj.vtable->klass;
111 esize = mono_array_element_size (ac);
112 ea = (gpointer*)((char*)ao->vector + (pos * esize));
114 if (ac->element_class->valuetype)
115 return mono_value_box (this->vtable->domain, ac->element_class, ea);
121 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
129 MONO_CHECK_ARG_NULL (idxs);
131 io = (MonoArray *)idxs;
132 ic = (MonoClass *)io->obj.vtable->klass;
134 ao = (MonoArray *)this;
135 ac = (MonoClass *)ao->obj.vtable->klass;
137 g_assert (ic->rank == 1);
138 if (io->bounds != NULL || io->max_length != ac->rank)
139 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
141 ind = (guint32 *)io->vector;
143 if (ao->bounds == NULL) {
144 if (*ind < 0 || *ind >= ao->max_length)
145 mono_raise_exception (mono_get_exception_index_out_of_range ());
147 return ves_icall_System_Array_GetValueImpl (this, *ind);
150 for (i = 0; i < ac->rank; i++)
151 if ((ind [i] < ao->bounds [i].lower_bound) ||
152 (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
153 mono_raise_exception (mono_get_exception_index_out_of_range ());
155 pos = ind [0] - ao->bounds [0].lower_bound;
156 for (i = 1; i < ac->rank; i++)
157 pos = pos*ao->bounds [i].length + ind [i] -
158 ao->bounds [i].lower_bound;
160 return ves_icall_System_Array_GetValueImpl (this, pos);
164 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
166 MonoClass *ac, *vc, *ec;
177 vc = value->vtable->klass;
181 ac = this->obj.vtable->klass;
182 ec = ac->element_class;
184 esize = mono_array_element_size (ac);
185 ea = (gpointer*)((char*)this->vector + (pos * esize));
186 va = (gpointer*)((char*)value + sizeof (MonoObject));
189 memset (ea, 0, esize);
193 #define NO_WIDENING_CONVERSION G_STMT_START{\
194 mono_raise_exception (mono_get_exception_argument ( \
195 "value", "not a widening conversion")); \
198 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
199 if (esize < vsize + (extra)) \
200 mono_raise_exception (mono_get_exception_argument ( \
201 "value", "not a widening conversion")); \
204 #define INVALID_CAST G_STMT_START{\
205 mono_raise_exception (mono_get_exception_invalid_cast ()); \
208 /* Check element (destination) type. */
209 switch (ec->byval_arg.type) {
210 case MONO_TYPE_STRING:
211 switch (vc->byval_arg.type) {
212 case MONO_TYPE_STRING:
218 case MONO_TYPE_BOOLEAN:
219 switch (vc->byval_arg.type) {
220 case MONO_TYPE_BOOLEAN:
233 NO_WIDENING_CONVERSION;
240 if (!ec->valuetype) {
241 if (!mono_object_isinst (value, ec))
243 *ea = (gpointer)value;
247 if (mono_object_isinst (value, ec)) {
248 memcpy (ea, (char *)value + sizeof (MonoObject), esize);
255 vsize = mono_class_instance_size (vc) - sizeof (MonoObject);
258 g_message (G_STRLOC ": %d (%d) <= %d (%d)",
259 ec->byval_arg.type, esize,
260 vc->byval_arg.type, vsize);
263 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
264 switch (vc->byval_arg.type) { \
269 case MONO_TYPE_CHAR: \
270 CHECK_WIDENING_CONVERSION(0); \
271 *(etype *) ea = (etype) u64; \
273 /* You can't assign a signed value to an unsigned array. */ \
278 /* You can't assign a floating point number to an integer array. */ \
281 NO_WIDENING_CONVERSION; \
285 #define ASSIGN_SIGNED(etype) G_STMT_START{\
286 switch (vc->byval_arg.type) { \
291 CHECK_WIDENING_CONVERSION(0); \
292 *(etype *) ea = (etype) i64; \
294 /* You can assign an unsigned value to a signed array if the array's */ \
295 /* element size is larger than the value size. */ \
300 case MONO_TYPE_CHAR: \
301 CHECK_WIDENING_CONVERSION(1); \
302 *(etype *) ea = (etype) u64; \
304 /* You can't assign a floating point number to an integer array. */ \
307 NO_WIDENING_CONVERSION; \
311 #define ASSIGN_REAL(etype) G_STMT_START{\
312 switch (vc->byval_arg.type) { \
315 CHECK_WIDENING_CONVERSION(0); \
316 *(etype *) ea = (etype) r64; \
318 /* All integer values fit into a floating point array, so we don't */ \
319 /* need to CHECK_WIDENING_CONVERSION here. */ \
324 *(etype *) ea = (etype) i64; \
330 case MONO_TYPE_CHAR: \
331 *(etype *) ea = (etype) u64; \
336 switch (vc->byval_arg.type) {
338 u64 = *(guint8 *) va;
341 u64 = *(guint16 *) va;
344 u64 = *(guint32 *) va;
347 u64 = *(guint64 *) va;
353 i64 = *(gint16 *) va;
356 i64 = *(gint32 *) va;
359 i64 = *(gint64 *) va;
362 r64 = *(gfloat *) va;
365 r64 = *(gdouble *) va;
368 u64 = *(guint16 *) va;
370 case MONO_TYPE_BOOLEAN:
371 /* Boolean is only compatible with itself. */
372 switch (ec->byval_arg.type) {
384 NO_WIDENING_CONVERSION;
391 /* If we can't do a direct copy, let's try a widening conversion. */
392 switch (ec->byval_arg.type) {
394 ASSIGN_UNSIGNED (guint16);
396 ASSIGN_UNSIGNED (guint8);
398 ASSIGN_UNSIGNED (guint16);
400 ASSIGN_UNSIGNED (guint32);
402 ASSIGN_UNSIGNED (guint64);
404 ASSIGN_SIGNED (gint8);
406 ASSIGN_SIGNED (gint16);
408 ASSIGN_SIGNED (gint32);
410 ASSIGN_SIGNED (gint64);
412 ASSIGN_REAL (gfloat);
414 ASSIGN_REAL (gdouble);
418 /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
422 #undef NO_WIDENING_CONVERSION
423 #undef CHECK_WIDENING_CONVERSION
424 #undef ASSIGN_UNSIGNED
430 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
438 MONO_CHECK_ARG_NULL (idxs);
440 ic = idxs->obj.vtable->klass;
441 ac = this->obj.vtable->klass;
443 g_assert (ic->rank == 1);
444 if (idxs->bounds != NULL || idxs->max_length != ac->rank)
445 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
447 ind = (guint32 *)idxs->vector;
449 if (this->bounds == NULL) {
450 if (*ind < 0 || *ind >= this->max_length)
451 mono_raise_exception (mono_get_exception_index_out_of_range ());
453 ves_icall_System_Array_SetValueImpl (this, value, *ind);
457 for (i = 0; i < ac->rank; i++)
458 if ((ind [i] < this->bounds [i].lower_bound) ||
459 (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
460 mono_raise_exception (mono_get_exception_index_out_of_range ());
462 pos = ind [0] - this->bounds [0].lower_bound;
463 for (i = 1; i < ac->rank; i++)
464 pos = pos * this->bounds [i].length + ind [i] -
465 this->bounds [i].lower_bound;
467 ves_icall_System_Array_SetValueImpl (this, value, pos);
471 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
476 gboolean bounded = FALSE;
480 MONO_CHECK_ARG_NULL (type);
481 MONO_CHECK_ARG_NULL (lengths);
483 MONO_CHECK_ARG (lengths, mono_array_length (lengths) > 0);
485 MONO_CHECK_ARG (bounds, mono_array_length (lengths) == mono_array_length (bounds));
487 for (i = 0; i < mono_array_length (lengths); i++)
488 if (mono_array_get (lengths, gint32, i) < 0)
489 mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
491 if (bounds && (mono_array_length (bounds) == 1) && (mono_array_get (bounds, gint32, 0) != 0))
492 /* vectors are not the same as one dimensional arrays with no-zero bounds */
497 aklass = mono_bounded_array_class_get (mono_class_from_mono_type (type->type), mono_array_length (lengths), bounded);
499 sizes = alloca (aklass->rank * sizeof(guint32) * 2);
500 for (i = 0; i < aklass->rank; ++i) {
501 sizes [i] = mono_array_get (lengths, gint32, i);
503 sizes [i + aklass->rank] = mono_array_get (bounds, gint32, i);
505 sizes [i + aklass->rank] = 0;
508 array = mono_array_new_full (mono_object_domain (type), aklass, sizes, sizes + aklass->rank);
514 ves_icall_System_Array_GetRank (MonoObject *this)
518 return this->vtable->klass->rank;
522 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
524 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
528 if ((dimension < 0) || (dimension >= rank))
529 mono_raise_exception (mono_get_exception_index_out_of_range ());
531 if (this->bounds == NULL)
532 return this->max_length;
534 return this->bounds [dimension].length;
538 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
540 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
544 if ((dimension < 0) || (dimension >= rank))
545 mono_raise_exception (mono_get_exception_index_out_of_range ());
547 if (this->bounds == NULL)
550 return this->bounds [dimension].lower_bound;
554 ves_icall_System_Array_ClearInternal (MonoArray *arr, int idx, int length)
556 int sz = mono_array_element_size (mono_object_class (arr));
557 memset (mono_array_addr_with_size (arr, idx, sz), 0, length * sz);
561 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
566 MonoClass *src_class;
567 MonoClass *dest_class;
572 if (source->obj.vtable->klass->rank != dest->obj.vtable->klass->rank)
575 if (source->bounds || dest->bounds)
578 if ((dest_idx + length > mono_array_length (dest)) ||
579 (source_idx + length > mono_array_length (source)))
582 element_size = mono_array_element_size (source->obj.vtable->klass);
583 dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
584 source_addr = mono_array_addr_with_size (source, element_size, source_idx);
586 src_class = source->obj.vtable->klass->element_class;
587 dest_class = dest->obj.vtable->klass->element_class;
590 * Handle common cases.
593 /* Case1: object[] -> valuetype[] (ArrayList::ToArray) */
594 if (src_class == mono_defaults.object_class && dest_class->valuetype) {
595 for (i = source_idx; i < source_idx + length; ++i) {
596 MonoObject *elem = mono_array_get (source, MonoObject*, i);
597 if (elem && !mono_object_isinst (elem, dest_class))
601 element_size = mono_array_element_size (dest->obj.vtable->klass);
602 for (i = 0; i < length; ++i) {
603 MonoObject *elem = mono_array_get (source, MonoObject*, source_idx + i);
604 void *addr = mono_array_addr_with_size (dest, element_size, dest_idx + i);
606 memset (addr, 0, element_size);
608 memcpy (addr, (char *)elem + sizeof (MonoObject), element_size);
613 if (src_class != dest_class) {
614 if (dest_class->valuetype || dest_class->enumtype || src_class->valuetype || src_class->enumtype)
617 if (mono_class_is_subclass_of (src_class, dest_class, FALSE))
619 /* Case2: object[] -> reftype[] (ArrayList::ToArray) */
620 else if (mono_class_is_subclass_of (dest_class, src_class, FALSE))
621 for (i = source_idx; i < source_idx + length; ++i) {
622 MonoObject *elem = mono_array_get (source, MonoObject*, i);
623 if (elem && !mono_object_isinst (elem, dest_class))
630 memmove (dest_addr, source_addr, element_size * length);
636 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArray *array, MonoClassField *field_handle)
638 MonoClass *klass = array->obj.vtable->klass;
639 guint32 size = mono_array_element_size (klass);
644 if (array->bounds == NULL)
645 size *= array->max_length;
647 for (i = 0; i < klass->rank; ++i)
648 size *= array->bounds [i].length;
650 memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
652 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
656 guint ## n *data = (guint ## n *) mono_array_addr (array, char, 0); \
658 for (i = 0; i < size; i += n/8, data++) { \
659 tmp = read ## n (data); \
664 /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
666 switch (klass->element_class->byval_arg.type) {
686 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
690 return offsetof (MonoString, chars);
694 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject *obj)
698 if ((obj == NULL) || (! (obj->vtable->klass->valuetype)))
701 return mono_object_clone (obj);
705 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
711 MONO_CHECK_ARG_NULL (handle);
713 klass = mono_class_from_mono_type (handle);
714 MONO_CHECK_ARG (handle, klass);
716 /* This will call the type constructor */
717 if (! (klass->flags & TYPE_ATTRIBUTE_INTERFACE))
718 mono_runtime_class_init (mono_class_vtable (mono_domain_get (), klass));
722 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
726 return mono_object_clone (this);
730 #define MONO_OBJECT_ALIGNMENT_SHIFT 3
732 #define MONO_OBJECT_ALIGNMENT_SHIFT 2
736 * Return hashcode based on object address. This function will need to be
737 * smarter in the presence of a moving garbage collector, which will cache
738 * the address hash before relocating the object.
740 * Wang's address-based hash function:
741 * http://www.concentric.net/~Ttwang/tech/addrhash.htm
744 ves_icall_System_Object_GetHashCode (MonoObject *this)
746 register guint32 key;
750 key = (GPOINTER_TO_UINT (this) >> MONO_OBJECT_ALIGNMENT_SHIFT) * 2654435761u;
752 return key & 0x7fffffff;
756 ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fields)
760 MonoObject **values = NULL;
767 klass = this->vtable->klass;
769 if (klass->field.count == 0)
770 return ves_icall_System_Object_GetHashCode (this);
773 * Compute the starting value of the hashcode for fields of primitive
774 * types, and return the remaining fields in an array to the managed side.
775 * This way, we can avoid costly reflection operations in managed code.
777 for (i = 0; i < klass->field.count; ++i) {
778 MonoClassField *field = &klass->fields [i];
779 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
781 if (mono_field_is_deleted (field))
783 /* FIXME: Add more types */
784 switch (field->type->type) {
786 result ^= *(gint32*)((guint8*)this + field->offset);
788 case MONO_TYPE_STRING: {
790 s = *(MonoString**)((guint8*)this + field->offset);
792 result ^= ves_icall_System_String_GetHashCode (s);
797 values = alloca (klass->field.count * sizeof (MonoObject*));
798 o = mono_field_get_value_object (mono_object_domain (this), field, this);
799 values [count++] = o;
804 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
805 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
813 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that, MonoArray **fields)
817 MonoObject **values = NULL;
823 MONO_CHECK_ARG_NULL (that);
825 if (this->vtable != that->vtable)
828 klass = this->vtable->klass;
831 * Do the comparison for fields of primitive type and return a result if
832 * possible. Otherwise, return the remaining fields in an array to the
833 * managed side. This way, we can avoid costly reflection operations in
837 for (i = 0; i < klass->field.count; ++i) {
838 MonoClassField *field = &klass->fields [i];
839 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
841 if (mono_field_is_deleted (field))
843 /* FIXME: Add more types */
844 switch (field->type->type) {
846 if (*(gint32*)((guint8*)this + field->offset) != *(gint32*)((guint8*)that + field->offset))
849 case MONO_TYPE_STRING: {
851 guint32 s1len, s2len;
852 s1 = *(MonoString**)((guint8*)this + field->offset);
853 s2 = *(MonoString**)((guint8*)that + field->offset);
856 if ((s1 == NULL) || (s2 == NULL))
858 s1len = mono_string_length (s1);
859 s2len = mono_string_length (s2);
863 if (memcmp (mono_string_chars (s1), mono_string_chars (s2), s1len * sizeof (gunichar2)) != 0)
869 values = alloca (klass->field.count * 2 * sizeof (MonoObject*));
870 o = mono_field_get_value_object (mono_object_domain (this), field, this);
871 values [count++] = o;
872 o = mono_field_get_value_object (mono_object_domain (this), field, that);
873 values [count++] = o;
878 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
879 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
887 static MonoReflectionType *
888 ves_icall_System_Object_GetType (MonoObject *obj)
892 if (obj->vtable->klass != mono_defaults.transparent_proxy_class)
893 return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
895 return mono_type_get_object (mono_object_domain (obj), &((MonoTransparentProxy*)obj)->remote_class->proxy_class->byval_arg);
899 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
903 mtype->type = &obj->vtable->klass->byval_arg;
904 g_assert (mtype->type->type);
908 ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj)
912 return mono_image_create_token (mb->dynamic_image, obj, TRUE);
916 ves_icall_ModuleBuilder_getMethodToken (MonoReflectionModuleBuilder *mb,
917 MonoReflectionMethod *method,
918 MonoArray *opt_param_types)
922 return mono_image_create_method_token (
923 mb->dynamic_image, (MonoObject *) method, opt_param_types);
927 ves_icall_ModuleBuilder_getDataChunk (MonoReflectionModuleBuilder *mb, MonoArray *buf, gint32 offset)
930 MonoDynamicImage *image = mb->dynamic_image;
931 char *p = mono_array_addr (buf, char, 0);
935 mono_image_create_pefile (mb);
937 if (offset >= image->pefile.index)
939 count = mono_array_length (buf);
940 count = MIN (count, image->pefile.index - offset);
942 memcpy (p, image->pefile.data + offset, count);
948 ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
952 mono_image_build_metadata (mb);
955 static MonoReflectionType *
956 type_from_name (const char *str, MonoBoolean ignoreCase)
958 MonoType *type = NULL;
959 MonoAssembly *assembly;
960 MonoTypeNameParse info;
961 char *temp_str = g_strdup (str);
962 gboolean type_resolve = FALSE;
966 /* mono_reflection_parse_type() mangles the string */
967 if (!mono_reflection_parse_type (temp_str, &info)) {
968 g_list_free (info.modifiers);
969 g_list_free (info.nested);
974 if (info.assembly.name) {
975 assembly = mono_assembly_load (&info.assembly, NULL, NULL);
977 MonoReflectionAssembly *refass;
979 refass = ves_icall_System_Reflection_Assembly_GetCallingAssembly ();
980 assembly = refass->assembly;
984 type = mono_reflection_get_type (assembly->image, &info, ignoreCase, &type_resolve);
986 if (!info.assembly.name && !type) /* try mscorlib */
987 type = mono_reflection_get_type (NULL, &info, ignoreCase, &type_resolve);
989 g_list_free (info.modifiers);
990 g_list_free (info.nested);
996 return mono_type_get_object (mono_domain_get (), type);
1000 MonoReflectionType *
1001 mono_type_get (const char *str)
1003 char *copy = g_strdup (str);
1004 MonoReflectionType *type = type_from_name (copy, FALSE);
1011 static MonoReflectionType*
1012 ves_icall_type_from_name (MonoString *name,
1013 MonoBoolean throwOnError,
1014 MonoBoolean ignoreCase)
1016 char *str = mono_string_to_utf8 (name);
1017 MonoReflectionType *type;
1019 type = type_from_name (str, ignoreCase);
1023 mono_raise_exception (mono_get_exception_type_load (name));
1030 static MonoReflectionType*
1031 ves_icall_type_from_handle (MonoType *handle)
1033 MonoDomain *domain = mono_domain_get ();
1034 MonoClass *klass = mono_class_from_mono_type (handle);
1036 MONO_ARCH_SAVE_REGS;
1038 mono_class_init (klass);
1039 return mono_type_get_object (domain, handle);
1043 ves_icall_type_Equals (MonoReflectionType *type, MonoReflectionType *c)
1045 MONO_ARCH_SAVE_REGS;
1047 if (type->type && c->type)
1048 return mono_metadata_type_equal (type->type, c->type);
1049 g_print ("type equals\n");
1053 /* System.TypeCode */
1072 TYPECODE_STRING = 18
1076 ves_icall_type_GetTypeCode (MonoReflectionType *type)
1078 int t = type->type->type;
1080 MONO_ARCH_SAVE_REGS;
1084 case MONO_TYPE_VOID:
1085 return TYPECODE_OBJECT;
1086 case MONO_TYPE_BOOLEAN:
1087 return TYPECODE_BOOLEAN;
1089 return TYPECODE_BYTE;
1091 return TYPECODE_SBYTE;
1093 return TYPECODE_UINT16;
1095 return TYPECODE_INT16;
1096 case MONO_TYPE_CHAR:
1097 return TYPECODE_CHAR;
1101 return TYPECODE_OBJECT;
1103 return TYPECODE_UINT32;
1105 return TYPECODE_INT32;
1107 return TYPECODE_UINT64;
1109 return TYPECODE_INT64;
1111 return TYPECODE_SINGLE;
1113 return TYPECODE_DOUBLE;
1114 case MONO_TYPE_VALUETYPE:
1115 if (type->type->data.klass->enumtype) {
1116 t = type->type->data.klass->enum_basetype->type;
1119 MonoClass *k = type->type->data.klass;
1120 if (strcmp (k->name_space, "System") == 0) {
1121 if (strcmp (k->name, "Decimal") == 0)
1122 return TYPECODE_DECIMAL;
1123 else if (strcmp (k->name, "DateTime") == 0)
1124 return TYPECODE_DATETIME;
1127 return TYPECODE_OBJECT;
1128 case MONO_TYPE_STRING:
1129 return TYPECODE_STRING;
1130 case MONO_TYPE_SZARRAY:
1131 case MONO_TYPE_ARRAY:
1132 case MONO_TYPE_OBJECT:
1134 case MONO_TYPE_MVAR:
1135 return TYPECODE_OBJECT;
1136 case MONO_TYPE_CLASS:
1138 MonoClass *k = type->type->data.klass;
1139 if (strcmp (k->name_space, "System") == 0) {
1140 if (strcmp (k->name, "DBNull") == 0)
1141 return TYPECODE_DBNULL;
1144 return TYPECODE_OBJECT;
1145 case MONO_TYPE_GENERICINST:
1146 return TYPECODE_OBJECT;
1148 g_error ("type 0x%02x not handled in GetTypeCode()", t);
1154 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
1160 MONO_ARCH_SAVE_REGS;
1162 g_assert (type != NULL);
1164 domain = ((MonoObject *)type)->vtable->domain;
1166 if (!c) /* FIXME: dont know what do do here */
1169 klass = mono_class_from_mono_type (type->type);
1170 klassc = mono_class_from_mono_type (c->type);
1172 return mono_class_is_subclass_of (klass, klassc, check_interfaces);
1176 ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
1182 MONO_ARCH_SAVE_REGS;
1184 g_assert (type != NULL);
1186 domain = ((MonoObject *)type)->vtable->domain;
1188 klass = mono_class_from_mono_type (type->type);
1189 klassc = mono_class_from_mono_type (c->type);
1191 return mono_class_is_assignable_from (klass, klassc);
1195 ves_icall_type_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
1197 MonoClass *klass = mono_class_from_mono_type (type->type);
1198 return mono_object_isinst (obj, klass) != NULL;
1202 ves_icall_get_attributes (MonoReflectionType *type)
1204 MonoClass *klass = mono_class_from_mono_type (type->type);
1206 MONO_ARCH_SAVE_REGS;
1208 return klass->flags;
1211 static MonoReflectionField*
1212 ves_icall_System_Reflection_FieldInfo_internal_from_handle (MonoClassField *handle)
1214 MONO_ARCH_SAVE_REGS;
1218 return mono_field_get_object (mono_domain_get (), handle->parent, handle);
1222 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
1224 MonoDomain *domain = mono_domain_get ();
1226 MONO_ARCH_SAVE_REGS;
1228 info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
1229 info->ret = mono_type_get_object (domain, method->signature->ret);
1230 info->attrs = method->flags;
1231 info->implattrs = method->iflags;
1232 if (method->signature->call_convention == MONO_CALL_DEFAULT)
1235 if (method->signature->call_convention == MONO_CALL_VARARG)
1240 info->callconv |= (method->signature->hasthis << 5) | (method->signature->explicit_this << 6);
1244 ves_icall_get_parameter_info (MonoMethod *method)
1246 MonoDomain *domain = mono_domain_get ();
1248 MONO_ARCH_SAVE_REGS;
1250 return mono_param_get_objects (domain, method);
1253 static MonoReflectionType*
1254 ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean declaring)
1257 MONO_ARCH_SAVE_REGS;
1259 parent = declaring? field->field->parent: field->klass;
1261 return mono_type_get_object (mono_object_domain (field), &parent->byval_arg);
1265 ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *obj)
1268 MonoClassField *cf = field->field;
1271 MonoDomain *domain = mono_object_domain (field);
1273 gboolean is_static = FALSE;
1274 gboolean is_ref = FALSE;
1276 MONO_ARCH_SAVE_REGS;
1278 mono_class_init (field->klass);
1280 switch (cf->type->type) {
1281 case MONO_TYPE_STRING:
1282 case MONO_TYPE_OBJECT:
1283 case MONO_TYPE_CLASS:
1284 case MONO_TYPE_ARRAY:
1285 case MONO_TYPE_SZARRAY:
1290 case MONO_TYPE_BOOLEAN:
1293 case MONO_TYPE_CHAR:
1302 case MONO_TYPE_VALUETYPE:
1303 is_ref = cf->type->byref;
1306 g_error ("type 0x%x not handled in "
1307 "ves_icall_Monofield_GetValue", cf->type->type);
1312 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1314 vtable = mono_class_vtable (domain, field->klass);
1315 if (!vtable->initialized && !(cf->type->attrs & FIELD_ATTRIBUTE_LITERAL))
1316 mono_runtime_class_init (vtable);
1321 mono_field_static_get_value (vtable, cf, &o);
1323 mono_field_get_value (obj, cf, &o);
1328 /* boxed value type */
1329 klass = mono_class_from_mono_type (cf->type);
1330 o = mono_object_new (domain, klass);
1331 v = ((gchar *) o) + sizeof (MonoObject);
1333 mono_field_static_get_value (vtable, cf, v);
1335 mono_field_get_value (obj, cf, v);
1342 ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
1344 MonoClassField *cf = field->field;
1347 MONO_ARCH_SAVE_REGS;
1349 v = (gchar *) value;
1350 if (!cf->type->byref) {
1351 switch (cf->type->type) {
1354 case MONO_TYPE_BOOLEAN:
1357 case MONO_TYPE_CHAR:
1366 case MONO_TYPE_VALUETYPE:
1367 v += sizeof (MonoObject);
1369 case MONO_TYPE_STRING:
1370 case MONO_TYPE_OBJECT:
1371 case MONO_TYPE_CLASS:
1372 case MONO_TYPE_ARRAY:
1373 case MONO_TYPE_SZARRAY:
1377 g_error ("type 0x%x not handled in "
1378 "ves_icall_FieldInfo_SetValueInternal", cf->type->type);
1383 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1384 MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), field->klass);
1385 if (!vtable->initialized)
1386 mono_runtime_class_init (vtable);
1387 mono_field_static_set_value (vtable, cf, v);
1389 mono_field_set_value (obj, cf, v);
1393 static MonoReflectionField*
1394 ves_icall_MonoField_Mono_GetGenericFieldDefinition (MonoReflectionField *field)
1396 MONO_ARCH_SAVE_REGS;
1398 if (field->field->generic_info && field->field->generic_info->reflection_info)
1399 return field->field->generic_info->reflection_info;
1404 /* From MonoProperty.cs */
1406 PInfo_Attributes = 1,
1407 PInfo_GetMethod = 1 << 1,
1408 PInfo_SetMethod = 1 << 2,
1409 PInfo_ReflectedType = 1 << 3,
1410 PInfo_DeclaringType = 1 << 4,
1415 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info)
1417 MonoDomain *domain = mono_object_domain (property);
1419 MONO_ARCH_SAVE_REGS;
1421 if ((req_info & PInfo_ReflectedType) != 0)
1422 info->parent = mono_type_get_object (domain, &property->klass->byval_arg);
1423 else if ((req_info & PInfo_DeclaringType) != 0)
1424 info->parent = mono_type_get_object (domain, &property->property->parent->byval_arg);
1426 if ((req_info & PInfo_Name) != 0)
1427 info->name = mono_string_new (domain, property->property->name);
1429 if ((req_info & PInfo_Attributes) != 0)
1430 info->attrs = property->property->attrs;
1432 if ((req_info & PInfo_GetMethod) != 0)
1433 info->get = property->property->get ?
1434 mono_method_get_object (domain, property->property->get, NULL): NULL;
1436 if ((req_info & PInfo_SetMethod) != 0)
1437 info->set = property->property->set ?
1438 mono_method_get_object (domain, property->property->set, NULL): NULL;
1440 * There may be other methods defined for properties, though, it seems they are not exposed
1441 * in the reflection API
1446 ves_icall_get_event_info (MonoReflectionEvent *event, MonoEventInfo *info)
1448 MonoDomain *domain = mono_object_domain (event);
1450 MONO_ARCH_SAVE_REGS;
1452 info->declaring_type = mono_type_get_object (domain, &event->klass->byval_arg);
1453 info->reflected_type = mono_type_get_object (domain, &event->event->parent->byval_arg);
1455 info->name = mono_string_new (domain, event->event->name);
1456 info->attrs = event->event->attrs;
1457 info->add_method = event->event->add ? mono_method_get_object (domain, event->event->add, NULL): NULL;
1458 info->remove_method = event->event->remove ? mono_method_get_object (domain, event->event->remove, NULL): NULL;
1459 info->raise_method = event->event->raise ? mono_method_get_object (domain, event->event->raise, NULL): NULL;
1463 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
1465 MonoDomain *domain = mono_object_domain (type);
1468 MonoClass *class = mono_class_from_mono_type (type->type);
1470 MonoBitSet *slots = mono_bitset_new (class->max_interface_id + 1, 0);
1472 MONO_ARCH_SAVE_REGS;
1475 /* GetInterfaces() returns an empty array in MS.NET (this may be a bug) */
1476 mono_bitset_free (slots);
1477 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1481 for (parent = class; parent; parent = parent->parent) {
1482 for (i = 0; i < parent->interface_count; ++i) {
1483 if (mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1486 mono_bitset_set (slots, parent->interfaces [i]->interface_id);
1491 intf = mono_array_new (domain, mono_defaults.monotype_class, ninterf);
1493 for (parent = class; parent; parent = parent->parent) {
1494 for (i = 0; i < parent->interface_count; ++i) {
1495 if (!mono_bitset_test (slots, parent->interfaces [i]->interface_id))
1498 mono_bitset_clear (slots, parent->interfaces [i]->interface_id);
1499 mono_array_set (intf, gpointer, ninterf,
1500 mono_type_get_object (domain, &parent->interfaces [i]->byval_arg));
1505 mono_bitset_free (slots);
1510 ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
1512 MonoClass *class = mono_class_from_mono_type (type->type);
1513 MonoClass *iclass = mono_class_from_mono_type (iface->type);
1514 MonoReflectionMethod *member;
1515 int i, len, ioffset;
1518 MONO_ARCH_SAVE_REGS;
1520 /* type doesn't implement iface: the exception is thrown in managed code */
1521 if ((iclass->interface_id > class->max_interface_id) || !class->interface_offsets [iclass->interface_id])
1524 len = iclass->method.count;
1525 ioffset = class->interface_offsets [iclass->interface_id];
1526 domain = mono_object_domain (type);
1527 *targets = mono_array_new (domain, mono_defaults.method_info_class, len);
1528 *methods = mono_array_new (domain, mono_defaults.method_info_class, len);
1529 for (i = 0; i < len; ++i) {
1530 member = mono_method_get_object (domain, iclass->methods [i], iclass);
1531 mono_array_set (*methods, gpointer, i, member);
1532 member = mono_method_get_object (domain, class->vtable [i + ioffset], class);
1533 mono_array_set (*targets, gpointer, i, member);
1537 static MonoReflectionType*
1538 ves_icall_MonoType_GetElementType (MonoReflectionType *type)
1540 MonoClass *class = mono_class_from_mono_type (type->type);
1542 MONO_ARCH_SAVE_REGS;
1544 // GelElementType should only return a type for:
1545 // Array Pointer PassedByRef
1546 if (type->type->byref)
1547 return mono_type_get_object (mono_object_domain (type), &class->byval_arg);
1548 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1549 return mono_type_get_object (mono_object_domain (type), class->enum_basetype);
1550 else if (class->element_class && MONO_CLASS_IS_ARRAY (class))
1551 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1552 else if (class->element_class && type->type->type == MONO_TYPE_PTR)
1553 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1558 static MonoReflectionType*
1559 ves_icall_get_type_parent (MonoReflectionType *type)
1561 MonoClass *class = mono_class_from_mono_type (type->type);
1563 MONO_ARCH_SAVE_REGS;
1565 return class->parent ? mono_type_get_object (mono_object_domain (type), &class->parent->byval_arg): NULL;
1569 ves_icall_type_ispointer (MonoReflectionType *type)
1571 MONO_ARCH_SAVE_REGS;
1573 return type->type->type == MONO_TYPE_PTR;
1577 ves_icall_type_isprimitive (MonoReflectionType *type)
1579 MONO_ARCH_SAVE_REGS;
1581 return (!type->type->byref && (type->type->type >= MONO_TYPE_BOOLEAN) && (type->type->type <= MONO_TYPE_R8));
1585 ves_icall_type_isbyref (MonoReflectionType *type)
1587 MONO_ARCH_SAVE_REGS;
1589 return type->type->byref;
1592 static MonoReflectionModule*
1593 ves_icall_MonoType_get_Module (MonoReflectionType *type)
1595 MonoClass *class = mono_class_from_mono_type (type->type);
1597 MONO_ARCH_SAVE_REGS;
1599 return mono_module_get_object (mono_object_domain (type), class->image);
1602 static MonoReflectionAssembly*
1603 ves_icall_MonoType_get_Assembly (MonoReflectionType *type)
1605 MonoDomain *domain = mono_domain_get ();
1606 MonoClass *class = mono_class_from_mono_type (type->type);
1608 MONO_ARCH_SAVE_REGS;
1610 return mono_assembly_get_object (domain, class->image->assembly);
1613 static MonoReflectionType*
1614 ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
1616 MonoDomain *domain = mono_domain_get ();
1617 MonoClass *class = mono_class_from_mono_type (type->type);
1619 MONO_ARCH_SAVE_REGS;
1621 return class->nested_in ? mono_type_get_object (domain, &class->nested_in->byval_arg) : NULL;
1624 static MonoReflectionType*
1625 ves_icall_MonoType_get_UnderlyingSystemType (MonoReflectionType *type)
1627 MonoDomain *domain = mono_domain_get ();
1628 MonoClass *class = mono_class_from_mono_type (type->type);
1630 MONO_ARCH_SAVE_REGS;
1632 if (class->enumtype && class->enum_basetype) /* types that are modified typebuilders may not have enum_basetype set */
1633 return mono_type_get_object (domain, class->enum_basetype);
1634 else if (class->element_class)
1635 return mono_type_get_object (domain, &class->element_class->byval_arg);
1641 ves_icall_MonoType_get_Name (MonoReflectionType *type)
1643 MonoDomain *domain = mono_domain_get ();
1644 MonoClass *class = mono_class_from_mono_type (type->type);
1646 MONO_ARCH_SAVE_REGS;
1648 return mono_string_new (domain, class->name);
1652 ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
1654 MonoDomain *domain = mono_domain_get ();
1655 MonoClass *class = mono_class_from_mono_type (type->type);
1657 MONO_ARCH_SAVE_REGS;
1659 while (class->nested_in)
1660 class = class->nested_in;
1662 return mono_string_new (domain, class->name_space);
1666 ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
1668 MonoClass *class = mono_class_from_mono_type (type->type);
1670 MONO_ARCH_SAVE_REGS;
1676 ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type)
1679 MonoClass *klass, *pklass;
1681 MONO_ARCH_SAVE_REGS;
1683 klass = mono_class_from_mono_type (type->type);
1685 if (type->type->byref) {
1686 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1687 } else if (klass->gen_params) {
1688 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, klass->num_gen_params);
1689 for (i = 0; i < klass->num_gen_params; ++i) {
1690 pklass = mono_class_from_generic_parameter (&klass->gen_params [i], klass->image, FALSE);
1691 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), &pklass->byval_arg));
1693 } else if (klass->generic_inst) {
1694 MonoGenericInst *inst = klass->generic_inst;
1695 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, inst->type_argc);
1696 for (i = 0; i < inst->type_argc; ++i) {
1697 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), inst->type_argv [i]));
1700 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1706 ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
1709 MONO_ARCH_SAVE_REGS;
1711 if (type->type->byref)
1713 klass = mono_class_from_mono_type (type->type);
1715 return klass->gen_params != NULL;
1718 static MonoReflectionType*
1719 ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
1722 MONO_ARCH_SAVE_REGS;
1724 if (type->type->byref)
1726 klass = mono_class_from_mono_type (type->type);
1727 if (klass->gen_params) {
1728 return type; /* check this one */
1730 if (klass->generic_inst) {
1731 MonoType *generic_type = klass->generic_inst->generic_type;
1732 MonoClass *generic_class = mono_class_from_mono_type (generic_type);
1734 if (generic_class->wastypebuilder && generic_class->reflection_info)
1735 return generic_class->reflection_info;
1737 return mono_type_get_object (mono_object_domain (type), generic_type);
1742 static MonoReflectionType*
1743 ves_icall_Type_BindGenericParameters (MonoReflectionType *type, MonoArray *type_array)
1745 MonoType *geninst, **types;
1748 MONO_ARCH_SAVE_REGS;
1750 if (type->type->byref)
1753 count = mono_array_length (type_array);
1754 types = g_new0 (MonoType *, count);
1756 for (i = 0; i < count; i++) {
1757 MonoReflectionType *t = mono_array_get (type_array, gpointer, i);
1758 types [i] = t->type;
1761 geninst = mono_reflection_bind_generic_parameters (type, count, types);
1763 return mono_type_get_object (mono_object_domain (type), geninst);
1767 ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
1770 MONO_ARCH_SAVE_REGS;
1772 if (type->type->byref)
1774 klass = mono_class_from_mono_type (type->type);
1775 return klass->generic_inst != NULL;
1779 ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
1781 MONO_ARCH_SAVE_REGS;
1783 if (type->type->byref)
1785 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1786 return type->type->data.generic_param->num;
1791 ves_icall_MonoType_get_HasGenericArguments (MonoReflectionType *type)
1794 MONO_ARCH_SAVE_REGS;
1796 if (type->type->byref)
1798 klass = mono_class_from_mono_type (type->type);
1799 if (klass->gen_params || klass->generic_inst)
1805 ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
1807 MONO_ARCH_SAVE_REGS;
1809 if (type->type->byref)
1811 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1817 ves_icall_TypeBuilder_get_IsGenericParameter (MonoReflectionTypeBuilder *tb)
1819 MONO_ARCH_SAVE_REGS;
1821 if (tb->type.type->byref)
1823 if (tb->type.type->type == MONO_TYPE_VAR || tb->type.type->type == MONO_TYPE_MVAR)
1829 ves_icall_EnumBuilder_setup_enum_type (MonoReflectionType *enumtype,
1830 MonoReflectionType *t)
1832 enumtype->type = t->type;
1835 static MonoReflectionType*
1836 ves_icall_MonoGenericInst_GetParentType (MonoReflectionGenericInst *type)
1838 MonoGenericInst *ginst;
1841 MONO_ARCH_SAVE_REGS;
1843 ginst = type->type.type->data.generic_inst;
1844 if (!ginst || !ginst->parent || (ginst->parent->type != MONO_TYPE_GENERICINST))
1847 klass = mono_class_from_mono_type (ginst->parent);
1848 if (!klass->generic_inst && !klass->gen_params)
1851 return mono_type_get_object (mono_object_domain (type), ginst->parent);
1855 ves_icall_MonoGenericInst_GetInterfaces (MonoReflectionGenericInst *type)
1857 static MonoClass *System_Reflection_MonoGenericInst;
1858 MonoGenericInst *ginst;
1864 MONO_ARCH_SAVE_REGS;
1866 if (!System_Reflection_MonoGenericInst) {
1867 System_Reflection_MonoGenericInst = mono_class_from_name (
1868 mono_defaults.corlib, "System.Reflection", "MonoGenericInst");
1869 g_assert (System_Reflection_MonoGenericInst);
1872 domain = mono_object_domain (type);
1874 ginst = type->type.type->data.generic_inst;
1875 if (!ginst || !ginst->ifaces)
1876 return mono_array_new (domain, System_Reflection_MonoGenericInst, 0);
1878 klass = mono_class_from_mono_type (ginst->generic_type);
1880 res = mono_array_new (domain, System_Reflection_MonoGenericInst, ginst->count_ifaces);
1882 for (i = 0; i < ginst->count_ifaces; i++) {
1883 MonoReflectionType *iface = mono_type_get_object (domain, ginst->ifaces [i]);
1885 mono_array_set (res, gpointer, i, iface);
1892 ves_icall_MonoGenericInst_GetMethods (MonoReflectionGenericInst *type,
1893 MonoReflectionType *reflected_type)
1895 MonoGenericInst *ginst;
1896 MonoDynamicGenericInst *dginst;
1898 MonoClass *refclass;
1902 MONO_ARCH_SAVE_REGS;
1904 ginst = type->type.type->data.generic_inst;
1905 g_assert ((dginst = ginst->dynamic_info) != NULL);
1907 refclass = mono_class_from_mono_type (reflected_type->type);
1909 domain = mono_object_domain (type);
1910 res = mono_array_new (domain, mono_defaults.method_info_class, dginst->count_methods);
1912 for (i = 0; i < dginst->count_methods; i++)
1913 mono_array_set (res, gpointer, i,
1914 mono_method_get_object (domain, dginst->methods [i], refclass));
1920 ves_icall_MonoGenericInst_GetConstructors (MonoReflectionGenericInst *type,
1921 MonoReflectionType *reflected_type)
1923 static MonoClass *System_Reflection_ConstructorInfo;
1924 MonoGenericInst *ginst;
1925 MonoDynamicGenericInst *dginst;
1927 MonoClass *refclass;
1931 MONO_ARCH_SAVE_REGS;
1933 if (!System_Reflection_ConstructorInfo)
1934 System_Reflection_ConstructorInfo = mono_class_from_name (
1935 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
1937 ginst = type->type.type->data.generic_inst;
1938 g_assert ((dginst = ginst->dynamic_info) != NULL);
1940 refclass = mono_class_from_mono_type (reflected_type->type);
1942 domain = mono_object_domain (type);
1943 res = mono_array_new (domain, System_Reflection_ConstructorInfo, dginst->count_ctors);
1945 for (i = 0; i < dginst->count_ctors; i++)
1946 mono_array_set (res, gpointer, i,
1947 mono_method_get_object (domain, dginst->ctors [i], refclass));
1953 ves_icall_MonoGenericInst_GetFields (MonoReflectionGenericInst *type,
1954 MonoReflectionType *reflected_type)
1956 MonoGenericInst *ginst;
1957 MonoDynamicGenericInst *dginst;
1959 MonoClass *refclass;
1963 MONO_ARCH_SAVE_REGS;
1965 ginst = type->type.type->data.generic_inst;
1966 g_assert ((dginst = ginst->dynamic_info) != NULL);
1968 refclass = mono_class_from_mono_type (reflected_type->type);
1970 domain = mono_object_domain (type);
1971 res = mono_array_new (domain, mono_defaults.field_info_class, dginst->count_fields);
1973 for (i = 0; i < dginst->count_fields; i++)
1974 mono_array_set (res, gpointer, i,
1975 mono_field_get_object (domain, refclass, &dginst->fields [i]));
1981 ves_icall_MonoGenericInst_GetProperties (MonoReflectionGenericInst *type,
1982 MonoReflectionType *reflected_type)
1984 static MonoClass *System_Reflection_PropertyInfo;
1985 MonoGenericInst *ginst;
1986 MonoDynamicGenericInst *dginst;
1988 MonoClass *refclass;
1992 MONO_ARCH_SAVE_REGS;
1994 if (!System_Reflection_PropertyInfo)
1995 System_Reflection_PropertyInfo = mono_class_from_name (
1996 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
1998 ginst = type->type.type->data.generic_inst;
1999 g_assert ((dginst = ginst->dynamic_info) != NULL);
2001 refclass = mono_class_from_mono_type (reflected_type->type);
2003 domain = mono_object_domain (type);
2004 res = mono_array_new (domain, System_Reflection_PropertyInfo, dginst->count_properties);
2006 for (i = 0; i < dginst->count_properties; i++)
2007 mono_array_set (res, gpointer, i,
2008 mono_property_get_object (domain, refclass, &dginst->properties [i]));
2014 ves_icall_MonoGenericInst_GetEvents (MonoReflectionGenericInst *type,
2015 MonoReflectionType *reflected_type)
2017 static MonoClass *System_Reflection_EventInfo;
2018 MonoGenericInst *ginst;
2019 MonoDynamicGenericInst *dginst;
2021 MonoClass *refclass;
2025 MONO_ARCH_SAVE_REGS;
2027 if (!System_Reflection_EventInfo)
2028 System_Reflection_EventInfo = mono_class_from_name (
2029 mono_defaults.corlib, "System.Reflection", "EventInfo");
2031 ginst = type->type.type->data.generic_inst;
2032 g_assert ((dginst = ginst->dynamic_info) != NULL);
2034 refclass = mono_class_from_mono_type (reflected_type->type);
2036 domain = mono_object_domain (type);
2037 res = mono_array_new (domain, System_Reflection_EventInfo, dginst->count_events);
2039 for (i = 0; i < dginst->count_events; i++)
2040 mono_array_set (res, gpointer, i,
2041 mono_event_get_object (domain, refclass, &dginst->events [i]));
2046 static MonoReflectionMethod *
2047 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *type)
2052 MONO_ARCH_SAVE_REGS;
2054 if (type->type->byref)
2057 method = type->type->data.generic_param->method;
2061 klass = mono_class_from_mono_type (type->type);
2062 return mono_method_get_object (mono_object_domain (type), method, klass);
2065 static MonoReflectionMethod *
2066 ves_icall_MonoMethod_GetGenericMethodDefinition (MonoReflectionMethod *method)
2068 MonoMethodInflated *imethod;
2070 MONO_ARCH_SAVE_REGS;
2072 if (!method->method->signature->is_inflated) {
2073 if (method->method->signature->generic_param_count)
2079 imethod = (MonoMethodInflated *) method->method;
2080 if (imethod->context->gmethod && imethod->context->gmethod->reflection_info)
2081 return imethod->context->gmethod->reflection_info;
2083 return mono_method_get_object (
2084 mono_object_domain (method), imethod->declaring, NULL);
2088 ves_icall_MonoMethod_get_HasGenericParameters (MonoReflectionMethod *method)
2090 MONO_ARCH_SAVE_REGS;
2092 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2093 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2096 return method->method->signature->generic_param_count != 0;
2100 ves_icall_MonoMethod_get_Mono_IsInflatedMethod (MonoReflectionMethod *method)
2102 MONO_ARCH_SAVE_REGS;
2104 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2105 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2108 return method->method->signature->is_inflated;
2112 ves_icall_MonoMethod_get_IsGenericMethodDefinition (MonoReflectionMethod *method)
2114 MONO_ARCH_SAVE_REGS;
2116 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2117 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2120 return method->method->signature->generic_param_count != 0;
2124 ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method)
2128 MonoMethodNormal *mn;
2130 MONO_ARCH_SAVE_REGS;
2132 domain = mono_object_domain (method);
2134 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2135 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2136 return mono_array_new (domain, mono_defaults.monotype_class, 0);
2138 if (method->method->signature->is_inflated) {
2139 MonoMethodInflated *imethod = (MonoMethodInflated *) method->method;
2140 MonoGenericMethod *gmethod = imethod->context->gmethod;
2143 count = gmethod->mtype_argc;
2144 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2146 for (i = 0; i < count; i++) {
2147 MonoType *t = gmethod->mtype_argv [i];
2149 res, gpointer, i, mono_type_get_object (domain, t));
2156 mn = (MonoMethodNormal *) method->method;
2157 count = method->method->signature->generic_param_count;
2158 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2160 for (i = 0; i < count; i++) {
2161 MonoGenericParam *param = &mn->gen_params [i];
2162 MonoClass *pklass = mono_class_from_generic_parameter (
2163 param, method->method->klass->image, TRUE);
2164 mono_array_set (res, gpointer, i,
2165 mono_type_get_object (domain, &pklass->byval_arg));
2172 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
2175 * Invoke from reflection is supposed to always be a virtual call (the API
2176 * is stupid), mono_runtime_invoke_*() calls the provided method, allowing
2177 * greater flexibility.
2179 MonoMethod *m = method->method;
2183 MONO_ARCH_SAVE_REGS;
2186 if (!mono_object_isinst (this, m->klass))
2187 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2188 m = mono_object_get_virtual_method (this, m);
2189 /* must pass the pointer to the value for valuetype methods */
2190 if (m->klass->valuetype)
2191 obj = mono_object_unbox (this);
2192 } else if (!(m->flags & METHOD_ATTRIBUTE_STATIC) && strcmp (m->name, ".ctor") && !m->wrapper_type)
2193 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2195 pcount = params? mono_array_length (params): 0;
2196 if (pcount != m->signature->param_count)
2197 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetParameterCountException"));
2199 if (m->klass->rank && !strcmp (m->name, ".ctor")) {
2202 guint32 *lower_bounds;
2203 pcount = mono_array_length (params);
2204 lengths = alloca (sizeof (guint32) * pcount);
2205 for (i = 0; i < pcount; ++i)
2206 lengths [i] = *(gint32*) ((char*)mono_array_get (params, gpointer, i) + sizeof (MonoObject));
2208 if (m->klass->rank == pcount) {
2209 /* Only lengths provided. */
2210 lower_bounds = NULL;
2212 g_assert (pcount == (m->klass->rank * 2));
2213 /* lower bounds are first. */
2214 lower_bounds = lengths;
2215 lengths += m->klass->rank;
2218 return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
2220 return mono_runtime_invoke_array (m, obj, params, NULL);
2224 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs)
2226 MonoDomain *domain = mono_object_domain (method);
2227 MonoMethod *m = method->method;
2228 MonoMethodSignature *sig = m->signature;
2229 MonoArray *out_args;
2231 int i, j, outarg_count = 0;
2233 MONO_ARCH_SAVE_REGS;
2235 if (m->klass == mono_defaults.object_class) {
2237 if (!strcmp (m->name, "FieldGetter")) {
2238 MonoClass *k = this->vtable->klass;
2240 /* If this is a proxy, then it must be a CBO */
2241 if (k == mono_defaults.transparent_proxy_class) {
2242 MonoTransparentProxy *tp = (MonoTransparentProxy*) this;
2243 this = tp->rp->unwrapped_server;
2245 k = this->vtable->klass;
2248 MonoString *name = mono_array_get (params, MonoString *, 1);
2251 str = mono_string_to_utf8 (name);
2254 for (i = 0; i < k->field.count; i++) {
2255 if (!strcmp (k->fields [i].name, str)) {
2256 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
2257 if (field_klass->valuetype)
2258 result = mono_value_box (domain, field_klass,
2259 (char *)this + k->fields [i].offset);
2261 result = *((gpointer *)((char *)this + k->fields [i].offset));
2264 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
2265 *outArgs = out_args;
2266 mono_array_set (out_args, gpointer, 0, result);
2276 g_assert_not_reached ();
2278 } else if (!strcmp (m->name, "FieldSetter")) {
2279 MonoClass *k = this->vtable->klass;
2281 /* If this is a proxy, then it must be a CBO */
2282 if (k == mono_defaults.transparent_proxy_class) {
2283 MonoTransparentProxy *tp = (MonoTransparentProxy*) this;
2284 this = tp->rp->unwrapped_server;
2286 k = this->vtable->klass;
2289 MonoString *name = mono_array_get (params, MonoString *, 1);
2293 str = mono_string_to_utf8 (name);
2296 for (i = 0; i < k->field.count; i++) {
2297 if (!strcmp (k->fields [i].name, str)) {
2298 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
2299 MonoObject *val = mono_array_get (params, gpointer, 2);
2301 if (field_klass->valuetype) {
2302 size = mono_type_size (k->fields [i].type, &align);
2303 memcpy ((char *)this + k->fields [i].offset,
2304 ((char *)val) + sizeof (MonoObject), size);
2306 *(MonoObject**)((char *)this + k->fields [i].offset) = val;
2308 out_args = mono_array_new (domain, mono_defaults.object_class, 0);
2309 *outArgs = out_args;
2320 g_assert_not_reached ();
2325 for (i = 0; i < mono_array_length (params); i++) {
2326 if (sig->params [i]->byref)
2330 out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
2332 /* handle constructors only for objects already allocated */
2333 if (!strcmp (method->method->name, ".ctor"))
2336 /* This can be called only on MBR objects, so no need to unbox for valuetypes. */
2337 g_assert (!method->method->klass->valuetype);
2338 result = mono_runtime_invoke_array (method->method, this, params, NULL);
2340 for (i = 0, j = 0; i < mono_array_length (params); i++) {
2341 if (sig->params [i]->byref) {
2343 arg = mono_array_get (params, gpointer, i);
2344 mono_array_set (out_args, gpointer, j, arg);
2349 *outArgs = out_args;
2355 ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
2358 MonoClass *enumc, *objc;
2362 MONO_ARCH_SAVE_REGS;
2364 MONO_CHECK_ARG_NULL (type);
2365 MONO_CHECK_ARG_NULL (obj);
2367 domain = mono_object_domain (type);
2368 enumc = mono_class_from_mono_type (type->type);
2369 objc = obj->vtable->klass;
2371 MONO_CHECK_ARG (obj, enumc->enumtype == TRUE);
2372 MONO_CHECK_ARG (obj, (objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 &&
2373 objc->byval_arg.type <= MONO_TYPE_U8));
2375 s1 = mono_class_value_size (enumc, NULL);
2376 s2 = mono_class_value_size (objc, NULL);
2378 res = mono_object_new (domain, enumc);
2380 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2381 memcpy ((char *)res + sizeof (MonoObject), (char *)obj + sizeof (MonoObject), MIN (s1, s2));
2383 memcpy ((char *)res + sizeof (MonoObject) + (s1 > s2 ? s1 - s2 : 0),
2384 (char *)obj + sizeof (MonoObject) + (s2 > s1 ? s2 - s1 : 0),
2391 ves_icall_System_Enum_get_value (MonoObject *this)
2399 MONO_ARCH_SAVE_REGS;
2404 g_assert (this->vtable->klass->enumtype);
2406 enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
2407 res = mono_object_new (mono_object_domain (this), enumc);
2408 dst = (char *)res + sizeof (MonoObject);
2409 src = (char *)this + sizeof (MonoObject);
2410 size = mono_class_value_size (enumc, NULL);
2412 memcpy (dst, src, size);
2418 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
2420 MonoDomain *domain = mono_object_domain (type);
2421 MonoClass *enumc = mono_class_from_mono_type (type->type);
2422 guint i, j, nvalues, crow;
2423 MonoClassField *field;
2425 MONO_ARCH_SAVE_REGS;
2427 info->utype = mono_type_get_object (domain, enumc->enum_basetype);
2428 nvalues = enumc->field.count - 1;
2429 info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
2430 info->values = mono_array_new (domain, enumc, nvalues);
2433 for (i = 0, j = 0; i < enumc->field.count; ++i) {
2437 field = &enumc->fields [i];
2438 if (strcmp ("value__", field->name) == 0)
2440 if (mono_field_is_deleted (field))
2442 mono_array_set (info->names, gpointer, j, mono_string_new (domain, field->name));
2445 crow = mono_metadata_get_constant_index (enumc->image, MONO_TOKEN_FIELD_DEF | (i+enumc->field.first+1), crow + 1);
2446 field->def_type = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_TYPE);
2447 crow = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_VALUE);
2448 field->data = (gpointer)mono_metadata_blob_heap (enumc->image, crow);
2452 len = mono_metadata_decode_blob_size (p, &p);
2453 switch (enumc->enum_basetype->type) {
2456 mono_array_set (info->values, gchar, j, *p);
2458 case MONO_TYPE_CHAR:
2461 mono_array_set (info->values, gint16, j, read16 (p));
2465 mono_array_set (info->values, gint32, j, read32 (p));
2469 mono_array_set (info->values, gint64, j, read64 (p));
2472 g_error ("Implement type 0x%02x in get_enum_info", enumc->enum_basetype->type);
2479 BFLAGS_IgnoreCase = 1,
2480 BFLAGS_DeclaredOnly = 2,
2481 BFLAGS_Instance = 4,
2483 BFLAGS_Public = 0x10,
2484 BFLAGS_NonPublic = 0x20,
2485 BFLAGS_FlattenHierarchy = 0x40,
2486 BFLAGS_InvokeMethod = 0x100,
2487 BFLAGS_CreateInstance = 0x200,
2488 BFLAGS_GetField = 0x400,
2489 BFLAGS_SetField = 0x800,
2490 BFLAGS_GetProperty = 0x1000,
2491 BFLAGS_SetProperty = 0x2000,
2492 BFLAGS_ExactBinding = 0x10000,
2493 BFLAGS_SuppressChangeType = 0x20000,
2494 BFLAGS_OptionalParamBinding = 0x40000
2497 static MonoReflectionField *
2498 ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
2501 MonoClass *startklass, *klass;
2503 MonoClassField *field;
2505 domain = ((MonoObject *)type)->vtable->domain;
2506 klass = startklass = mono_class_from_mono_type (type->type);
2508 MONO_ARCH_SAVE_REGS;
2511 mono_raise_exception (mono_get_exception_argument_null ("name"));
2514 for (i = 0; i < klass->field.count; ++i) {
2516 field = &klass->fields [i];
2517 if (mono_field_is_deleted (field))
2519 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2520 if (bflags & BFLAGS_Public)
2523 if (bflags & BFLAGS_NonPublic)
2529 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2530 if (bflags & BFLAGS_Static)
2531 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2534 if (bflags & BFLAGS_Instance)
2541 utf8_name = mono_string_to_utf8 (name);
2543 if (strcmp (field->name, utf8_name)) {
2549 return mono_field_get_object (domain, startklass, field);
2551 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2558 ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2561 GSList *l = NULL, *tmp;
2562 MonoClass *startklass, *klass, *refklass;
2566 MonoClassField *field;
2568 MONO_ARCH_SAVE_REGS;
2570 domain = ((MonoObject *)type)->vtable->domain;
2571 klass = startklass = mono_class_from_mono_type (type->type);
2572 refklass = mono_class_from_mono_type (reftype->type);
2575 for (i = 0; i < klass->field.count; ++i) {
2577 field = &klass->fields [i];
2578 if (mono_field_is_deleted (field))
2580 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2581 if (bflags & BFLAGS_Public)
2584 if (bflags & BFLAGS_NonPublic)
2590 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2591 if (bflags & BFLAGS_Static)
2592 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2595 if (bflags & BFLAGS_Instance)
2601 member = (MonoObject*)mono_field_get_object (domain, refklass, field);
2602 l = g_slist_prepend (l, member);
2604 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2606 len = g_slist_length (l);
2607 res = mono_array_new (domain, mono_defaults.field_info_class, len);
2609 tmp = l = g_slist_reverse (l);
2610 for (; tmp; tmp = tmp->next, ++i)
2611 mono_array_set (res, gpointer, i, tmp->data);
2617 ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
2620 GSList *l = NULL, *tmp;
2621 MonoClass *startklass, *klass, *refklass;
2626 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2627 gchar *mname = NULL;
2628 int (*compare_func) (const char *s1, const char *s2) = NULL;
2630 MONO_ARCH_SAVE_REGS;
2632 domain = ((MonoObject *)type)->vtable->domain;
2633 klass = startklass = mono_class_from_mono_type (type->type);
2634 refklass = mono_class_from_mono_type (reftype->type);
2637 mname = mono_string_to_utf8 (name);
2638 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2642 for (i = 0; i < klass->method.count; ++i) {
2644 method = klass->methods [i];
2645 if (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0)
2647 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2648 if (bflags & BFLAGS_Public)
2651 if (bflags & BFLAGS_NonPublic)
2657 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2658 if (bflags & BFLAGS_Static)
2659 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2662 if (bflags & BFLAGS_Instance)
2670 if (compare_func (mname, method->name))
2675 if (method->slot != -1) {
2676 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
2678 g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), method);
2681 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
2683 l = g_slist_prepend (l, member);
2686 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2690 res = mono_array_new (domain, mono_defaults.method_info_class, len);
2693 tmp = l = g_slist_reverse (l);
2695 for (; tmp; tmp = tmp->next, ++i)
2696 mono_array_set (res, gpointer, i, tmp->data);
2698 g_hash_table_destroy (method_slots);
2703 ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2706 GSList *l = NULL, *tmp;
2707 static MonoClass *System_Reflection_ConstructorInfo;
2708 MonoClass *startklass, *klass, *refklass;
2714 MONO_ARCH_SAVE_REGS;
2716 domain = ((MonoObject *)type)->vtable->domain;
2717 klass = startklass = mono_class_from_mono_type (type->type);
2718 refklass = mono_class_from_mono_type (reftype->type);
2720 for (i = 0; i < klass->method.count; ++i) {
2722 method = klass->methods [i];
2723 if (strcmp (method->name, ".ctor") && strcmp (method->name, ".cctor"))
2725 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2726 if (bflags & BFLAGS_Public)
2729 if (bflags & BFLAGS_NonPublic)
2735 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2736 if (bflags & BFLAGS_Static)
2737 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2740 if (bflags & BFLAGS_Instance)
2746 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
2748 l = g_slist_prepend (l, member);
2750 len = g_slist_length (l);
2751 if (!System_Reflection_ConstructorInfo)
2752 System_Reflection_ConstructorInfo = mono_class_from_name (
2753 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
2754 res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
2756 tmp = l = g_slist_reverse (l);
2757 for (; tmp; tmp = tmp->next, ++i)
2758 mono_array_set (res, gpointer, i, tmp->data);
2764 ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
2767 GSList *l = NULL, *tmp;
2768 static MonoClass *System_Reflection_PropertyInfo;
2769 MonoClass *startklass, *klass;
2775 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2776 gchar *propname = NULL;
2777 int (*compare_func) (const char *s1, const char *s2) = NULL;
2779 MONO_ARCH_SAVE_REGS;
2781 domain = ((MonoObject *)type)->vtable->domain;
2782 klass = startklass = mono_class_from_mono_type (type->type);
2784 propname = mono_string_to_utf8 (name);
2785 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2789 for (i = 0; i < klass->property.count; ++i) {
2790 prop = &klass->properties [i];
2795 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2796 if (bflags & BFLAGS_Public)
2799 if (bflags & BFLAGS_NonPublic)
2805 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2806 if (bflags & BFLAGS_Static)
2807 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2810 if (bflags & BFLAGS_Instance)
2819 if (compare_func (propname, prop->name))
2823 if (prop->get && prop->get->slot != -1) {
2824 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (prop->get->slot)))
2826 g_hash_table_insert (method_slots, GUINT_TO_POINTER (prop->get->slot), prop);
2828 if (prop->set && prop->set->slot != -1) {
2829 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (prop->set->slot)))
2831 g_hash_table_insert (method_slots, GUINT_TO_POINTER (prop->set->slot), prop);
2834 l = g_slist_prepend (l, mono_property_get_object (domain, startklass, prop));
2837 if ((!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
2841 if (!System_Reflection_PropertyInfo)
2842 System_Reflection_PropertyInfo = mono_class_from_name (
2843 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
2844 res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
2847 tmp = l = g_slist_reverse (l);
2849 for (; tmp; tmp = tmp->next, ++i)
2850 mono_array_set (res, gpointer, i, tmp->data);
2852 g_hash_table_destroy (method_slots);
2856 static MonoReflectionEvent *
2857 ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
2860 MonoClass *klass, *startklass;
2866 MONO_ARCH_SAVE_REGS;
2868 event_name = mono_string_to_utf8 (name);
2869 klass = startklass = mono_class_from_mono_type (type->type);
2870 domain = mono_object_domain (type);
2873 for (i = 0; i < klass->event.count; i++) {
2874 event = &klass->events [i];
2875 if (strcmp (event->name, event_name))
2878 method = event->add;
2880 method = event->remove;
2882 method = event->raise;
2884 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2885 if (!(bflags & BFLAGS_Public))
2888 if (!(bflags & BFLAGS_NonPublic))
2893 if (!(bflags & BFLAGS_NonPublic))
2896 g_free (event_name);
2897 return mono_event_get_object (domain, startklass, event);
2900 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2903 g_free (event_name);
2908 ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2911 GSList *l = NULL, *tmp;
2912 static MonoClass *System_Reflection_EventInfo;
2913 MonoClass *startklass, *klass;
2919 MONO_ARCH_SAVE_REGS;
2921 domain = ((MonoObject *)type)->vtable->domain;
2922 klass = startklass = mono_class_from_mono_type (type->type);
2925 for (i = 0; i < klass->event.count; ++i) {
2926 event = &klass->events [i];
2928 method = event->add;
2930 method = event->remove;
2932 method = event->raise;
2934 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2935 if (bflags & BFLAGS_Public)
2938 if (bflags & BFLAGS_NonPublic)
2943 if (bflags & BFLAGS_NonPublic)
2949 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2950 if (bflags & BFLAGS_Static)
2951 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2954 if (bflags & BFLAGS_Instance)
2959 if (bflags & BFLAGS_Instance)
2964 l = g_slist_prepend (l, mono_event_get_object (domain, klass, event));
2966 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2968 len = g_slist_length (l);
2969 if (!System_Reflection_EventInfo)
2970 System_Reflection_EventInfo = mono_class_from_name (
2971 mono_defaults.corlib, "System.Reflection", "EventInfo");
2972 res = mono_array_new (domain, System_Reflection_EventInfo, len);
2975 tmp = l = g_slist_reverse (l);
2977 for (; tmp; tmp = tmp->next, ++i)
2978 mono_array_set (res, gpointer, i, tmp->data);
2983 static MonoReflectionType *
2984 ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
2987 MonoClass *startklass, *klass;
2992 MONO_ARCH_SAVE_REGS;
2994 domain = ((MonoObject *)type)->vtable->domain;
2995 klass = startklass = mono_class_from_mono_type (type->type);
2996 str = mono_string_to_utf8 (name);
2999 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
3001 nested = tmpn->data;
3002 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
3003 if (bflags & BFLAGS_Public)
3006 if (bflags & BFLAGS_NonPublic)
3011 if (strcmp (nested->name, str) == 0){
3013 return mono_type_get_object (domain, &nested->byval_arg);
3016 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3023 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
3026 GSList *l = NULL, *tmp;
3028 MonoClass *startklass, *klass;
3034 MONO_ARCH_SAVE_REGS;
3036 domain = ((MonoObject *)type)->vtable->domain;
3037 klass = startklass = mono_class_from_mono_type (type->type);
3039 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
3041 nested = tmpn->data;
3042 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
3043 if (bflags & BFLAGS_Public)
3046 if (bflags & BFLAGS_NonPublic)
3051 member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
3052 l = g_slist_prepend (l, member);
3054 len = g_slist_length (l);
3055 res = mono_array_new (domain, mono_defaults.monotype_class, len);
3057 tmp = l = g_slist_reverse (l);
3058 for (; tmp; tmp = tmp->next, ++i)
3059 mono_array_set (res, gpointer, i, tmp->data);
3064 static MonoReflectionType*
3065 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoReflectionModule *module, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
3068 MonoType *type = NULL;
3069 MonoTypeNameParse info;
3070 gboolean type_resolve = FALSE;
3072 MONO_ARCH_SAVE_REGS;
3074 str = mono_string_to_utf8 (name);
3075 /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
3076 if (!mono_reflection_parse_type (str, &info)) {
3078 g_list_free (info.modifiers);
3079 g_list_free (info.nested);
3080 if (throwOnError) /* uhm: this is a parse error, though... */
3081 mono_raise_exception (mono_get_exception_type_load (name));
3082 /*g_print ("failed parse\n");*/
3086 if (module != NULL) {
3088 type = mono_reflection_get_type (module->image, &info, ignoreCase, &type_resolve);
3093 if (assembly->assembly->dynamic) {
3094 /* Enumerate all modules */
3095 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
3099 if (abuilder->modules) {
3100 for (i = 0; i < mono_array_length (abuilder->modules); ++i) {
3101 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
3102 type = mono_reflection_get_type (&mb->dynamic_image->image, &info, ignoreCase, &type_resolve);
3108 if (!type && abuilder->loaded_modules) {
3109 for (i = 0; i < mono_array_length (abuilder->loaded_modules); ++i) {
3110 MonoReflectionModule *mod = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
3111 type = mono_reflection_get_type (mod->image, &info, ignoreCase, &type_resolve);
3118 type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase, &type_resolve);
3120 g_list_free (info.modifiers);
3121 g_list_free (info.nested);
3124 mono_raise_exception (mono_get_exception_type_load (name));
3125 /* g_print ("failed find\n"); */
3128 /* g_print ("got it\n"); */
3129 return mono_type_get_object (mono_object_domain (assembly), type);
3134 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly)
3136 MonoDomain *domain = mono_object_domain (assembly);
3137 MonoAssembly *mass = assembly->assembly;
3142 MONO_ARCH_SAVE_REGS;
3144 absolute = g_build_filename (mass->basedir, mass->image->module_name, NULL);
3145 uri = g_filename_to_uri (absolute, NULL, NULL);
3146 res = mono_string_new (domain, uri);
3153 ves_icall_System_Reflection_Assembly_get_global_assembly_cache (MonoReflectionAssembly *assembly)
3155 MonoAssembly *mass = assembly->assembly;
3157 MONO_ARCH_SAVE_REGS;
3159 return mass->in_gac;
3162 static MonoReflectionAssembly*
3163 ves_icall_System_Reflection_Assembly_load_with_partial_name (MonoString *mname, MonoObject *evidence)
3167 MonoImageOpenStatus status;
3169 MONO_ARCH_SAVE_REGS;
3171 name = mono_string_to_utf8 (mname);
3172 res = mono_assembly_load_with_partial_name (name, &status);
3178 return mono_assembly_get_object (mono_domain_get (), res);
3182 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assembly)
3184 MonoDomain *domain = mono_object_domain (assembly);
3187 MONO_ARCH_SAVE_REGS;
3189 res = mono_string_new (domain, mono_image_get_filename (assembly->assembly->image));
3195 ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflectionAssembly *assembly)
3197 MonoDomain *domain = mono_object_domain (assembly);
3199 MONO_ARCH_SAVE_REGS;
3201 return mono_string_new (domain, assembly->assembly->image->version);
3204 static MonoReflectionMethod*
3205 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly)
3207 guint32 token = mono_image_get_entry_point (assembly->assembly->image);
3209 MONO_ARCH_SAVE_REGS;
3213 return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL), NULL);
3216 static MonoReflectionModule*
3217 ves_icall_System_Reflection_Assembly_get_ManifestModule (MonoReflectionAssembly *assembly)
3219 return mono_module_get_object (mono_object_domain (assembly), assembly->assembly->image);
3223 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly)
3225 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3226 MonoArray *result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3230 MONO_ARCH_SAVE_REGS;
3232 for (i = 0; i < table->rows; ++i) {
3233 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_MANIFEST_NAME));
3234 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), val));
3240 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly)
3242 static MonoClass *System_Reflection_AssemblyName;
3244 MonoDomain *domain = mono_object_domain (assembly);
3246 static MonoMethod *create_culture = NULL;
3249 MONO_ARCH_SAVE_REGS;
3251 if (!System_Reflection_AssemblyName)
3252 System_Reflection_AssemblyName = mono_class_from_name (
3253 mono_defaults.corlib, "System.Reflection", "AssemblyName");
3255 t = &assembly->assembly->image->tables [MONO_TABLE_ASSEMBLYREF];
3258 result = mono_array_new (domain, System_Reflection_AssemblyName, count);
3261 MonoMethodDesc *desc = mono_method_desc_new (
3262 "System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3263 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3264 g_assert (create_culture);
3265 mono_method_desc_free (desc);
3268 for (i = 0; i < count; i++) {
3269 MonoAssembly *assem;
3270 MonoReflectionAssemblyName *aname;
3271 char *codebase, *absolute;
3273 /* FIXME: There is no need to load the assemblies themselves */
3274 mono_assembly_load_reference (assembly->assembly->image, i);
3276 assem = assembly->assembly->image->references [i];
3277 if (assem == (gpointer)-1) {
3278 char *msg = g_strdup_printf ("Assembly %d referenced from assembly %s not found ", i, assembly->assembly->image->name);
3279 MonoException *ex = mono_get_exception_file_not_found2 (msg, NULL);
3281 mono_raise_exception (ex);
3284 aname = (MonoReflectionAssemblyName *) mono_object_new (
3285 domain, System_Reflection_AssemblyName);
3287 aname->name = mono_string_new (domain, assem->aname.name);
3289 aname->major = assem->aname.major;
3290 aname->minor = assem->aname.minor;
3291 aname->build = assem->aname.build;
3292 aname->revision = assem->aname.revision;
3293 aname->revision = assem->aname.revision;
3294 aname->hashalg = assem->aname.hash_alg;
3295 aname->flags = assem->aname.flags;
3297 if (create_culture) {
3299 args [0] = mono_string_new (domain, assem->aname.culture);
3300 aname->cultureInfo = mono_runtime_invoke (create_culture, NULL, args, NULL);
3303 if (assem->aname.public_key) {
3305 const char *pkey_ptr = assem->aname.public_key;
3306 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3308 aname->publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
3309 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3312 /* public key token isn't copied - the class library will
3313 automatically generate it from the public key if required */
3315 absolute = g_build_filename (assem->basedir, assem->image->module_name, NULL);
3316 codebase = g_filename_to_uri (absolute, NULL, NULL);
3317 aname->codebase = mono_string_new (domain, codebase);
3320 mono_array_set (result, gpointer, i, aname);
3331 foreach_namespace (const char* key, gconstpointer val, NameSpaceInfo *info)
3333 MonoString *name = mono_string_new (mono_object_domain (info->res), key);
3335 mono_array_set (info->res, gpointer, info->idx, name);
3340 ves_icall_System_Reflection_Assembly_GetNamespaces (MonoReflectionAssembly *assembly)
3342 MonoImage *img = assembly->assembly->image;
3346 MonoTableInfo *t = &img->tables [MONO_TABLE_EXPORTEDTYPE];
3349 MONO_ARCH_SAVE_REGS;
3351 n = g_hash_table_size (img->name_cache);
3352 res = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n);
3355 g_hash_table_foreach (img->name_cache, (GHFunc)foreach_namespace, &info);
3357 /* Add namespaces from the EXPORTEDTYPES table as well */
3360 GPtrArray *nspaces = g_ptr_array_new ();
3361 for (i = 0; i < t->rows; ++i) {
3362 const char *nspace = mono_metadata_string_heap (img, mono_metadata_decode_row_col (t, i, MONO_EXP_TYPE_NAMESPACE));
3363 if (!g_hash_table_lookup (img->name_cache, nspace)) {
3364 g_ptr_array_add (nspaces, (char*)nspace);
3367 if (nspaces->len > 0) {
3368 res2 = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, n + nspaces->len);
3369 memcpy (mono_array_addr (res2, MonoString*, 0),
3370 mono_array_addr (res, MonoString*, 0),
3371 n * sizeof (MonoString*));
3372 for (i = 0; i < nspaces->len; ++i)
3373 mono_array_set (res2, MonoString*, n + i,
3374 mono_string_new (mono_object_domain (assembly),
3375 g_ptr_array_index (nspaces, i)));
3378 g_ptr_array_free (nspaces, TRUE);
3384 /* move this in some file in mono/util/ */
3386 g_concat_dir_and_file (const char *dir, const char *file)
3388 g_return_val_if_fail (dir != NULL, NULL);
3389 g_return_val_if_fail (file != NULL, NULL);
3392 * If the directory name doesn't have a / on the end, we need
3393 * to add one so we get a proper path to the file
3395 if (dir [strlen(dir) - 1] != G_DIR_SEPARATOR)
3396 return g_strconcat (dir, G_DIR_SEPARATOR_S, file, NULL);
3398 return g_strconcat (dir, file, NULL);
3402 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name, gint32 *size, MonoReflectionModule **ref_module)
3404 char *n = mono_string_to_utf8 (name);
3405 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3407 guint32 cols [MONO_MANIFEST_SIZE];
3408 guint32 impl, file_idx;
3412 MONO_ARCH_SAVE_REGS;
3414 for (i = 0; i < table->rows; ++i) {
3415 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3416 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3417 if (strcmp (val, n) == 0)
3421 if (i == table->rows)
3424 impl = cols [MONO_MANIFEST_IMPLEMENTATION];
3427 * this code should only be called after obtaining the
3428 * ResourceInfo and handling the other cases.
3430 g_assert ((impl & MONO_IMPLEMENTATION_MASK) == MONO_IMPLEMENTATION_FILE);
3431 file_idx = impl >> MONO_IMPLEMENTATION_BITS;
3433 module = mono_image_load_file_for_image (assembly->assembly->image, file_idx);
3438 module = assembly->assembly->image;
3440 *ref_module = mono_module_get_object (mono_domain_get (), module);
3442 return (void*)mono_image_get_resource (module, cols [MONO_MANIFEST_OFFSET], size);
3446 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoManifestResourceInfo *info)
3448 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3450 guint32 cols [MONO_MANIFEST_SIZE];
3451 guint32 file_cols [MONO_FILE_SIZE];
3455 MONO_ARCH_SAVE_REGS;
3457 n = mono_string_to_utf8 (name);
3458 for (i = 0; i < table->rows; ++i) {
3459 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3460 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3461 if (strcmp (val, n) == 0)
3465 if (i == table->rows)
3468 if (!cols [MONO_MANIFEST_IMPLEMENTATION]) {
3469 info->location = RESOURCE_LOCATION_EMBEDDED | RESOURCE_LOCATION_IN_MANIFEST;
3472 switch (cols [MONO_MANIFEST_IMPLEMENTATION] & MONO_IMPLEMENTATION_MASK) {
3473 case MONO_IMPLEMENTATION_FILE:
3474 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> MONO_IMPLEMENTATION_BITS;
3475 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3476 mono_metadata_decode_row (table, i - 1, file_cols, MONO_FILE_SIZE);
3477 val = mono_metadata_string_heap (assembly->assembly->image, file_cols [MONO_FILE_NAME]);
3478 info->filename = mono_string_new (mono_object_domain (assembly), val);
3479 if (file_cols [MONO_FILE_FLAGS] && FILE_CONTAINS_NO_METADATA)
3482 info->location = RESOURCE_LOCATION_EMBEDDED;
3485 case MONO_IMPLEMENTATION_ASSEMBLYREF:
3486 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> MONO_IMPLEMENTATION_BITS;
3487 mono_assembly_load_reference (assembly->assembly->image, i - 1);
3488 if (assembly->assembly->image->references [i - 1] == (gpointer)-1) {
3489 char *msg = g_strdup_printf ("Assembly %d referenced from assembly %s not found ", i - 1, assembly->assembly->image->name);
3490 MonoException *ex = mono_get_exception_file_not_found2 (msg, NULL);
3492 mono_raise_exception (ex);
3494 info->assembly = mono_assembly_get_object (mono_domain_get (), assembly->assembly->image->references [i - 1]);
3496 /* Obtain info recursively */
3497 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (info->assembly, name, info);
3498 info->location |= RESOURCE_LOCATION_ANOTHER_ASSEMBLY;
3501 case MONO_IMPLEMENTATION_EXP_TYPE:
3502 g_assert_not_reached ();
3511 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name)
3513 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3514 MonoArray *result = NULL;
3519 MONO_ARCH_SAVE_REGS;
3521 /* check hash if needed */
3523 n = mono_string_to_utf8 (name);
3524 for (i = 0; i < table->rows; ++i) {
3525 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3526 if (strcmp (val, n) == 0) {
3529 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3530 fn = mono_string_new (mono_object_domain (assembly), n);
3532 return (MonoObject*)fn;
3539 for (i = 0; i < table->rows; ++i) {
3540 result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3541 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3542 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3543 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), n));
3546 return (MonoObject*)result;
3550 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly *assembly)
3552 MonoDomain *domain = mono_domain_get();
3555 int i, module_count = 0, file_count = 0;
3556 MonoImage **modules = assembly->assembly->image->modules;
3557 MonoTableInfo *table;
3560 while (modules[module_count])
3564 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3565 file_count = table->rows;
3567 g_assert( assembly->assembly->image != NULL);
3570 klass = mono_class_from_name ( mono_defaults.corlib, "System.Reflection", "Module");
3571 res = mono_array_new (domain, klass, module_count + file_count);
3573 mono_array_set (res, gpointer, 0, mono_module_get_object (domain, assembly->assembly->image));
3574 for ( i = 1; i < module_count; ++i )
3575 mono_array_set (res, gpointer, i, mono_module_get_object (domain, modules[i]));
3577 for (i = 0; i < table->rows; ++i)
3578 mono_array_set (res, gpointer, module_count + i, mono_module_file_get_object (domain, assembly->assembly->image, i));
3583 static MonoReflectionMethod*
3584 ves_icall_GetCurrentMethod (void)
3586 MonoMethod *m = mono_method_get_last_managed ();
3588 MONO_ARCH_SAVE_REGS;
3590 return mono_method_get_object (mono_domain_get (), m, NULL);
3593 static MonoReflectionMethod*
3594 ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternal (MonoMethod *method)
3596 return mono_method_get_object (mono_domain_get (), method, NULL);
3599 static MonoReflectionAssembly*
3600 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
3602 MonoMethod *m = mono_method_get_last_managed ();
3604 MONO_ARCH_SAVE_REGS;
3606 return mono_assembly_get_object (mono_domain_get (), m->klass->image->assembly);
3611 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
3613 MonoMethod **dest = data;
3615 /* skip unmanaged frames */
3630 static MonoReflectionAssembly*
3631 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
3633 MonoDomain* domain = mono_domain_get ();
3635 MONO_ARCH_SAVE_REGS;
3637 if (!domain->entry_assembly)
3638 domain = mono_get_root_domain ();
3640 return mono_assembly_get_object (domain, domain->entry_assembly);
3644 static MonoReflectionAssembly*
3645 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
3647 MonoMethod *m = mono_method_get_last_managed ();
3648 MonoMethod *dest = m;
3650 MONO_ARCH_SAVE_REGS;
3652 mono_stack_walk (get_caller, &dest);
3655 return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
3659 ves_icall_System_MonoType_getFullName (MonoReflectionType *object, gboolean full_name)
3661 MonoDomain *domain = mono_object_domain (object);
3665 MONO_ARCH_SAVE_REGS;
3668 name = mono_type_get_full_name (object->type);
3670 name = mono_type_get_name (object->type);
3671 res = mono_string_new (domain, name);
3678 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute)
3680 static MonoMethod *create_culture = NULL;
3683 const char *pkey_ptr;
3686 MONO_ARCH_SAVE_REGS;
3688 aname->name = mono_string_new (domain, name->name);
3689 aname->major = name->major;
3690 aname->minor = name->minor;
3691 aname->build = name->build;
3692 aname->revision = name->revision;
3693 aname->hashalg = name->hash_alg;
3695 codebase = g_filename_to_uri (absolute, NULL, NULL);
3697 aname->codebase = mono_string_new (domain, codebase);
3701 if (!create_culture) {
3702 MonoMethodDesc *desc = mono_method_desc_new ("System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3703 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3704 g_assert (create_culture);
3705 mono_method_desc_free (desc);
3708 args [0] = mono_string_new (domain, name->culture);
3709 aname->cultureInfo =
3710 mono_runtime_invoke (create_culture, NULL, args, NULL);
3712 if (name->public_key) {
3713 pkey_ptr = name->public_key;
3714 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3716 aname->publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
3717 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3722 ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
3726 MONO_ARCH_SAVE_REGS;
3728 absolute = g_build_filename (assembly->assembly->basedir, assembly->assembly->image->module_name, NULL);
3730 fill_reflection_assembly_name (mono_object_domain (assembly), aname,
3731 &assembly->assembly->aname, absolute);
3737 ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname, MonoReflectionAssemblyName *aname)
3740 MonoImageOpenStatus status = MONO_IMAGE_OK;
3743 MonoAssemblyName name;
3745 MONO_ARCH_SAVE_REGS;
3747 filename = mono_string_to_utf8 (fname);
3749 image = mono_image_open (filename, &status);
3755 exc = mono_get_exception_file_not_found (fname);
3756 mono_raise_exception (exc);
3759 res = mono_assembly_fill_assembly_name (image, &name);
3761 mono_image_close (image);
3763 mono_raise_exception (mono_get_exception_argument ("assemblyFile", "The file does not contain a manifest"));
3766 fill_reflection_assembly_name (mono_domain_get (), aname, &name, filename);
3769 mono_image_close (image);
3773 mono_module_get_types (MonoDomain *domain, MonoImage *image,
3774 MonoBoolean exportedOnly)
3778 MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF];
3780 guint32 attrs, visibility;
3782 /* we start the count from 1 because we skip the special type <Module> */
3785 for (i = 1; i < tdef->rows; ++i) {
3786 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3787 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3788 if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
3792 count = tdef->rows - 1;
3794 res = mono_array_new (domain, mono_defaults.monotype_class, count);
3796 for (i = 1; i < tdef->rows; ++i) {
3797 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3798 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3799 if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
3800 klass = mono_class_get (image, (i + 1) | MONO_TOKEN_TYPE_DEF);
3801 mono_array_set (res, gpointer, count, mono_type_get_object (domain, &klass->byval_arg));
3810 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
3812 MonoArray *res = NULL;
3813 MonoImage *image = NULL;
3814 MonoTableInfo *table = NULL;
3818 MONO_ARCH_SAVE_REGS;
3820 domain = mono_object_domain (assembly);
3822 if (assembly->assembly->dynamic) {
3823 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
3824 if (abuilder->modules)
3825 for (i = 0; i < mono_array_length(abuilder->modules); i++) {
3826 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
3830 MonoArray *append = mb->types;
3831 if (mono_array_length (append) > 0) {
3834 len1 = mono_array_length (res);
3835 len2 = mono_array_length (append);
3836 new = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
3837 memcpy (mono_array_addr (new, MonoReflectionType*, 0),
3838 mono_array_addr (res, MonoReflectionType*, 0),
3839 len1 * sizeof (MonoReflectionType*));
3840 memcpy (mono_array_addr (new, MonoReflectionType*, len1),
3841 mono_array_addr (append, MonoReflectionType*, 0),
3842 len2 * sizeof (MonoReflectionType*));
3847 if (abuilder->loaded_modules)
3848 for (i = 0; i < mono_array_length(abuilder->loaded_modules); i++) {
3849 MonoReflectionModule *rm = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
3851 res = mono_module_get_types (domain, rm->image, exportedOnly);
3853 MonoArray *append = mono_module_get_types (domain, rm->image, exportedOnly);
3854 if (mono_array_length (append) > 0) {
3857 len1 = mono_array_length (res);
3858 len2 = mono_array_length (append);
3859 new = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
3860 memcpy (mono_array_addr (new, MonoReflectionType*, 0),
3861 mono_array_addr (res, MonoReflectionType*, 0),
3862 len1 * sizeof (MonoReflectionType*));
3863 memcpy (mono_array_addr (new, MonoReflectionType*, len1),
3864 mono_array_addr (append, MonoReflectionType*, 0),
3865 len2 * sizeof (MonoReflectionType*));
3872 image = assembly->assembly->image;
3873 table = &image->tables [MONO_TABLE_FILE];
3874 res = mono_module_get_types (domain, image, exportedOnly);
3876 /* Append data from all modules in the assembly */
3877 for (i = 0; i < table->rows; ++i) {
3878 if (!(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
3879 MonoImage *loaded_image = mono_assembly_load_module (image->assembly, i + 1);
3881 MonoArray *res2 = mono_module_get_types (domain, loaded_image, exportedOnly);
3882 /* Append the new types to the end of the array */
3883 if (mono_array_length (res2) > 0) {
3887 len1 = mono_array_length (res);
3888 len2 = mono_array_length (res2);
3889 res3 = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
3890 memcpy (mono_array_addr (res3, MonoReflectionType*, 0),
3891 mono_array_addr (res, MonoReflectionType*, 0),
3892 len1 * sizeof (MonoReflectionType*));
3893 memcpy (mono_array_addr (res3, MonoReflectionType*, len1),
3894 mono_array_addr (res2, MonoReflectionType*, 0),
3895 len2 * sizeof (MonoReflectionType*));
3904 static MonoReflectionType*
3905 ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module)
3907 MonoDomain *domain = mono_object_domain (module);
3910 MONO_ARCH_SAVE_REGS;
3912 g_assert (module->image);
3913 klass = mono_class_get (module->image, 1 | MONO_TOKEN_TYPE_DEF);
3914 return mono_type_get_object (domain, &klass->byval_arg);
3918 ves_icall_System_Reflection_Module_Close (MonoReflectionModule *module)
3921 mono_image_close (module->image);
3925 ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module)
3927 MonoDomain *domain = mono_object_domain (module);
3929 MONO_ARCH_SAVE_REGS;
3931 g_assert (module->image);
3932 return mono_string_new (domain, module->image->guid);
3936 ves_icall_System_Reflection_Module_GetPEKind (MonoImage *image, gint32 *pe_kind, gint32 *machine)
3938 if (image->dynamic) {
3939 *pe_kind = 0x1; /* ILOnly */
3940 *machine = 0x14c; /* I386 */
3943 *pe_kind = ((MonoCLIImageInfo*)(image->image_info))->cli_cli_header.ch_flags & 0x3;
3944 *machine = ((MonoCLIImageInfo*)(image->image_info))->cli_header.coff.coff_machine;
3949 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *module)
3951 MONO_ARCH_SAVE_REGS;
3954 return mono_array_new (mono_object_domain (module), mono_defaults.monotype_class, 0);
3956 return mono_module_get_types (mono_object_domain (module), module->image, FALSE);
3960 mono_metadata_memberref_is_method (MonoImage *image, guint32 token)
3962 guint32 cols [MONO_MEMBERREF_SIZE];
3964 mono_metadata_decode_row (&image->tables [MONO_TABLE_MEMBERREF], mono_metadata_token_index (token) - 1, cols, MONO_MEMBERREF_SIZE);
3965 sig = mono_metadata_blob_heap (image, cols [MONO_MEMBERREF_SIGNATURE]);
3966 mono_metadata_decode_blob_size (sig, &sig);
3967 return (*sig == 0x6);
3971 ves_icall_System_Reflection_Module_ResolveTypeToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
3974 int table = mono_metadata_token_table (token);
3975 int index = mono_metadata_token_index (token);
3977 *error = ResolveTokenError_Other;
3979 /* Validate token */
3980 if ((table != MONO_TABLE_TYPEDEF) && (table != MONO_TABLE_TYPEREF) &&
3981 (table != MONO_TABLE_TYPESPEC)) {
3982 *error = ResolveTokenError_BadTable;
3987 return mono_lookup_dynamic_token (image, token);
3989 if ((index <= 0) || (index > image->tables [table].rows)) {
3990 *error = ResolveTokenError_OutOfRange;
3994 klass = mono_class_get (image, token);
3996 return &klass->byval_arg;
4002 ves_icall_System_Reflection_Module_ResolveMethodToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4004 int table = mono_metadata_token_table (token);
4005 int index = mono_metadata_token_index (token);
4007 *error = ResolveTokenError_Other;
4009 /* Validate token */
4010 if ((table != MONO_TABLE_METHOD) && (table != MONO_TABLE_METHODSPEC) &&
4011 (table != MONO_TABLE_MEMBERREF)) {
4012 *error = ResolveTokenError_BadTable;
4017 /* FIXME: validate memberref token type */
4018 return mono_lookup_dynamic_token (image, token);
4020 if ((index <= 0) || (index > image->tables [table].rows)) {
4021 *error = ResolveTokenError_OutOfRange;
4024 if ((table == MONO_TABLE_MEMBERREF) && (!mono_metadata_memberref_is_method (image, token))) {
4025 *error = ResolveTokenError_BadTable;
4029 return mono_get_method (image, token, NULL);
4033 ves_icall_System_Reflection_Module_ResolveStringToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4035 int index = mono_metadata_token_index (token);
4037 *error = ResolveTokenError_Other;
4039 /* Validate token */
4040 if (mono_metadata_token_code (token) != MONO_TOKEN_STRING) {
4041 *error = ResolveTokenError_BadTable;
4046 return mono_lookup_dynamic_token (image, token);
4048 if ((index <= 0) || (index >= image->heap_us.size)) {
4049 *error = ResolveTokenError_OutOfRange;
4053 /* FIXME: What to do if the index points into the middle of a string ? */
4055 return mono_ldstr (mono_domain_get (), image, index);
4058 static MonoClassField*
4059 ves_icall_System_Reflection_Module_ResolveFieldToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4062 int table = mono_metadata_token_table (token);
4063 int index = mono_metadata_token_index (token);
4065 *error = ResolveTokenError_Other;
4067 /* Validate token */
4068 if ((table != MONO_TABLE_FIELD) && (table != MONO_TABLE_MEMBERREF)) {
4069 *error = ResolveTokenError_BadTable;
4074 /* FIXME: validate memberref token type */
4075 return mono_lookup_dynamic_token (image, token);
4077 if ((index <= 0) || (index > image->tables [table].rows)) {
4078 *error = ResolveTokenError_OutOfRange;
4081 if ((table == MONO_TABLE_MEMBERREF) && (mono_metadata_memberref_is_method (image, token))) {
4082 *error = ResolveTokenError_BadTable;
4086 return mono_field_from_token (image, token, &klass, NULL);
4091 ves_icall_System_Reflection_Module_ResolveMemberToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4093 int table = mono_metadata_token_table (token);
4095 *error = ResolveTokenError_Other;
4098 case MONO_TABLE_TYPEDEF:
4099 case MONO_TABLE_TYPEREF:
4100 case MONO_TABLE_TYPESPEC: {
4101 MonoType *t = ves_icall_System_Reflection_Module_ResolveTypeToken (image, token, error);
4103 return (MonoObject*)mono_type_get_object (mono_domain_get (), t);
4107 case MONO_TABLE_METHOD:
4108 case MONO_TABLE_METHODSPEC: {
4109 MonoMethod *m = ves_icall_System_Reflection_Module_ResolveMethodToken (image, token, error);
4111 return (MonoObject*)mono_method_get_object (mono_domain_get (), m, m->klass);
4115 case MONO_TABLE_FIELD: {
4116 MonoClassField *f = ves_icall_System_Reflection_Module_ResolveFieldToken (image, token, error);
4118 return (MonoObject*)mono_field_get_object (mono_domain_get (), f->parent, f);
4122 case MONO_TABLE_MEMBERREF:
4123 if (mono_metadata_memberref_is_method (image, token)) {
4124 MonoMethod *m = ves_icall_System_Reflection_Module_ResolveMethodToken (image, token, error);
4126 return (MonoObject*)mono_method_get_object (mono_domain_get (), m, m->klass);
4131 MonoClassField *f = ves_icall_System_Reflection_Module_ResolveFieldToken (image, token, error);
4133 return (MonoObject*)mono_field_get_object (mono_domain_get (), f->parent, f);
4140 *error = ResolveTokenError_BadTable;
4146 static MonoReflectionType*
4147 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
4150 int isbyref = 0, rank;
4151 char *str = mono_string_to_utf8 (smodifiers);
4154 MONO_ARCH_SAVE_REGS;
4156 klass = mono_class_from_mono_type (tb->type.type);
4158 /* logic taken from mono_reflection_parse_type(): keep in sync */
4162 if (isbyref) { /* only one level allowed by the spec */
4169 return mono_type_get_object (mono_object_domain (tb), &klass->this_arg);
4172 klass = mono_ptr_class_get (&klass->byval_arg);
4173 mono_class_init (klass);
4184 else if (*p != '*') { /* '*' means unknown lower bound */
4195 klass = mono_array_class_get (klass, rank);
4196 mono_class_init (klass);
4203 return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
4207 ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
4212 MONO_ARCH_SAVE_REGS;
4215 res = !type->byref && (type->type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY);
4220 static MonoReflectionType *
4221 ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
4223 MonoClass *klass, *aklass;
4225 MONO_ARCH_SAVE_REGS;
4227 klass = mono_class_from_mono_type (type->type);
4228 aklass = mono_array_class_get (klass, rank);
4230 return mono_type_get_object (mono_object_domain (type), &aklass->byval_arg);
4233 static MonoReflectionType *
4234 ves_icall_Type_make_byref_type (MonoReflectionType *type)
4238 MONO_ARCH_SAVE_REGS;
4240 klass = mono_class_from_mono_type (type->type);
4242 return mono_type_get_object (mono_object_domain (type), &klass->this_arg);
4246 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target,
4247 MonoReflectionMethod *info)
4249 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
4250 MonoObject *delegate;
4253 MONO_ARCH_SAVE_REGS;
4255 mono_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
4257 delegate = mono_object_new (mono_object_domain (type), delegate_class);
4259 func = mono_compile_method (info->method);
4261 mono_delegate_ctor (delegate, target, func);
4267 ves_icall_System_Delegate_FreeTrampoline (MonoDelegate *this)
4269 mono_delegate_free_ftnptr (this);
4273 * Magic number to convert a time which is relative to
4274 * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
4276 #define EPOCH_ADJUST ((guint64)62135596800LL)
4279 * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
4281 #define FILETIME_ADJUST ((guint64)504911232000000000LL)
4284 * This returns Now in UTC
4287 ves_icall_System_DateTime_GetNow (void)
4289 #ifdef PLATFORM_WIN32
4293 GetSystemTime (&st);
4294 SystemTimeToFileTime (&st, &ft);
4295 return (gint64) FILETIME_ADJUST + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
4297 /* FIXME: put this in io-layer and call it GetLocalTime */
4301 MONO_ARCH_SAVE_REGS;
4303 if (gettimeofday (&tv, NULL) == 0) {
4304 res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
4307 /* fixme: raise exception */
4312 #ifdef PLATFORM_WIN32
4313 /* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
4315 convert_to_absolute_date(SYSTEMTIME *date)
4317 #define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
4318 static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4319 static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4320 /* from the calendar FAQ */
4321 int a = (14 - date->wMonth) / 12;
4322 int y = date->wYear - a;
4323 int m = date->wMonth + 12 * a - 2;
4324 int d = (1 + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
4326 /* d is now the day of the week for the first of the month (0 == Sunday) */
4328 int day_of_week = date->wDayOfWeek;
4330 /* set day_in_month to the first day in the month which falls on day_of_week */
4331 int day_in_month = 1 + (day_of_week - d);
4332 if (day_in_month <= 0)
4335 /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
4336 date->wDay = day_in_month + (date->wDay - 1) * 7;
4337 if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
4342 #ifndef PLATFORM_WIN32
4344 * Return's the offset from GMT of a local time.
4346 * tm is a local time
4347 * t is the same local time as seconds.
4350 gmt_offset(struct tm *tm, time_t t)
4352 #if defined (HAVE_TM_GMTOFF)
4353 return tm->tm_gmtoff;
4358 g.tm_isdst = tm->tm_isdst;
4360 return (int)difftime(t, t2);
4365 * This is heavily based on zdump.c from glibc 2.2.
4367 * * data[0]: start of daylight saving time (in DateTime ticks).
4368 * * data[1]: end of daylight saving time (in DateTime ticks).
4369 * * data[2]: utcoffset (in TimeSpan ticks).
4370 * * data[3]: additional offset when daylight saving (in TimeSpan ticks).
4371 * * name[0]: name of this timezone when not daylight saving.
4372 * * name[1]: name of this timezone when daylight saving.
4374 * FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
4375 * the class library allows years between 1 and 9999.
4377 * Returns true on success and zero on failure.
4380 ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
4382 #ifndef PLATFORM_WIN32
4383 MonoDomain *domain = mono_domain_get ();
4384 struct tm start, tt;
4388 int is_daylight = 0, day;
4391 MONO_ARCH_SAVE_REGS;
4393 MONO_CHECK_ARG_NULL (data);
4394 MONO_CHECK_ARG_NULL (names);
4396 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
4397 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
4400 * no info is better than crashing: we'll need our own tz data to make
4401 * this work properly, anyway. The range is reduced to 1970 .. 2037 because
4402 * that is what mktime is guaranteed to support (we get into an infinite loop
4405 if ((year < 1970) || (year > 2037)) {
4407 tt = *localtime (&t);
4408 strftime (tzone, sizeof (tzone), "%Z", &tt);
4409 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4410 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4414 memset (&start, 0, sizeof (start));
4417 start.tm_year = year-1900;
4419 t = mktime (&start);
4420 gmtoff = gmt_offset (&start, t);
4422 /* For each day of the year, calculate the tm_gmtoff. */
4423 for (day = 0; day < 365; day++) {
4426 tt = *localtime (&t);
4428 /* Daylight saving starts or ends here. */
4429 if (gmt_offset (&tt, t) != gmtoff) {
4433 /* Try to find the exact hour when daylight saving starts/ends. */
4437 tt1 = *localtime (&t1);
4438 } while (gmt_offset (&tt1, t1) != gmtoff);
4440 /* Try to find the exact minute when daylight saving starts/ends. */
4443 tt1 = *localtime (&t1);
4444 } while (gmt_offset (&tt1, t1) == gmtoff);
4446 strftime (tzone, sizeof (tzone), "%Z", &tt);
4448 /* Write data, if we're already in daylight saving, we're done. */
4450 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4451 mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
4454 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4455 mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
4459 /* This is only set once when we enter daylight saving. */
4460 mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
4461 mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (&tt, t) - gmtoff) * 10000000L);
4463 gmtoff = gmt_offset (&tt, t);
4468 strftime (tzone, sizeof (tzone), "%Z", &tt);
4469 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4470 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4471 mono_array_set ((*data), gint64, 0, 0);
4472 mono_array_set ((*data), gint64, 1, 0);
4473 mono_array_set ((*data), gint64, 2, (gint64) gmtoff * 10000000L);
4474 mono_array_set ((*data), gint64, 3, 0);
4479 MonoDomain *domain = mono_domain_get ();
4480 TIME_ZONE_INFORMATION tz_info;
4485 tz_id = GetTimeZoneInformation (&tz_info);
4486 if (tz_id == TIME_ZONE_ID_INVALID)
4489 MONO_CHECK_ARG_NULL (data);
4490 MONO_CHECK_ARG_NULL (names);
4492 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
4493 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
4495 for (i = 0; i < 32; ++i)
4496 if (!tz_info.DaylightName [i])
4498 mono_array_set ((*names), gpointer, 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
4499 for (i = 0; i < 32; ++i)
4500 if (!tz_info.StandardName [i])
4502 mono_array_set ((*names), gpointer, 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
4504 if ((year <= 1601) || (year > 30827)) {
4506 * According to MSDN, the MS time functions can't handle dates outside
4512 /* even if the timezone has no daylight savings it may have Bias (e.g. GMT+13 it seems) */
4513 if (tz_id != TIME_ZONE_ID_UNKNOWN) {
4514 tz_info.StandardDate.wYear = year;
4515 convert_to_absolute_date(&tz_info.StandardDate);
4516 err = SystemTimeToFileTime (&tz_info.StandardDate, &ft);
4518 mono_array_set ((*data), gint64, 1, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
4519 tz_info.DaylightDate.wYear = year;
4520 convert_to_absolute_date(&tz_info.DaylightDate);
4521 err = SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
4523 mono_array_set ((*data), gint64, 0, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
4525 mono_array_set ((*data), gint64, 2, (tz_info.Bias + tz_info.StandardBias) * -600000000LL);
4526 mono_array_set ((*data), gint64, 3, (tz_info.DaylightBias - tz_info.StandardBias) * -600000000LL);
4533 ves_icall_System_Object_obj_address (MonoObject *this)
4535 MONO_ARCH_SAVE_REGS;
4542 static inline gint32
4543 mono_array_get_byte_length (MonoArray *array)
4549 klass = array->obj.vtable->klass;
4551 if (array->bounds == NULL)
4552 length = array->max_length;
4555 for (i = 0; i < klass->rank; ++ i)
4556 length *= array->bounds [i].length;
4559 switch (klass->element_class->byval_arg.type) {
4562 case MONO_TYPE_BOOLEAN:
4566 case MONO_TYPE_CHAR:
4574 return length * sizeof (gpointer);
4585 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
4587 MONO_ARCH_SAVE_REGS;
4589 return mono_array_get_byte_length (array);
4593 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx)
4595 MONO_ARCH_SAVE_REGS;
4597 return mono_array_get (array, gint8, idx);
4601 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value)
4603 MONO_ARCH_SAVE_REGS;
4605 mono_array_set (array, gint8, idx, value);
4609 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count)
4611 char *src_buf, *dest_buf;
4613 MONO_ARCH_SAVE_REGS;
4615 /* watch out for integer overflow */
4616 if ((src_offset > mono_array_get_byte_length (src) - count) || (dest_offset > mono_array_get_byte_length (dest) - count))
4619 src_buf = (gint8 *)src->vector + src_offset;
4620 dest_buf = (gint8 *)dest->vector + dest_offset;
4622 memcpy (dest_buf, src_buf, count);
4628 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this, MonoString *class_name)
4630 MonoDomain *domain = mono_object_domain (this);
4632 MonoRealProxy *rp = ((MonoRealProxy *)this);
4633 MonoTransparentProxy *tp;
4637 MONO_ARCH_SAVE_REGS;
4639 res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
4640 tp = (MonoTransparentProxy*) res;
4643 type = ((MonoReflectionType *)rp->class_to_proxy)->type;
4644 klass = mono_class_from_mono_type (type);
4646 tp->custom_type_info = (mono_object_isinst (this, mono_defaults.iremotingtypeinfo_class) != NULL);
4647 tp->remote_class = mono_remote_class (domain, class_name, klass);
4648 res->vtable = tp->remote_class->vtable;
4653 static MonoReflectionType *
4654 ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy *tp)
4656 return mono_type_get_object (mono_object_domain (tp), &tp->remote_class->proxy_class->byval_arg);
4659 /* System.Environment */
4662 ves_icall_System_Environment_get_MachineName (void)
4664 #if defined (PLATFORM_WIN32)
4669 len = MAX_COMPUTERNAME_LENGTH + 1;
4670 buf = g_new (gunichar2, len);
4673 if (GetComputerName (buf, (PDWORD) &len))
4674 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
4683 MONO_ARCH_SAVE_REGS;
4686 buf = g_new (gchar, len);
4689 if (gethostname (buf, len) == 0)
4690 result = mono_string_new (mono_domain_get (), buf);
4698 ves_icall_System_Environment_get_Platform (void)
4700 MONO_ARCH_SAVE_REGS;
4702 #if defined (PLATFORM_WIN32)
4712 ves_icall_System_Environment_get_NewLine (void)
4714 MONO_ARCH_SAVE_REGS;
4716 #if defined (PLATFORM_WIN32)
4717 return mono_string_new (mono_domain_get (), "\r\n");
4719 return mono_string_new (mono_domain_get (), "\n");
4724 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
4729 MONO_ARCH_SAVE_REGS;
4734 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
4735 value = g_getenv (utf8_name);
4741 return mono_string_new (mono_domain_get (), value);
4745 * There is no standard way to get at environ.
4753 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
4761 MONO_ARCH_SAVE_REGS;
4764 for (e = environ; *e != 0; ++ e)
4767 domain = mono_domain_get ();
4768 names = mono_array_new (domain, mono_defaults.string_class, n);
4771 for (e = environ; *e != 0; ++ e) {
4772 parts = g_strsplit (*e, "=", 2);
4774 str = mono_string_new (domain, *parts);
4775 mono_array_set (names, MonoString *, n, str);
4787 * Returns the number of milliseconds elapsed since the system started.
4790 ves_icall_System_Environment_get_TickCount (void)
4792 #if defined (PLATFORM_WIN32)
4793 return GetTickCount();
4799 MONO_ARCH_SAVE_REGS;
4801 res = (gint32) gettimeofday (&tv, &tz);
4804 res = (gint32) ((tv.tv_sec & 0xFFFFF) * 1000 + (tv.tv_usec / 1000));
4811 ves_icall_System_Environment_Exit (int result)
4813 MONO_ARCH_SAVE_REGS;
4815 mono_runtime_quit ();
4817 /* we may need to do some cleanup here... */
4822 ves_icall_System_Environment_GetGacPath (void)
4824 return mono_string_new (mono_domain_get (), mono_assembly_getrootdir ());
4828 ves_icall_System_Environment_GetWindowsFolderPath (int folder)
4830 #if defined (PLATFORM_WIN32)
4831 #ifndef CSIDL_FLAG_CREATE
4832 #define CSIDL_FLAG_CREATE 0x8000
4835 WCHAR path [MAX_PATH];
4836 /* Create directory if no existing */
4837 if (SUCCEEDED (SHGetFolderPathW (NULL, folder | CSIDL_FLAG_CREATE, NULL, 0, path))) {
4841 return mono_string_new_utf16 (mono_domain_get (), path, len);
4844 g_warning ("ves_icall_System_Environment_GetWindowsFolderPath should only be called on Windows!");
4846 return mono_string_new (mono_domain_get (), "");
4850 ves_icall_System_Environment_GetLogicalDrives (void)
4852 gunichar2 buf [128], *ptr, *dname;
4854 gint initial_size = 127, size = 128;
4857 MonoString *drivestr;
4858 MonoDomain *domain = mono_domain_get ();
4860 MONO_ARCH_SAVE_REGS;
4865 while (size > initial_size) {
4866 size = GetLogicalDriveStrings (initial_size, ptr);
4867 if (size > initial_size) {
4870 ptr = g_malloc0 ((size + 1) * sizeof (gunichar2));
4871 initial_size = size;
4885 result = mono_array_new (domain, mono_defaults.string_class, ndrives);
4888 u8 = g_utf16_to_utf8 (dname, -1, NULL, NULL, NULL);
4889 drivestr = mono_string_new (domain, u8);
4891 mono_array_set (result, gpointer, ndrives++, drivestr);
4902 ves_icall_System_Environment_InternalGetHome (void)
4904 MONO_ARCH_SAVE_REGS;
4906 return mono_string_new (mono_domain_get (), g_get_home_dir ());
4909 static const char *encodings [] = {
4911 "ascii", "us_ascii", "us", "ansi_x3.4_1968",
4912 "ansi_x3.4_1986", "cp367", "csascii", "ibm367",
4913 "iso_ir_6", "iso646_us", "iso_646.irv:1991",
4915 "utf_7", "csunicode11utf7", "unicode_1_1_utf_7",
4916 "unicode_2_0_utf_7", "x_unicode_1_1_utf_7",
4917 "x_unicode_2_0_utf_7",
4919 "utf_8", "unicode_1_1_utf_8", "unicode_2_0_utf_8",
4920 "x_unicode_1_1_utf_8", "x_unicode_2_0_utf_8",
4922 "utf_16", "UTF_16LE", "ucs_2", "unicode",
4925 "unicodefffe", "utf_16be",
4932 * Returns the internal codepage, if the value of "int_code_page" is
4933 * 1 at entry, and we can not compute a suitable code page number,
4934 * returns the code page as a string
4937 ves_icall_System_Text_Encoding_InternalCodePage (gint32 *int_code_page)
4942 char *codepage = NULL;
4944 int want_name = *int_code_page;
4947 *int_code_page = -1;
4948 MONO_ARCH_SAVE_REGS;
4950 g_get_charset (&cset);
4951 c = codepage = strdup (cset);
4952 for (c = codepage; *c; c++){
4953 if (isascii (*c) && isalpha (*c))
4958 /* g_print ("charset: %s\n", cset); */
4960 /* handle some common aliases */
4963 for (i = 0; p != 0; ){
4966 p = encodings [++i];
4969 if (strcmp (p, codepage) == 0){
4970 *int_code_page = code;
4973 p = encodings [++i];
4976 if (strstr (codepage, "utf_8") != NULL)
4977 *int_code_page |= 0x10000000;
4980 if (want_name && *int_code_page == -1)
4981 return mono_string_new (mono_domain_get (), cset);
4987 ves_icall_System_Environment_get_HasShutdownStarted (void)
4989 if (mono_runtime_is_shutting_down ())
4992 if (mono_domain_is_unloading (mono_domain_get ()))
4999 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
5000 MonoReflectionMethod *method,
5001 MonoArray *out_args)
5003 MONO_ARCH_SAVE_REGS;
5005 mono_message_init (mono_object_domain (this), this, method, out_args);
5009 ves_icall_IsTransparentProxy (MonoObject *proxy)
5011 MONO_ARCH_SAVE_REGS;
5016 if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
5023 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
5028 MONO_ARCH_SAVE_REGS;
5030 klass = mono_class_from_mono_type (type->type);
5031 vtable = mono_class_vtable (mono_domain_get (), klass);
5033 if (enable) vtable->remote = 1;
5034 else vtable->remote = 0;
5038 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType *type)
5043 MONO_ARCH_SAVE_REGS;
5045 domain = mono_object_domain (type);
5046 klass = mono_class_from_mono_type (type->type);
5048 if (klass->rank >= 1) {
5049 g_assert (klass->rank == 1);
5050 return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
5052 /* Bypass remoting object creation check */
5053 return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
5058 ves_icall_System_IO_get_temp_path (void)
5060 MONO_ARCH_SAVE_REGS;
5062 return mono_string_new (mono_domain_get (), g_get_tmp_dir ());
5066 ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
5068 MONO_ARCH_SAVE_REGS;
5070 return mono_compile_method (method);
5074 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
5079 MONO_ARCH_SAVE_REGS;
5081 path = g_build_path (G_DIR_SEPARATOR_S, mono_get_config_dir (), "mono", mono_get_framework_version (), "machine.config", NULL);
5083 #if defined (PLATFORM_WIN32)
5084 /* Avoid mixing '/' and '\\' */
5087 for (i = strlen (path) - 1; i >= 0; i--)
5088 if (path [i] == '/')
5092 mcpath = mono_string_new (mono_domain_get (), path);
5099 ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
5104 MONO_ARCH_SAVE_REGS;
5106 path = g_path_get_dirname (mono_get_config_dir ());
5108 #if defined (PLATFORM_WIN32)
5109 /* Avoid mixing '/' and '\\' */
5112 for (i = strlen (path) - 1; i >= 0; i--)
5113 if (path [i] == '/')
5117 ipath = mono_string_new (mono_domain_get (), path);
5124 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
5126 #if defined (PLATFORM_WIN32)
5127 static void (*output_debug) (gchar *);
5128 static gboolean tried_loading = FALSE;
5130 MONO_ARCH_SAVE_REGS;
5132 if (!tried_loading && output_debug == NULL) {
5135 tried_loading = TRUE;
5136 k32 = g_module_open ("kernel32", G_MODULE_BIND_LAZY);
5138 gchar *error = g_strdup (g_module_error ());
5139 g_warning ("Failed to load kernel32.dll: %s\n", error);
5144 g_module_symbol (k32, "OutputDebugStringW", (gpointer *) &output_debug);
5145 if (!output_debug) {
5146 gchar *error = g_strdup (g_module_error ());
5147 g_warning ("Failed to load OutputDebugStringW: %s\n", error);
5153 if (output_debug == NULL)
5156 output_debug (mono_string_chars (message));
5158 g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
5162 /* Only used for value types */
5164 ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
5169 MONO_ARCH_SAVE_REGS;
5171 domain = mono_object_domain (type);
5172 klass = mono_class_from_mono_type (type->type);
5174 return mono_object_new (domain, klass);
5177 static MonoReflectionMethod *
5178 ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
5181 MonoMethod *method = m->method;
5182 MonoMethod *result = NULL;
5184 MONO_ARCH_SAVE_REGS;
5186 if (!(method->flags & METHOD_ATTRIBUTE_VIRTUAL) ||
5187 MONO_CLASS_IS_INTERFACE (method->klass) ||
5188 method->flags & METHOD_ATTRIBUTE_NEW_SLOT)
5191 if (method->klass == NULL || (klass = method->klass->parent) == NULL)
5194 if (klass->generic_inst)
5195 klass = mono_class_from_mono_type (klass->generic_inst->generic_type);
5197 while (result == NULL && klass != NULL && (klass->vtable_size > method->slot))
5199 result = klass->vtable [method->slot];
5200 if (result == NULL) {
5201 /* It is an abstract method */
5203 for (i=0; i<klass->method.count; i++) {
5204 if (klass->methods [i]->slot == method->slot) {
5205 result = klass->methods [i];
5210 klass = klass->parent;
5216 return mono_method_get_object (mono_domain_get (), result, NULL);
5220 mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
5222 MONO_ARCH_SAVE_REGS;
5224 iter->sig = *(MonoMethodSignature**)argsp;
5226 g_assert (iter->sig->sentinelpos <= iter->sig->param_count);
5227 g_assert (iter->sig->call_convention == MONO_CALL_VARARG);
5230 /* FIXME: it's not documented what start is exactly... */
5234 int i, align, arg_size;
5235 iter->args = argsp + sizeof (gpointer);
5236 for (i = 0; i < iter->sig->sentinelpos; ++i) {
5237 arg_size = mono_type_stack_size (iter->sig->params [i], &align);
5238 iter->args = (char*)iter->args + arg_size;
5241 iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
5243 /* g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos); */
5247 mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
5249 gint i, align, arg_size;
5251 MONO_ARCH_SAVE_REGS;
5253 i = iter->sig->sentinelpos + iter->next_arg;
5255 g_assert (i < iter->sig->param_count);
5257 res.type = iter->sig->params [i];
5258 res.klass = mono_class_from_mono_type (res.type);
5259 /* FIXME: endianess issue... */
5260 res.value = iter->args;
5261 arg_size = mono_type_stack_size (res.type, &align);
5262 iter->args = (char*)iter->args + arg_size;
5265 /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
5271 mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
5273 gint i, align, arg_size;
5275 MONO_ARCH_SAVE_REGS;
5277 i = iter->sig->sentinelpos + iter->next_arg;
5279 g_assert (i < iter->sig->param_count);
5281 while (i < iter->sig->param_count) {
5282 if (!mono_metadata_type_equal (type, iter->sig->params [i]))
5284 res.type = iter->sig->params [i];
5285 res.klass = mono_class_from_mono_type (res.type);
5286 /* FIXME: endianess issue... */
5287 res.value = iter->args;
5288 arg_size = mono_type_stack_size (res.type, &align);
5289 iter->args = (char*)iter->args + arg_size;
5291 /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
5294 /* g_print ("arg type 0x%02x not found\n", res.type->type); */
5303 mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
5306 MONO_ARCH_SAVE_REGS;
5308 i = iter->sig->sentinelpos + iter->next_arg;
5310 g_assert (i < iter->sig->param_count);
5312 return iter->sig->params [i];
5316 mono_TypedReference_ToObject (MonoTypedRef tref)
5318 MONO_ARCH_SAVE_REGS;
5320 if (MONO_TYPE_IS_REFERENCE (tref.type)) {
5321 MonoObject** objp = tref.value;
5325 return mono_value_box (mono_domain_get (), tref.klass, tref.value);
5329 prelink_method (MonoMethod *method)
5331 const char *exc_class, *exc_arg;
5332 if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
5334 mono_lookup_pinvoke_call (method, &exc_class, &exc_arg);
5336 mono_raise_exception(
5337 mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg ) );
5339 /* create the wrapper, too? */
5343 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod *method)
5345 MONO_ARCH_SAVE_REGS;
5346 prelink_method (method->method);
5350 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType *type)
5352 MonoClass *klass = mono_class_from_mono_type (type->type);
5354 MONO_ARCH_SAVE_REGS;
5356 mono_class_init (klass);
5357 for (i = 0; i < klass->method.count; ++i)
5358 prelink_method (klass->methods [i]);
5361 /* These parameters are "readonly" in corlib/System/Char.cs */
5363 ves_icall_System_Char_GetDataTablePointers (guint8 const **category_data,
5364 guint8 const **numeric_data,
5365 gdouble const **numeric_data_values,
5366 guint16 const **to_lower_data_low,
5367 guint16 const **to_lower_data_high,
5368 guint16 const **to_upper_data_low,
5369 guint16 const **to_upper_data_high)
5371 *category_data = CategoryData;
5372 *numeric_data = NumericData;
5373 *numeric_data_values = NumericDataValues;
5374 *to_lower_data_low = ToLowerDataLow;
5375 *to_lower_data_high = ToLowerDataHigh;
5376 *to_upper_data_low = ToUpperDataLow;
5377 *to_upper_data_high = ToUpperDataHigh;
5381 ves_icall_MonoDebugger_check_runtime_version (MonoString *fname)
5383 gchar *filename, *error = NULL;
5385 MONO_ARCH_SAVE_REGS;
5387 filename = mono_string_to_utf8 (fname);
5388 error = mono_debugger_check_runtime_version (filename);
5392 return mono_string_new (mono_domain_get (), error);
5405 const IcallEntry *icalls;
5409 static const IcallEntry activator_icalls [] = {
5410 {"CreateInstanceInternal", ves_icall_System_Activator_CreateInstanceInternal}
5412 static const IcallEntry appdomain_icalls [] = {
5413 {"ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly},
5414 {"GetAssemblies", ves_icall_System_AppDomain_GetAssemblies},
5415 {"GetData", ves_icall_System_AppDomain_GetData},
5416 {"InternalGetContext", ves_icall_System_AppDomain_InternalGetContext},
5417 {"InternalGetDefaultContext", ves_icall_System_AppDomain_InternalGetDefaultContext},
5418 {"InternalGetProcessGuid", ves_icall_System_AppDomain_InternalGetProcessGuid},
5419 {"InternalIsFinalizingForUnload", ves_icall_System_AppDomain_InternalIsFinalizingForUnload},
5420 {"InternalPopDomainRef", ves_icall_System_AppDomain_InternalPopDomainRef},
5421 {"InternalPushDomainRef", ves_icall_System_AppDomain_InternalPushDomainRef},
5422 {"InternalPushDomainRefByID", ves_icall_System_AppDomain_InternalPushDomainRefByID},
5423 {"InternalSetContext", ves_icall_System_AppDomain_InternalSetContext},
5424 {"InternalSetDomain", ves_icall_System_AppDomain_InternalSetDomain},
5425 {"InternalSetDomainByID", ves_icall_System_AppDomain_InternalSetDomainByID},
5426 {"InternalUnload", ves_icall_System_AppDomain_InternalUnload},
5427 {"LoadAssembly", ves_icall_System_AppDomain_LoadAssembly},
5428 {"LoadAssemblyRaw", ves_icall_System_AppDomain_LoadAssemblyRaw},
5429 {"SetData", ves_icall_System_AppDomain_SetData},
5430 {"createDomain", ves_icall_System_AppDomain_createDomain},
5431 {"getCurDomain", ves_icall_System_AppDomain_getCurDomain},
5432 {"getDomainByID", ves_icall_System_AppDomain_getDomainByID},
5433 {"getFriendlyName", ves_icall_System_AppDomain_getFriendlyName},
5434 {"getSetup", ves_icall_System_AppDomain_getSetup}
5437 static const IcallEntry argiterator_icalls [] = {
5438 {"IntGetNextArg()", mono_ArgIterator_IntGetNextArg},
5439 {"IntGetNextArg(intptr)", mono_ArgIterator_IntGetNextArgT},
5440 {"IntGetNextArgType", mono_ArgIterator_IntGetNextArgType},
5441 {"Setup", mono_ArgIterator_Setup}
5444 static const IcallEntry array_icalls [] = {
5445 {"ClearInternal", ves_icall_System_Array_ClearInternal},
5446 {"Clone", mono_array_clone},
5447 {"CreateInstanceImpl", ves_icall_System_Array_CreateInstanceImpl},
5448 {"FastCopy", ves_icall_System_Array_FastCopy},
5449 {"GetLength", ves_icall_System_Array_GetLength},
5450 {"GetLowerBound", ves_icall_System_Array_GetLowerBound},
5451 {"GetRank", ves_icall_System_Array_GetRank},
5452 {"GetValue", ves_icall_System_Array_GetValue},
5453 {"GetValueImpl", ves_icall_System_Array_GetValueImpl},
5454 {"SetValue", ves_icall_System_Array_SetValue},
5455 {"SetValueImpl", ves_icall_System_Array_SetValueImpl}
5458 static const IcallEntry buffer_icalls [] = {
5459 {"BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal},
5460 {"ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal},
5461 {"GetByteInternal", ves_icall_System_Buffer_GetByteInternal},
5462 {"SetByteInternal", ves_icall_System_Buffer_SetByteInternal}
5465 static const IcallEntry char_icalls [] = {
5466 {"GetDataTablePointers", ves_icall_System_Char_GetDataTablePointers},
5467 {"InternalToLower(char,System.Globalization.CultureInfo)", ves_icall_System_Char_InternalToLower_Comp},
5468 {"InternalToUpper(char,System.Globalization.CultureInfo)", ves_icall_System_Char_InternalToUpper_Comp}
5471 static const IcallEntry defaultconf_icalls [] = {
5472 {"get_machine_config_path", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path}
5475 static const IcallEntry timezone_icalls [] = {
5476 {"GetTimeZoneData", ves_icall_System_CurrentTimeZone_GetTimeZoneData}
5479 static const IcallEntry datetime_icalls [] = {
5480 {"GetNow", ves_icall_System_DateTime_GetNow}
5483 static const IcallEntry decimal_icalls [] = {
5484 {"decimal2Int64", mono_decimal2Int64},
5485 {"decimal2UInt64", mono_decimal2UInt64},
5486 {"decimal2double", mono_decimal2double},
5487 {"decimal2string", mono_decimal2string},
5488 {"decimalCompare", mono_decimalCompare},
5489 {"decimalDiv", mono_decimalDiv},
5490 {"decimalFloorAndTrunc", mono_decimalFloorAndTrunc},
5491 {"decimalIncr", mono_decimalIncr},
5492 {"decimalIntDiv", mono_decimalIntDiv},
5493 {"decimalMult", mono_decimalMult},
5494 {"decimalRound", mono_decimalRound},
5495 {"decimalSetExponent", mono_decimalSetExponent},
5496 {"double2decimal", mono_double2decimal}, /* FIXME: wrong signature. */
5497 {"string2decimal", mono_string2decimal}
5500 static const IcallEntry delegate_icalls [] = {
5501 {"CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal},
5502 {"FreeTrampoline", ves_icall_System_Delegate_FreeTrampoline}
5505 static const IcallEntry tracelist_icalls [] = {
5506 {"WriteWindowsDebugString", ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString}
5509 static const IcallEntry fileversion_icalls [] = {
5510 {"GetVersionInfo_internal(string)", ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal}
5513 static const IcallEntry process_icalls [] = {
5514 {"ExitCode_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitCode_internal},
5515 {"ExitTime_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitTime_internal},
5516 {"GetModules_internal()", ves_icall_System_Diagnostics_Process_GetModules_internal},
5517 {"GetPid_internal()", ves_icall_System_Diagnostics_Process_GetPid_internal},
5518 {"GetProcess_internal(int)", ves_icall_System_Diagnostics_Process_GetProcess_internal},
5519 {"GetProcesses_internal()", ves_icall_System_Diagnostics_Process_GetProcesses_internal},
5520 {"GetWorkingSet_internal(intptr,int&,int&)", ves_icall_System_Diagnostics_Process_GetWorkingSet_internal},
5521 {"Kill_internal", ves_icall_System_Diagnostics_Process_Kill_internal},
5522 {"ProcessName_internal(intptr)", ves_icall_System_Diagnostics_Process_ProcessName_internal},
5523 {"Process_free_internal(intptr)", ves_icall_System_Diagnostics_Process_Process_free_internal},
5524 {"SetWorkingSet_internal(intptr,int,int,bool)", ves_icall_System_Diagnostics_Process_SetWorkingSet_internal},
5525 {"StartTime_internal(intptr)", ves_icall_System_Diagnostics_Process_StartTime_internal},
5526 {"Start_internal(string,string,string,intptr,intptr,intptr,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_Start_internal},
5527 {"WaitForExit_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForExit_internal}
5530 static const IcallEntry double_icalls [] = {
5531 {"AssertEndianity", ves_icall_System_Double_AssertEndianity},
5532 {"ParseImpl", mono_double_ParseImpl}
5535 static const IcallEntry enum_icalls [] = {
5536 {"ToObject", ves_icall_System_Enum_ToObject},
5537 {"get_value", ves_icall_System_Enum_get_value}
5540 static const IcallEntry environment_icalls [] = {
5541 {"Exit", ves_icall_System_Environment_Exit},
5542 {"GetCommandLineArgs", mono_runtime_get_main_args},
5543 {"GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable},
5544 {"GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames},
5545 {"GetLogicalDrivesInternal", ves_icall_System_Environment_GetLogicalDrives },
5546 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
5547 {"GetOSVersionString", ves_icall_System_Environment_GetOSVersionString},
5548 {"GetWindowsFolderPath", ves_icall_System_Environment_GetWindowsFolderPath},
5549 {"get_ExitCode", mono_environment_exitcode_get},
5550 {"get_HasShutdownStarted", ves_icall_System_Environment_get_HasShutdownStarted},
5551 {"get_MachineName", ves_icall_System_Environment_get_MachineName},
5552 {"get_NewLine", ves_icall_System_Environment_get_NewLine},
5553 {"get_Platform", ves_icall_System_Environment_get_Platform},
5554 {"get_TickCount", ves_icall_System_Environment_get_TickCount},
5555 {"get_UserName", ves_icall_System_Environment_get_UserName},
5556 {"internalGetGacPath", ves_icall_System_Environment_GetGacPath},
5557 {"internalGetHome", ves_icall_System_Environment_InternalGetHome},
5558 {"set_ExitCode", mono_environment_exitcode_set}
5561 static const IcallEntry cultureinfo_icalls [] = {
5562 {"construct_compareinfo(object,string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
5563 {"construct_datetime_format", ves_icall_System_Globalization_CultureInfo_construct_datetime_format},
5564 {"construct_internal_locale(string)", ves_icall_System_Globalization_CultureInfo_construct_internal_locale},
5565 {"construct_internal_locale_from_current_locale", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_current_locale},
5566 {"construct_internal_locale_from_lcid", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_lcid},
5567 {"construct_internal_locale_from_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name},
5568 {"construct_internal_locale_from_specific_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_specific_name},
5569 {"construct_number_format", ves_icall_System_Globalization_CultureInfo_construct_number_format},
5570 {"internal_get_cultures", ves_icall_System_Globalization_CultureInfo_internal_get_cultures},
5571 {"internal_is_lcid_neutral", ves_icall_System_Globalization_CultureInfo_internal_is_lcid_neutral}
5574 static const IcallEntry compareinfo_icalls [] = {
5575 {"assign_sortkey(object,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_assign_sortkey},
5576 {"construct_compareinfo(string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
5577 {"free_internal_collator()", ves_icall_System_Globalization_CompareInfo_free_internal_collator},
5578 {"internal_compare(string,int,int,string,int,int,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_internal_compare},
5579 {"internal_index(string,int,int,char,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index_char},
5580 {"internal_index(string,int,int,string,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index}
5583 static const IcallEntry gc_icalls [] = {
5584 {"GetTotalMemory", ves_icall_System_GC_GetTotalMemory},
5585 {"InternalCollect", ves_icall_System_GC_InternalCollect},
5586 {"KeepAlive", ves_icall_System_GC_KeepAlive},
5587 {"ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize},
5588 {"SuppressFinalize", ves_icall_System_GC_SuppressFinalize},
5589 {"WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers}
5592 static const IcallEntry famwatcher_icalls [] = {
5593 {"InternalFAMNextEvent", ves_icall_System_IO_FAMW_InternalFAMNextEvent}
5596 static const IcallEntry filewatcher_icalls [] = {
5597 {"InternalCloseDirectory", ves_icall_System_IO_FSW_CloseDirectory},
5598 {"InternalOpenDirectory", ves_icall_System_IO_FSW_OpenDirectory},
5599 {"InternalReadDirectoryChanges", ves_icall_System_IO_FSW_ReadDirectoryChanges},
5600 {"InternalSupportsFSW", ves_icall_System_IO_FSW_SupportsFSW}
5603 static const IcallEntry path_icalls [] = {
5604 {"get_temp_path", ves_icall_System_IO_get_temp_path}
5607 static const IcallEntry monoio_icalls [] = {
5608 {"BeginRead", ves_icall_System_IO_MonoIO_BeginRead },
5609 {"BeginWrite", ves_icall_System_IO_MonoIO_BeginWrite },
5610 {"Close(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Close},
5611 {"CopyFile(string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CopyFile},
5612 {"CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CreateDirectory},
5613 {"CreatePipe(intptr&,intptr&)", ves_icall_System_IO_MonoIO_CreatePipe},
5614 {"DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile},
5615 {"FindClose(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindClose},
5616 {"FindFirstFile(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindFirstFile},
5617 {"FindNextFile(intptr,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindNextFile},
5618 {"Flush(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush},
5619 {"GetCurrentDirectory(System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetCurrentDirectory},
5620 {"GetFileAttributes(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileAttributes},
5621 {"GetFileStat(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileStat},
5622 {"GetFileType(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType},
5623 {"GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength},
5624 {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
5625 {"GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath},
5626 {"Lock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Lock},
5627 {"MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile},
5628 {"Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open},
5629 {"Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read},
5630 {"RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory},
5631 {"Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek},
5632 {"SetCurrentDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetCurrentDirectory},
5633 {"SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes},
5634 {"SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime},
5635 {"SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength},
5636 {"Unlock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Unlock},
5637 {"Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write},
5638 {"get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar},
5639 {"get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError},
5640 {"get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput},
5641 {"get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput},
5642 {"get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar},
5643 {"get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars},
5644 {"get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator},
5645 {"get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar}
5648 static const IcallEntry math_icalls [] = {
5649 {"Acos", ves_icall_System_Math_Acos},
5650 {"Asin", ves_icall_System_Math_Asin},
5651 {"Atan", ves_icall_System_Math_Atan},
5652 {"Atan2", ves_icall_System_Math_Atan2},
5653 {"Cos", ves_icall_System_Math_Cos},
5654 {"Cosh", ves_icall_System_Math_Cosh},
5655 {"Exp", ves_icall_System_Math_Exp},
5656 {"Floor", ves_icall_System_Math_Floor},
5657 {"Log", ves_icall_System_Math_Log},
5658 {"Log10", ves_icall_System_Math_Log10},
5659 {"Pow", ves_icall_System_Math_Pow},
5660 {"Round", ves_icall_System_Math_Round},
5661 {"Round2", ves_icall_System_Math_Round2},
5662 {"Sin", ves_icall_System_Math_Sin},
5663 {"Sinh", ves_icall_System_Math_Sinh},
5664 {"Sqrt", ves_icall_System_Math_Sqrt},
5665 {"Tan", ves_icall_System_Math_Tan},
5666 {"Tanh", ves_icall_System_Math_Tanh}
5669 static const IcallEntry customattrs_icalls [] = {
5670 {"GetCustomAttributes", mono_reflection_get_custom_attrs}
5673 static const IcallEntry enuminfo_icalls [] = {
5674 {"get_enum_info", ves_icall_get_enum_info}
5677 static const IcallEntry fieldinfo_icalls [] = {
5678 {"internal_from_handle", ves_icall_System_Reflection_FieldInfo_internal_from_handle}
5681 static const IcallEntry memberinfo_icalls [] = {
5682 {"get_MetadataToken", mono_reflection_get_token}
5685 static const IcallEntry monotype_icalls [] = {
5686 {"GetArrayRank", ves_icall_MonoType_GetArrayRank},
5687 {"GetConstructors", ves_icall_Type_GetConstructors_internal},
5688 {"GetConstructors_internal", ves_icall_Type_GetConstructors_internal},
5689 {"GetElementType", ves_icall_MonoType_GetElementType},
5690 {"GetEvents_internal", ves_icall_Type_GetEvents_internal},
5691 {"GetField", ves_icall_Type_GetField},
5692 {"GetFields_internal", ves_icall_Type_GetFields_internal},
5693 {"GetGenericArguments", ves_icall_MonoType_GetGenericArguments},
5694 {"GetInterfaces", ves_icall_Type_GetInterfaces},
5695 {"GetMethodsByName", ves_icall_Type_GetMethodsByName},
5696 {"GetNestedType", ves_icall_Type_GetNestedType},
5697 {"GetNestedTypes", ves_icall_Type_GetNestedTypes},
5698 {"GetPropertiesByName", ves_icall_Type_GetPropertiesByName},
5699 {"InternalGetEvent", ves_icall_MonoType_GetEvent},
5700 {"IsByRefImpl", ves_icall_type_isbyref},
5701 {"IsPointerImpl", ves_icall_type_ispointer},
5702 {"IsPrimitiveImpl", ves_icall_type_isprimitive},
5703 {"getFullName", ves_icall_System_MonoType_getFullName},
5704 {"get_Assembly", ves_icall_MonoType_get_Assembly},
5705 {"get_BaseType", ves_icall_get_type_parent},
5706 {"get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod},
5707 {"get_DeclaringType", ves_icall_MonoType_get_DeclaringType},
5708 {"get_HasGenericArguments", ves_icall_MonoType_get_HasGenericArguments},
5709 {"get_IsGenericParameter", ves_icall_MonoType_get_IsGenericParameter},
5710 {"get_Module", ves_icall_MonoType_get_Module},
5711 {"get_Name", ves_icall_MonoType_get_Name},
5712 {"get_Namespace", ves_icall_MonoType_get_Namespace},
5713 {"get_UnderlyingSystemType", ves_icall_MonoType_get_UnderlyingSystemType},
5714 {"get_attributes", ves_icall_get_attributes},
5715 {"type_from_obj", mono_type_type_from_obj}
5718 static const IcallEntry assembly_icalls [] = {
5719 {"FillName", ves_icall_System_Reflection_Assembly_FillName},
5720 {"GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly},
5721 {"GetEntryAssembly", ves_icall_System_Reflection_Assembly_GetEntryAssembly},
5722 {"GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly},
5723 {"GetFilesInternal", ves_icall_System_Reflection_Assembly_GetFilesInternal},
5724 {"GetManifestResourceInfoInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal},
5725 {"GetManifestResourceInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInternal},
5726 {"GetManifestResourceNames", ves_icall_System_Reflection_Assembly_GetManifestResourceNames},
5727 {"GetModulesInternal", ves_icall_System_Reflection_Assembly_GetModulesInternal},
5728 {"GetNamespaces", ves_icall_System_Reflection_Assembly_GetNamespaces},
5729 {"GetReferencedAssemblies", ves_icall_System_Reflection_Assembly_GetReferencedAssemblies},
5730 {"GetTypes", ves_icall_System_Reflection_Assembly_GetTypes},
5731 {"InternalGetAssemblyName", ves_icall_System_Reflection_Assembly_InternalGetAssemblyName},
5732 {"InternalGetType", ves_icall_System_Reflection_Assembly_InternalGetType},
5733 {"InternalImageRuntimeVersion", ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion},
5734 {"LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom},
5736 * Private icalls for the Mono Debugger
5738 {"MonoDebugger_CheckRuntimeVersion", ves_icall_MonoDebugger_check_runtime_version},
5739 {"MonoDebugger_GetLocalTypeFromSignature", ves_icall_MonoDebugger_GetLocalTypeFromSignature},
5740 {"MonoDebugger_GetMethod", ves_icall_MonoDebugger_GetMethod},
5741 {"MonoDebugger_GetMethodToken", ves_icall_MonoDebugger_GetMethodToken},
5742 {"MonoDebugger_GetType", ves_icall_MonoDebugger_GetType},
5744 /* normal icalls again */
5745 {"get_EntryPoint", ves_icall_System_Reflection_Assembly_get_EntryPoint},
5746 {"get_ManifestModule", ves_icall_System_Reflection_Assembly_get_ManifestModule},
5747 {"get_MetadataToken", mono_reflection_get_token},
5748 {"get_code_base", ves_icall_System_Reflection_Assembly_get_code_base},
5749 {"get_global_assembly_cache", ves_icall_System_Reflection_Assembly_get_global_assembly_cache},
5750 {"get_location", ves_icall_System_Reflection_Assembly_get_location},
5751 {"load_with_partial_name", ves_icall_System_Reflection_Assembly_load_with_partial_name}
5754 static const IcallEntry methodbase_icalls [] = {
5755 {"GetCurrentMethod", ves_icall_GetCurrentMethod},
5756 {"GetMethodFromHandleInternal", ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternal}
5759 static const IcallEntry module_icalls [] = {
5760 {"Close", ves_icall_System_Reflection_Module_Close},
5761 {"GetGlobalType", ves_icall_System_Reflection_Module_GetGlobalType},
5762 {"GetGuidInternal", ves_icall_System_Reflection_Module_GetGuidInternal},
5763 {"GetPEKind", ves_icall_System_Reflection_Module_GetPEKind},
5764 {"InternalGetTypes", ves_icall_System_Reflection_Module_InternalGetTypes},
5765 {"ResolveFieldToken", ves_icall_System_Reflection_Module_ResolveFieldToken},
5766 {"ResolveMemberToken", ves_icall_System_Reflection_Module_ResolveMemberToken},
5767 {"ResolveMethodToken", ves_icall_System_Reflection_Module_ResolveMethodToken},
5768 {"ResolveStringToken", ves_icall_System_Reflection_Module_ResolveStringToken},
5769 {"ResolveTypeToken", ves_icall_System_Reflection_Module_ResolveTypeToken},
5770 {"get_MetadataToken", mono_reflection_get_token}
5773 static const IcallEntry monocmethod_icalls [] = {
5774 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
5775 {"InternalInvoke", ves_icall_InternalInvoke},
5776 {"get_Mono_IsInflatedMethod", ves_icall_MonoMethod_get_Mono_IsInflatedMethod}
5779 static const IcallEntry monoeventinfo_icalls [] = {
5780 {"get_event_info", ves_icall_get_event_info}
5783 static const IcallEntry monofield_icalls [] = {
5784 {"GetParentType", ves_icall_MonoField_GetParentType},
5785 {"GetValueInternal", ves_icall_MonoField_GetValueInternal},
5786 {"Mono_GetGenericFieldDefinition", ves_icall_MonoField_Mono_GetGenericFieldDefinition},
5787 {"SetValueInternal", ves_icall_FieldInfo_SetValueInternal}
5790 static const IcallEntry monogenericinst_icalls [] = {
5791 {"GetConstructors_internal", ves_icall_MonoGenericInst_GetConstructors},
5792 {"GetEvents_internal", ves_icall_MonoGenericInst_GetEvents},
5793 {"GetFields_internal", ves_icall_MonoGenericInst_GetFields},
5794 {"GetInterfaces_internal", ves_icall_MonoGenericInst_GetInterfaces},
5795 {"GetMethods_internal", ves_icall_MonoGenericInst_GetMethods},
5796 {"GetParentType", ves_icall_MonoGenericInst_GetParentType},
5797 {"GetProperties_internal", ves_icall_MonoGenericInst_GetProperties},
5798 {"initialize", mono_reflection_generic_inst_initialize}
5801 static const IcallEntry generictypeparambuilder_icalls [] = {
5802 {"initialize", mono_reflection_initialize_generic_parameter}
5805 static const IcallEntry monomethod_icalls [] = {
5806 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters},
5807 {"GetGenericArguments", ves_icall_MonoMethod_GetGenericArguments},
5808 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
5809 {"InternalInvoke", ves_icall_InternalInvoke},
5810 {"get_HasGenericParameters", ves_icall_MonoMethod_get_HasGenericParameters},
5811 {"get_IsGenericMethodDefinition", ves_icall_MonoMethod_get_IsGenericMethodDefinition},
5812 {"get_Mono_IsInflatedMethod", ves_icall_MonoMethod_get_Mono_IsInflatedMethod},
5813 {"get_base_definition", ves_icall_MonoMethod_get_base_definition}
5816 static const IcallEntry monomethodinfo_icalls [] = {
5817 {"get_method_info", ves_icall_get_method_info},
5818 {"get_parameter_info", ves_icall_get_parameter_info}
5821 static const IcallEntry monopropertyinfo_icalls [] = {
5822 {"get_property_info", ves_icall_get_property_info}
5825 static const IcallEntry parameterinfo_icalls [] = {
5826 {"get_MetadataToken", mono_reflection_get_token}
5829 static const IcallEntry dns_icalls [] = {
5830 {"GetHostByAddr_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByAddr_internal},
5831 {"GetHostByName_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByName_internal},
5832 {"GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal}
5835 static const IcallEntry socket_icalls [] = {
5836 {"Accept_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Accept_internal},
5837 {"AsyncReceiveInternal", ves_icall_System_Net_Sockets_Socket_AsyncReceive},
5838 {"AsyncSendInternal", ves_icall_System_Net_Sockets_Socket_AsyncSend},
5839 {"Available_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Available_internal},
5840 {"Bind_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Bind_internal},
5841 {"Blocking_internal(intptr,bool,int&)", ves_icall_System_Net_Sockets_Socket_Blocking_internal},
5842 {"Close_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Close_internal},
5843 {"Connect_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Connect_internal},
5844 {"GetSocketOption_arr_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,byte[]&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal},
5845 {"GetSocketOption_obj_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal},
5846 {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
5847 {"Listen_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_Listen_internal},
5848 {"LocalEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal},
5849 {"Poll_internal", ves_icall_System_Net_Sockets_Socket_Poll_internal},
5850 {"Receive_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Receive_internal},
5851 {"RecvFrom_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal},
5852 {"RemoteEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal},
5853 {"Select_internal(System.Net.Sockets.Socket[]&,System.Net.Sockets.Socket[]&,System.Net.Sockets.Socket[]&,int,int&)", ves_icall_System_Net_Sockets_Socket_Select_internal},
5854 {"SendTo_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_SendTo_internal},
5855 {"Send_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Send_internal},
5856 {"SetSocketOption_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object,byte[],int,int&)", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal},
5857 {"Shutdown_internal(intptr,System.Net.Sockets.SocketShutdown,int&)", ves_icall_System_Net_Sockets_Socket_Shutdown_internal},
5858 {"Socket_internal(System.Net.Sockets.AddressFamily,System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,int&)", ves_icall_System_Net_Sockets_Socket_Socket_internal},
5859 {"WSAIoctl(intptr,int,byte[],byte[],int&)", ves_icall_System_Net_Sockets_Socket_WSAIoctl}
5862 static const IcallEntry socketex_icalls [] = {
5863 {"WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal}
5866 static const IcallEntry object_icalls [] = {
5867 {"GetType", ves_icall_System_Object_GetType},
5868 {"InternalGetHashCode", ves_icall_System_Object_GetHashCode},
5869 {"MemberwiseClone", ves_icall_System_Object_MemberwiseClone},
5870 {"obj_address", ves_icall_System_Object_obj_address}
5873 static const IcallEntry assemblybuilder_icalls[] = {
5874 {"InternalAddModule", mono_image_load_module},
5875 {"basic_init", mono_image_basic_init}
5878 static const IcallEntry customattrbuilder_icalls [] = {
5879 {"GetBlob", mono_reflection_get_custom_attrs_blob}
5882 static const IcallEntry dynamicmethod_icalls [] = {
5883 {"create_dynamic_method", mono_reflection_create_dynamic_method}
5886 static const IcallEntry methodbuilder_icalls [] = {
5887 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters}
5890 static const IcallEntry modulebuilder_icalls [] = {
5891 {"basic_init", mono_image_module_basic_init},
5892 {"build_metadata", ves_icall_ModuleBuilder_build_metadata},
5893 {"create_modified_type", ves_icall_ModuleBuilder_create_modified_type},
5894 {"getDataChunk", ves_icall_ModuleBuilder_getDataChunk},
5895 {"getMethodToken", ves_icall_ModuleBuilder_getMethodToken},
5896 {"getToken", ves_icall_ModuleBuilder_getToken},
5897 {"getUSIndex", mono_image_insert_string}
5900 static const IcallEntry signaturehelper_icalls [] = {
5901 {"get_signature_field", mono_reflection_sighelper_get_signature_field},
5902 {"get_signature_local", mono_reflection_sighelper_get_signature_local}
5905 static const IcallEntry typebuilder_icalls [] = {
5906 {"create_internal_class", mono_reflection_create_internal_class},
5907 {"create_runtime_class", mono_reflection_create_runtime_class},
5908 {"get_IsGenericParameter", ves_icall_TypeBuilder_get_IsGenericParameter},
5909 {"get_event_info", mono_reflection_event_builder_get_event_info},
5910 {"setup_generic_class", mono_reflection_setup_generic_class},
5911 {"setup_internal_class", mono_reflection_setup_internal_class}
5914 static const IcallEntry enumbuilder_icalls [] = {
5915 {"setup_enum_type", ves_icall_EnumBuilder_setup_enum_type}
5918 static const IcallEntry runtimehelpers_icalls [] = {
5919 {"GetObjectValue", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue},
5920 /* REMOVEME: no longer needed, just so we dont break things when not needed */
5921 {"GetOffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData},
5922 {"InitializeArray", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray},
5923 {"RunClassConstructor", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor},
5924 {"get_OffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData}
5927 static const IcallEntry gchandle_icalls [] = {
5928 {"FreeHandle", ves_icall_System_GCHandle_FreeHandle},
5929 {"GetAddrOfPinnedObject", ves_icall_System_GCHandle_GetAddrOfPinnedObject},
5930 {"GetTarget", ves_icall_System_GCHandle_GetTarget},
5931 {"GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle}
5934 static const IcallEntry marshal_icalls [] = {
5935 {"AllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem},
5936 {"AllocHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_AllocHGlobal},
5937 {"DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure},
5938 {"FreeCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem},
5939 {"FreeHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_FreeHGlobal},
5940 {"GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error},
5941 {"OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf},
5942 {"Prelink", ves_icall_System_Runtime_InteropServices_Marshal_Prelink},
5943 {"PrelinkAll", ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll},
5944 {"PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
5945 {"PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
5946 {"PtrToStringAuto(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
5947 {"PtrToStringAuto(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
5948 {"PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR},
5949 {"PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni},
5950 {"PtrToStringUni(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len},
5951 {"PtrToStructure(intptr,System.Type)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type},
5952 {"PtrToStructure(intptr,object)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure},
5953 {"ReAllocHGlobal", mono_marshal_realloc},
5954 {"ReadByte", ves_icall_System_Runtime_InteropServices_Marshal_ReadByte},
5955 {"ReadInt16", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt16},
5956 {"ReadInt32", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt32},
5957 {"ReadInt64", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64},
5958 {"ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr},
5959 {"SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf},
5960 {"StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
5961 {"StringToHGlobalAuto", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
5962 {"StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni},
5963 {"StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr},
5964 {"UnsafeAddrOfPinnedArrayElement", ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement},
5965 {"WriteByte", ves_icall_System_Runtime_InteropServices_Marshal_WriteByte},
5966 {"WriteInt16", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt16},
5967 {"WriteInt32", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt32},
5968 {"WriteInt64", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt64},
5969 {"WriteIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_WriteIntPtr},
5970 {"copy_from_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged},
5971 {"copy_to_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged}
5974 static const IcallEntry activationservices_icalls [] = {
5975 {"AllocateUninitializedClassInstance", ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance},
5976 {"EnableProxyActivation", ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation}
5979 static const IcallEntry monomethodmessage_icalls [] = {
5980 {"InitMessage", ves_icall_MonoMethodMessage_InitMessage}
5983 static const IcallEntry realproxy_icalls [] = {
5984 {"InternalGetProxyType", ves_icall_Remoting_RealProxy_InternalGetProxyType},
5985 {"InternalGetTransparentProxy", ves_icall_Remoting_RealProxy_GetTransparentProxy}
5988 static const IcallEntry remotingservices_icalls [] = {
5989 {"InternalExecute", ves_icall_InternalExecute},
5990 {"IsTransparentProxy", ves_icall_IsTransparentProxy}
5993 static const IcallEntry rng_icalls [] = {
5994 {"RngClose", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose},
5995 {"RngGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes},
5996 {"RngInitialize", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize}
5999 static const IcallEntry methodhandle_icalls [] = {
6000 {"GetFunctionPointer", ves_icall_RuntimeMethod_GetFunctionPointer}
6003 static const IcallEntry string_icalls [] = {
6004 {".ctor(char*)", ves_icall_System_String_ctor_charp},
6005 {".ctor(char*,int,int)", ves_icall_System_String_ctor_charp_int_int},
6006 {".ctor(char,int)", ves_icall_System_String_ctor_char_int},
6007 {".ctor(char[])", ves_icall_System_String_ctor_chara},
6008 {".ctor(char[],int,int)", ves_icall_System_String_ctor_chara_int_int},
6009 {".ctor(sbyte*)", ves_icall_System_String_ctor_sbytep},
6010 {".ctor(sbyte*,int,int)", ves_icall_System_String_ctor_sbytep_int_int},
6011 {".ctor(sbyte*,int,int,System.Text.Encoding)", ves_icall_System_String_ctor_encoding},
6012 {"GetHashCode", ves_icall_System_String_GetHashCode},
6013 {"InternalAllocateStr", ves_icall_System_String_InternalAllocateStr},
6014 {"InternalCharCopy", ves_icall_System_String_InternalCharCopy},
6015 {"InternalCopyTo", ves_icall_System_String_InternalCopyTo},
6016 {"InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny},
6017 {"InternalInsert", ves_icall_System_String_InternalInsert},
6018 {"InternalIntern", ves_icall_System_String_InternalIntern},
6019 {"InternalIsInterned", ves_icall_System_String_InternalIsInterned},
6020 {"InternalJoin", ves_icall_System_String_InternalJoin},
6021 {"InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny},
6022 {"InternalPad", ves_icall_System_String_InternalPad},
6023 {"InternalRemove", ves_icall_System_String_InternalRemove},
6024 {"InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char},
6025 {"InternalReplace(string,string,System.Globalization.CompareInfo)", ves_icall_System_String_InternalReplace_Str_Comp},
6026 {"InternalSplit", ves_icall_System_String_InternalSplit},
6027 {"InternalStrcpy(string,int,char[])", ves_icall_System_String_InternalStrcpy_Chars},
6028 {"InternalStrcpy(string,int,char[],int,int)", ves_icall_System_String_InternalStrcpy_CharsN},
6029 {"InternalStrcpy(string,int,string)", ves_icall_System_String_InternalStrcpy_Str},
6030 {"InternalStrcpy(string,int,string,int,int)", ves_icall_System_String_InternalStrcpy_StrN},
6031 {"InternalToLower(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToLower_Comp},
6032 {"InternalToUpper(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToUpper_Comp},
6033 {"InternalTrim", ves_icall_System_String_InternalTrim},
6034 {"get_Chars", ves_icall_System_String_get_Chars}
6037 static const IcallEntry encoding_icalls [] = {
6038 {"InternalCodePage", ves_icall_System_Text_Encoding_InternalCodePage}
6041 static const IcallEntry monitor_icalls [] = {
6042 {"Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit},
6043 {"Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse},
6044 {"Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all},
6045 {"Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner},
6046 {"Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised},
6047 {"Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter},
6048 {"Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait}
6051 static const IcallEntry interlocked_icalls [] = {
6052 {"CompareExchange(int&,int,int)", ves_icall_System_Threading_Interlocked_CompareExchange_Int},
6053 {"CompareExchange(object&,object,object)", ves_icall_System_Threading_Interlocked_CompareExchange_Object},
6054 {"CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single},
6055 {"Decrement(int&)", ves_icall_System_Threading_Interlocked_Decrement_Int},
6056 {"Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long},
6057 {"Exchange(int&,int)", ves_icall_System_Threading_Interlocked_Exchange_Int},
6058 {"Exchange(object&,object)", ves_icall_System_Threading_Interlocked_Exchange_Object},
6059 {"Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single},
6060 {"Increment(int&)", ves_icall_System_Threading_Interlocked_Increment_Int},
6061 {"Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long}
6064 static const IcallEntry mutex_icalls [] = {
6065 {"CreateMutex_internal(bool,string,bool&)", ves_icall_System_Threading_Mutex_CreateMutex_internal},
6066 {"ReleaseMutex_internal(intptr)", ves_icall_System_Threading_Mutex_ReleaseMutex_internal}
6069 static const IcallEntry nativeevents_icalls [] = {
6070 {"CloseEvent_internal", ves_icall_System_Threading_Events_CloseEvent_internal},
6071 {"CreateEvent_internal", ves_icall_System_Threading_Events_CreateEvent_internal},
6072 {"ResetEvent_internal", ves_icall_System_Threading_Events_ResetEvent_internal},
6073 {"SetEvent_internal", ves_icall_System_Threading_Events_SetEvent_internal}
6076 static const IcallEntry thread_icalls [] = {
6077 {"Abort_internal(object)", ves_icall_System_Threading_Thread_Abort},
6078 {"CurrentThread_internal", mono_thread_current},
6079 {"GetDomainID", ves_icall_System_Threading_Thread_GetDomainID},
6080 {"GetName_internal", ves_icall_System_Threading_Thread_GetName_internal},
6081 {"Join_internal", ves_icall_System_Threading_Thread_Join_internal},
6082 {"ResetAbort_internal()", ves_icall_System_Threading_Thread_ResetAbort},
6083 {"Resume_internal()", ves_icall_System_Threading_Thread_Resume},
6084 {"SetName_internal", ves_icall_System_Threading_Thread_SetName_internal},
6085 {"Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal},
6086 {"SlotHash_lookup", ves_icall_System_Threading_Thread_SlotHash_lookup},
6087 {"SlotHash_store", ves_icall_System_Threading_Thread_SlotHash_store},
6088 {"Start_internal", ves_icall_System_Threading_Thread_Start_internal},
6089 {"Suspend_internal", ves_icall_System_Threading_Thread_Suspend},
6090 {"Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal},
6091 {"Thread_internal", ves_icall_System_Threading_Thread_Thread_internal},
6092 {"VolatileRead(byte&)", ves_icall_System_Threading_Thread_VolatileRead1},
6093 {"VolatileRead(double&)", ves_icall_System_Threading_Thread_VolatileRead8},
6094 {"VolatileRead(int&)", ves_icall_System_Threading_Thread_VolatileRead4},
6095 {"VolatileRead(int16&)", ves_icall_System_Threading_Thread_VolatileRead2},
6096 {"VolatileRead(intptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
6097 {"VolatileRead(long&)", ves_icall_System_Threading_Thread_VolatileRead8},
6098 {"VolatileRead(object&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
6099 {"VolatileRead(sbyte&)", ves_icall_System_Threading_Thread_VolatileRead1},
6100 {"VolatileRead(single&)", ves_icall_System_Threading_Thread_VolatileRead4},
6101 {"VolatileRead(uint&)", ves_icall_System_Threading_Thread_VolatileRead2},
6102 {"VolatileRead(uint16&)", ves_icall_System_Threading_Thread_VolatileRead2},
6103 {"VolatileRead(uintptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
6104 {"VolatileRead(ulong&)", ves_icall_System_Threading_Thread_VolatileRead8},
6105 {"VolatileWrite(byte&,byte)", ves_icall_System_Threading_Thread_VolatileWrite1},
6106 {"VolatileWrite(double&,double)", ves_icall_System_Threading_Thread_VolatileWrite8},
6107 {"VolatileWrite(int&,int)", ves_icall_System_Threading_Thread_VolatileWrite4},
6108 {"VolatileWrite(int16&,int16)", ves_icall_System_Threading_Thread_VolatileWrite2},
6109 {"VolatileWrite(intptr&,intptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
6110 {"VolatileWrite(long&,long)", ves_icall_System_Threading_Thread_VolatileWrite8},
6111 {"VolatileWrite(object&,object)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
6112 {"VolatileWrite(sbyte&,sbyte)", ves_icall_System_Threading_Thread_VolatileWrite1},
6113 {"VolatileWrite(single&,single)", ves_icall_System_Threading_Thread_VolatileWrite4},
6114 {"VolatileWrite(uint&,uint)", ves_icall_System_Threading_Thread_VolatileWrite2},
6115 {"VolatileWrite(uint16&,uint16)", ves_icall_System_Threading_Thread_VolatileWrite2},
6116 {"VolatileWrite(uintptr&,uintptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
6117 {"VolatileWrite(ulong&,ulong)", ves_icall_System_Threading_Thread_VolatileWrite8},
6118 {"current_lcid()", ves_icall_System_Threading_Thread_current_lcid}
6121 static const IcallEntry threadpool_icalls [] = {
6122 {"BindHandleInternal", ves_icall_System_Threading_ThreadPool_BindHandle},
6123 {"GetAvailableThreads", ves_icall_System_Threading_ThreadPool_GetAvailableThreads},
6124 {"GetMaxThreads", ves_icall_System_Threading_ThreadPool_GetMaxThreads},
6125 {"GetMinThreads", ves_icall_System_Threading_ThreadPool_GetMinThreads},
6126 {"SetMinThreads", ves_icall_System_Threading_ThreadPool_SetMinThreads}
6129 static const IcallEntry waithandle_icalls [] = {
6130 {"WaitAll_internal", ves_icall_System_Threading_WaitHandle_WaitAll_internal},
6131 {"WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny_internal},
6132 {"WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal}
6135 static const IcallEntry type_icalls [] = {
6136 {"BindGenericParameters", ves_icall_Type_BindGenericParameters},
6137 {"Equals", ves_icall_type_Equals},
6138 {"GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition},
6139 {"GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl},
6140 {"GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData},
6141 {"GetTypeCode", ves_icall_type_GetTypeCode},
6142 {"IsArrayImpl", ves_icall_Type_IsArrayImpl},
6143 {"IsInstanceOfType", ves_icall_type_IsInstanceOfType},
6144 {"get_IsGenericInstance", ves_icall_Type_get_IsGenericInstance},
6145 {"get_IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition},
6146 {"internal_from_handle", ves_icall_type_from_handle},
6147 {"internal_from_name", ves_icall_type_from_name},
6148 {"make_array_type", ves_icall_Type_make_array_type},
6149 {"make_byref_type", ves_icall_Type_make_byref_type},
6150 {"type_is_assignable_from", ves_icall_type_is_assignable_from},
6151 {"type_is_subtype_of", ves_icall_type_is_subtype_of}
6154 static const IcallEntry typedref_icalls [] = {
6155 {"ToObject", mono_TypedReference_ToObject}
6158 static const IcallEntry valuetype_icalls [] = {
6159 {"InternalEquals", ves_icall_System_ValueType_Equals},
6160 {"InternalGetHashCode", ves_icall_System_ValueType_InternalGetHashCode}
6163 static const IcallEntry web_icalls [] = {
6164 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
6165 {"GetMachineInstallDirectory", ves_icall_System_Web_Util_ICalls_get_machine_install_dir}
6168 static const IcallEntry identity_icalls [] = {
6169 {"GetCurrentToken", ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken},
6170 {"GetTokenName", ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName},
6171 {"GetUserToken", ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken},
6172 {"_GetRoles", ves_icall_System_Security_Principal_WindowsIdentity_GetRoles}
6175 static const IcallEntry impersonation_icalls [] = {
6176 {"CloseToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_CloseToken},
6177 {"DuplicateToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_DuplicateToken},
6178 {"RevertToSelf", ves_icall_System_Security_Principal_WindowsImpersonationContext_RevertToSelf},
6179 {"SetCurrentToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_SetCurrentToken}
6182 static const IcallEntry principal_icalls [] = {
6183 {"IsMemberOfGroupId", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupId},
6184 {"IsMemberOfGroupName", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupName}
6187 static const IcallEntry keypair_icalls [] = {
6188 {"_CanSecure", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_CanSecure},
6189 {"_IsMachineProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsMachineProtected},
6190 {"_IsUserProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsUserProtected},
6191 {"_ProtectMachine", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectMachine},
6192 {"_ProtectUser", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectUser}
6196 static const IcallEntry array_icalls [] = {
6201 /* keep the entries all sorted */
6202 static const IcallMap icall_entries [] = {
6203 {"Mono.Security.Cryptography.KeyPairPersistence", keypair_icalls, G_N_ELEMENTS (keypair_icalls)},
6204 {"System.Activator", activator_icalls, G_N_ELEMENTS (activator_icalls)},
6205 {"System.AppDomain", appdomain_icalls, G_N_ELEMENTS (appdomain_icalls)},
6206 {"System.ArgIterator", argiterator_icalls, G_N_ELEMENTS (argiterator_icalls)},
6207 {"System.Array", array_icalls, G_N_ELEMENTS (array_icalls)},
6208 {"System.Buffer", buffer_icalls, G_N_ELEMENTS (buffer_icalls)},
6209 {"System.Char", char_icalls, G_N_ELEMENTS (char_icalls)},
6210 {"System.Configuration.DefaultConfig", defaultconf_icalls, G_N_ELEMENTS (defaultconf_icalls)},
6211 {"System.CurrentTimeZone", timezone_icalls, G_N_ELEMENTS (timezone_icalls)},
6212 {"System.DateTime", datetime_icalls, G_N_ELEMENTS (datetime_icalls)},
6213 {"System.Decimal", decimal_icalls, G_N_ELEMENTS (decimal_icalls)},
6214 {"System.Delegate", delegate_icalls, G_N_ELEMENTS (delegate_icalls)},
6215 {"System.Diagnostics.DefaultTraceListener", tracelist_icalls, G_N_ELEMENTS (tracelist_icalls)},
6216 {"System.Diagnostics.FileVersionInfo", fileversion_icalls, G_N_ELEMENTS (fileversion_icalls)},
6217 {"System.Diagnostics.Process", process_icalls, G_N_ELEMENTS (process_icalls)},
6218 {"System.Double", double_icalls, G_N_ELEMENTS (double_icalls)},
6219 {"System.Enum", enum_icalls, G_N_ELEMENTS (enum_icalls)},
6220 {"System.Environment", environment_icalls, G_N_ELEMENTS (environment_icalls)},
6221 {"System.GC", gc_icalls, G_N_ELEMENTS (gc_icalls)},
6222 {"System.Globalization.CompareInfo", compareinfo_icalls, G_N_ELEMENTS (compareinfo_icalls)},
6223 {"System.Globalization.CultureInfo", cultureinfo_icalls, G_N_ELEMENTS (cultureinfo_icalls)},
6224 {"System.IO.FAMWatcher", famwatcher_icalls, G_N_ELEMENTS (famwatcher_icalls)},
6225 {"System.IO.FileSystemWatcher", filewatcher_icalls, G_N_ELEMENTS (filewatcher_icalls)},
6226 {"System.IO.MonoIO", monoio_icalls, G_N_ELEMENTS (monoio_icalls)},
6227 {"System.IO.Path", path_icalls, G_N_ELEMENTS (path_icalls)},
6228 {"System.Math", math_icalls, G_N_ELEMENTS (math_icalls)},
6229 {"System.MonoCustomAttrs", customattrs_icalls, G_N_ELEMENTS (customattrs_icalls)},
6230 {"System.MonoEnumInfo", enuminfo_icalls, G_N_ELEMENTS (enuminfo_icalls)},
6231 {"System.MonoType", monotype_icalls, G_N_ELEMENTS (monotype_icalls)},
6232 {"System.Net.Dns", dns_icalls, G_N_ELEMENTS (dns_icalls)},
6233 {"System.Net.Sockets.Socket", socket_icalls, G_N_ELEMENTS (socket_icalls)},
6234 {"System.Net.Sockets.SocketException", socketex_icalls, G_N_ELEMENTS (socketex_icalls)},
6235 {"System.Object", object_icalls, G_N_ELEMENTS (object_icalls)},
6236 {"System.Reflection.Assembly", assembly_icalls, G_N_ELEMENTS (assembly_icalls)},
6237 {"System.Reflection.Emit.AssemblyBuilder", assemblybuilder_icalls, G_N_ELEMENTS (assemblybuilder_icalls)},
6238 {"System.Reflection.Emit.CustomAttributeBuilder", customattrbuilder_icalls, G_N_ELEMENTS (customattrbuilder_icalls)},
6239 {"System.Reflection.Emit.DynamicMethod", dynamicmethod_icalls, G_N_ELEMENTS (dynamicmethod_icalls)},
6240 {"System.Reflection.Emit.EnumBuilder", enumbuilder_icalls, G_N_ELEMENTS (enumbuilder_icalls)},
6241 {"System.Reflection.Emit.GenericTypeParameterBuilder", generictypeparambuilder_icalls, G_N_ELEMENTS (generictypeparambuilder_icalls)},
6242 {"System.Reflection.Emit.MethodBuilder", methodbuilder_icalls, G_N_ELEMENTS (methodbuilder_icalls)},
6243 {"System.Reflection.Emit.ModuleBuilder", modulebuilder_icalls, G_N_ELEMENTS (modulebuilder_icalls)},
6244 {"System.Reflection.Emit.SignatureHelper", signaturehelper_icalls, G_N_ELEMENTS (signaturehelper_icalls)},
6245 {"System.Reflection.Emit.TypeBuilder", typebuilder_icalls, G_N_ELEMENTS (typebuilder_icalls)},
6246 {"System.Reflection.FieldInfo", fieldinfo_icalls, G_N_ELEMENTS (fieldinfo_icalls)},
6247 {"System.Reflection.MemberInfo", memberinfo_icalls, G_N_ELEMENTS (memberinfo_icalls)},
6248 {"System.Reflection.MethodBase", methodbase_icalls, G_N_ELEMENTS (methodbase_icalls)},
6249 {"System.Reflection.Module", module_icalls, G_N_ELEMENTS (module_icalls)},
6250 {"System.Reflection.MonoCMethod", monocmethod_icalls, G_N_ELEMENTS (monocmethod_icalls)},
6251 {"System.Reflection.MonoEventInfo", monoeventinfo_icalls, G_N_ELEMENTS (monoeventinfo_icalls)},
6252 {"System.Reflection.MonoField", monofield_icalls, G_N_ELEMENTS (monofield_icalls)},
6253 {"System.Reflection.MonoGenericInst", monogenericinst_icalls, G_N_ELEMENTS (monogenericinst_icalls)},
6254 {"System.Reflection.MonoMethod", monomethod_icalls, G_N_ELEMENTS (monomethod_icalls)},
6255 {"System.Reflection.MonoMethodInfo", monomethodinfo_icalls, G_N_ELEMENTS (monomethodinfo_icalls)},
6256 {"System.Reflection.MonoPropertyInfo", monopropertyinfo_icalls, G_N_ELEMENTS (monopropertyinfo_icalls)},
6257 {"System.Reflection.ParameterInfo", parameterinfo_icalls, G_N_ELEMENTS (parameterinfo_icalls)},
6258 {"System.Runtime.CompilerServices.RuntimeHelpers", runtimehelpers_icalls, G_N_ELEMENTS (runtimehelpers_icalls)},
6259 {"System.Runtime.InteropServices.GCHandle", gchandle_icalls, G_N_ELEMENTS (gchandle_icalls)},
6260 {"System.Runtime.InteropServices.Marshal", marshal_icalls, G_N_ELEMENTS (marshal_icalls)},
6261 {"System.Runtime.Remoting.Activation.ActivationServices", activationservices_icalls, G_N_ELEMENTS (activationservices_icalls)},
6262 {"System.Runtime.Remoting.Messaging.MonoMethodMessage", monomethodmessage_icalls, G_N_ELEMENTS (monomethodmessage_icalls)},
6263 {"System.Runtime.Remoting.Proxies.RealProxy", realproxy_icalls, G_N_ELEMENTS (realproxy_icalls)},
6264 {"System.Runtime.Remoting.RemotingServices", remotingservices_icalls, G_N_ELEMENTS (remotingservices_icalls)},
6265 {"System.RuntimeMethodHandle", methodhandle_icalls, G_N_ELEMENTS (methodhandle_icalls)},
6266 {"System.Security.Cryptography.RNGCryptoServiceProvider", rng_icalls, G_N_ELEMENTS (rng_icalls)},
6267 {"System.Security.Principal.WindowsIdentity", identity_icalls, G_N_ELEMENTS (identity_icalls)},
6268 {"System.Security.Principal.WindowsImpersonationContext", impersonation_icalls, G_N_ELEMENTS (impersonation_icalls)},
6269 {"System.Security.Principal.WindowsPrincipal", principal_icalls, G_N_ELEMENTS (principal_icalls)},
6270 {"System.String", string_icalls, G_N_ELEMENTS (string_icalls)},
6271 {"System.Text.Encoding", encoding_icalls, G_N_ELEMENTS (encoding_icalls)},
6272 {"System.Threading.Interlocked", interlocked_icalls, G_N_ELEMENTS (interlocked_icalls)},
6273 {"System.Threading.Monitor", monitor_icalls, G_N_ELEMENTS (monitor_icalls)},
6274 {"System.Threading.Mutex", mutex_icalls, G_N_ELEMENTS (mutex_icalls)},
6275 {"System.Threading.NativeEventCalls", nativeevents_icalls, G_N_ELEMENTS (nativeevents_icalls)},
6276 {"System.Threading.Thread", thread_icalls, G_N_ELEMENTS (thread_icalls)},
6277 {"System.Threading.ThreadPool", threadpool_icalls, G_N_ELEMENTS (threadpool_icalls)},
6278 {"System.Threading.WaitHandle", waithandle_icalls, G_N_ELEMENTS (waithandle_icalls)},
6279 {"System.Type", type_icalls, G_N_ELEMENTS (type_icalls)},
6280 {"System.TypedReference", typedref_icalls, G_N_ELEMENTS (typedref_icalls)},
6281 {"System.ValueType", valuetype_icalls, G_N_ELEMENTS (valuetype_icalls)},
6282 {"System.Web.Util.ICalls", web_icalls, G_N_ELEMENTS (web_icalls)}
6285 static GHashTable *icall_hash = NULL;
6286 static GHashTable *jit_icall_hash_name = NULL;
6287 static GHashTable *jit_icall_hash_addr = NULL;
6290 mono_init_icall (void)
6294 /* check that tables are sorted: disable in release */
6297 const IcallMap *imap;
6298 const IcallEntry *ientry;
6299 const char *prev_class = NULL;
6300 const char *prev_method;
6302 for (i = 0; i < G_N_ELEMENTS (icall_entries); ++i) {
6303 imap = &icall_entries [i];
6305 if (prev_class && strcmp (prev_class, imap->klass) >= 0)
6306 g_print ("class %s should come before class %s\n", imap->klass, prev_class);
6307 prev_class = imap->klass;
6308 for (j = 0; j < imap->size; ++j) {
6309 ientry = &imap->icalls [j];
6310 if (prev_method && strcmp (prev_method, ientry->method) >= 0)
6311 g_print ("method %s should come before method %s\n", ientry->method, prev_method);
6312 prev_method = ientry->method;
6317 icall_hash = g_hash_table_new (g_str_hash , g_str_equal);
6321 mono_add_internal_call (const char *name, gconstpointer method)
6323 mono_loader_lock ();
6325 g_hash_table_insert (icall_hash, g_strdup (name), (gpointer) method);
6327 mono_loader_unlock ();
6331 compare_class_imap (const void *key, const void *elem)
6333 const IcallMap* imap = (const IcallMap*)elem;
6334 return strcmp (key, imap->klass);
6337 static const IcallMap*
6338 find_class_icalls (const char *name)
6340 return (const IcallMap*) bsearch (name, icall_entries, G_N_ELEMENTS (icall_entries), sizeof (IcallMap), compare_class_imap);
6344 compare_method_imap (const void *key, const void *elem)
6346 const IcallEntry* ientry = (const IcallEntry*)elem;
6347 return strcmp (key, ientry->method);
6351 find_method_icall (const IcallMap *imap, const char *name)
6353 const IcallEntry *ientry = (const IcallEntry*) bsearch (name, imap->icalls, imap->size, sizeof (IcallEntry), compare_method_imap);
6355 return (void*)ientry->func;
6360 * we should probably export this as an helper (handle nested types).
6361 * Returns the number of chars written in buf.
6364 concat_class_name (char *buf, int bufsize, MonoClass *klass)
6366 int nspacelen, cnamelen;
6367 nspacelen = strlen (klass->name_space);
6368 cnamelen = strlen (klass->name);
6369 if (nspacelen + cnamelen + 2 > bufsize)
6372 memcpy (buf, klass->name_space, nspacelen);
6373 buf [nspacelen ++] = '.';
6375 memcpy (buf + nspacelen, klass->name, cnamelen);
6376 buf [nspacelen + cnamelen] = 0;
6377 return nspacelen + cnamelen;
6381 mono_lookup_internal_call (MonoMethod *method)
6386 int typelen = 0, mlen, siglen;
6388 const IcallMap *imap;
6390 g_assert (method != NULL);
6392 typelen = concat_class_name (mname, sizeof (mname), method->klass);
6396 imap = find_class_icalls (mname);
6398 mname [typelen] = ':';
6399 mname [typelen + 1] = ':';
6401 mlen = strlen (method->name);
6402 memcpy (mname + typelen + 2, method->name, mlen);
6403 sigstart = mname + typelen + 2 + mlen;
6406 tmpsig = mono_signature_get_desc (method->signature, TRUE);
6407 siglen = strlen (tmpsig);
6408 if (typelen + mlen + siglen + 6 > sizeof (mname))
6411 memcpy (sigstart + 1, tmpsig, siglen);
6412 sigstart [siglen + 1] = ')';
6413 sigstart [siglen + 2] = 0;
6416 mono_loader_lock ();
6418 res = g_hash_table_lookup (icall_hash, mname);
6420 mono_loader_unlock ();
6423 /* try without signature */
6425 res = g_hash_table_lookup (icall_hash, mname);
6427 mono_loader_unlock ();
6431 /* it wasn't found in the static call tables */
6433 mono_loader_unlock ();
6436 res = find_method_icall (imap, sigstart - mlen);
6438 mono_loader_unlock ();
6441 /* try _with_ signature */
6443 res = find_method_icall (imap, sigstart - mlen);
6445 mono_loader_unlock ();
6449 g_warning ("cant resolve internal call to \"%s\" (tested without signature also)", mname);
6450 g_print ("\nYour mono runtime and class libraries are out of sync.\n");
6451 g_print ("The out of sync library is: %s\n", method->klass->image->name);
6452 g_print ("\nWhen you update one from cvs you need to update, compile and install\nthe other too.\n");
6453 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");
6454 g_print ("If you see other errors or faults after this message they are probably related\n");
6455 g_print ("and you need to fix your mono install first.\n");
6457 mono_loader_unlock ();
6463 type_from_typename (char *typename)
6465 MonoClass *klass = NULL; /* assignment to shut GCC warning up */
6467 if (!strcmp (typename, "int"))
6468 klass = mono_defaults.int_class;
6469 else if (!strcmp (typename, "ptr"))
6470 klass = mono_defaults.int_class;
6471 else if (!strcmp (typename, "void"))
6472 klass = mono_defaults.void_class;
6473 else if (!strcmp (typename, "int32"))
6474 klass = mono_defaults.int32_class;
6475 else if (!strcmp (typename, "uint32"))
6476 klass = mono_defaults.uint32_class;
6477 else if (!strcmp (typename, "long"))
6478 klass = mono_defaults.int64_class;
6479 else if (!strcmp (typename, "ulong"))
6480 klass = mono_defaults.uint64_class;
6481 else if (!strcmp (typename, "float"))
6482 klass = mono_defaults.single_class;
6483 else if (!strcmp (typename, "double"))
6484 klass = mono_defaults.double_class;
6485 else if (!strcmp (typename, "object"))
6486 klass = mono_defaults.object_class;
6487 else if (!strcmp (typename, "obj"))
6488 klass = mono_defaults.object_class;
6491 g_assert_not_reached ();
6493 return &klass->byval_arg;
6496 MonoMethodSignature*
6497 mono_create_icall_signature (const char *sigstr)
6502 MonoMethodSignature *res;
6504 mono_loader_lock ();
6505 res = g_hash_table_lookup (mono_defaults.corlib->helper_signatures, sigstr);
6507 mono_loader_unlock ();
6511 parts = g_strsplit (sigstr, " ", 256);
6520 res = mono_metadata_signature_alloc (mono_defaults.corlib, len - 1);
6523 #ifdef PLATFORM_WIN32
6525 * Under windows, the default pinvoke calling convention is STDCALL but
6528 res->call_convention = MONO_CALL_C;
6531 res->ret = type_from_typename (parts [0]);
6532 for (i = 1; i < len; ++i) {
6533 res->params [i - 1] = type_from_typename (parts [i]);
6538 g_hash_table_insert (mono_defaults.corlib->helper_signatures, (gpointer)sigstr, res);
6540 mono_loader_unlock ();
6546 mono_find_jit_icall_by_name (const char *name)
6548 MonoJitICallInfo *info;
6549 g_assert (jit_icall_hash_name);
6551 mono_loader_lock ();
6552 info = g_hash_table_lookup (jit_icall_hash_name, name);
6553 mono_loader_unlock ();
6558 mono_find_jit_icall_by_addr (gconstpointer addr)
6560 MonoJitICallInfo *info;
6561 g_assert (jit_icall_hash_addr);
6563 mono_loader_lock ();
6564 info = g_hash_table_lookup (jit_icall_hash_addr, (gpointer)addr);
6565 mono_loader_unlock ();
6571 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper)
6573 mono_loader_lock ();
6574 g_hash_table_insert (jit_icall_hash_addr, (gpointer)info->wrapper, info);
6575 mono_loader_unlock ();
6579 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save)
6581 MonoJitICallInfo *info;
6586 mono_loader_lock ();
6588 if (!jit_icall_hash_name) {
6589 jit_icall_hash_name = g_hash_table_new (g_str_hash, g_str_equal);
6590 jit_icall_hash_addr = g_hash_table_new (NULL, NULL);
6593 if (g_hash_table_lookup (jit_icall_hash_name, name)) {
6594 g_warning ("jit icall already defined \"%s\"\n", name);
6595 g_assert_not_reached ();
6598 info = g_new (MonoJitICallInfo, 1);
6605 info->wrapper = func;
6607 info->wrapper = NULL;
6610 g_hash_table_insert (jit_icall_hash_name, (gpointer)info->name, info);
6611 g_hash_table_insert (jit_icall_hash_addr, (gpointer)func, info);
6613 mono_loader_unlock ();