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/console-io.h>
34 #include <mono/metadata/socket-io.h>
35 #include <mono/metadata/mono-endian.h>
36 #include <mono/metadata/tokentype.h>
37 #include <mono/metadata/unicode.h>
38 #include <mono/metadata/domain-internals.h>
39 #include <mono/metadata/metadata-internals.h>
40 #include <mono/metadata/class-internals.h>
41 #include <mono/metadata/marshal.h>
42 #include <mono/metadata/gc-internal.h>
43 #include <mono/metadata/rand.h>
44 #include <mono/metadata/sysmath.h>
45 #include <mono/metadata/string-icalls.h>
46 #include <mono/metadata/debug-helpers.h>
47 #include <mono/metadata/process.h>
48 #include <mono/metadata/environment.h>
49 #include <mono/metadata/profiler-private.h>
50 #include <mono/metadata/locales.h>
51 #include <mono/metadata/filewatcher.h>
52 #include <mono/metadata/char-conversions.h>
53 #include <mono/metadata/security.h>
54 #include <mono/metadata/mono-config.h>
55 #include <mono/metadata/cil-coff.h>
56 #include <mono/metadata/security-manager.h>
57 #include <mono/io-layer/io-layer.h>
58 #include <mono/utils/strtod.h>
59 #include <mono/utils/monobitset.h>
61 #if defined (PLATFORM_WIN32)
67 static MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
71 * We expect a pointer to a char, not a string
74 mono_double_ParseImpl (char *ptr, double *result)
83 *result = strtod (ptr, &endptr);
86 *result = bsd_strtod (ptr, &endptr);
89 if (!*ptr || (endptr && *endptr))
96 mono_class_get_throw (MonoImage *image, guint32 type_token)
98 MonoClass *class = mono_class_get (image, type_token);
99 MonoLoaderError *error;
103 if (class->exception_type) {
104 MonoException *exc = mono_class_get_exception_for_failure (class);
106 mono_raise_exception (exc);
110 error = mono_loader_get_last_error ();
111 g_assert (error != NULL);
113 ex = mono_loader_error_prepare_exception (error);
114 mono_raise_exception (ex);
119 ves_icall_System_Double_AssertEndianity (double *value)
123 MONO_DOUBLE_ASSERT_ENDIANITY (value);
127 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
136 ao = (MonoArray *)this;
137 ac = (MonoClass *)ao->obj.vtable->klass;
139 esize = mono_array_element_size (ac);
140 ea = (gpointer*)((char*)ao->vector + (pos * esize));
142 if (ac->element_class->valuetype)
143 return mono_value_box (this->vtable->domain, ac->element_class, ea);
149 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
157 MONO_CHECK_ARG_NULL (idxs);
159 io = (MonoArray *)idxs;
160 ic = (MonoClass *)io->obj.vtable->klass;
162 ao = (MonoArray *)this;
163 ac = (MonoClass *)ao->obj.vtable->klass;
165 g_assert (ic->rank == 1);
166 if (io->bounds != NULL || io->max_length != ac->rank)
167 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
169 ind = (gint32 *)io->vector;
171 if (ao->bounds == NULL) {
172 if (*ind < 0 || *ind >= ao->max_length)
173 mono_raise_exception (mono_get_exception_index_out_of_range ());
175 return ves_icall_System_Array_GetValueImpl (this, *ind);
178 for (i = 0; i < ac->rank; i++)
179 if ((ind [i] < ao->bounds [i].lower_bound) ||
180 (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
181 mono_raise_exception (mono_get_exception_index_out_of_range ());
183 pos = ind [0] - ao->bounds [0].lower_bound;
184 for (i = 1; i < ac->rank; i++)
185 pos = pos*ao->bounds [i].length + ind [i] -
186 ao->bounds [i].lower_bound;
188 return ves_icall_System_Array_GetValueImpl (this, pos);
192 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
194 MonoClass *ac, *vc, *ec;
205 vc = value->vtable->klass;
209 ac = this->obj.vtable->klass;
210 ec = ac->element_class;
212 esize = mono_array_element_size (ac);
213 ea = (gpointer*)((char*)this->vector + (pos * esize));
214 va = (gpointer*)((char*)value + sizeof (MonoObject));
217 memset (ea, 0, esize);
221 #define NO_WIDENING_CONVERSION G_STMT_START{\
222 mono_raise_exception (mono_get_exception_argument ( \
223 "value", "not a widening conversion")); \
226 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
227 if (esize < vsize + (extra)) \
228 mono_raise_exception (mono_get_exception_argument ( \
229 "value", "not a widening conversion")); \
232 #define INVALID_CAST G_STMT_START{\
233 mono_raise_exception (mono_get_exception_invalid_cast ()); \
236 /* Check element (destination) type. */
237 switch (ec->byval_arg.type) {
238 case MONO_TYPE_STRING:
239 switch (vc->byval_arg.type) {
240 case MONO_TYPE_STRING:
246 case MONO_TYPE_BOOLEAN:
247 switch (vc->byval_arg.type) {
248 case MONO_TYPE_BOOLEAN:
261 NO_WIDENING_CONVERSION;
268 if (!ec->valuetype) {
269 if (!mono_object_isinst (value, ec))
271 *ea = (gpointer)value;
275 if (mono_object_isinst (value, ec)) {
276 memcpy (ea, (char *)value + sizeof (MonoObject), esize);
283 vsize = mono_class_instance_size (vc) - sizeof (MonoObject);
285 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
286 switch (vc->byval_arg.type) { \
291 case MONO_TYPE_CHAR: \
292 CHECK_WIDENING_CONVERSION(0); \
293 *(etype *) ea = (etype) u64; \
295 /* You can't assign a signed value to an unsigned array. */ \
300 /* You can't assign a floating point number to an integer array. */ \
303 NO_WIDENING_CONVERSION; \
307 #define ASSIGN_SIGNED(etype) G_STMT_START{\
308 switch (vc->byval_arg.type) { \
313 CHECK_WIDENING_CONVERSION(0); \
314 *(etype *) ea = (etype) i64; \
316 /* You can assign an unsigned value to a signed array if the array's */ \
317 /* element size is larger than the value size. */ \
322 case MONO_TYPE_CHAR: \
323 CHECK_WIDENING_CONVERSION(1); \
324 *(etype *) ea = (etype) u64; \
326 /* You can't assign a floating point number to an integer array. */ \
329 NO_WIDENING_CONVERSION; \
333 #define ASSIGN_REAL(etype) G_STMT_START{\
334 switch (vc->byval_arg.type) { \
337 CHECK_WIDENING_CONVERSION(0); \
338 *(etype *) ea = (etype) r64; \
340 /* All integer values fit into a floating point array, so we don't */ \
341 /* need to CHECK_WIDENING_CONVERSION here. */ \
346 *(etype *) ea = (etype) i64; \
352 case MONO_TYPE_CHAR: \
353 *(etype *) ea = (etype) u64; \
358 switch (vc->byval_arg.type) {
360 u64 = *(guint8 *) va;
363 u64 = *(guint16 *) va;
366 u64 = *(guint32 *) va;
369 u64 = *(guint64 *) va;
375 i64 = *(gint16 *) va;
378 i64 = *(gint32 *) va;
381 i64 = *(gint64 *) va;
384 r64 = *(gfloat *) va;
387 r64 = *(gdouble *) va;
390 u64 = *(guint16 *) va;
392 case MONO_TYPE_BOOLEAN:
393 /* Boolean is only compatible with itself. */
394 switch (ec->byval_arg.type) {
406 NO_WIDENING_CONVERSION;
413 /* If we can't do a direct copy, let's try a widening conversion. */
414 switch (ec->byval_arg.type) {
416 ASSIGN_UNSIGNED (guint16);
418 ASSIGN_UNSIGNED (guint8);
420 ASSIGN_UNSIGNED (guint16);
422 ASSIGN_UNSIGNED (guint32);
424 ASSIGN_UNSIGNED (guint64);
426 ASSIGN_SIGNED (gint8);
428 ASSIGN_SIGNED (gint16);
430 ASSIGN_SIGNED (gint32);
432 ASSIGN_SIGNED (gint64);
434 ASSIGN_REAL (gfloat);
436 ASSIGN_REAL (gdouble);
440 /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
444 #undef NO_WIDENING_CONVERSION
445 #undef CHECK_WIDENING_CONVERSION
446 #undef ASSIGN_UNSIGNED
452 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
460 MONO_CHECK_ARG_NULL (idxs);
462 ic = idxs->obj.vtable->klass;
463 ac = this->obj.vtable->klass;
465 g_assert (ic->rank == 1);
466 if (idxs->bounds != NULL || idxs->max_length != ac->rank)
467 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
469 ind = (gint32 *)idxs->vector;
471 if (this->bounds == NULL) {
472 if (*ind < 0 || *ind >= this->max_length)
473 mono_raise_exception (mono_get_exception_index_out_of_range ());
475 ves_icall_System_Array_SetValueImpl (this, value, *ind);
479 for (i = 0; i < ac->rank; i++)
480 if ((ind [i] < this->bounds [i].lower_bound) ||
481 (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
482 mono_raise_exception (mono_get_exception_index_out_of_range ());
484 pos = ind [0] - this->bounds [0].lower_bound;
485 for (i = 1; i < ac->rank; i++)
486 pos = pos * this->bounds [i].length + ind [i] -
487 this->bounds [i].lower_bound;
489 ves_icall_System_Array_SetValueImpl (this, value, pos);
493 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
498 gboolean bounded = FALSE;
502 MONO_CHECK_ARG_NULL (type);
503 MONO_CHECK_ARG_NULL (lengths);
505 MONO_CHECK_ARG (lengths, mono_array_length (lengths) > 0);
507 MONO_CHECK_ARG (bounds, mono_array_length (lengths) == mono_array_length (bounds));
509 for (i = 0; i < mono_array_length (lengths); i++)
510 if (mono_array_get (lengths, gint32, i) < 0)
511 mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
513 if (bounds && (mono_array_length (bounds) == 1) && (mono_array_get (bounds, gint32, 0) != 0))
514 /* vectors are not the same as one dimensional arrays with no-zero bounds */
519 aklass = mono_bounded_array_class_get (mono_class_from_mono_type (type->type), mono_array_length (lengths), bounded);
521 sizes = alloca (aklass->rank * sizeof(guint32) * 2);
522 for (i = 0; i < aklass->rank; ++i) {
523 sizes [i] = mono_array_get (lengths, guint32, i);
525 sizes [i + aklass->rank] = mono_array_get (bounds, guint32, i);
527 sizes [i + aklass->rank] = 0;
530 array = mono_array_new_full (mono_object_domain (type), aklass, sizes, sizes + aklass->rank);
536 ves_icall_System_Array_GetRank (MonoObject *this)
540 return this->vtable->klass->rank;
544 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
546 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
550 if ((dimension < 0) || (dimension >= rank))
551 mono_raise_exception (mono_get_exception_index_out_of_range ());
553 if (this->bounds == NULL)
554 return this->max_length;
556 return this->bounds [dimension].length;
560 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
562 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
566 if ((dimension < 0) || (dimension >= rank))
567 mono_raise_exception (mono_get_exception_index_out_of_range ());
569 if (this->bounds == NULL)
572 return this->bounds [dimension].lower_bound;
576 ves_icall_System_Array_ClearInternal (MonoArray *arr, int idx, int length)
578 int sz = mono_array_element_size (mono_object_class (arr));
579 memset (mono_array_addr_with_size (arr, sz, idx), 0, length * sz);
583 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
588 MonoClass *src_class;
589 MonoClass *dest_class;
594 if (source->obj.vtable->klass->rank != dest->obj.vtable->klass->rank)
597 if (source->bounds || dest->bounds)
600 if ((dest_idx + length > mono_array_length (dest)) ||
601 (source_idx + length > mono_array_length (source)))
604 src_class = source->obj.vtable->klass->element_class;
605 dest_class = dest->obj.vtable->klass->element_class;
608 * Handle common cases.
611 /* Case1: object[] -> valuetype[] (ArrayList::ToArray) */
612 if (src_class == mono_defaults.object_class && dest_class->valuetype) {
613 int has_refs = dest_class->has_references;
614 for (i = source_idx; i < source_idx + length; ++i) {
615 MonoObject *elem = mono_array_get (source, MonoObject*, i);
616 if (elem && !mono_object_isinst (elem, dest_class))
620 element_size = mono_array_element_size (dest->obj.vtable->klass);
621 memset (mono_array_addr_with_size (dest, element_size, dest_idx), 0, element_size * length);
622 for (i = 0; i < length; ++i) {
623 MonoObject *elem = mono_array_get (source, MonoObject*, source_idx + i);
624 void *addr = mono_array_addr_with_size (dest, element_size, dest_idx + i);
628 mono_value_copy (addr, (char *)elem + sizeof (MonoObject), dest_class);
630 memcpy (addr, (char *)elem + sizeof (MonoObject), element_size);
635 /* Check if we're copying a char[] <==> (u)short[] */
636 if (src_class != dest_class) {
637 if (dest_class->valuetype || dest_class->enumtype || src_class->valuetype || src_class->enumtype)
640 if (mono_class_is_subclass_of (src_class, dest_class, FALSE))
642 /* Case2: object[] -> reftype[] (ArrayList::ToArray) */
643 else if (mono_class_is_subclass_of (dest_class, src_class, FALSE))
644 for (i = source_idx; i < source_idx + length; ++i) {
645 MonoObject *elem = mono_array_get (source, MonoObject*, i);
646 if (elem && !mono_object_isinst (elem, dest_class))
653 if (dest_class->valuetype) {
654 element_size = mono_array_element_size (source->obj.vtable->klass);
655 source_addr = mono_array_addr_with_size (source, element_size, source_idx);
656 if (dest_class->has_references) {
657 mono_value_copy_array (dest, dest_idx, source_addr, length);
659 dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
660 memmove (dest_addr, source_addr, element_size * length);
663 mono_array_memcpy_refs (dest, dest_idx, source, source_idx, length);
670 ves_icall_System_Array_InternalArray_GetGenericValueImpl (MonoObject *this, guint32 pos,
680 ao = (MonoArray *)this;
681 ac = (MonoClass *)ao->obj.vtable->klass;
683 esize = mono_array_element_size (ac);
684 ea = (gpointer*)((char*)ao->vector + (pos * esize));
686 memcpy (value, ea, esize);
690 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArray *array, MonoClassField *field_handle)
692 MonoClass *klass = array->obj.vtable->klass;
693 guint32 size = mono_array_element_size (klass);
698 if (array->bounds == NULL)
699 size *= array->max_length;
701 for (i = 0; i < klass->rank; ++i)
702 size *= array->bounds [i].length;
704 memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
706 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
710 guint ## n *data = (guint ## n *) mono_array_addr (array, char, 0); \
712 for (i = 0; i < size; i += n/8, data++) { \
713 tmp = read ## n (data); \
718 /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
720 switch (mono_type_get_underlying_type (&klass->element_class->byval_arg)->type) {
740 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
744 return offsetof (MonoString, chars);
748 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject *obj)
752 if ((obj == NULL) || (! (obj->vtable->klass->valuetype)))
755 return mono_object_clone (obj);
759 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
765 MONO_CHECK_ARG_NULL (handle);
767 klass = mono_class_from_mono_type (handle);
768 MONO_CHECK_ARG (handle, klass);
770 /* This will call the type constructor */
771 if (! (klass->flags & TYPE_ATTRIBUTE_INTERFACE))
772 mono_runtime_class_init (mono_class_vtable (mono_domain_get (), klass));
776 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
780 return mono_object_clone (this);
784 ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fields)
787 MonoObject **values = NULL;
791 MonoClassField* field;
796 klass = mono_object_class (this);
798 if (mono_class_num_fields (klass) == 0)
799 return mono_object_hash (this);
802 * Compute the starting value of the hashcode for fields of primitive
803 * types, and return the remaining fields in an array to the managed side.
804 * This way, we can avoid costly reflection operations in managed code.
807 while ((field = mono_class_get_fields (klass, &iter))) {
808 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
810 if (mono_field_is_deleted (field))
812 /* FIXME: Add more types */
813 switch (field->type->type) {
815 result ^= *(gint32*)((guint8*)this + field->offset);
817 case MONO_TYPE_STRING: {
819 s = *(MonoString**)((guint8*)this + field->offset);
821 result ^= mono_string_hash (s);
826 values = g_newa (MonoObject*, mono_class_num_fields (klass));
827 o = mono_field_get_value_object (mono_object_domain (this), field, this);
828 values [count++] = o;
834 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
835 for (i = 0; i < count; ++i)
836 mono_array_setref (*fields, i, values [i]);
844 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that, MonoArray **fields)
847 MonoObject **values = NULL;
849 MonoClassField* field;
855 MONO_CHECK_ARG_NULL (that);
857 if (this->vtable != that->vtable)
860 klass = mono_object_class (this);
863 * Do the comparison for fields of primitive type and return a result if
864 * possible. Otherwise, return the remaining fields in an array to the
865 * managed side. This way, we can avoid costly reflection operations in
870 while ((field = mono_class_get_fields (klass, &iter))) {
871 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
873 if (mono_field_is_deleted (field))
875 /* FIXME: Add more types */
876 switch (field->type->type) {
878 if (*(gint32*)((guint8*)this + field->offset) != *(gint32*)((guint8*)that + field->offset))
881 case MONO_TYPE_STRING: {
883 guint32 s1len, s2len;
884 s1 = *(MonoString**)((guint8*)this + field->offset);
885 s2 = *(MonoString**)((guint8*)that + field->offset);
888 if ((s1 == NULL) || (s2 == NULL))
890 s1len = mono_string_length (s1);
891 s2len = mono_string_length (s2);
895 if (memcmp (mono_string_chars (s1), mono_string_chars (s2), s1len * sizeof (gunichar2)) != 0)
901 values = g_newa (MonoObject*, mono_class_num_fields (klass) * 2);
902 o = mono_field_get_value_object (mono_object_domain (this), field, this);
903 values [count++] = o;
904 o = mono_field_get_value_object (mono_object_domain (this), field, that);
905 values [count++] = o;
911 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
912 for (i = 0; i < count; ++i)
913 mono_array_setref (*fields, i, values [i]);
920 static MonoReflectionType *
921 ves_icall_System_Object_GetType (MonoObject *obj)
925 if (obj->vtable->klass != mono_defaults.transparent_proxy_class)
926 return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
928 return mono_type_get_object (mono_object_domain (obj), &((MonoTransparentProxy*)obj)->remote_class->proxy_class->byval_arg);
932 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
936 mtype->type = &obj->vtable->klass->byval_arg;
937 g_assert (mtype->type->type);
941 ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj)
945 MONO_CHECK_ARG_NULL (obj);
947 return mono_image_create_token (mb->dynamic_image, obj, TRUE);
951 ves_icall_ModuleBuilder_getMethodToken (MonoReflectionModuleBuilder *mb,
952 MonoReflectionMethod *method,
953 MonoArray *opt_param_types)
957 MONO_CHECK_ARG_NULL (method);
959 return mono_image_create_method_token (
960 mb->dynamic_image, (MonoObject *) method, opt_param_types);
964 ves_icall_ModuleBuilder_WriteToFile (MonoReflectionModuleBuilder *mb, HANDLE file)
968 mono_image_create_pefile (mb, file);
972 ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
976 mono_image_build_metadata (mb);
980 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
982 MonoMethod **dest = data;
984 /* skip unmanaged frames */
999 static MonoReflectionType *
1000 type_from_name (const char *str, MonoBoolean ignoreCase)
1002 MonoType *type = NULL;
1003 MonoAssembly *assembly = NULL;
1004 MonoTypeNameParse info;
1005 char *temp_str = g_strdup (str);
1006 gboolean type_resolve = FALSE;
1008 MONO_ARCH_SAVE_REGS;
1010 /* mono_reflection_parse_type() mangles the string */
1011 if (!mono_reflection_parse_type (temp_str, &info)) {
1012 g_list_free (info.modifiers);
1013 g_list_free (info.nested);
1018 if (info.assembly.name) {
1019 assembly = mono_assembly_load (&info.assembly, NULL, NULL);
1021 MonoMethod *m = mono_method_get_last_managed ();
1022 MonoMethod *dest = m;
1024 mono_stack_walk_no_il (get_caller, &dest);
1029 * FIXME: mono_method_get_last_managed() sometimes returns NULL, thus
1030 * causing ves_icall_System_Reflection_Assembly_GetCallingAssembly()
1031 * to crash. This only seems to happen in some strange remoting
1032 * scenarios and I was unable to figure out what's happening there.
1033 * Dec 10, 2005 - Martin.
1037 assembly = dest->klass->image->assembly;
1039 g_warning (G_STRLOC);
1044 type = mono_reflection_get_type (assembly->image, &info, ignoreCase, &type_resolve);
1046 if (!info.assembly.name && !type) /* try mscorlib */
1047 type = mono_reflection_get_type (NULL, &info, ignoreCase, &type_resolve);
1049 g_list_free (info.modifiers);
1050 g_list_free (info.nested);
1056 return mono_type_get_object (mono_domain_get (), type);
1060 MonoReflectionType *
1061 mono_type_get (const char *str)
1063 char *copy = g_strdup (str);
1064 MonoReflectionType *type = type_from_name (copy, FALSE);
1071 static MonoReflectionType*
1072 ves_icall_type_from_name (MonoString *name,
1073 MonoBoolean throwOnError,
1074 MonoBoolean ignoreCase)
1076 char *str = mono_string_to_utf8 (name);
1077 MonoReflectionType *type;
1079 type = type_from_name (str, ignoreCase);
1083 mono_raise_exception (mono_get_exception_type_load (name, NULL));
1090 static MonoReflectionType*
1091 ves_icall_type_from_handle (MonoType *handle)
1093 MonoDomain *domain = mono_domain_get ();
1094 MonoClass *klass = mono_class_from_mono_type (handle);
1096 MONO_ARCH_SAVE_REGS;
1098 mono_class_init (klass);
1099 return mono_type_get_object (domain, handle);
1103 ves_icall_type_Equals (MonoReflectionType *type, MonoReflectionType *c)
1105 MONO_ARCH_SAVE_REGS;
1107 if (c && type->type && c->type)
1108 return mono_metadata_type_equal (type->type, c->type);
1113 /* System.TypeCode */
1132 TYPECODE_STRING = 18
1136 ves_icall_type_GetTypeCodeInternal (MonoReflectionType *type)
1138 int t = type->type->type;
1140 MONO_ARCH_SAVE_REGS;
1142 if (type->type->byref)
1143 return TYPECODE_OBJECT;
1147 case MONO_TYPE_VOID:
1148 return TYPECODE_OBJECT;
1149 case MONO_TYPE_BOOLEAN:
1150 return TYPECODE_BOOLEAN;
1152 return TYPECODE_BYTE;
1154 return TYPECODE_SBYTE;
1156 return TYPECODE_UINT16;
1158 return TYPECODE_INT16;
1159 case MONO_TYPE_CHAR:
1160 return TYPECODE_CHAR;
1164 return TYPECODE_OBJECT;
1166 return TYPECODE_UINT32;
1168 return TYPECODE_INT32;
1170 return TYPECODE_UINT64;
1172 return TYPECODE_INT64;
1174 return TYPECODE_SINGLE;
1176 return TYPECODE_DOUBLE;
1177 case MONO_TYPE_VALUETYPE:
1178 if (type->type->data.klass->enumtype) {
1179 t = type->type->data.klass->enum_basetype->type;
1182 MonoClass *k = type->type->data.klass;
1183 if (strcmp (k->name_space, "System") == 0) {
1184 if (strcmp (k->name, "Decimal") == 0)
1185 return TYPECODE_DECIMAL;
1186 else if (strcmp (k->name, "DateTime") == 0)
1187 return TYPECODE_DATETIME;
1190 return TYPECODE_OBJECT;
1191 case MONO_TYPE_STRING:
1192 return TYPECODE_STRING;
1193 case MONO_TYPE_SZARRAY:
1194 case MONO_TYPE_ARRAY:
1195 case MONO_TYPE_OBJECT:
1197 case MONO_TYPE_MVAR:
1198 return TYPECODE_OBJECT;
1199 case MONO_TYPE_CLASS:
1201 MonoClass *k = type->type->data.klass;
1202 if (strcmp (k->name_space, "System") == 0) {
1203 if (strcmp (k->name, "DBNull") == 0)
1204 return TYPECODE_DBNULL;
1207 return TYPECODE_OBJECT;
1208 case MONO_TYPE_GENERICINST:
1209 return TYPECODE_OBJECT;
1211 g_error ("type 0x%02x not handled in GetTypeCode()", t);
1217 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
1223 MONO_ARCH_SAVE_REGS;
1225 g_assert (type != NULL);
1227 domain = ((MonoObject *)type)->vtable->domain;
1229 if (!c) /* FIXME: dont know what do do here */
1232 klass = mono_class_from_mono_type (type->type);
1233 klassc = mono_class_from_mono_type (c->type);
1235 if (type->type->byref)
1236 return klassc == mono_defaults.object_class;
1238 return mono_class_is_subclass_of (klass, klassc, check_interfaces);
1242 ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
1248 MONO_ARCH_SAVE_REGS;
1250 g_assert (type != NULL);
1252 domain = ((MonoObject *)type)->vtable->domain;
1254 klass = mono_class_from_mono_type (type->type);
1255 klassc = mono_class_from_mono_type (c->type);
1257 if (type->type->byref && !c->type->byref)
1260 return mono_class_is_assignable_from (klass, klassc);
1264 ves_icall_type_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
1266 MonoClass *klass = mono_class_from_mono_type (type->type);
1267 return mono_object_isinst (obj, klass) != NULL;
1271 ves_icall_get_attributes (MonoReflectionType *type)
1273 MonoClass *klass = mono_class_from_mono_type (type->type);
1275 MONO_ARCH_SAVE_REGS;
1277 return klass->flags;
1280 static MonoReflectionMarshal*
1281 ves_icall_System_Reflection_FieldInfo_GetUnmanagedMarshal (MonoReflectionField *field)
1283 MonoClass *klass = field->field->parent;
1284 MonoMarshalType *info;
1287 if (klass->generic_container ||
1288 (klass->generic_class && klass->generic_class->inst->is_open))
1291 info = mono_marshal_load_type_info (klass);
1293 for (i = 0; i < info->num_fields; ++i) {
1294 if (info->fields [i].field == field->field) {
1295 if (!info->fields [i].mspec)
1298 return mono_reflection_marshal_from_marshal_spec (field->object.vtable->domain, klass, info->fields [i].mspec);
1305 static MonoReflectionField*
1306 ves_icall_System_Reflection_FieldInfo_internal_from_handle (MonoClassField *handle)
1308 MONO_ARCH_SAVE_REGS;
1312 return mono_field_get_object (mono_domain_get (), handle->parent, handle);
1316 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
1318 MonoDomain *domain = mono_domain_get ();
1319 MonoMethodSignature* sig;
1320 MONO_ARCH_SAVE_REGS;
1322 if (method->is_inflated)
1323 method = mono_get_inflated_method (method);
1325 sig = mono_method_signature (method);
1327 info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
1328 info->ret = mono_type_get_object (domain, sig->ret);
1329 info->attrs = method->flags;
1330 info->implattrs = method->iflags;
1331 if (sig->call_convention == MONO_CALL_DEFAULT)
1334 if (sig->call_convention == MONO_CALL_VARARG)
1339 info->callconv |= (sig->hasthis << 5) | (sig->explicit_this << 6);
1343 ves_icall_get_parameter_info (MonoMethod *method)
1345 MonoDomain *domain = mono_domain_get ();
1347 MONO_ARCH_SAVE_REGS;
1349 if (method->is_inflated)
1350 method = mono_get_inflated_method (method);
1352 return mono_param_get_objects (domain, method);
1355 static MonoReflectionMarshal*
1356 ves_icall_System_MonoMethodInfo_get_retval_marshal (MonoMethod *method)
1358 MonoDomain *domain = mono_domain_get ();
1359 MonoReflectionMarshal* res = NULL;
1360 MonoMarshalSpec **mspecs;
1363 MONO_ARCH_SAVE_REGS;
1365 if (method->is_inflated)
1366 method = mono_get_inflated_method (method);
1368 mspecs = g_new (MonoMarshalSpec*, mono_method_signature (method)->param_count + 1);
1369 mono_method_get_marshal_info (method, mspecs);
1372 res = mono_reflection_marshal_from_marshal_spec (domain, method->klass, mspecs [0]);
1374 for (i = mono_method_signature (method)->param_count; i >= 0; i--)
1376 mono_metadata_free_marshal_spec (mspecs [i]);
1383 ves_icall_MonoField_GetFieldOffset (MonoReflectionField *field)
1385 return field->field->offset - sizeof (MonoObject);
1388 static MonoReflectionType*
1389 ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean declaring)
1392 MONO_ARCH_SAVE_REGS;
1394 parent = declaring? field->field->parent: field->klass;
1396 return mono_type_get_object (mono_object_domain (field), &parent->byval_arg);
1400 ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *obj)
1403 MonoClassField *cf = field->field;
1407 MonoDomain *domain = mono_object_domain (field);
1409 gboolean is_static = FALSE;
1410 gboolean is_ref = FALSE;
1412 MONO_ARCH_SAVE_REGS;
1414 if (field->klass->image->assembly->ref_only)
1415 mono_raise_exception (mono_get_exception_invalid_operation (
1416 "It is illegal to get the value on a field on a type loaded using the ReflectionOnly methods."));
1418 mono_class_init (field->klass);
1420 t = mono_type_get_underlying_type (cf->type);
1422 case MONO_TYPE_STRING:
1423 case MONO_TYPE_OBJECT:
1424 case MONO_TYPE_CLASS:
1425 case MONO_TYPE_ARRAY:
1426 case MONO_TYPE_SZARRAY:
1431 case MONO_TYPE_BOOLEAN:
1434 case MONO_TYPE_CHAR:
1443 case MONO_TYPE_VALUETYPE:
1446 case MONO_TYPE_GENERICINST:
1447 if (mono_type_generic_inst_is_valuetype (t)) {
1454 g_error ("type 0x%x not handled in "
1455 "ves_icall_Monofield_GetValue", t->type);
1460 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1462 vtable = mono_class_vtable (domain, field->klass);
1463 if (!vtable->initialized && !(cf->type->attrs & FIELD_ATTRIBUTE_LITERAL))
1464 mono_runtime_class_init (vtable);
1469 mono_field_static_get_value (vtable, cf, &o);
1471 mono_field_get_value (obj, cf, &o);
1476 if (mono_class_is_nullable (mono_class_from_mono_type (cf->type))) {
1477 MonoClass *nklass = mono_class_from_mono_type (cf->type);
1480 /* Convert the Nullable structure into a boxed vtype */
1482 buf = (guint8*)vtable->data + cf->offset;
1484 buf = (guint8*)obj + cf->offset;
1486 return mono_nullable_box (buf, nklass);
1489 /* boxed value type */
1490 klass = mono_class_from_mono_type (cf->type);
1491 o = mono_object_new (domain, klass);
1492 v = ((gchar *) o) + sizeof (MonoObject);
1494 mono_field_static_get_value (vtable, cf, v);
1496 mono_field_get_value (obj, cf, v);
1503 ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
1505 MonoClassField *cf = field->field;
1508 MONO_ARCH_SAVE_REGS;
1510 if (field->klass->image->assembly->ref_only)
1511 mono_raise_exception (mono_get_exception_invalid_operation (
1512 "It is illegal to set the value on a field on a type loaded using the ReflectionOnly methods."));
1514 v = (gchar *) value;
1515 if (!cf->type->byref) {
1516 switch (cf->type->type) {
1519 case MONO_TYPE_BOOLEAN:
1522 case MONO_TYPE_CHAR:
1531 case MONO_TYPE_VALUETYPE:
1533 v += sizeof (MonoObject);
1535 case MONO_TYPE_STRING:
1536 case MONO_TYPE_OBJECT:
1537 case MONO_TYPE_CLASS:
1538 case MONO_TYPE_ARRAY:
1539 case MONO_TYPE_SZARRAY:
1542 case MONO_TYPE_GENERICINST: {
1543 MonoGenericClass *gclass = cf->type->data.generic_class;
1544 g_assert (!gclass->inst->is_open);
1546 if (mono_class_is_nullable (mono_class_from_mono_type (cf->type))) {
1547 MonoClass *nklass = mono_class_from_mono_type (cf->type);
1551 * Convert the boxed vtype into a Nullable structure.
1552 * This is complicated by the fact that Nullables have
1553 * a variable structure.
1555 /* Allocate using alloca so it gets GC tracking */
1556 buf = alloca (nklass->instance_size);
1558 mono_nullable_init (buf, value, nklass);
1563 if (gclass->container_class->valuetype && (v != NULL))
1564 v += sizeof (MonoObject);
1568 g_error ("type 0x%x not handled in "
1569 "ves_icall_FieldInfo_SetValueInternal", cf->type->type);
1574 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1575 MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), field->klass);
1576 if (!vtable->initialized)
1577 mono_runtime_class_init (vtable);
1578 mono_field_static_set_value (vtable, cf, v);
1580 mono_field_set_value (obj, cf, v);
1584 static MonoReflectionType*
1585 ves_icall_MonoGenericMethod_get_ReflectedType (MonoReflectionGenericMethod *rmethod)
1587 MonoMethod *method = mono_get_inflated_method (rmethod->method.method);
1589 return mono_type_get_object (mono_object_domain (rmethod), &method->klass->byval_arg);
1592 /* From MonoProperty.cs */
1594 PInfo_Attributes = 1,
1595 PInfo_GetMethod = 1 << 1,
1596 PInfo_SetMethod = 1 << 2,
1597 PInfo_ReflectedType = 1 << 3,
1598 PInfo_DeclaringType = 1 << 4,
1603 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info)
1605 MonoDomain *domain = mono_object_domain (property);
1607 MONO_ARCH_SAVE_REGS;
1609 if ((req_info & PInfo_ReflectedType) != 0)
1610 info->parent = mono_type_get_object (domain, &property->klass->byval_arg);
1611 else if ((req_info & PInfo_DeclaringType) != 0)
1612 info->parent = mono_type_get_object (domain, &property->property->parent->byval_arg);
1614 if ((req_info & PInfo_Name) != 0)
1615 info->name = mono_string_new (domain, property->property->name);
1617 if ((req_info & PInfo_Attributes) != 0)
1618 info->attrs = property->property->attrs;
1620 if ((req_info & PInfo_GetMethod) != 0)
1621 info->get = property->property->get ?
1622 mono_method_get_object (domain, property->property->get, NULL): NULL;
1624 if ((req_info & PInfo_SetMethod) != 0)
1625 info->set = property->property->set ?
1626 mono_method_get_object (domain, property->property->set, NULL): NULL;
1628 * There may be other methods defined for properties, though, it seems they are not exposed
1629 * in the reflection API
1634 ves_icall_get_event_info (MonoReflectionEvent *event, MonoEventInfo *info)
1636 MonoDomain *domain = mono_object_domain (event);
1638 MONO_ARCH_SAVE_REGS;
1640 info->reflected_type = mono_type_get_object (domain, &event->klass->byval_arg);
1641 info->declaring_type = mono_type_get_object (domain, &event->event->parent->byval_arg);
1643 info->name = mono_string_new (domain, event->event->name);
1644 info->attrs = event->event->attrs;
1645 info->add_method = event->event->add ? mono_method_get_object (domain, event->event->add, NULL): NULL;
1646 info->remove_method = event->event->remove ? mono_method_get_object (domain, event->event->remove, NULL): NULL;
1647 info->raise_method = event->event->raise ? mono_method_get_object (domain, event->event->raise, NULL): NULL;
1649 if (event->event->other) {
1651 while (event->event->other [n])
1653 info->other_methods = mono_array_new (domain, mono_defaults.method_info_class, n);
1655 for (i = 0; i < n; i++)
1656 mono_array_setref (info->other_methods, i, mono_method_get_object (domain, event->event->other [i], NULL));
1661 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
1663 MonoDomain *domain = mono_object_domain (type);
1665 GPtrArray *ifaces = NULL;
1667 MonoClass *class = mono_class_from_mono_type (type->type);
1670 MonoGenericContext *context = NULL;
1672 MONO_ARCH_SAVE_REGS;
1674 /* open generic-instance classes can share their interface_id */
1675 if (class->generic_class && class->generic_class->inst->is_open) {
1676 context = class->generic_class->context;
1677 class = class->generic_class->container_class;
1680 mono_class_setup_vtable (class);
1682 slots = mono_bitset_new (class->max_interface_id + 1, 0);
1685 /* GetInterfaces() returns an empty array in MS.NET (this may be a bug) */
1686 mono_bitset_free (slots);
1687 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1690 for (parent = class; parent; parent = parent->parent) {
1691 GPtrArray *tmp_ifaces = mono_class_get_implemented_interfaces (parent);
1693 for (i = 0; i < tmp_ifaces->len; ++i) {
1694 MonoClass *ic = g_ptr_array_index (tmp_ifaces, i);
1696 if (mono_bitset_test (slots, ic->interface_id))
1699 mono_bitset_set (slots, ic->interface_id);
1701 ifaces = g_ptr_array_new ();
1702 g_ptr_array_add (ifaces, ic);
1704 g_ptr_array_free (tmp_ifaces, TRUE);
1707 mono_bitset_free (slots);
1710 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1712 intf = mono_array_new (domain, mono_defaults.monotype_class, ifaces->len);
1713 for (i = 0; i < ifaces->len; ++i) {
1714 MonoClass *ic = g_ptr_array_index (ifaces, i);
1715 MonoType *ret = &ic->byval_arg;
1716 if (context && ic->generic_class && ic->generic_class->inst->is_open)
1717 ret = mono_class_inflate_generic_type (ret, context);
1719 mono_array_setref (intf, i, mono_type_get_object (domain, ret));
1721 g_ptr_array_free (ifaces, TRUE);
1727 ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
1729 MonoClass *class = mono_class_from_mono_type (type->type);
1730 MonoClass *iclass = mono_class_from_mono_type (iface->type);
1731 MonoReflectionMethod *member;
1734 int i = 0, len, ioffset;
1737 MONO_ARCH_SAVE_REGS;
1739 mono_class_setup_vtable (class);
1741 /* type doesn't implement iface: the exception is thrown in managed code */
1742 if ((iclass->interface_id > class->max_interface_id) || !class->interface_offsets [iclass->interface_id])
1745 len = mono_class_num_methods (iclass);
1746 ioffset = class->interface_offsets [iclass->interface_id];
1747 domain = mono_object_domain (type);
1748 *targets = mono_array_new (domain, mono_defaults.method_info_class, len);
1749 *methods = mono_array_new (domain, mono_defaults.method_info_class, len);
1752 while ((method = mono_class_get_methods (iclass, &iter))) {
1753 member = mono_method_get_object (domain, method, iclass);
1754 mono_array_setref (*methods, i, member);
1755 member = mono_method_get_object (domain, class->vtable [i + ioffset], class);
1756 mono_array_setref (*targets, i, member);
1763 ves_icall_Type_GetPacking (MonoReflectionType *type, guint32 *packing, guint32 *size)
1765 MonoClass *klass = mono_class_from_mono_type (type->type);
1767 g_assert (!klass->image->dynamic);
1769 mono_metadata_packing_from_typedef (klass->image, klass->type_token, packing, size);
1772 static MonoReflectionType*
1773 ves_icall_MonoType_GetElementType (MonoReflectionType *type)
1775 MonoClass *class = mono_class_from_mono_type (type->type);
1777 MONO_ARCH_SAVE_REGS;
1779 // GelElementType should only return a type for:
1780 // Array Pointer PassedByRef
1781 if (type->type->byref)
1782 return mono_type_get_object (mono_object_domain (type), &class->byval_arg);
1783 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1784 return mono_type_get_object (mono_object_domain (type), class->enum_basetype);
1785 else if (class->element_class && MONO_CLASS_IS_ARRAY (class))
1786 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1787 else if (class->element_class && type->type->type == MONO_TYPE_PTR)
1788 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1793 static MonoReflectionType*
1794 ves_icall_get_type_parent (MonoReflectionType *type)
1796 MonoClass *class = mono_class_from_mono_type (type->type);
1798 MONO_ARCH_SAVE_REGS;
1800 return class->parent ? mono_type_get_object (mono_object_domain (type), &class->parent->byval_arg): NULL;
1804 ves_icall_type_ispointer (MonoReflectionType *type)
1806 MONO_ARCH_SAVE_REGS;
1808 return type->type->type == MONO_TYPE_PTR;
1812 ves_icall_type_isprimitive (MonoReflectionType *type)
1814 MONO_ARCH_SAVE_REGS;
1816 return (!type->type->byref && (((type->type->type >= MONO_TYPE_BOOLEAN) && (type->type->type <= MONO_TYPE_R8)) || (type->type->type == MONO_TYPE_I) || (type->type->type == MONO_TYPE_U)));
1820 ves_icall_type_isbyref (MonoReflectionType *type)
1822 MONO_ARCH_SAVE_REGS;
1824 return type->type->byref;
1827 static MonoReflectionModule*
1828 ves_icall_MonoType_get_Module (MonoReflectionType *type)
1830 MonoClass *class = mono_class_from_mono_type (type->type);
1832 MONO_ARCH_SAVE_REGS;
1834 return mono_module_get_object (mono_object_domain (type), class->image);
1837 static MonoReflectionAssembly*
1838 ves_icall_MonoType_get_Assembly (MonoReflectionType *type)
1840 MonoDomain *domain = mono_domain_get ();
1841 MonoClass *class = mono_class_from_mono_type (type->type);
1843 MONO_ARCH_SAVE_REGS;
1845 return mono_assembly_get_object (domain, class->image->assembly);
1848 static MonoReflectionType*
1849 ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
1851 MonoDomain *domain = mono_domain_get ();
1854 MONO_ARCH_SAVE_REGS;
1856 if (type->type->byref)
1858 if (type->type->type == MONO_TYPE_VAR)
1859 class = type->type->data.generic_param->owner->klass;
1860 else if (type->type->type == MONO_TYPE_MVAR)
1861 class = type->type->data.generic_param->method->klass;
1863 class = mono_class_from_mono_type (type->type)->nested_in;
1865 return class ? mono_type_get_object (domain, &class->byval_arg) : NULL;
1868 static MonoReflectionType*
1869 ves_icall_MonoType_get_UnderlyingSystemType (MonoReflectionType *type)
1871 MonoDomain *domain = mono_domain_get ();
1872 MonoClass *class = mono_class_from_mono_type (type->type);
1874 MONO_ARCH_SAVE_REGS;
1876 if (class->enumtype && class->enum_basetype) /* types that are modified typebuilders may not have enum_basetype set */
1877 return mono_type_get_object (domain, class->enum_basetype);
1878 else if (class->element_class)
1879 return mono_type_get_object (domain, &class->element_class->byval_arg);
1885 ves_icall_MonoType_get_Name (MonoReflectionType *type)
1887 MonoDomain *domain = mono_domain_get ();
1888 MonoClass *class = mono_class_from_mono_type (type->type);
1890 MONO_ARCH_SAVE_REGS;
1892 return mono_string_new (domain, class->name);
1896 ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
1898 MonoDomain *domain = mono_domain_get ();
1899 MonoClass *class = mono_class_from_mono_type (type->type);
1901 MONO_ARCH_SAVE_REGS;
1903 while (class->nested_in)
1904 class = class->nested_in;
1906 if (class->name_space [0] == '\0')
1909 return mono_string_new (domain, class->name_space);
1913 ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
1915 MonoClass *class = mono_class_from_mono_type (type->type);
1917 MONO_ARCH_SAVE_REGS;
1923 ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type)
1926 MonoClass *klass, *pklass;
1928 MONO_ARCH_SAVE_REGS;
1930 klass = mono_class_from_mono_type (type->type);
1932 if (klass->generic_container) {
1933 MonoGenericContainer *container = klass->generic_container;
1934 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, container->type_argc);
1935 for (i = 0; i < container->type_argc; ++i) {
1936 pklass = mono_class_from_generic_parameter (&container->type_params [i], klass->image, FALSE);
1937 mono_array_setref (res, i, mono_type_get_object (mono_object_domain (type), &pklass->byval_arg));
1939 } else if (klass->generic_class) {
1940 MonoGenericInst *inst = klass->generic_class->inst;
1941 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, inst->type_argc);
1942 for (i = 0; i < inst->type_argc; ++i)
1943 mono_array_setref (res, i, mono_type_get_object (mono_object_domain (type), inst->type_argv [i]));
1945 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1951 ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
1954 MONO_ARCH_SAVE_REGS;
1956 klass = mono_class_from_mono_type (type->type);
1958 return klass->generic_container != NULL;
1961 static MonoReflectionType*
1962 ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
1965 MONO_ARCH_SAVE_REGS;
1967 klass = mono_class_from_mono_type (type->type);
1968 if (klass->generic_container) {
1969 return type; /* check this one */
1971 if (klass->generic_class) {
1972 MonoClass *generic_class = klass->generic_class->container_class;
1974 if (generic_class->wastypebuilder && generic_class->reflection_info)
1975 return generic_class->reflection_info;
1977 return mono_type_get_object (mono_object_domain (type), &generic_class->byval_arg);
1982 static MonoReflectionType*
1983 ves_icall_Type_MakeGenericType (MonoReflectionType *type, MonoArray *type_array)
1985 MonoType *geninst, **types;
1988 MONO_ARCH_SAVE_REGS;
1990 count = mono_array_length (type_array);
1991 types = g_new0 (MonoType *, count);
1993 for (i = 0; i < count; i++) {
1994 MonoReflectionType *t = mono_array_get (type_array, gpointer, i);
1995 types [i] = t->type;
1998 geninst = mono_reflection_bind_generic_parameters (type, count, types);
2002 return mono_type_get_object (mono_object_domain (type), geninst);
2006 ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
2009 MONO_ARCH_SAVE_REGS;
2011 klass = mono_class_from_mono_type (type->type);
2012 return klass->generic_class != NULL;
2016 ves_icall_Type_get_IsGenericType (MonoReflectionType *type)
2019 MONO_ARCH_SAVE_REGS;
2021 klass = mono_class_from_mono_type (type->type);
2022 return klass->generic_class != NULL || klass->generic_container != NULL;
2026 ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
2028 MONO_ARCH_SAVE_REGS;
2030 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
2031 return type->type->data.generic_param->num;
2035 static GenericParameterAttributes
2036 ves_icall_Type_GetGenericParameterAttributes (MonoReflectionType *type)
2038 MONO_ARCH_SAVE_REGS;
2039 return type->type->data.generic_param->flags;
2043 ves_icall_Type_GetGenericParameterConstraints (MonoReflectionType *type)
2045 MonoGenericParam *param;
2051 MONO_ARCH_SAVE_REGS;
2053 domain = mono_object_domain (type);
2054 param = type->type->data.generic_param;
2055 for (count = 0, ptr = param->constraints; ptr && *ptr; ptr++, count++)
2058 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2059 for (i = 0; i < count; i++)
2060 mono_array_setref (res, i, mono_type_get_object (domain, ¶m->constraints [i]->byval_arg));
2067 ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
2069 MONO_ARCH_SAVE_REGS;
2071 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
2072 return !type->type->byref;
2077 ves_icall_TypeBuilder_get_IsGenericParameter (MonoReflectionTypeBuilder *tb)
2079 MONO_ARCH_SAVE_REGS;
2081 if (tb->type.type->type == MONO_TYPE_VAR || tb->type.type->type == MONO_TYPE_MVAR)
2082 return !tb->type.type->byref;
2087 ves_icall_EnumBuilder_setup_enum_type (MonoReflectionType *enumtype,
2088 MonoReflectionType *t)
2090 enumtype->type = t->type;
2093 static MonoReflectionType*
2094 ves_icall_MonoGenericClass_GetParentType (MonoReflectionGenericClass *type)
2096 MonoDynamicGenericClass *gclass;
2097 MonoReflectionType *parent = NULL;
2102 MONO_ARCH_SAVE_REGS;
2104 g_assert (type->type.type->data.generic_class->is_dynamic);
2105 gclass = (MonoDynamicGenericClass *) type->type.type->data.generic_class;
2107 domain = mono_object_domain (type);
2108 klass = mono_class_from_mono_type (type->generic_type->type);
2110 if (!klass->generic_class && !klass->generic_container)
2113 if (!strcmp (type->generic_type->object.vtable->klass->name, "TypeBuilder")) {
2114 MonoReflectionTypeBuilder *tb = (MonoReflectionTypeBuilder *) type->generic_type;
2115 parent = tb->parent;
2116 } else if (klass->wastypebuilder) {
2117 MonoReflectionTypeBuilder *tb = (MonoReflectionTypeBuilder *) type->generic_type;
2118 parent = tb->parent;
2120 MonoClass *pklass = klass->parent;
2122 parent = mono_type_get_object (domain, &pklass->byval_arg);
2125 if (!parent || (parent->type->type != MONO_TYPE_GENERICINST))
2128 inflated = mono_class_inflate_generic_type (
2129 parent->type, gclass->generic_class.generic_class.context);
2131 return mono_type_get_object (domain, inflated);
2135 ves_icall_MonoGenericClass_GetInterfaces (MonoReflectionGenericClass *type)
2137 static MonoClass *System_Reflection_MonoGenericClass;
2138 MonoDynamicGenericClass *gclass;
2139 MonoReflectionTypeBuilder *tb = NULL;
2140 MonoClass *klass = NULL;
2145 MONO_ARCH_SAVE_REGS;
2147 if (!System_Reflection_MonoGenericClass) {
2148 System_Reflection_MonoGenericClass = mono_class_from_name (
2149 mono_defaults.corlib, "System.Reflection", "MonoGenericClass");
2150 g_assert (System_Reflection_MonoGenericClass);
2153 domain = mono_object_domain (type);
2155 g_assert (type->type.type->data.generic_class->is_dynamic);
2156 gclass = (MonoDynamicGenericClass *) type->type.type->data.generic_class;
2158 if (!strcmp (type->generic_type->object.vtable->klass->name, "TypeBuilder")) {
2159 tb = (MonoReflectionTypeBuilder *) type->generic_type;
2160 icount = tb->interfaces ? mono_array_length (tb->interfaces) : 0;
2162 klass = gclass->generic_class.generic_class.container_class;
2163 mono_class_init (klass);
2164 icount = klass->interface_count;
2167 res = mono_array_new (domain, System_Reflection_MonoGenericClass, icount);
2169 for (i = 0; i < icount; i++) {
2170 MonoReflectionType *iface;
2174 iface = mono_array_get (tb->interfaces, MonoReflectionType *, i);
2177 it = &klass->interfaces [i]->byval_arg;
2179 it = mono_class_inflate_generic_type (
2180 it, gclass->generic_class.generic_class.context);
2182 iface = mono_type_get_object (domain, it);
2183 mono_array_setref (res, i, iface);
2189 static MonoReflectionMethod*
2190 ves_icall_MonoGenericClass_GetCorrespondingInflatedMethod (MonoReflectionGenericClass *type,
2191 MonoReflectionMethod* generic)
2193 MonoGenericClass *gclass;
2194 MonoDynamicGenericClass *dgclass;
2198 MONO_ARCH_SAVE_REGS;
2200 gclass = type->type.type->data.generic_class;
2201 g_assert (gclass->is_dynamic);
2203 dgclass = (MonoDynamicGenericClass *) gclass;
2205 domain = mono_object_domain (type);
2207 for (i = 0; i < dgclass->count_methods; i++)
2208 if (generic->method->token == dgclass->methods [i]->token)
2209 return mono_method_get_object (domain, dgclass->methods [i], NULL);
2214 static MonoReflectionMethod*
2215 ves_icall_MonoGenericClass_GetCorrespondingInflatedConstructor (MonoReflectionGenericClass *type,
2216 MonoReflectionMethod* generic)
2218 MonoGenericClass *gclass;
2219 MonoDynamicGenericClass *dgclass;
2223 MONO_ARCH_SAVE_REGS;
2225 gclass = type->type.type->data.generic_class;
2226 g_assert (gclass->is_dynamic);
2228 dgclass = (MonoDynamicGenericClass *) gclass;
2230 domain = mono_object_domain (type);
2232 for (i = 0; i < dgclass->count_ctors; i++)
2233 if (generic->method->token == dgclass->ctors [i]->token)
2234 return mono_method_get_object (domain, dgclass->ctors [i], NULL);
2240 static MonoReflectionField*
2241 ves_icall_MonoGenericClass_GetCorrespondingInflatedField (MonoReflectionGenericClass *type,
2242 MonoString* generic_name)
2244 MonoGenericClass *gclass;
2245 MonoDynamicGenericClass *dgclass;
2247 MonoClass *refclass;
2248 char *utf8_name = mono_string_to_utf8 (generic_name);
2251 MONO_ARCH_SAVE_REGS;
2253 gclass = type->type.type->data.generic_class;
2254 g_assert (gclass->is_dynamic);
2256 dgclass = (MonoDynamicGenericClass *) gclass;
2258 refclass = mono_class_from_mono_type (type->type.type);
2260 domain = mono_object_domain (type);
2262 for (i = 0; i < dgclass->count_fields; i++)
2263 if (strcmp (utf8_name, dgclass->fields [i].name) == 0) {
2265 return mono_field_get_object (domain, refclass, &dgclass->fields [i]);
2274 static MonoReflectionMethod*
2275 ves_icall_MonoType_GetCorrespondingInflatedMethod (MonoReflectionType *type,
2276 MonoReflectionMethod* generic)
2283 MONO_ARCH_SAVE_REGS;
2285 domain = ((MonoObject *)type)->vtable->domain;
2287 klass = mono_class_from_mono_type (type->type);
2290 while ((method = mono_class_get_methods (klass, &iter))) {
2291 if (method->token == generic->method->token)
2292 return mono_method_get_object (domain, method, klass);
2299 ves_icall_MonoGenericClass_GetMethods (MonoReflectionGenericClass *type,
2300 MonoReflectionType *reflected_type)
2302 MonoGenericClass *gclass;
2303 MonoDynamicGenericClass *dgclass;
2305 MonoClass *refclass;
2309 MONO_ARCH_SAVE_REGS;
2311 gclass = type->type.type->data.generic_class;
2312 g_assert (gclass->is_dynamic);
2313 dgclass = (MonoDynamicGenericClass *) gclass;
2315 refclass = mono_class_from_mono_type (reflected_type->type);
2317 domain = mono_object_domain (type);
2318 res = mono_array_new (domain, mono_defaults.method_info_class, dgclass->count_methods);
2320 for (i = 0; i < dgclass->count_methods; i++)
2321 mono_array_setref (res, i, mono_method_get_object (domain, dgclass->methods [i], refclass));
2327 ves_icall_MonoGenericClass_GetConstructors (MonoReflectionGenericClass *type,
2328 MonoReflectionType *reflected_type)
2330 static MonoClass *System_Reflection_ConstructorInfo;
2331 MonoGenericClass *gclass;
2332 MonoDynamicGenericClass *dgclass;
2334 MonoClass *refclass;
2338 MONO_ARCH_SAVE_REGS;
2340 if (!System_Reflection_ConstructorInfo)
2341 System_Reflection_ConstructorInfo = mono_class_from_name (
2342 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
2344 gclass = type->type.type->data.generic_class;
2345 g_assert (gclass->is_dynamic);
2346 dgclass = (MonoDynamicGenericClass *) gclass;
2348 refclass = mono_class_from_mono_type (reflected_type->type);
2350 domain = mono_object_domain (type);
2351 res = mono_array_new (domain, System_Reflection_ConstructorInfo, dgclass->count_ctors);
2353 for (i = 0; i < dgclass->count_ctors; i++)
2354 mono_array_setref (res, i, mono_method_get_object (domain, dgclass->ctors [i], refclass));
2360 ves_icall_MonoGenericClass_GetFields (MonoReflectionGenericClass *type,
2361 MonoReflectionType *reflected_type)
2363 MonoGenericClass *gclass;
2364 MonoDynamicGenericClass *dgclass;
2366 MonoClass *refclass;
2370 MONO_ARCH_SAVE_REGS;
2372 gclass = type->type.type->data.generic_class;
2373 g_assert (gclass->is_dynamic);
2374 dgclass = (MonoDynamicGenericClass *) gclass;
2376 refclass = mono_class_from_mono_type (reflected_type->type);
2378 domain = mono_object_domain (type);
2379 res = mono_array_new (domain, mono_defaults.field_info_class, dgclass->count_fields);
2381 for (i = 0; i < dgclass->count_fields; i++)
2382 mono_array_setref (res, i, mono_field_get_object (domain, refclass, &dgclass->fields [i]));
2388 ves_icall_MonoGenericClass_GetProperties (MonoReflectionGenericClass *type,
2389 MonoReflectionType *reflected_type)
2391 static MonoClass *System_Reflection_PropertyInfo;
2392 MonoGenericClass *gclass;
2393 MonoDynamicGenericClass *dgclass;
2395 MonoClass *refclass;
2399 MONO_ARCH_SAVE_REGS;
2401 if (!System_Reflection_PropertyInfo)
2402 System_Reflection_PropertyInfo = mono_class_from_name (
2403 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
2405 gclass = type->type.type->data.generic_class;
2406 g_assert (gclass->is_dynamic);
2407 dgclass = (MonoDynamicGenericClass *) gclass;
2409 refclass = mono_class_from_mono_type (reflected_type->type);
2411 domain = mono_object_domain (type);
2412 res = mono_array_new (domain, System_Reflection_PropertyInfo, dgclass->count_properties);
2414 for (i = 0; i < dgclass->count_properties; i++)
2415 mono_array_setref (res, i, mono_property_get_object (domain, refclass, &dgclass->properties [i]));
2421 ves_icall_MonoGenericClass_GetEvents (MonoReflectionGenericClass *type,
2422 MonoReflectionType *reflected_type)
2424 static MonoClass *System_Reflection_EventInfo;
2425 MonoGenericClass *gclass;
2426 MonoDynamicGenericClass *dgclass;
2428 MonoClass *refclass;
2432 MONO_ARCH_SAVE_REGS;
2434 if (!System_Reflection_EventInfo)
2435 System_Reflection_EventInfo = mono_class_from_name (
2436 mono_defaults.corlib, "System.Reflection", "EventInfo");
2438 gclass = type->type.type->data.generic_class;
2439 g_assert (gclass->is_dynamic);
2440 dgclass = (MonoDynamicGenericClass *) gclass;
2442 refclass = mono_class_from_mono_type (reflected_type->type);
2444 domain = mono_object_domain (type);
2445 res = mono_array_new (domain, System_Reflection_EventInfo, dgclass->count_events);
2447 for (i = 0; i < dgclass->count_events; i++)
2448 mono_array_setref (res, i, mono_event_get_object (domain, refclass, &dgclass->events [i]));
2453 static MonoReflectionMethod *
2454 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *type)
2459 MONO_ARCH_SAVE_REGS;
2461 if (type->type->byref || type->type->type != MONO_TYPE_MVAR)
2464 method = type->type->data.generic_param->method;
2466 klass = mono_class_from_mono_type (type->type);
2467 return mono_method_get_object (mono_object_domain (type), method, klass);
2470 static MonoReflectionDllImportAttribute*
2471 ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
2473 static MonoClass *DllImportAttributeClass = NULL;
2474 MonoDomain *domain = mono_domain_get ();
2475 MonoReflectionDllImportAttribute *attr;
2476 MonoImage *image = method->klass->image;
2477 MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)method;
2478 MonoTableInfo *tables = image->tables;
2479 MonoTableInfo *im = &tables [MONO_TABLE_IMPLMAP];
2480 MonoTableInfo *mr = &tables [MONO_TABLE_MODULEREF];
2481 guint32 im_cols [MONO_IMPLMAP_SIZE];
2482 guint32 scope_token;
2483 const char *import = NULL;
2484 const char *scope = NULL;
2487 if (!method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
2490 if (!DllImportAttributeClass) {
2491 DllImportAttributeClass =
2492 mono_class_from_name (mono_defaults.corlib,
2493 "System.Runtime.InteropServices", "DllImportAttribute");
2494 g_assert (DllImportAttributeClass);
2497 if (method->klass->image->dynamic) {
2498 MonoReflectionMethodAux *method_aux =
2499 g_hash_table_lookup (
2500 ((MonoDynamicImage*)method->klass->image)->method_aux_hash, method);
2502 import = method_aux->dllentry;
2503 scope = method_aux->dll;
2507 if (piinfo->implmap_idx) {
2508 mono_metadata_decode_row (im, piinfo->implmap_idx - 1, im_cols, MONO_IMPLMAP_SIZE);
2510 piinfo->piflags = im_cols [MONO_IMPLMAP_FLAGS];
2511 import = mono_metadata_string_heap (image, im_cols [MONO_IMPLMAP_NAME]);
2512 scope_token = mono_metadata_decode_row_col (mr, im_cols [MONO_IMPLMAP_SCOPE] - 1, MONO_MODULEREF_NAME);
2513 scope = mono_metadata_string_heap (image, scope_token);
2516 flags = piinfo->piflags;
2518 attr = (MonoReflectionDllImportAttribute*)mono_object_new (domain, DllImportAttributeClass);
2520 MONO_OBJECT_SETREF (attr, dll, mono_string_new (domain, scope));
2521 MONO_OBJECT_SETREF (attr, entry_point, mono_string_new (domain, import));
2522 attr->call_conv = (flags & 0x700) >> 8;
2523 attr->charset = ((flags & 0x6) >> 1) + 1;
2524 if (attr->charset == 1)
2526 attr->exact_spelling = (flags & 0x1) != 0;
2527 attr->set_last_error = (flags & 0x40) != 0;
2528 attr->best_fit_mapping = (flags & 0x30) == 0x10;
2529 attr->throw_on_unmappable = (flags & 0x3000) == 0x1000;
2530 attr->preserve_sig = FALSE;
2535 static MonoReflectionMethod *
2536 ves_icall_MonoMethod_GetGenericMethodDefinition (MonoReflectionMethod *method)
2538 MonoMethodInflated *imethod;
2540 MONO_ARCH_SAVE_REGS;
2542 if (!method->method->is_inflated) {
2543 if (mono_method_signature (method->method)->generic_param_count)
2549 imethod = (MonoMethodInflated *) method->method;
2550 if (imethod->context->gmethod && imethod->context->gmethod->reflection_info)
2551 return imethod->context->gmethod->reflection_info;
2553 return mono_method_get_object (
2554 mono_object_domain (method), imethod->declaring, NULL);
2558 ves_icall_MonoMethod_get_IsGenericMethod (MonoReflectionMethod *method)
2560 MONO_ARCH_SAVE_REGS;
2562 return mono_method_signature (method->method)->generic_param_count != 0;
2566 ves_icall_MonoMethod_get_IsGenericMethodDefinition (MonoReflectionMethod *method)
2568 MONO_ARCH_SAVE_REGS;
2570 return !method->method->is_inflated &&
2571 (mono_method_signature (method->method)->generic_param_count != 0);
2575 ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method)
2580 MONO_ARCH_SAVE_REGS;
2582 domain = mono_object_domain (method);
2584 if (method->method->is_inflated) {
2585 MonoMethodInflated *imethod = (MonoMethodInflated *) method->method;
2586 MonoGenericMethod *gmethod = imethod->context->gmethod;
2589 count = gmethod->inst->type_argc;
2590 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2592 for (i = 0; i < count; i++)
2593 mono_array_setref (res, i, mono_type_get_object (domain, gmethod->inst->type_argv [i]));
2599 count = mono_method_signature (method->method)->generic_param_count;
2600 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2602 for (i = 0; i < count; i++) {
2603 MonoGenericParam *param = &method->method->generic_container->type_params [i];
2604 MonoClass *pklass = mono_class_from_generic_parameter (
2605 param, method->method->klass->image, TRUE);
2606 mono_array_setref (res, i,
2607 mono_type_get_object (domain, &pklass->byval_arg));
2614 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
2617 * Invoke from reflection is supposed to always be a virtual call (the API
2618 * is stupid), mono_runtime_invoke_*() calls the provided method, allowing
2619 * greater flexibility.
2621 MonoMethod *m = mono_get_inflated_method (method->method);
2625 MONO_ARCH_SAVE_REGS;
2627 if (!(m->flags & METHOD_ATTRIBUTE_STATIC)) {
2629 if (!mono_object_isinst (this, m->klass))
2630 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2631 m = mono_object_get_virtual_method (this, m);
2632 /* must pass the pointer to the value for valuetype methods */
2633 if (m->klass->valuetype)
2634 obj = mono_object_unbox (this);
2635 } else if (strcmp (m->name, ".ctor") && !m->wrapper_type)
2636 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2639 pcount = params? mono_array_length (params): 0;
2640 if (pcount != mono_method_signature (m)->param_count)
2641 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetParameterCountException"));
2643 if ((m->klass->flags & TYPE_ATTRIBUTE_ABSTRACT) && !strcmp (m->name, ".ctor"))
2644 mono_raise_exception (mono_exception_from_name_msg (mono_defaults.corlib, "System", "MethodAccessException", "Cannot invoke constructor of an abstract class."));
2646 if (m->klass->image->assembly->ref_only)
2647 mono_raise_exception (mono_get_exception_invalid_operation ("It is illegal to invoke a method on a type loaded using the ReflectionOnly api."));
2649 if (m->klass->rank && !strcmp (m->name, ".ctor")) {
2652 guint32 *lower_bounds;
2653 pcount = mono_array_length (params);
2654 lengths = alloca (sizeof (guint32) * pcount);
2655 for (i = 0; i < pcount; ++i)
2656 lengths [i] = *(gint32*) ((char*)mono_array_get (params, gpointer, i) + sizeof (MonoObject));
2658 if (m->klass->rank == pcount) {
2659 /* Only lengths provided. */
2660 lower_bounds = NULL;
2662 g_assert (pcount == (m->klass->rank * 2));
2663 /* lower bounds are first. */
2664 lower_bounds = lengths;
2665 lengths += m->klass->rank;
2668 return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
2670 return mono_runtime_invoke_array (m, obj, params, NULL);
2674 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs)
2676 MonoDomain *domain = mono_object_domain (method);
2677 MonoMethod *m = method->method;
2678 MonoMethodSignature *sig = mono_method_signature (m);
2679 MonoArray *out_args;
2681 int i, j, outarg_count = 0;
2683 MONO_ARCH_SAVE_REGS;
2685 if (m->klass == mono_defaults.object_class) {
2687 if (!strcmp (m->name, "FieldGetter")) {
2688 MonoClass *k = this->vtable->klass;
2692 /* If this is a proxy, then it must be a CBO */
2693 if (k == mono_defaults.transparent_proxy_class) {
2694 MonoTransparentProxy *tp = (MonoTransparentProxy*) this;
2695 this = tp->rp->unwrapped_server;
2697 k = this->vtable->klass;
2700 name = mono_array_get (params, MonoString *, 1);
2701 str = mono_string_to_utf8 (name);
2704 MonoClassField* field = mono_class_get_field_from_name (k, str);
2706 MonoClass *field_klass = mono_class_from_mono_type (field->type);
2707 if (field_klass->valuetype)
2708 result = mono_value_box (domain, field_klass, (char *)this + field->offset);
2710 result = *((gpointer *)((char *)this + field->offset));
2712 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
2713 *outArgs = out_args;
2714 mono_array_setref (out_args, 0, result);
2722 g_assert_not_reached ();
2724 } else if (!strcmp (m->name, "FieldSetter")) {
2725 MonoClass *k = this->vtable->klass;
2730 /* If this is a proxy, then it must be a CBO */
2731 if (k == mono_defaults.transparent_proxy_class) {
2732 MonoTransparentProxy *tp = (MonoTransparentProxy*) this;
2733 this = tp->rp->unwrapped_server;
2735 k = this->vtable->klass;
2738 name = mono_array_get (params, MonoString *, 1);
2739 str = mono_string_to_utf8 (name);
2742 MonoClassField* field = mono_class_get_field_from_name (k, str);
2744 MonoClass *field_klass = mono_class_from_mono_type (field->type);
2745 MonoObject *val = mono_array_get (params, gpointer, 2);
2747 if (field_klass->valuetype) {
2748 size = mono_type_size (field->type, &align);
2749 memcpy ((char *)this + field->offset,
2750 ((char *)val) + sizeof (MonoObject), size);
2752 *(MonoObject**)((char *)this + field->offset) = val;
2754 out_args = mono_array_new (domain, mono_defaults.object_class, 0);
2755 *outArgs = out_args;
2765 g_assert_not_reached ();
2770 for (i = 0; i < mono_array_length (params); i++) {
2771 if (sig->params [i]->byref)
2775 out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
2777 /* handle constructors only for objects already allocated */
2778 if (!strcmp (method->method->name, ".ctor"))
2781 /* This can be called only on MBR objects, so no need to unbox for valuetypes. */
2782 g_assert (!method->method->klass->valuetype);
2783 result = mono_runtime_invoke_array (method->method, this, params, NULL);
2785 for (i = 0, j = 0; i < mono_array_length (params); i++) {
2786 if (sig->params [i]->byref) {
2788 arg = mono_array_get (params, gpointer, i);
2789 mono_array_setref (out_args, j, arg);
2794 *outArgs = out_args;
2800 read_enum_value (char *mem, int type)
2804 return *(guint8*)mem;
2806 return *(gint8*)mem;
2808 return *(guint16*)mem;
2810 return *(gint16*)mem;
2812 return *(guint32*)mem;
2814 return *(gint32*)mem;
2816 return *(guint64*)mem;
2818 return *(gint64*)mem;
2820 g_assert_not_reached ();
2826 write_enum_value (char *mem, int type, guint64 value)
2830 case MONO_TYPE_I1: {
2831 guint8 *p = (guint8*)mem;
2836 case MONO_TYPE_I2: {
2837 guint16 *p = (void*)mem;
2842 case MONO_TYPE_I4: {
2843 guint32 *p = (void*)mem;
2848 case MONO_TYPE_I8: {
2849 guint64 *p = (void*)mem;
2854 g_assert_not_reached ();
2860 ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
2863 MonoClass *enumc, *objc;
2867 MONO_ARCH_SAVE_REGS;
2869 MONO_CHECK_ARG_NULL (type);
2870 MONO_CHECK_ARG_NULL (obj);
2872 domain = mono_object_domain (type);
2873 enumc = mono_class_from_mono_type (type->type);
2874 objc = obj->vtable->klass;
2876 if (!enumc->enumtype)
2877 mono_raise_exception (mono_get_exception_argument ("enumType", "Type provided must be an Enum."));
2878 if (!((objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 && objc->byval_arg.type <= MONO_TYPE_U8)))
2879 mono_raise_exception (mono_get_exception_argument ("value", "The value passed in must be an enum base or an underlying type for an enum, such as an Int32."));
2881 res = mono_object_new (domain, enumc);
2882 val = read_enum_value ((char *)obj + sizeof (MonoObject), objc->enumtype? objc->enum_basetype->type: objc->byval_arg.type);
2883 write_enum_value ((char *)res + sizeof (MonoObject), enumc->enum_basetype->type, val);
2889 ves_icall_System_Enum_get_value (MonoObject *this)
2897 MONO_ARCH_SAVE_REGS;
2902 g_assert (this->vtable->klass->enumtype);
2904 enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
2905 res = mono_object_new (mono_object_domain (this), enumc);
2906 dst = (char *)res + sizeof (MonoObject);
2907 src = (char *)this + sizeof (MonoObject);
2908 size = mono_class_value_size (enumc, NULL);
2910 memcpy (dst, src, size);
2916 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
2918 MonoDomain *domain = mono_object_domain (type);
2919 MonoClass *enumc = mono_class_from_mono_type (type->type);
2920 guint j = 0, nvalues, crow;
2922 MonoClassField *field;
2924 MONO_ARCH_SAVE_REGS;
2926 info->utype = mono_type_get_object (domain, enumc->enum_basetype);
2927 nvalues = mono_class_num_fields (enumc) ? mono_class_num_fields (enumc) - 1 : 0;
2928 info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
2929 info->values = mono_array_new (domain, enumc, nvalues);
2933 while ((field = mono_class_get_fields (enumc, &iter))) {
2937 if (strcmp ("value__", field->name) == 0)
2939 if (mono_field_is_deleted (field))
2941 mono_array_setref (info->names, j, mono_string_new (domain, field->name));
2944 crow = mono_metadata_get_constant_index (enumc->image, mono_class_get_field_token (field), crow + 1);
2945 field->def_type = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_TYPE);
2946 crow = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_VALUE);
2947 field->data = (gpointer)mono_metadata_blob_heap (enumc->image, crow);
2951 len = mono_metadata_decode_blob_size (p, &p);
2952 switch (enumc->enum_basetype->type) {
2955 mono_array_set (info->values, gchar, j, *p);
2957 case MONO_TYPE_CHAR:
2960 mono_array_set (info->values, gint16, j, read16 (p));
2964 mono_array_set (info->values, gint32, j, read32 (p));
2968 mono_array_set (info->values, gint64, j, read64 (p));
2971 g_error ("Implement type 0x%02x in get_enum_info", enumc->enum_basetype->type);
2978 BFLAGS_IgnoreCase = 1,
2979 BFLAGS_DeclaredOnly = 2,
2980 BFLAGS_Instance = 4,
2982 BFLAGS_Public = 0x10,
2983 BFLAGS_NonPublic = 0x20,
2984 BFLAGS_FlattenHierarchy = 0x40,
2985 BFLAGS_InvokeMethod = 0x100,
2986 BFLAGS_CreateInstance = 0x200,
2987 BFLAGS_GetField = 0x400,
2988 BFLAGS_SetField = 0x800,
2989 BFLAGS_GetProperty = 0x1000,
2990 BFLAGS_SetProperty = 0x2000,
2991 BFLAGS_ExactBinding = 0x10000,
2992 BFLAGS_SuppressChangeType = 0x20000,
2993 BFLAGS_OptionalParamBinding = 0x40000
2996 static MonoReflectionField *
2997 ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
3000 MonoClass *startklass, *klass;
3002 MonoClassField *field;
3005 int (*compare_func) (const char *s1, const char *s2) = NULL;
3006 domain = ((MonoObject *)type)->vtable->domain;
3007 klass = startklass = mono_class_from_mono_type (type->type);
3009 MONO_ARCH_SAVE_REGS;
3012 mono_raise_exception (mono_get_exception_argument_null ("name"));
3013 if (type->type->byref)
3016 compare_func = (bflags & BFLAGS_IgnoreCase) ? g_strcasecmp : strcmp;
3020 while ((field = mono_class_get_fields (klass, &iter))) {
3022 if (mono_field_is_deleted (field))
3024 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
3025 if (bflags & BFLAGS_Public)
3028 if (bflags & BFLAGS_NonPublic)
3034 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
3035 if (bflags & BFLAGS_Static)
3036 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3039 if (bflags & BFLAGS_Instance)
3046 utf8_name = mono_string_to_utf8 (name);
3048 if (compare_func (field->name, utf8_name)) {
3054 return mono_field_get_object (domain, klass, field);
3056 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3063 ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
3066 MonoClass *startklass, *klass, *refklass;
3071 MonoClassField *field;
3073 MONO_ARCH_SAVE_REGS;
3075 domain = ((MonoObject *)type)->vtable->domain;
3076 if (type->type->byref)
3077 return mono_array_new (domain, mono_defaults.field_info_class, 0);
3078 klass = startklass = mono_class_from_mono_type (type->type);
3079 refklass = mono_class_from_mono_type (reftype->type);
3083 res = mono_array_new (domain, mono_defaults.field_info_class, len);
3086 while ((field = mono_class_get_fields (klass, &iter))) {
3088 if (mono_field_is_deleted (field))
3090 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
3091 if (bflags & BFLAGS_Public)
3094 if (bflags & BFLAGS_NonPublic)
3100 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
3101 if (bflags & BFLAGS_Static)
3102 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3105 if (bflags & BFLAGS_Instance)
3111 member = (MonoObject*)mono_field_get_object (domain, refklass, field);
3113 MonoArray *new_res = mono_array_new (domain, mono_defaults.field_info_class, len * 2);
3114 mono_array_memcpy_refs (new_res, 0, res, 0, len);
3118 mono_array_setref (res, i, member);
3121 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3124 MonoArray *new_res = mono_array_new (domain, mono_defaults.field_info_class, i);
3125 mono_array_memcpy_refs (new_res, 0, res, 0, i);
3128 * Better solution for the new GC.
3129 * res->max_length = i;
3136 ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
3139 MonoClass *startklass, *klass, *refklass;
3144 int i, len, match, nslots;
3145 guint32 method_slots_default [8];
3146 guint32 *method_slots;
3147 gchar *mname = NULL;
3148 int (*compare_func) (const char *s1, const char *s2) = NULL;
3150 MONO_ARCH_SAVE_REGS;
3152 domain = ((MonoObject *)type)->vtable->domain;
3153 if (type->type->byref)
3154 return mono_array_new (domain, mono_defaults.method_info_class, 0);
3155 klass = startklass = mono_class_from_mono_type (type->type);
3156 refklass = mono_class_from_mono_type (reftype->type);
3159 mname = mono_string_to_utf8 (name);
3160 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
3163 mono_class_setup_vtable (klass);
3165 nslots = MONO_CLASS_IS_INTERFACE (klass) ? mono_class_num_methods (klass) : klass->vtable_size;
3166 if (nslots >= sizeof (method_slots_default) * 8) {
3167 method_slots = g_new0 (guint32, nslots / 32 + 1);
3169 method_slots = method_slots_default;
3170 memset (method_slots, 0, sizeof (method_slots_default));
3174 res = mono_array_new (domain, mono_defaults.method_info_class, len);
3176 mono_class_setup_vtable (klass);
3178 while ((method = mono_class_get_methods (klass, &iter))) {
3180 if (method->name [0] == '.' && (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0))
3182 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
3183 if (bflags & BFLAGS_Public)
3186 if (bflags & BFLAGS_NonPublic)
3192 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
3193 if (bflags & BFLAGS_Static)
3194 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3197 if (bflags & BFLAGS_Instance)
3205 if (compare_func (mname, method->name))
3210 if (method->slot != -1) {
3211 g_assert (method->slot < nslots);
3212 if (method_slots [method->slot >> 5] & (1 << (method->slot & 0x1f)))
3214 method_slots [method->slot >> 5] |= 1 << (method->slot & 0x1f);
3217 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
3220 MonoArray *new_res = mono_array_new (domain, mono_defaults.method_info_class, len * 2);
3221 mono_array_memcpy_refs (new_res, 0, res, 0, len);
3225 mono_array_setref (res, i, member);
3228 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3232 if (method_slots != method_slots_default)
3233 g_free (method_slots);
3235 MonoArray *new_res = mono_array_new (domain, mono_defaults.method_info_class, i);
3236 mono_array_memcpy_refs (new_res, 0, res, 0, i);
3239 * Better solution for the new GC.
3240 * res->max_length = i;
3247 ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
3250 static MonoClass *System_Reflection_ConstructorInfo;
3251 MonoClass *startklass, *klass, *refklass;
3256 gpointer iter = NULL;
3258 MONO_ARCH_SAVE_REGS;
3260 domain = ((MonoObject *)type)->vtable->domain;
3261 if (type->type->byref)
3262 return mono_array_new (domain, mono_defaults.method_info_class, 0);
3263 klass = startklass = mono_class_from_mono_type (type->type);
3264 refklass = mono_class_from_mono_type (reftype->type);
3266 if (!System_Reflection_ConstructorInfo)
3267 System_Reflection_ConstructorInfo = mono_class_from_name (
3268 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
3272 res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
3274 while ((method = mono_class_get_methods (klass, &iter))) {
3276 if (strcmp (method->name, ".ctor") && strcmp (method->name, ".cctor"))
3278 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
3279 if (bflags & BFLAGS_Public)
3282 if (bflags & BFLAGS_NonPublic)
3288 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
3289 if (bflags & BFLAGS_Static)
3290 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3293 if (bflags & BFLAGS_Instance)
3299 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
3302 MonoArray *new_res = mono_array_new (domain, System_Reflection_ConstructorInfo, len * 2);
3303 mono_array_memcpy_refs (new_res, 0, res, 0, len);
3307 mono_array_setref (res, i, member);
3311 MonoArray *new_res = mono_array_new (domain, System_Reflection_ConstructorInfo, i);
3312 mono_array_memcpy_refs (new_res, 0, res, 0, i);
3315 * Better solution for the new GC.
3316 * res->max_length = i;
3323 ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
3326 static MonoClass *System_Reflection_PropertyInfo;
3327 MonoClass *startklass, *klass;
3331 int i, match, nslots;
3334 guint32 method_slots_default [8];
3335 guint32 *method_slots;
3336 gchar *propname = NULL;
3337 int (*compare_func) (const char *s1, const char *s2) = NULL;
3340 MONO_ARCH_SAVE_REGS;
3342 if (!System_Reflection_PropertyInfo)
3343 System_Reflection_PropertyInfo = mono_class_from_name (
3344 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
3346 domain = ((MonoObject *)type)->vtable->domain;
3347 if (type->type->byref)
3348 return mono_array_new (domain, System_Reflection_PropertyInfo, 0);
3349 klass = startklass = mono_class_from_mono_type (type->type);
3351 propname = mono_string_to_utf8 (name);
3352 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
3355 mono_class_setup_vtable (klass);
3357 nslots = MONO_CLASS_IS_INTERFACE (klass) ? mono_class_num_methods (klass) : klass->vtable_size;
3358 if (nslots >= sizeof (method_slots_default) * 8) {
3359 method_slots = g_new0 (guint32, nslots / 32 + 1);
3361 method_slots = method_slots_default;
3362 memset (method_slots, 0, sizeof (method_slots_default));
3366 res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
3368 mono_class_setup_vtable (klass);
3370 while ((prop = mono_class_get_properties (klass, &iter))) {
3376 flags = method->flags;
3379 if ((prop->get && ((prop->get->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC)) ||
3380 (prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC))) {
3381 if (bflags & BFLAGS_Public)
3384 if (bflags & BFLAGS_NonPublic)
3390 if (flags & METHOD_ATTRIBUTE_STATIC) {
3391 if (bflags & BFLAGS_Static)
3392 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3395 if (bflags & BFLAGS_Instance)
3404 if (compare_func (propname, prop->name))
3408 if (prop->get && prop->get->slot != -1) {
3409 if (method_slots [prop->get->slot >> 5] & (1 << (prop->get->slot & 0x1f)))
3411 method_slots [prop->get->slot >> 5] |= 1 << (prop->get->slot & 0x1f);
3413 if (prop->set && prop->set->slot != -1) {
3414 if (method_slots [prop->set->slot >> 5] & (1 << (prop->set->slot & 0x1f)))
3416 method_slots [prop->set->slot >> 5] |= 1 << (prop->set->slot & 0x1f);
3420 MonoArray *new_res = mono_array_new (domain, System_Reflection_PropertyInfo, len * 2);
3421 mono_array_memcpy_refs (new_res, 0, res, 0, len);
3425 mono_array_setref (res, i, mono_property_get_object (domain, startklass, prop));
3428 if ((!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
3432 if (method_slots != method_slots_default)
3433 g_free (method_slots);
3435 MonoArray *new_res = mono_array_new (domain, System_Reflection_PropertyInfo, i);
3436 mono_array_memcpy_refs (new_res, 0, res, 0, i);
3439 * Better solution for the new GC.
3440 * res->max_length = i;
3446 static MonoReflectionEvent *
3447 ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
3450 MonoClass *klass, *startklass;
3456 MONO_ARCH_SAVE_REGS;
3458 event_name = mono_string_to_utf8 (name);
3459 if (type->type->byref)
3461 klass = startklass = mono_class_from_mono_type (type->type);
3462 domain = mono_object_domain (type);
3466 while ((event = mono_class_get_events (klass, &iter))) {
3467 if (strcmp (event->name, event_name))
3470 method = event->add;
3472 method = event->remove;
3474 method = event->raise;
3476 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
3477 if (!(bflags & BFLAGS_Public))
3480 if (!(bflags & BFLAGS_NonPublic))
3485 if (!(bflags & BFLAGS_NonPublic))
3488 g_free (event_name);
3489 return mono_event_get_object (domain, startklass, event);
3492 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3495 g_free (event_name);
3500 ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
3503 static MonoClass *System_Reflection_EventInfo;
3504 MonoClass *startklass, *klass;
3511 MONO_ARCH_SAVE_REGS;
3513 if (!System_Reflection_EventInfo)
3514 System_Reflection_EventInfo = mono_class_from_name (
3515 mono_defaults.corlib, "System.Reflection", "EventInfo");
3517 domain = mono_object_domain (type);
3518 if (type->type->byref)
3519 return mono_array_new (domain, System_Reflection_EventInfo, 0);
3520 klass = startklass = mono_class_from_mono_type (type->type);
3524 res = mono_array_new (domain, System_Reflection_EventInfo, len);
3527 while ((event = mono_class_get_events (klass, &iter))) {
3529 method = event->add;
3531 method = event->remove;
3533 method = event->raise;
3535 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
3536 if (bflags & BFLAGS_Public)
3539 if (bflags & BFLAGS_NonPublic)
3544 if (bflags & BFLAGS_NonPublic)
3550 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
3551 if (bflags & BFLAGS_Static)
3552 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3555 if (bflags & BFLAGS_Instance)
3560 if (bflags & BFLAGS_Instance)
3566 MonoArray *new_res = mono_array_new (domain, System_Reflection_EventInfo, len * 2);
3567 mono_array_memcpy_refs (new_res, 0, res, 0, len);
3571 mono_array_setref (res, i, mono_event_get_object (domain, startklass, event));
3574 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3577 MonoArray *new_res = mono_array_new (domain, System_Reflection_EventInfo, i);
3578 mono_array_memcpy_refs (new_res, 0, res, 0, i);
3581 * Better solution for the new GC.
3582 * res->max_length = i;
3588 static MonoReflectionType *
3589 ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
3592 MonoClass *startklass, *klass;
3597 MONO_ARCH_SAVE_REGS;
3599 domain = ((MonoObject *)type)->vtable->domain;
3600 if (type->type->byref)
3602 klass = startklass = mono_class_from_mono_type (type->type);
3603 str = mono_string_to_utf8 (name);
3606 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
3608 nested = tmpn->data;
3609 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
3610 if (bflags & BFLAGS_Public)
3613 if (bflags & BFLAGS_NonPublic)
3618 if (strcmp (nested->name, str) == 0){
3620 return mono_type_get_object (domain, &nested->byval_arg);
3623 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3630 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
3634 MonoClass *startklass, *klass;
3640 MONO_ARCH_SAVE_REGS;
3642 domain = ((MonoObject *)type)->vtable->domain;
3643 if (type->type->byref)
3644 return mono_array_new (domain, mono_defaults.monotype_class, 0);
3645 klass = startklass = mono_class_from_mono_type (type->type);
3649 res = mono_array_new (domain, mono_defaults.monotype_class, len);
3650 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
3652 nested = tmpn->data;
3653 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
3654 if (bflags & BFLAGS_Public)
3657 if (bflags & BFLAGS_NonPublic)
3662 member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
3664 MonoArray *new_res = mono_array_new (domain, mono_defaults.monotype_class, len * 2);
3665 mono_array_memcpy_refs (new_res, 0, res, 0, len);
3669 mono_array_setref (res, i, member);
3673 MonoArray *new_res = mono_array_new (domain, mono_defaults.monotype_class, i);
3674 mono_array_memcpy_refs (new_res, 0, res, 0, i);
3677 * Better solution for the new GC.
3678 * res->max_length = i;
3684 static MonoReflectionType*
3685 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoReflectionModule *module, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
3688 MonoType *type = NULL;
3689 MonoTypeNameParse info;
3690 gboolean type_resolve;
3692 MONO_ARCH_SAVE_REGS;
3694 /* On MS.NET, this does not fire a TypeResolve event */
3695 type_resolve = TRUE;
3696 str = mono_string_to_utf8 (name);
3697 /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
3698 if (!mono_reflection_parse_type (str, &info)) {
3700 g_list_free (info.modifiers);
3701 g_list_free (info.nested);
3702 if (throwOnError) /* uhm: this is a parse error, though... */
3703 mono_raise_exception (mono_get_exception_type_load (name, NULL));
3704 /*g_print ("failed parse\n");*/
3708 if (module != NULL) {
3710 type = mono_reflection_get_type (module->image, &info, ignoreCase, &type_resolve);
3715 if (assembly->assembly->dynamic) {
3716 /* Enumerate all modules */
3717 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
3721 if (abuilder->modules) {
3722 for (i = 0; i < mono_array_length (abuilder->modules); ++i) {
3723 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
3724 type = mono_reflection_get_type (&mb->dynamic_image->image, &info, ignoreCase, &type_resolve);
3730 if (!type && abuilder->loaded_modules) {
3731 for (i = 0; i < mono_array_length (abuilder->loaded_modules); ++i) {
3732 MonoReflectionModule *mod = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
3733 type = mono_reflection_get_type (mod->image, &info, ignoreCase, &type_resolve);
3740 type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase, &type_resolve);
3742 g_list_free (info.modifiers);
3743 g_list_free (info.nested);
3746 mono_raise_exception (mono_get_exception_type_load (name, NULL));
3747 /* g_print ("failed find\n"); */
3751 if (type->type == MONO_TYPE_CLASS) {
3752 MonoClass *klass = mono_type_get_class (type);
3753 /* need to report exceptions ? */
3754 if (throwOnError && klass->exception_type) {
3755 /* report SecurityException (or others) that occured when loading the assembly */
3756 MonoException *exc = mono_class_get_exception_for_failure (klass);
3757 mono_raise_exception (exc);
3758 } else if (klass->exception_type == MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND) {
3763 /* g_print ("got it\n"); */
3764 return mono_type_get_object (mono_object_domain (assembly), type);
3768 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly, MonoBoolean escaped)
3770 MonoDomain *domain = mono_object_domain (assembly);
3771 MonoAssembly *mass = assembly->assembly;
3772 MonoString *res = NULL;
3776 MONO_ARCH_SAVE_REGS;
3778 absolute = g_build_filename (mass->basedir, mass->image->module_name, NULL);
3782 for (i = strlen (absolute) - 1; i >= 0; i--)
3783 if (absolute [i] == '\\')
3788 uri = g_filename_to_uri (absolute, NULL, NULL);
3790 uri = g_strconcat ("file://", absolute, NULL);
3794 res = mono_string_new (domain, uri);
3802 ves_icall_System_Reflection_Assembly_get_global_assembly_cache (MonoReflectionAssembly *assembly)
3804 MonoAssembly *mass = assembly->assembly;
3806 MONO_ARCH_SAVE_REGS;
3808 return mass->in_gac;
3811 static MonoReflectionAssembly*
3812 ves_icall_System_Reflection_Assembly_load_with_partial_name (MonoString *mname, MonoObject *evidence)
3816 MonoImageOpenStatus status;
3818 MONO_ARCH_SAVE_REGS;
3820 name = mono_string_to_utf8 (mname);
3821 res = mono_assembly_load_with_partial_name (name, &status);
3827 return mono_assembly_get_object (mono_domain_get (), res);
3831 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assembly)
3833 MonoDomain *domain = mono_object_domain (assembly);
3836 MONO_ARCH_SAVE_REGS;
3838 res = mono_string_new (domain, mono_image_get_filename (assembly->assembly->image));
3844 ves_icall_System_Reflection_Assembly_get_ReflectionOnly (MonoReflectionAssembly *assembly)
3846 MONO_ARCH_SAVE_REGS;
3848 return assembly->assembly->ref_only;
3852 ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflectionAssembly *assembly)
3854 MonoDomain *domain = mono_object_domain (assembly);
3856 MONO_ARCH_SAVE_REGS;
3858 return mono_string_new (domain, assembly->assembly->image->version);
3861 static MonoReflectionMethod*
3862 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly)
3864 guint32 token = mono_image_get_entry_point (assembly->assembly->image);
3866 MONO_ARCH_SAVE_REGS;
3870 return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL), NULL);
3873 static MonoReflectionModule*
3874 ves_icall_System_Reflection_Assembly_get_ManifestModule (MonoReflectionAssembly *assembly)
3876 return mono_module_get_object (mono_object_domain (assembly), assembly->assembly->image);
3880 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly)
3882 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3883 MonoArray *result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3887 MONO_ARCH_SAVE_REGS;
3889 for (i = 0; i < table->rows; ++i) {
3890 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_MANIFEST_NAME));
3891 mono_array_setref (result, i, mono_string_new (mono_object_domain (assembly), val));
3897 create_version (MonoDomain *domain, guint32 major, guint32 minor, guint32 build, guint32 revision)
3899 static MonoClass *System_Version = NULL;
3900 static MonoMethod *create_version = NULL;
3904 if (!System_Version) {
3905 System_Version = mono_class_from_name (mono_defaults.corlib, "System", "Version");
3906 g_assert (System_Version);
3909 if (!create_version) {
3910 MonoMethodDesc *desc = mono_method_desc_new (":.ctor(int,int,int,int)", FALSE);
3911 create_version = mono_method_desc_search_in_class (desc, System_Version);
3912 g_assert (create_version);
3913 mono_method_desc_free (desc);
3919 args [3] = &revision;
3920 result = mono_object_new (domain, System_Version);
3921 mono_runtime_invoke (create_version, result, args, NULL);
3927 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly)
3929 static MonoClass *System_Reflection_AssemblyName;
3931 MonoDomain *domain = mono_object_domain (assembly);
3933 static MonoMethod *create_culture = NULL;
3934 MonoImage *image = assembly->assembly->image;
3937 MONO_ARCH_SAVE_REGS;
3939 if (!System_Reflection_AssemblyName)
3940 System_Reflection_AssemblyName = mono_class_from_name (
3941 mono_defaults.corlib, "System.Reflection", "AssemblyName");
3943 t = &assembly->assembly->image->tables [MONO_TABLE_ASSEMBLYREF];
3946 result = mono_array_new (domain, System_Reflection_AssemblyName, count);
3949 MonoMethodDesc *desc = mono_method_desc_new (
3950 "System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3951 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3952 g_assert (create_culture);
3953 mono_method_desc_free (desc);
3956 for (i = 0; i < count; i++) {
3957 MonoReflectionAssemblyName *aname;
3958 guint32 cols [MONO_ASSEMBLYREF_SIZE];
3960 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
3962 aname = (MonoReflectionAssemblyName *) mono_object_new (
3963 domain, System_Reflection_AssemblyName);
3965 MONO_OBJECT_SETREF (aname, name, mono_string_new (domain, mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_NAME])));
3967 aname->major = cols [MONO_ASSEMBLYREF_MAJOR_VERSION];
3968 aname->minor = cols [MONO_ASSEMBLYREF_MINOR_VERSION];
3969 aname->build = cols [MONO_ASSEMBLYREF_BUILD_NUMBER];
3970 aname->revision = cols [MONO_ASSEMBLYREF_REV_NUMBER];
3971 aname->flags = cols [MONO_ASSEMBLYREF_FLAGS];
3972 aname->versioncompat = 1; /* SameMachine (default) */
3973 aname->hashalg = ASSEMBLY_HASH_SHA1; /* SHA1 (default) */
3974 MONO_OBJECT_SETREF (aname, version, create_version (domain, aname->major, aname->minor, aname->build, aname->revision));
3976 if (create_culture) {
3978 args [0] = mono_string_new (domain, mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_CULTURE]));
3979 MONO_OBJECT_SETREF (aname, cultureInfo, mono_runtime_invoke (create_culture, NULL, args, NULL));
3982 if (cols [MONO_ASSEMBLYREF_PUBLIC_KEY]) {
3983 const gchar *pkey_ptr = mono_metadata_blob_heap (image, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
3984 guint32 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3986 if ((cols [MONO_ASSEMBLYREF_FLAGS] & ASSEMBLYREF_FULL_PUBLIC_KEY_FLAG)) {
3987 /* public key token isn't copied - the class library will
3988 automatically generate it from the public key if required */
3989 MONO_OBJECT_SETREF (aname, publicKey, mono_array_new (domain, mono_defaults.byte_class, pkey_len));
3990 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3992 MONO_OBJECT_SETREF (aname, keyToken, mono_array_new (domain, mono_defaults.byte_class, pkey_len));
3993 memcpy (mono_array_addr (aname->keyToken, guint8, 0), pkey_ptr, pkey_len);
3997 /* note: this function doesn't return the codebase on purpose (i.e. it can
3998 be used under partial trust as path information isn't present). */
4000 mono_array_setref (result, i, aname);
4011 foreach_namespace (const char* key, gconstpointer val, NameSpaceInfo *info)
4013 MonoString *name = mono_string_new (mono_object_domain (info->res), key);
4015 mono_array_setref (info->res, info->idx, name);
4020 ves_icall_System_Reflection_Assembly_GetNamespaces (MonoReflectionAssembly *assembly)
4022 MonoImage *img = assembly->assembly->image;
4026 MONO_ARCH_SAVE_REGS;
4028 res = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, g_hash_table_size (img->name_cache));
4031 g_hash_table_foreach (img->name_cache, (GHFunc)foreach_namespace, &info);
4036 /* move this in some file in mono/util/ */
4038 g_concat_dir_and_file (const char *dir, const char *file)
4040 g_return_val_if_fail (dir != NULL, NULL);
4041 g_return_val_if_fail (file != NULL, NULL);
4044 * If the directory name doesn't have a / on the end, we need
4045 * to add one so we get a proper path to the file
4047 if (dir [strlen(dir) - 1] != G_DIR_SEPARATOR)
4048 return g_strconcat (dir, G_DIR_SEPARATOR_S, file, NULL);
4050 return g_strconcat (dir, file, NULL);
4054 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name, gint32 *size, MonoReflectionModule **ref_module)
4056 char *n = mono_string_to_utf8 (name);
4057 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
4059 guint32 cols [MONO_MANIFEST_SIZE];
4060 guint32 impl, file_idx;
4064 MONO_ARCH_SAVE_REGS;
4066 for (i = 0; i < table->rows; ++i) {
4067 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
4068 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
4069 if (strcmp (val, n) == 0)
4073 if (i == table->rows)
4076 impl = cols [MONO_MANIFEST_IMPLEMENTATION];
4079 * this code should only be called after obtaining the
4080 * ResourceInfo and handling the other cases.
4082 g_assert ((impl & MONO_IMPLEMENTATION_MASK) == MONO_IMPLEMENTATION_FILE);
4083 file_idx = impl >> MONO_IMPLEMENTATION_BITS;
4085 module = mono_image_load_file_for_image (assembly->assembly->image, file_idx);
4090 module = assembly->assembly->image;
4092 *ref_module = mono_module_get_object (mono_domain_get (), module);
4094 return (void*)mono_image_get_resource (module, cols [MONO_MANIFEST_OFFSET], (guint32*)size);
4098 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoManifestResourceInfo *info)
4100 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
4102 guint32 cols [MONO_MANIFEST_SIZE];
4103 guint32 file_cols [MONO_FILE_SIZE];
4107 MONO_ARCH_SAVE_REGS;
4109 n = mono_string_to_utf8 (name);
4110 for (i = 0; i < table->rows; ++i) {
4111 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
4112 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
4113 if (strcmp (val, n) == 0)
4117 if (i == table->rows)
4120 if (!cols [MONO_MANIFEST_IMPLEMENTATION]) {
4121 info->location = RESOURCE_LOCATION_EMBEDDED | RESOURCE_LOCATION_IN_MANIFEST;
4124 switch (cols [MONO_MANIFEST_IMPLEMENTATION] & MONO_IMPLEMENTATION_MASK) {
4125 case MONO_IMPLEMENTATION_FILE:
4126 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> MONO_IMPLEMENTATION_BITS;
4127 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
4128 mono_metadata_decode_row (table, i - 1, file_cols, MONO_FILE_SIZE);
4129 val = mono_metadata_string_heap (assembly->assembly->image, file_cols [MONO_FILE_NAME]);
4130 MONO_OBJECT_SETREF (info, filename, mono_string_new (mono_object_domain (assembly), val));
4131 if (file_cols [MONO_FILE_FLAGS] && FILE_CONTAINS_NO_METADATA)
4134 info->location = RESOURCE_LOCATION_EMBEDDED;
4137 case MONO_IMPLEMENTATION_ASSEMBLYREF:
4138 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> MONO_IMPLEMENTATION_BITS;
4139 mono_assembly_load_reference (assembly->assembly->image, i - 1);
4140 if (assembly->assembly->image->references [i - 1] == (gpointer)-1) {
4141 char *msg = g_strdup_printf ("Assembly %d referenced from assembly %s not found ", i - 1, assembly->assembly->image->name);
4142 MonoException *ex = mono_get_exception_file_not_found2 (msg, NULL);
4144 mono_raise_exception (ex);
4146 MONO_OBJECT_SETREF (info, assembly, mono_assembly_get_object (mono_domain_get (), assembly->assembly->image->references [i - 1]));
4148 /* Obtain info recursively */
4149 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (info->assembly, name, info);
4150 info->location |= RESOURCE_LOCATION_ANOTHER_ASSEMBLY;
4153 case MONO_IMPLEMENTATION_EXP_TYPE:
4154 g_assert_not_reached ();
4163 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoBoolean resource_modules)
4165 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
4166 MonoArray *result = NULL;
4171 MONO_ARCH_SAVE_REGS;
4173 /* check hash if needed */
4175 n = mono_string_to_utf8 (name);
4176 for (i = 0; i < table->rows; ++i) {
4177 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
4178 if (strcmp (val, n) == 0) {
4181 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
4182 fn = mono_string_new (mono_object_domain (assembly), n);
4184 return (MonoObject*)fn;
4192 for (i = 0; i < table->rows; ++i) {
4193 if (resource_modules || !(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA))
4197 result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, count);
4200 for (i = 0; i < table->rows; ++i) {
4201 if (resource_modules || !(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
4202 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
4203 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
4204 mono_array_setref (result, count, mono_string_new (mono_object_domain (assembly), n));
4209 return (MonoObject*)result;
4213 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly *assembly)
4215 MonoDomain *domain = mono_domain_get();
4218 int i, j, file_count = 0;
4219 MonoImage **modules;
4220 guint32 module_count, real_module_count;
4221 MonoTableInfo *table;
4223 g_assert (assembly->assembly->image != NULL);
4225 if (assembly->assembly->dynamic) {
4226 MonoReflectionAssemblyBuilder *assemblyb = (MonoReflectionAssemblyBuilder*)assembly;
4228 if (assemblyb->modules)
4229 module_count = mono_array_length (assemblyb->modules);
4232 real_module_count = module_count;
4234 modules = g_new0 (MonoImage*, module_count);
4235 if (assemblyb->modules) {
4236 for (i = 0; i < mono_array_length (assemblyb->modules); ++i) {
4238 mono_array_get (assemblyb->modules, MonoReflectionModuleBuilder*, i)->module.image;
4243 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
4244 file_count = table->rows;
4246 modules = assembly->assembly->image->modules;
4247 module_count = assembly->assembly->image->module_count;
4249 real_module_count = 0;
4250 for (i = 0; i < module_count; ++i)
4252 real_module_count ++;
4255 klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "Module");
4256 res = mono_array_new (domain, klass, 1 + real_module_count + file_count);
4258 mono_array_setref (res, 0, mono_module_get_object (domain, assembly->assembly->image));
4260 for (i = 0; i < module_count; ++i)
4262 mono_array_setref (res, j, mono_module_get_object (domain, modules[i]));
4266 for (i = 0; i < file_count; ++i, ++j)
4267 mono_array_setref (res, j, mono_module_file_get_object (domain, assembly->assembly->image, i));
4269 if (assembly->assembly->dynamic)
4275 static MonoReflectionMethod*
4276 ves_icall_GetCurrentMethod (void)
4278 MonoMethod *m = mono_method_get_last_managed ();
4280 MONO_ARCH_SAVE_REGS;
4282 return mono_method_get_object (mono_domain_get (), m, NULL);
4285 static MonoReflectionMethod*
4286 ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternal (MonoMethod *method)
4288 return mono_method_get_object (mono_domain_get (), method, NULL);
4291 static MonoReflectionMethodBody*
4292 ves_icall_System_Reflection_MethodBase_GetMethodBodyInternal (MonoMethod *method)
4294 return mono_method_body_get_object (mono_domain_get (), method);
4297 static MonoReflectionAssembly*
4298 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
4300 MonoMethod *m = mono_method_get_last_managed ();
4302 MONO_ARCH_SAVE_REGS;
4304 return mono_assembly_get_object (mono_domain_get (), m->klass->image->assembly);
4308 static MonoReflectionAssembly*
4309 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
4311 MonoDomain* domain = mono_domain_get ();
4313 MONO_ARCH_SAVE_REGS;
4315 if (!domain->entry_assembly)
4318 return mono_assembly_get_object (domain, domain->entry_assembly);
4321 static MonoReflectionAssembly*
4322 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
4324 MonoMethod *m = mono_method_get_last_managed ();
4325 MonoMethod *dest = m;
4327 MONO_ARCH_SAVE_REGS;
4329 mono_stack_walk_no_il (get_caller, &dest);
4332 return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
4336 ves_icall_System_MonoType_getFullName (MonoReflectionType *object, gboolean full_name,
4337 gboolean assembly_qualified)
4339 MonoDomain *domain = mono_object_domain (object);
4340 MonoTypeNameFormat format;
4344 MONO_ARCH_SAVE_REGS;
4346 format = assembly_qualified ?
4347 MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED :
4348 MONO_TYPE_NAME_FORMAT_FULL_NAME;
4350 format = MONO_TYPE_NAME_FORMAT_REFLECTION;
4352 name = mono_type_get_name_full (object->type, format);
4356 if (full_name && (object->type->type == MONO_TYPE_VAR || object->type->type == MONO_TYPE_MVAR))
4359 res = mono_string_new (domain, name);
4366 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute, gboolean by_default_version)
4368 static MonoMethod *create_culture = NULL;
4371 const char *pkey_ptr;
4374 MONO_ARCH_SAVE_REGS;
4376 MONO_OBJECT_SETREF (aname, name, mono_string_new (domain, name->name));
4377 aname->major = name->major;
4378 aname->minor = name->minor;
4379 aname->build = name->build;
4380 aname->revision = name->revision;
4381 aname->hashalg = name->hash_alg;
4382 if (by_default_version)
4383 MONO_OBJECT_SETREF (aname, version, create_version (domain, name->major, name->minor, name->build, name->revision));
4385 codebase = g_filename_to_uri (absolute, NULL, NULL);
4387 MONO_OBJECT_SETREF (aname, codebase, mono_string_new (domain, codebase));
4391 if (!create_culture) {
4392 MonoMethodDesc *desc = mono_method_desc_new ("System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
4393 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
4394 g_assert (create_culture);
4395 mono_method_desc_free (desc);
4398 if (name->culture) {
4399 args [0] = mono_string_new (domain, name->culture);
4400 MONO_OBJECT_SETREF (aname, cultureInfo, mono_runtime_invoke (create_culture, NULL, args, NULL));
4403 if (name->public_key) {
4404 pkey_ptr = (char*)name->public_key;
4405 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
4407 MONO_OBJECT_SETREF (aname, publicKey, mono_array_new (domain, mono_defaults.byte_class, pkey_len));
4408 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
4411 /* MonoAssemblyName keeps the public key token as an hexadecimal string */
4412 if (name->public_key_token [0]) {
4416 MONO_OBJECT_SETREF (aname, keyToken, mono_array_new (domain, mono_defaults.byte_class, 8));
4417 p = mono_array_addr (aname->keyToken, char, 0);
4419 for (i = 0, j = 0; i < 8; i++) {
4420 *p = g_ascii_xdigit_value (name->public_key_token [j++]) << 4;
4421 *p |= g_ascii_xdigit_value (name->public_key_token [j++]);
4428 ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
4432 MONO_ARCH_SAVE_REGS;
4434 absolute = g_build_filename (assembly->assembly->basedir, assembly->assembly->image->module_name, NULL);
4436 fill_reflection_assembly_name (mono_object_domain (assembly), aname,
4437 &assembly->assembly->aname, absolute, TRUE);
4443 ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname, MonoReflectionAssemblyName *aname)
4446 MonoImageOpenStatus status = MONO_IMAGE_OK;
4449 MonoAssemblyName name;
4451 MONO_ARCH_SAVE_REGS;
4453 filename = mono_string_to_utf8 (fname);
4455 image = mono_image_open (filename, &status);
4461 exc = mono_get_exception_file_not_found (fname);
4462 mono_raise_exception (exc);
4465 res = mono_assembly_fill_assembly_name (image, &name);
4467 mono_image_close (image);
4469 mono_raise_exception (mono_get_exception_argument ("assemblyFile", "The file does not contain a manifest"));
4472 fill_reflection_assembly_name (mono_domain_get (), aname, &name, filename, TRUE);
4475 mono_image_close (image);
4479 ves_icall_System_Reflection_Assembly_LoadPermissions (MonoReflectionAssembly *assembly,
4480 char **minimum, guint32 *minLength, char **optional, guint32 *optLength, char **refused, guint32 *refLength)
4482 MonoBoolean result = FALSE;
4483 MonoDeclSecurityEntry entry;
4485 /* SecurityAction.RequestMinimum */
4486 if (mono_declsec_get_assembly_action (assembly->assembly, SECURITY_ACTION_REQMIN, &entry)) {
4487 *minimum = entry.blob;
4488 *minLength = entry.size;
4491 /* SecurityAction.RequestOptional */
4492 if (mono_declsec_get_assembly_action (assembly->assembly, SECURITY_ACTION_REQOPT, &entry)) {
4493 *optional = entry.blob;
4494 *optLength = entry.size;
4497 /* SecurityAction.RequestRefuse */
4498 if (mono_declsec_get_assembly_action (assembly->assembly, SECURITY_ACTION_REQREFUSE, &entry)) {
4499 *refused = entry.blob;
4500 *refLength = entry.size;
4508 mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoBoolean exportedOnly)
4512 MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF];
4514 guint32 attrs, visibility;
4516 /* we start the count from 1 because we skip the special type <Module> */
4519 for (i = 1; i < tdef->rows; ++i) {
4520 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
4521 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
4522 if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
4526 count = tdef->rows - 1;
4528 res = mono_array_new (domain, mono_defaults.monotype_class, count);
4530 for (i = 1; i < tdef->rows; ++i) {
4531 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
4532 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
4533 if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
4534 klass = mono_class_get_throw (image, (i + 1) | MONO_TOKEN_TYPE_DEF);
4535 if (mono_loader_get_last_error ())
4536 mono_loader_clear_error ();
4537 mono_array_setref (res, count, mono_type_get_object (domain, &klass->byval_arg));
4546 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
4548 MonoArray *res = NULL;
4549 MonoImage *image = NULL;
4550 MonoTableInfo *table = NULL;
4555 MONO_ARCH_SAVE_REGS;
4557 domain = mono_object_domain (assembly);
4559 if (assembly->assembly->dynamic) {
4560 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
4561 if (abuilder->modules) {
4562 for (i = 0; i < mono_array_length(abuilder->modules); i++) {
4563 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
4564 MonoArray *append = mb->types;
4565 if (append && mono_array_length (append) > 0) {
4568 len1 = res ? mono_array_length (res) : 0;
4569 len2 = mono_array_length (append);
4570 new = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
4572 mono_array_memcpy_refs (new, 0, res, 0, len1);
4573 mono_array_memcpy_refs (new, len1, append, 0, len2);
4579 * Replace TypeBuilders with the created types to be compatible
4583 for (i = 0; i < mono_array_length (res); ++i) {
4584 MonoReflectionTypeBuilder *tb = mono_array_get (res, MonoReflectionTypeBuilder*, i);
4586 mono_array_setref (res, i, tb->created);
4591 if (abuilder->loaded_modules)
4592 for (i = 0; i < mono_array_length(abuilder->loaded_modules); i++) {
4593 MonoReflectionModule *rm = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
4594 MonoArray *append = mono_module_get_types (domain, rm->image, exportedOnly);
4595 if (append && mono_array_length (append) > 0) {
4598 len1 = res ? mono_array_length (res) : 0;
4599 len2 = mono_array_length (append);
4600 new = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
4602 mono_array_memcpy_refs (new, 0, res, 0, len1);
4603 mono_array_memcpy_refs (new, len1, append, 0, len2);
4610 return mono_array_new (domain, mono_defaults.monotype_class, 0);
4612 image = assembly->assembly->image;
4613 table = &image->tables [MONO_TABLE_FILE];
4614 res = mono_module_get_types (domain, image, exportedOnly);
4616 /* Append data from all modules in the assembly */
4617 for (i = 0; i < table->rows; ++i) {
4618 if (!(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
4619 MonoImage *loaded_image = mono_assembly_load_module (image->assembly, i + 1);
4621 MonoArray *res2 = mono_module_get_types (domain, loaded_image, exportedOnly);
4622 /* Append the new types to the end of the array */
4623 if (mono_array_length (res2) > 0) {
4627 len1 = mono_array_length (res);
4628 len2 = mono_array_length (res2);
4629 res3 = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
4630 mono_array_memcpy_refs (res3, 0, res, 0, len1);
4631 mono_array_memcpy_refs (res3, len1, res2, 0, len2);
4638 /* the ReflectionTypeLoadException must have all the types (Types property),
4639 * NULL replacing types which throws an exception. The LoaderException must
4640 * contain all exceptions for NULL items.
4643 len = mono_array_length (res);
4645 for (i = 0; i < len; i++) {
4646 MonoReflectionType *t = mono_array_get (res, gpointer, i);
4647 MonoClass *klass = mono_type_get_class (t->type);
4648 if ((klass != NULL) && klass->exception_type) {
4649 /* keep the class in the list */
4650 list = g_list_append (list, klass);
4651 /* and replace Type with NULL */
4652 mono_array_setref (res, i, NULL);
4658 MonoException *exc = NULL;
4659 int length = g_list_length (list);
4661 mono_loader_clear_error ();
4663 MonoArray *exl = mono_array_new (domain, mono_defaults.exception_class, length);
4664 for (i = 0, tmp = list; i < length; i++, tmp = tmp->next) {
4665 MonoException *exc = mono_class_get_exception_for_failure (tmp->data);
4666 mono_array_setref (exl, i, exc);
4671 exc = mono_get_exception_reflection_type_load (res, exl);
4672 mono_raise_exception (exc);
4679 ves_icall_System_Reflection_AssemblyName_ParseName (MonoReflectionAssemblyName *name, MonoString *assname)
4681 MonoAssemblyName aname;
4682 MonoDomain *domain = mono_object_domain (name);
4684 gboolean is_version_defined;
4686 val = mono_string_to_utf8 (assname);
4687 if (!mono_assembly_name_parse_full (val, &aname, TRUE, &is_version_defined))
4690 fill_reflection_assembly_name (domain, name, &aname, "", is_version_defined);
4692 mono_assembly_name_free (&aname);
4693 g_free ((guint8*) aname.public_key);
4699 static MonoReflectionType*
4700 ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module)
4702 MonoDomain *domain = mono_object_domain (module);
4705 MONO_ARCH_SAVE_REGS;
4707 g_assert (module->image);
4709 if (module->image->dynamic && ((MonoDynamicImage*)(module->image))->initial_image)
4710 /* These images do not have a global type */
4713 klass = mono_class_get (module->image, 1 | MONO_TOKEN_TYPE_DEF);
4714 return mono_type_get_object (domain, &klass->byval_arg);
4718 ves_icall_System_Reflection_Module_Close (MonoReflectionModule *module)
4720 /*if (module->image)
4721 mono_image_close (module->image);*/
4725 ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module)
4727 MonoDomain *domain = mono_object_domain (module);
4729 MONO_ARCH_SAVE_REGS;
4731 g_assert (module->image);
4732 return mono_string_new (domain, module->image->guid);
4736 ves_icall_System_Reflection_Module_GetPEKind (MonoImage *image, gint32 *pe_kind, gint32 *machine)
4738 if (image->dynamic) {
4739 MonoDynamicImage *dyn = (MonoDynamicImage*)image;
4740 *pe_kind = dyn->pe_kind;
4741 *machine = dyn->machine;
4744 *pe_kind = ((MonoCLIImageInfo*)(image->image_info))->cli_cli_header.ch_flags & 0x3;
4745 *machine = ((MonoCLIImageInfo*)(image->image_info))->cli_header.coff.coff_machine;
4750 ves_icall_System_Reflection_Module_get_MDStreamVersion (MonoReflectionModule *module)
4752 MonoImage *image = module->image;
4755 mono_raise_exception (mono_get_exception_not_supported (""));
4757 return (image->md_version_major << 16) | (image->md_version_minor);
4761 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *module)
4763 MONO_ARCH_SAVE_REGS;
4766 return mono_array_new (mono_object_domain (module), mono_defaults.monotype_class, 0);
4768 return mono_module_get_types (mono_object_domain (module), module->image, FALSE);
4772 mono_metadata_memberref_is_method (MonoImage *image, guint32 token)
4774 guint32 cols [MONO_MEMBERREF_SIZE];
4776 mono_metadata_decode_row (&image->tables [MONO_TABLE_MEMBERREF], mono_metadata_token_index (token) - 1, cols, MONO_MEMBERREF_SIZE);
4777 sig = mono_metadata_blob_heap (image, cols [MONO_MEMBERREF_SIGNATURE]);
4778 mono_metadata_decode_blob_size (sig, &sig);
4779 return (*sig != 0x6);
4783 ves_icall_System_Reflection_Module_ResolveTypeToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4786 int table = mono_metadata_token_table (token);
4787 int index = mono_metadata_token_index (token);
4789 *error = ResolveTokenError_Other;
4791 /* Validate token */
4792 if ((table != MONO_TABLE_TYPEDEF) && (table != MONO_TABLE_TYPEREF) &&
4793 (table != MONO_TABLE_TYPESPEC)) {
4794 *error = ResolveTokenError_BadTable;
4799 return mono_lookup_dynamic_token (image, token);
4801 if ((index <= 0) || (index > image->tables [table].rows)) {
4802 *error = ResolveTokenError_OutOfRange;
4806 klass = mono_class_get (image, token);
4808 return &klass->byval_arg;
4814 ves_icall_System_Reflection_Module_ResolveMethodToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4816 int table = mono_metadata_token_table (token);
4817 int index = mono_metadata_token_index (token);
4819 *error = ResolveTokenError_Other;
4821 /* Validate token */
4822 if ((table != MONO_TABLE_METHOD) && (table != MONO_TABLE_METHODSPEC) &&
4823 (table != MONO_TABLE_MEMBERREF)) {
4824 *error = ResolveTokenError_BadTable;
4829 /* FIXME: validate memberref token type */
4830 return mono_lookup_dynamic_token (image, token);
4832 if ((index <= 0) || (index > image->tables [table].rows)) {
4833 *error = ResolveTokenError_OutOfRange;
4836 if ((table == MONO_TABLE_MEMBERREF) && (!mono_metadata_memberref_is_method (image, token))) {
4837 *error = ResolveTokenError_BadTable;
4841 return mono_get_method (image, token, NULL);
4845 ves_icall_System_Reflection_Module_ResolveStringToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4847 int index = mono_metadata_token_index (token);
4849 *error = ResolveTokenError_Other;
4851 /* Validate token */
4852 if (mono_metadata_token_code (token) != MONO_TOKEN_STRING) {
4853 *error = ResolveTokenError_BadTable;
4858 return mono_lookup_dynamic_token (image, token);
4860 if ((index <= 0) || (index >= image->heap_us.size)) {
4861 *error = ResolveTokenError_OutOfRange;
4865 /* FIXME: What to do if the index points into the middle of a string ? */
4867 return mono_ldstr (mono_domain_get (), image, index);
4870 static MonoClassField*
4871 ves_icall_System_Reflection_Module_ResolveFieldToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4874 int table = mono_metadata_token_table (token);
4875 int index = mono_metadata_token_index (token);
4877 *error = ResolveTokenError_Other;
4879 /* Validate token */
4880 if ((table != MONO_TABLE_FIELD) && (table != MONO_TABLE_MEMBERREF)) {
4881 *error = ResolveTokenError_BadTable;
4886 /* FIXME: validate memberref token type */
4887 return mono_lookup_dynamic_token (image, token);
4889 if ((index <= 0) || (index > image->tables [table].rows)) {
4890 *error = ResolveTokenError_OutOfRange;
4893 if ((table == MONO_TABLE_MEMBERREF) && (mono_metadata_memberref_is_method (image, token))) {
4894 *error = ResolveTokenError_BadTable;
4898 return mono_field_from_token (image, token, &klass, NULL);
4903 ves_icall_System_Reflection_Module_ResolveMemberToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4905 int table = mono_metadata_token_table (token);
4907 *error = ResolveTokenError_Other;
4910 case MONO_TABLE_TYPEDEF:
4911 case MONO_TABLE_TYPEREF:
4912 case MONO_TABLE_TYPESPEC: {
4913 MonoType *t = ves_icall_System_Reflection_Module_ResolveTypeToken (image, token, error);
4915 return (MonoObject*)mono_type_get_object (mono_domain_get (), t);
4919 case MONO_TABLE_METHOD:
4920 case MONO_TABLE_METHODSPEC: {
4921 MonoMethod *m = ves_icall_System_Reflection_Module_ResolveMethodToken (image, token, error);
4923 return (MonoObject*)mono_method_get_object (mono_domain_get (), m, m->klass);
4927 case MONO_TABLE_FIELD: {
4928 MonoClassField *f = ves_icall_System_Reflection_Module_ResolveFieldToken (image, token, error);
4930 return (MonoObject*)mono_field_get_object (mono_domain_get (), f->parent, f);
4934 case MONO_TABLE_MEMBERREF:
4935 if (mono_metadata_memberref_is_method (image, token)) {
4936 MonoMethod *m = ves_icall_System_Reflection_Module_ResolveMethodToken (image, token, error);
4938 return (MonoObject*)mono_method_get_object (mono_domain_get (), m, m->klass);
4943 MonoClassField *f = ves_icall_System_Reflection_Module_ResolveFieldToken (image, token, error);
4945 return (MonoObject*)mono_field_get_object (mono_domain_get (), f->parent, f);
4952 *error = ResolveTokenError_BadTable;
4958 static MonoReflectionType*
4959 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
4962 int isbyref = 0, rank;
4963 char *str = mono_string_to_utf8 (smodifiers);
4966 MONO_ARCH_SAVE_REGS;
4968 klass = mono_class_from_mono_type (tb->type.type);
4970 /* logic taken from mono_reflection_parse_type(): keep in sync */
4974 if (isbyref) { /* only one level allowed by the spec */
4981 return mono_type_get_object (mono_object_domain (tb), &klass->this_arg);
4984 klass = mono_ptr_class_get (&klass->byval_arg);
4985 mono_class_init (klass);
4996 else if (*p != '*') { /* '*' means unknown lower bound */
5007 klass = mono_array_class_get (klass, rank);
5008 mono_class_init (klass);
5015 return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
5019 ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
5024 MONO_ARCH_SAVE_REGS;
5027 res = !type->byref && (type->type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY);
5032 static MonoReflectionType *
5033 ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
5035 MonoClass *klass, *aklass;
5037 MONO_ARCH_SAVE_REGS;
5039 klass = mono_class_from_mono_type (type->type);
5040 aklass = mono_array_class_get (klass, rank);
5042 return mono_type_get_object (mono_object_domain (type), &aklass->byval_arg);
5045 static MonoReflectionType *
5046 ves_icall_Type_make_byref_type (MonoReflectionType *type)
5050 MONO_ARCH_SAVE_REGS;
5052 klass = mono_class_from_mono_type (type->type);
5054 return mono_type_get_object (mono_object_domain (type), &klass->this_arg);
5057 static MonoReflectionType *
5058 ves_icall_Type_MakePointerType (MonoReflectionType *type)
5062 MONO_ARCH_SAVE_REGS;
5064 pklass = mono_ptr_class_get (type->type);
5066 return mono_type_get_object (mono_object_domain (type), &pklass->byval_arg);
5070 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target,
5071 MonoReflectionMethod *info)
5073 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
5074 MonoObject *delegate;
5077 MONO_ARCH_SAVE_REGS;
5079 mono_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
5081 delegate = mono_object_new (mono_object_domain (type), delegate_class);
5083 func = mono_compile_method (info->method);
5085 mono_delegate_ctor (delegate, target, func);
5091 ves_icall_System_Delegate_FreeTrampoline (MonoDelegate *this)
5094 Delegates have a finalizer only when needed, now.
5095 mono_delegate_free_ftnptr (this);*/
5099 * Magic number to convert a time which is relative to
5100 * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
5102 #define EPOCH_ADJUST ((guint64)62135596800LL)
5105 * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
5107 #define FILETIME_ADJUST ((guint64)504911232000000000LL)
5110 * This returns Now in UTC
5113 ves_icall_System_DateTime_GetNow (void)
5115 #ifdef PLATFORM_WIN32
5119 GetSystemTime (&st);
5120 SystemTimeToFileTime (&st, &ft);
5121 return (gint64) FILETIME_ADJUST + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
5123 /* FIXME: put this in io-layer and call it GetLocalTime */
5127 MONO_ARCH_SAVE_REGS;
5129 if (gettimeofday (&tv, NULL) == 0) {
5130 res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
5133 /* fixme: raise exception */
5138 #ifdef PLATFORM_WIN32
5139 /* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
5141 convert_to_absolute_date(SYSTEMTIME *date)
5143 #define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
5144 static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
5145 static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
5146 /* from the calendar FAQ */
5147 int a = (14 - date->wMonth) / 12;
5148 int y = date->wYear - a;
5149 int m = date->wMonth + 12 * a - 2;
5150 int d = (1 + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
5152 /* d is now the day of the week for the first of the month (0 == Sunday) */
5154 int day_of_week = date->wDayOfWeek;
5156 /* set day_in_month to the first day in the month which falls on day_of_week */
5157 int day_in_month = 1 + (day_of_week - d);
5158 if (day_in_month <= 0)
5161 /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
5162 date->wDay = day_in_month + (date->wDay - 1) * 7;
5163 if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
5168 #ifndef PLATFORM_WIN32
5170 * Return's the offset from GMT of a local time.
5172 * tm is a local time
5173 * t is the same local time as seconds.
5176 gmt_offset(struct tm *tm, time_t t)
5178 #if defined (HAVE_TM_GMTOFF)
5179 return tm->tm_gmtoff;
5184 g.tm_isdst = tm->tm_isdst;
5186 return (int)difftime(t, t2);
5191 * This is heavily based on zdump.c from glibc 2.2.
5193 * * data[0]: start of daylight saving time (in DateTime ticks).
5194 * * data[1]: end of daylight saving time (in DateTime ticks).
5195 * * data[2]: utcoffset (in TimeSpan ticks).
5196 * * data[3]: additional offset when daylight saving (in TimeSpan ticks).
5197 * * name[0]: name of this timezone when not daylight saving.
5198 * * name[1]: name of this timezone when daylight saving.
5200 * FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
5201 * the class library allows years between 1 and 9999.
5203 * Returns true on success and zero on failure.
5206 ves_icall_System_CurrentSystemTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
5208 #ifndef PLATFORM_WIN32
5209 MonoDomain *domain = mono_domain_get ();
5210 struct tm start, tt;
5214 int is_daylight = 0, day;
5217 MONO_ARCH_SAVE_REGS;
5219 MONO_CHECK_ARG_NULL (data);
5220 MONO_CHECK_ARG_NULL (names);
5222 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
5223 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
5226 * no info is better than crashing: we'll need our own tz data
5227 * to make this work properly, anyway. The range is probably
5228 * reduced to 1970 .. 2037 because that is what mktime is
5229 * guaranteed to support (we get into an infinite loop
5233 memset (&start, 0, sizeof (start));
5236 start.tm_year = year-1900;
5238 t = mktime (&start);
5240 if ((year < 1970) || (year > 2037) || (t == -1)) {
5242 tt = *localtime (&t);
5243 strftime (tzone, sizeof (tzone), "%Z", &tt);
5244 mono_array_setref ((*names), 0, mono_string_new (domain, tzone));
5245 mono_array_setref ((*names), 1, mono_string_new (domain, tzone));
5249 gmtoff = gmt_offset (&start, t);
5251 /* For each day of the year, calculate the tm_gmtoff. */
5252 for (day = 0; day < 365; day++) {
5255 tt = *localtime (&t);
5257 /* Daylight saving starts or ends here. */
5258 if (gmt_offset (&tt, t) != gmtoff) {
5262 /* Try to find the exact hour when daylight saving starts/ends. */
5266 tt1 = *localtime (&t1);
5267 } while (gmt_offset (&tt1, t1) != gmtoff);
5269 /* Try to find the exact minute when daylight saving starts/ends. */
5272 tt1 = *localtime (&t1);
5273 } while (gmt_offset (&tt1, t1) == gmtoff);
5275 strftime (tzone, sizeof (tzone), "%Z", &tt);
5277 /* Write data, if we're already in daylight saving, we're done. */
5279 mono_array_setref ((*names), 0, mono_string_new (domain, tzone));
5280 mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
5283 mono_array_setref ((*names), 1, mono_string_new (domain, tzone));
5284 mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
5288 /* This is only set once when we enter daylight saving. */
5289 mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
5290 mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (&tt, t) - gmtoff) * 10000000L);
5292 gmtoff = gmt_offset (&tt, t);
5297 strftime (tzone, sizeof (tzone), "%Z", &tt);
5298 mono_array_setref ((*names), 0, mono_string_new (domain, tzone));
5299 mono_array_setref ((*names), 1, mono_string_new (domain, tzone));
5300 mono_array_set ((*data), gint64, 0, 0);
5301 mono_array_set ((*data), gint64, 1, 0);
5302 mono_array_set ((*data), gint64, 2, (gint64) gmtoff * 10000000L);
5303 mono_array_set ((*data), gint64, 3, 0);
5308 MonoDomain *domain = mono_domain_get ();
5309 TIME_ZONE_INFORMATION tz_info;
5314 tz_id = GetTimeZoneInformation (&tz_info);
5315 if (tz_id == TIME_ZONE_ID_INVALID)
5318 MONO_CHECK_ARG_NULL (data);
5319 MONO_CHECK_ARG_NULL (names);
5321 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
5322 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
5324 for (i = 0; i < 32; ++i)
5325 if (!tz_info.DaylightName [i])
5327 mono_array_setref ((*names), 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
5328 for (i = 0; i < 32; ++i)
5329 if (!tz_info.StandardName [i])
5331 mono_array_setref ((*names), 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
5333 if ((year <= 1601) || (year > 30827)) {
5335 * According to MSDN, the MS time functions can't handle dates outside
5341 /* even if the timezone has no daylight savings it may have Bias (e.g. GMT+13 it seems) */
5342 if (tz_id != TIME_ZONE_ID_UNKNOWN) {
5343 tz_info.StandardDate.wYear = year;
5344 convert_to_absolute_date(&tz_info.StandardDate);
5345 err = SystemTimeToFileTime (&tz_info.StandardDate, &ft);
5347 mono_array_set ((*data), gint64, 1, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
5348 tz_info.DaylightDate.wYear = year;
5349 convert_to_absolute_date(&tz_info.DaylightDate);
5350 err = SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
5352 mono_array_set ((*data), gint64, 0, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
5354 mono_array_set ((*data), gint64, 2, (tz_info.Bias + tz_info.StandardBias) * -600000000LL);
5355 mono_array_set ((*data), gint64, 3, (tz_info.DaylightBias - tz_info.StandardBias) * -600000000LL);
5362 ves_icall_System_Object_obj_address (MonoObject *this)
5364 MONO_ARCH_SAVE_REGS;
5371 static inline gint32
5372 mono_array_get_byte_length (MonoArray *array)
5378 klass = array->obj.vtable->klass;
5380 if (array->bounds == NULL)
5381 length = array->max_length;
5384 for (i = 0; i < klass->rank; ++ i)
5385 length *= array->bounds [i].length;
5388 switch (klass->element_class->byval_arg.type) {
5391 case MONO_TYPE_BOOLEAN:
5395 case MONO_TYPE_CHAR:
5403 return length * sizeof (gpointer);
5414 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
5416 MONO_ARCH_SAVE_REGS;
5418 return mono_array_get_byte_length (array);
5422 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx)
5424 MONO_ARCH_SAVE_REGS;
5426 return mono_array_get (array, gint8, idx);
5430 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value)
5432 MONO_ARCH_SAVE_REGS;
5434 mono_array_set (array, gint8, idx, value);
5438 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count)
5440 guint8 *src_buf, *dest_buf;
5442 MONO_ARCH_SAVE_REGS;
5444 /* watch out for integer overflow */
5445 if ((src_offset > mono_array_get_byte_length (src) - count) || (dest_offset > mono_array_get_byte_length (dest) - count))
5448 src_buf = (guint8 *)src->vector + src_offset;
5449 dest_buf = (guint8 *)dest->vector + dest_offset;
5452 memcpy (dest_buf, src_buf, count);
5454 memmove (dest_buf, src_buf, count); /* Source and dest are the same array */
5460 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this, MonoString *class_name)
5462 MonoDomain *domain = mono_object_domain (this);
5464 MonoRealProxy *rp = ((MonoRealProxy *)this);
5465 MonoTransparentProxy *tp;
5469 MONO_ARCH_SAVE_REGS;
5471 res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
5472 tp = (MonoTransparentProxy*) res;
5474 MONO_OBJECT_SETREF (tp, rp, rp);
5475 type = ((MonoReflectionType *)rp->class_to_proxy)->type;
5476 klass = mono_class_from_mono_type (type);
5478 tp->custom_type_info = (mono_object_isinst (this, mono_defaults.iremotingtypeinfo_class) != NULL);
5479 tp->remote_class = mono_remote_class (domain, class_name, klass);
5481 res->vtable = mono_remote_class_vtable (domain, tp->remote_class, rp);
5485 static MonoReflectionType *
5486 ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy *tp)
5488 return mono_type_get_object (mono_object_domain (tp), &tp->remote_class->proxy_class->byval_arg);
5491 /* System.Environment */
5494 ves_icall_System_Environment_get_MachineName (void)
5496 #if defined (PLATFORM_WIN32)
5501 len = MAX_COMPUTERNAME_LENGTH + 1;
5502 buf = g_new (gunichar2, len);
5505 if (GetComputerName (buf, (PDWORD) &len))
5506 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
5514 if (gethostname (buf, sizeof (buf)) == 0)
5515 result = mono_string_new (mono_domain_get (), buf);
5524 ves_icall_System_Environment_get_Platform (void)
5526 MONO_ARCH_SAVE_REGS;
5528 #if defined (PLATFORM_WIN32)
5538 ves_icall_System_Environment_get_NewLine (void)
5540 MONO_ARCH_SAVE_REGS;
5542 #if defined (PLATFORM_WIN32)
5543 return mono_string_new (mono_domain_get (), "\r\n");
5545 return mono_string_new (mono_domain_get (), "\n");
5550 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
5555 MONO_ARCH_SAVE_REGS;
5560 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
5561 value = g_getenv (utf8_name);
5568 return mono_string_new (mono_domain_get (), value);
5572 * There is no standard way to get at environ.
5580 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
5588 MONO_ARCH_SAVE_REGS;
5591 for (e = environ; *e != 0; ++ e)
5594 domain = mono_domain_get ();
5595 names = mono_array_new (domain, mono_defaults.string_class, n);
5598 for (e = environ; *e != 0; ++ e) {
5599 parts = g_strsplit (*e, "=", 2);
5601 str = mono_string_new (domain, *parts);
5602 mono_array_setref (names, n, str);
5614 * If your platform lacks setenv/unsetenv, you must upgrade your glib.
5616 #if !GLIB_CHECK_VERSION(2,4,0)
5617 #define g_setenv(a,b,c) setenv(a,b,c)
5618 #define g_unsetenv(a) unsetenv(a)
5622 ves_icall_System_Environment_InternalSetEnvironmentVariable (MonoString *name, MonoString *value)
5624 gchar *utf8_name, *utf8_value;
5626 MONO_ARCH_SAVE_REGS;
5628 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
5630 if ((value == NULL) || (mono_string_length (value) == 0) || (mono_string_chars (value)[0] == 0)) {
5631 g_unsetenv (utf8_name);
5635 utf8_value = mono_string_to_utf8 (value);
5637 g_setenv (utf8_name, utf8_value, TRUE);
5640 g_free (utf8_value);
5644 * Returns: the number of milliseconds elapsed since the system started.
5647 ves_icall_System_Environment_get_TickCount (void)
5649 return GetTickCount ();
5654 ves_icall_System_Environment_Exit (int result)
5656 MONO_ARCH_SAVE_REGS;
5658 mono_runtime_set_shutting_down ();
5660 /* Suspend all managed threads since the runtime is going away */
5661 mono_thread_suspend_all_other_threads ();
5663 mono_runtime_quit ();
5665 /* we may need to do some cleanup here... */
5670 ves_icall_System_Environment_GetGacPath (void)
5672 return mono_string_new (mono_domain_get (), mono_assembly_getrootdir ());
5676 ves_icall_System_Environment_GetWindowsFolderPath (int folder)
5678 #if defined (PLATFORM_WIN32)
5679 #ifndef CSIDL_FLAG_CREATE
5680 #define CSIDL_FLAG_CREATE 0x8000
5683 WCHAR path [MAX_PATH];
5684 /* Create directory if no existing */
5685 if (SUCCEEDED (SHGetFolderPathW (NULL, folder | CSIDL_FLAG_CREATE, NULL, 0, path))) {
5689 return mono_string_new_utf16 (mono_domain_get (), path, len);
5692 g_warning ("ves_icall_System_Environment_GetWindowsFolderPath should only be called on Windows!");
5694 return mono_string_new (mono_domain_get (), "");
5698 ves_icall_System_Environment_GetLogicalDrives (void)
5700 gunichar2 buf [128], *ptr, *dname;
5702 gint initial_size = 127, size = 128;
5705 MonoString *drivestr;
5706 MonoDomain *domain = mono_domain_get ();
5709 MONO_ARCH_SAVE_REGS;
5714 while (size > initial_size) {
5715 size = GetLogicalDriveStrings (initial_size, ptr);
5716 if (size > initial_size) {
5719 ptr = g_malloc0 ((size + 1) * sizeof (gunichar2));
5720 initial_size = size;
5734 result = mono_array_new (domain, mono_defaults.string_class, ndrives);
5739 while (*u16) { u16++; len ++; }
5740 drivestr = mono_string_new_utf16 (domain, dname, len);
5741 mono_array_setref (result, ndrives++, drivestr);
5752 ves_icall_System_Environment_InternalGetHome (void)
5754 MONO_ARCH_SAVE_REGS;
5756 return mono_string_new (mono_domain_get (), g_get_home_dir ());
5759 static const char *encodings [] = {
5761 "ascii", "us_ascii", "us", "ansi_x3.4_1968",
5762 "ansi_x3.4_1986", "cp367", "csascii", "ibm367",
5763 "iso_ir_6", "iso646_us", "iso_646.irv:1991",
5765 "utf_7", "csunicode11utf7", "unicode_1_1_utf_7",
5766 "unicode_2_0_utf_7", "x_unicode_1_1_utf_7",
5767 "x_unicode_2_0_utf_7",
5769 "utf_8", "unicode_1_1_utf_8", "unicode_2_0_utf_8",
5770 "x_unicode_1_1_utf_8", "x_unicode_2_0_utf_8",
5772 "utf_16", "UTF_16LE", "ucs_2", "unicode",
5775 "unicodefffe", "utf_16be",
5782 * Returns the internal codepage, if the value of "int_code_page" is
5783 * 1 at entry, and we can not compute a suitable code page number,
5784 * returns the code page as a string
5787 ves_icall_System_Text_Encoding_InternalCodePage (gint32 *int_code_page)
5792 char *codepage = NULL;
5794 int want_name = *int_code_page;
5797 *int_code_page = -1;
5798 MONO_ARCH_SAVE_REGS;
5800 g_get_charset (&cset);
5801 c = codepage = strdup (cset);
5802 for (c = codepage; *c; c++){
5803 if (isascii (*c) && isalpha (*c))
5808 /* g_print ("charset: %s\n", cset); */
5810 /* handle some common aliases */
5813 for (i = 0; p != 0; ){
5814 if ((gssize) p < 7){
5816 p = encodings [++i];
5819 if (strcmp (p, codepage) == 0){
5820 *int_code_page = code;
5823 p = encodings [++i];
5826 if (strstr (codepage, "utf_8") != NULL)
5827 *int_code_page |= 0x10000000;
5830 if (want_name && *int_code_page == -1)
5831 return mono_string_new (mono_domain_get (), cset);
5837 ves_icall_System_Environment_get_HasShutdownStarted (void)
5839 if (mono_runtime_is_shutting_down ())
5842 if (mono_domain_is_unloading (mono_domain_get ()))
5849 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
5850 MonoReflectionMethod *method,
5851 MonoArray *out_args)
5853 MONO_ARCH_SAVE_REGS;
5855 mono_message_init (mono_object_domain (this), this, method, out_args);
5859 ves_icall_IsTransparentProxy (MonoObject *proxy)
5861 MONO_ARCH_SAVE_REGS;
5866 if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
5873 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
5878 MONO_ARCH_SAVE_REGS;
5880 klass = mono_class_from_mono_type (type->type);
5881 vtable = mono_class_vtable (mono_domain_get (), klass);
5883 if (enable) vtable->remote = 1;
5884 else vtable->remote = 0;
5888 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType *type)
5893 MONO_ARCH_SAVE_REGS;
5895 domain = mono_object_domain (type);
5896 klass = mono_class_from_mono_type (type->type);
5898 if (klass->rank >= 1) {
5899 g_assert (klass->rank == 1);
5900 return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
5902 /* Bypass remoting object creation check */
5903 return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
5908 ves_icall_System_IO_get_temp_path (void)
5910 MONO_ARCH_SAVE_REGS;
5912 return mono_string_new (mono_domain_get (), g_get_tmp_dir ());
5916 ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
5918 MONO_ARCH_SAVE_REGS;
5920 return mono_compile_method (method);
5924 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
5929 MONO_ARCH_SAVE_REGS;
5931 path = g_build_path (G_DIR_SEPARATOR_S, mono_get_config_dir (), "mono", mono_get_runtime_info ()->framework_version, "machine.config", NULL);
5933 #if defined (PLATFORM_WIN32)
5934 /* Avoid mixing '/' and '\\' */
5937 for (i = strlen (path) - 1; i >= 0; i--)
5938 if (path [i] == '/')
5942 mcpath = mono_string_new (mono_domain_get (), path);
5949 ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
5954 MONO_ARCH_SAVE_REGS;
5956 path = g_path_get_dirname (mono_get_config_dir ());
5958 #if defined (PLATFORM_WIN32)
5959 /* Avoid mixing '/' and '\\' */
5962 for (i = strlen (path) - 1; i >= 0; i--)
5963 if (path [i] == '/')
5967 ipath = mono_string_new (mono_domain_get (), path);
5974 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
5976 #if defined (PLATFORM_WIN32)
5977 static void (*output_debug) (gunichar2 *);
5978 static gboolean tried_loading = FALSE;
5980 MONO_ARCH_SAVE_REGS;
5982 if (!tried_loading && output_debug == NULL) {
5985 tried_loading = TRUE;
5986 k32 = g_module_open ("kernel32", G_MODULE_BIND_LAZY);
5988 gchar *error = g_strdup (g_module_error ());
5989 g_warning ("Failed to load kernel32.dll: %s\n", error);
5994 g_module_symbol (k32, "OutputDebugStringW", (gpointer *) &output_debug);
5995 if (!output_debug) {
5996 gchar *error = g_strdup (g_module_error ());
5997 g_warning ("Failed to load OutputDebugStringW: %s\n", error);
6003 if (output_debug == NULL)
6006 output_debug (mono_string_chars (message));
6008 g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
6012 /* Only used for value types */
6014 ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
6019 MONO_ARCH_SAVE_REGS;
6021 domain = mono_object_domain (type);
6022 klass = mono_class_from_mono_type (type->type);
6024 if (mono_class_is_nullable (klass))
6025 /* No arguments -> null */
6028 return mono_object_new (domain, klass);
6031 static MonoReflectionMethod *
6032 ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
6035 MonoMethod *method = m->method;
6036 MonoMethod *result = NULL;
6038 MONO_ARCH_SAVE_REGS;
6040 if (!(method->flags & METHOD_ATTRIBUTE_VIRTUAL) ||
6041 MONO_CLASS_IS_INTERFACE (method->klass) ||
6042 method->flags & METHOD_ATTRIBUTE_NEW_SLOT)
6045 if (method->klass == NULL || (klass = method->klass->parent) == NULL)
6048 if (klass->generic_class)
6049 klass = klass->generic_class->container_class;
6051 mono_class_setup_vtable (klass);
6052 mono_class_setup_vtable (method->klass);
6053 while (result == NULL && klass != NULL && (klass->vtable_size > method->slot))
6055 mono_class_setup_vtable (klass);
6057 result = klass->vtable [method->slot];
6058 if (result == NULL) {
6060 gpointer iter = NULL;
6061 /* It is an abstract method */
6062 while ((m = mono_class_get_methods (klass, &iter))) {
6063 if (m->slot == method->slot) {
6069 klass = klass->parent;
6075 return mono_method_get_object (mono_domain_get (), result, NULL);
6079 mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
6081 MONO_ARCH_SAVE_REGS;
6083 iter->sig = *(MonoMethodSignature**)argsp;
6085 g_assert (iter->sig->sentinelpos <= iter->sig->param_count);
6086 g_assert (iter->sig->call_convention == MONO_CALL_VARARG);
6089 /* FIXME: it's not documented what start is exactly... */
6093 int i, align, arg_size;
6094 iter->args = argsp + sizeof (gpointer);
6095 #ifndef MONO_ARCH_REGPARMS
6096 for (i = 0; i < iter->sig->sentinelpos; ++i) {
6097 arg_size = mono_type_stack_size (iter->sig->params [i], &align);
6098 iter->args = (char*)iter->args + arg_size;
6102 iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
6104 /* g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos); */
6108 mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
6110 gint i, align, arg_size;
6112 MONO_ARCH_SAVE_REGS;
6114 i = iter->sig->sentinelpos + iter->next_arg;
6116 g_assert (i < iter->sig->param_count);
6118 res.type = iter->sig->params [i];
6119 res.klass = mono_class_from_mono_type (res.type);
6120 /* FIXME: endianess issue... */
6121 res.value = iter->args;
6122 arg_size = mono_type_stack_size (res.type, &align);
6123 iter->args = (char*)iter->args + arg_size;
6126 /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
6132 mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
6134 gint i, align, arg_size;
6136 MONO_ARCH_SAVE_REGS;
6138 i = iter->sig->sentinelpos + iter->next_arg;
6140 g_assert (i < iter->sig->param_count);
6142 while (i < iter->sig->param_count) {
6143 if (!mono_metadata_type_equal (type, iter->sig->params [i]))
6145 res.type = iter->sig->params [i];
6146 res.klass = mono_class_from_mono_type (res.type);
6147 /* FIXME: endianess issue... */
6148 res.value = iter->args;
6149 arg_size = mono_type_stack_size (res.type, &align);
6150 iter->args = (char*)iter->args + arg_size;
6152 /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
6155 /* g_print ("arg type 0x%02x not found\n", res.type->type); */
6164 mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
6167 MONO_ARCH_SAVE_REGS;
6169 i = iter->sig->sentinelpos + iter->next_arg;
6171 g_assert (i < iter->sig->param_count);
6173 return iter->sig->params [i];
6177 mono_TypedReference_ToObject (MonoTypedRef tref)
6179 MONO_ARCH_SAVE_REGS;
6181 if (MONO_TYPE_IS_REFERENCE (tref.type)) {
6182 MonoObject** objp = tref.value;
6186 return mono_value_box (mono_domain_get (), tref.klass, tref.value);
6190 mono_TypedReference_ToObjectInternal (MonoType *type, gpointer value, MonoClass *klass)
6192 MONO_ARCH_SAVE_REGS;
6194 if (MONO_TYPE_IS_REFERENCE (type)) {
6195 MonoObject** objp = value;
6199 return mono_value_box (mono_domain_get (), klass, value);
6203 prelink_method (MonoMethod *method)
6205 const char *exc_class, *exc_arg;
6206 if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
6208 mono_lookup_pinvoke_call (method, &exc_class, &exc_arg);
6210 mono_raise_exception(
6211 mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg ) );
6213 /* create the wrapper, too? */
6217 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod *method)
6219 MONO_ARCH_SAVE_REGS;
6220 prelink_method (method->method);
6224 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType *type)
6226 MonoClass *klass = mono_class_from_mono_type (type->type);
6228 gpointer iter = NULL;
6229 MONO_ARCH_SAVE_REGS;
6231 while ((m = mono_class_get_methods (klass, &iter)))
6235 /* These parameters are "readonly" in corlib/System/Char.cs */
6237 ves_icall_System_Char_GetDataTablePointers (guint8 const **category_data,
6238 guint8 const **numeric_data,
6239 gdouble const **numeric_data_values,
6240 guint16 const **to_lower_data_low,
6241 guint16 const **to_lower_data_high,
6242 guint16 const **to_upper_data_low,
6243 guint16 const **to_upper_data_high)
6245 *category_data = CategoryData;
6246 *numeric_data = NumericData;
6247 *numeric_data_values = NumericDataValues;
6248 *to_lower_data_low = ToLowerDataLow;
6249 *to_lower_data_high = ToLowerDataHigh;
6250 *to_upper_data_low = ToUpperDataLow;
6251 *to_upper_data_high = ToUpperDataHigh;
6255 ves_icall_MonoDebugger_GetMethodToken (MonoReflectionMethod *method)
6257 return method->method->token;
6261 custom_attrs_defined_internal (MonoObject *obj, MonoReflectionType *attr_type)
6263 MonoCustomAttrInfo *cinfo;
6266 cinfo = mono_reflection_get_custom_attrs_info (obj);
6269 found = mono_custom_attrs_has_attr (cinfo, mono_class_from_mono_type (attr_type->type));
6271 mono_custom_attrs_free (cinfo);
6276 custom_attrs_get_by_type (MonoObject *obj, MonoReflectionType *attr_type)
6278 return mono_reflection_get_custom_attrs_by_type (obj, attr_type ? mono_class_from_mono_type (attr_type->type) : NULL);
6282 GCHandle_CheckCurrentDomain (guint32 gchandle)
6284 return mono_gchandle_is_in_domain (gchandle, mono_domain_get ());
6288 ves_icall_Mono_Runtime_GetDisplayName (void)
6290 static const char display_name_str [] = "Mono " VERSION;
6291 MonoString *display_name = mono_string_new (mono_domain_get (), display_name_str);
6292 return display_name;
6297 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
6298 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
6299 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 62, 128, 128, 128, 63,
6300 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 128, 128, 128, 0, 128, 128,
6301 128, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
6302 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 128, 128, 128, 128, 128,
6303 128, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
6304 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
6308 base64_to_byte_array (gunichar2 *start, gint ilength, MonoBoolean allowWhitespaceOnly)
6313 gunichar2 last, prev_last;
6321 last = prev_last = 0;
6322 for (i = 0; i < ilength; i++) {
6324 if (c >= sizeof (dbase64)) {
6325 exc = mono_exception_from_name_msg (mono_get_corlib (),
6326 "System", "FormatException",
6327 "Invalid character found.");
6328 mono_raise_exception (exc);
6329 } else if (isspace (c)) {
6337 olength = ilength - ignored;
6339 if (allowWhitespaceOnly && olength == 0) {
6340 return mono_array_new (mono_domain_get (), mono_defaults.byte_class, 0);
6343 if ((olength & 3) != 0 || olength <= 0) {
6344 exc = mono_exception_from_name_msg (mono_get_corlib (), "System",
6345 "FormatException", "Invalid length.");
6346 mono_raise_exception (exc);
6349 olength = (olength * 3) / 4;
6353 if (prev_last == '=')
6356 result = mono_array_new (mono_domain_get (), mono_defaults.byte_class, olength);
6357 res_ptr = mono_array_addr (result, guchar, 0);
6358 for (i = 0; i < ilength; ) {
6361 for (k = 0; k < 4 && i < ilength;) {
6367 if (((b [k] = dbase64 [c]) & 0x80) != 0) {
6368 exc = mono_exception_from_name_msg (mono_get_corlib (),
6369 "System", "FormatException",
6370 "Invalid character found.");
6371 mono_raise_exception (exc);
6376 *res_ptr++ = (b [0] << 2) | (b [1] >> 4);
6378 *res_ptr++ = (b [1] << 4) | (b [2] >> 2);
6380 *res_ptr++ = (b [2] << 6) | b [3];
6382 while (i < ilength && isspace (start [i]))
6390 InternalFromBase64String (MonoString *str, MonoBoolean allowWhitespaceOnly)
6392 MONO_ARCH_SAVE_REGS;
6394 return base64_to_byte_array (mono_string_chars (str),
6395 mono_string_length (str), allowWhitespaceOnly);
6399 InternalFromBase64CharArray (MonoArray *input, gint offset, gint length)
6401 MONO_ARCH_SAVE_REGS;
6403 return base64_to_byte_array (mono_array_addr (input, gunichar2, offset),
6415 const IcallEntry *icalls;
6419 static const IcallEntry runtime_icalls [] = {
6420 {"GetDisplayName", ves_icall_Mono_Runtime_GetDisplayName}
6423 static const IcallEntry activator_icalls [] = {
6424 {"CreateInstanceInternal", ves_icall_System_Activator_CreateInstanceInternal}
6426 static const IcallEntry appdomain_icalls [] = {
6427 {"ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly},
6428 {"GetAssemblies", ves_icall_System_AppDomain_GetAssemblies},
6429 {"GetData", ves_icall_System_AppDomain_GetData},
6430 {"InternalGetContext", ves_icall_System_AppDomain_InternalGetContext},
6431 {"InternalGetDefaultContext", ves_icall_System_AppDomain_InternalGetDefaultContext},
6432 {"InternalGetProcessGuid", ves_icall_System_AppDomain_InternalGetProcessGuid},
6433 {"InternalIsFinalizingForUnload", ves_icall_System_AppDomain_InternalIsFinalizingForUnload},
6434 {"InternalPopDomainRef", ves_icall_System_AppDomain_InternalPopDomainRef},
6435 {"InternalPushDomainRef", ves_icall_System_AppDomain_InternalPushDomainRef},
6436 {"InternalPushDomainRefByID", ves_icall_System_AppDomain_InternalPushDomainRefByID},
6437 {"InternalSetContext", ves_icall_System_AppDomain_InternalSetContext},
6438 {"InternalSetDomain", ves_icall_System_AppDomain_InternalSetDomain},
6439 {"InternalSetDomainByID", ves_icall_System_AppDomain_InternalSetDomainByID},
6440 {"InternalUnload", ves_icall_System_AppDomain_InternalUnload},
6441 {"LoadAssembly", ves_icall_System_AppDomain_LoadAssembly},
6442 {"LoadAssemblyRaw", ves_icall_System_AppDomain_LoadAssemblyRaw},
6443 {"SetData", ves_icall_System_AppDomain_SetData},
6444 {"createDomain", ves_icall_System_AppDomain_createDomain},
6445 {"getCurDomain", ves_icall_System_AppDomain_getCurDomain},
6446 {"getFriendlyName", ves_icall_System_AppDomain_getFriendlyName},
6447 {"getRootDomain", ves_icall_System_AppDomain_getRootDomain},
6448 {"getSetup", ves_icall_System_AppDomain_getSetup}
6451 static const IcallEntry argiterator_icalls [] = {
6452 {"IntGetNextArg()", mono_ArgIterator_IntGetNextArg},
6453 {"IntGetNextArg(intptr)", mono_ArgIterator_IntGetNextArgT},
6454 {"IntGetNextArgType", mono_ArgIterator_IntGetNextArgType},
6455 {"Setup", mono_ArgIterator_Setup}
6458 static const IcallEntry array_icalls [] = {
6459 {"ClearInternal", ves_icall_System_Array_ClearInternal},
6460 {"Clone", mono_array_clone},
6461 {"CreateInstanceImpl", ves_icall_System_Array_CreateInstanceImpl},
6462 {"FastCopy", ves_icall_System_Array_FastCopy},
6463 {"GetLength", ves_icall_System_Array_GetLength},
6464 {"GetLowerBound", ves_icall_System_Array_GetLowerBound},
6465 {"GetRank", ves_icall_System_Array_GetRank},
6466 {"GetValue", ves_icall_System_Array_GetValue},
6467 {"GetValueImpl", ves_icall_System_Array_GetValueImpl},
6468 {"SetValue", ves_icall_System_Array_SetValue},
6469 {"SetValueImpl", ves_icall_System_Array_SetValueImpl}
6472 static const IcallEntry buffer_icalls [] = {
6473 {"BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal},
6474 {"ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal},
6475 {"GetByteInternal", ves_icall_System_Buffer_GetByteInternal},
6476 {"SetByteInternal", ves_icall_System_Buffer_SetByteInternal}
6479 static const IcallEntry char_icalls [] = {
6480 {"GetDataTablePointers", ves_icall_System_Char_GetDataTablePointers}
6483 static const IcallEntry defaultconf_icalls [] = {
6484 {"get_machine_config_path", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path}
6487 static const IcallEntry consoledriver_icalls [] = {
6488 {"GetTtySize", ves_icall_System_ConsoleDriver_GetTtySize },
6489 {"InternalKeyAvailable", ves_icall_System_ConsoleDriver_InternalKeyAvailable },
6490 {"Isatty", ves_icall_System_ConsoleDriver_Isatty },
6491 {"SetBreak", ves_icall_System_ConsoleDriver_SetBreak },
6492 {"SetEcho", ves_icall_System_ConsoleDriver_SetEcho },
6493 {"TtySetup", ves_icall_System_ConsoleDriver_TtySetup }
6496 static const IcallEntry convert_icalls [] = {
6497 {"InternalFromBase64CharArray", InternalFromBase64CharArray },
6498 {"InternalFromBase64String", InternalFromBase64String }
6501 static const IcallEntry timezone_icalls [] = {
6502 {"GetTimeZoneData", ves_icall_System_CurrentSystemTimeZone_GetTimeZoneData}
6505 static const IcallEntry datetime_icalls [] = {
6506 {"GetNow", ves_icall_System_DateTime_GetNow}
6509 #ifndef DISABLE_DECIMAL
6510 static const IcallEntry decimal_icalls [] = {
6511 {"decimal2Int64", mono_decimal2Int64},
6512 {"decimal2UInt64", mono_decimal2UInt64},
6513 {"decimal2double", mono_decimal2double},
6514 {"decimal2string", mono_decimal2string},
6515 {"decimalCompare", mono_decimalCompare},
6516 {"decimalDiv", mono_decimalDiv},
6517 {"decimalFloorAndTrunc", mono_decimalFloorAndTrunc},
6518 {"decimalIncr", mono_decimalIncr},
6519 {"decimalIntDiv", mono_decimalIntDiv},
6520 {"decimalMult", mono_decimalMult},
6521 {"decimalRound", mono_decimalRound},
6522 {"decimalSetExponent", mono_decimalSetExponent},
6523 {"double2decimal", mono_double2decimal}, /* FIXME: wrong signature. */
6524 {"string2decimal", mono_string2decimal}
6528 static const IcallEntry delegate_icalls [] = {
6529 {"CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal},
6530 {"FreeTrampoline", ves_icall_System_Delegate_FreeTrampoline}
6533 static const IcallEntry tracelist_icalls [] = {
6534 {"WriteWindowsDebugString", ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString}
6537 static const IcallEntry fileversion_icalls [] = {
6538 {"GetVersionInfo_internal(string)", ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal}
6541 static const IcallEntry process_icalls [] = {
6542 {"CreateProcess_internal(System.Diagnostics.ProcessStartInfo,intptr,intptr,intptr,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_CreateProcess_internal},
6543 {"ExitCode_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitCode_internal},
6544 {"ExitTime_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitTime_internal},
6545 {"GetModules_internal()", ves_icall_System_Diagnostics_Process_GetModules_internal},
6546 {"GetPid_internal()", ves_icall_System_Diagnostics_Process_GetPid_internal},
6547 {"GetProcess_internal(int)", ves_icall_System_Diagnostics_Process_GetProcess_internal},
6548 {"GetProcesses_internal()", ves_icall_System_Diagnostics_Process_GetProcesses_internal},
6549 {"GetWorkingSet_internal(intptr,int&,int&)", ves_icall_System_Diagnostics_Process_GetWorkingSet_internal},
6550 {"Kill_internal", ves_icall_System_Diagnostics_Process_Kill_internal},
6551 {"ProcessName_internal(intptr)", ves_icall_System_Diagnostics_Process_ProcessName_internal},
6552 {"Process_free_internal(intptr)", ves_icall_System_Diagnostics_Process_Process_free_internal},
6553 {"SetWorkingSet_internal(intptr,int,int,bool)", ves_icall_System_Diagnostics_Process_SetWorkingSet_internal},
6554 {"ShellExecuteEx_internal(System.Diagnostics.ProcessStartInfo,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal},
6555 {"StartTime_internal(intptr)", ves_icall_System_Diagnostics_Process_StartTime_internal},
6556 {"WaitForExit_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForExit_internal}
6559 static const IcallEntry double_icalls [] = {
6560 {"AssertEndianity", ves_icall_System_Double_AssertEndianity},
6561 {"ParseImpl", mono_double_ParseImpl}
6564 static const IcallEntry enum_icalls [] = {
6565 {"ToObject", ves_icall_System_Enum_ToObject},
6566 {"get_value", ves_icall_System_Enum_get_value}
6569 static const IcallEntry environment_icalls [] = {
6570 {"Exit", ves_icall_System_Environment_Exit},
6571 {"GetCommandLineArgs", mono_runtime_get_main_args},
6572 {"GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames},
6573 {"GetLogicalDrivesInternal", ves_icall_System_Environment_GetLogicalDrives },
6574 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
6575 {"GetOSVersionString", ves_icall_System_Environment_GetOSVersionString},
6576 {"GetWindowsFolderPath", ves_icall_System_Environment_GetWindowsFolderPath},
6577 {"InternalSetEnvironmentVariable", ves_icall_System_Environment_InternalSetEnvironmentVariable},
6578 {"get_ExitCode", mono_environment_exitcode_get},
6579 {"get_HasShutdownStarted", ves_icall_System_Environment_get_HasShutdownStarted},
6580 {"get_MachineName", ves_icall_System_Environment_get_MachineName},
6581 {"get_NewLine", ves_icall_System_Environment_get_NewLine},
6582 {"get_Platform", ves_icall_System_Environment_get_Platform},
6583 {"get_TickCount", ves_icall_System_Environment_get_TickCount},
6584 {"get_UserName", ves_icall_System_Environment_get_UserName},
6585 {"internalGetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable},
6586 {"internalGetGacPath", ves_icall_System_Environment_GetGacPath},
6587 {"internalGetHome", ves_icall_System_Environment_InternalGetHome},
6588 {"set_ExitCode", mono_environment_exitcode_set}
6591 static const IcallEntry cultureinfo_icalls [] = {
6592 {"construct_compareinfo(object,string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
6593 {"construct_datetime_format", ves_icall_System_Globalization_CultureInfo_construct_datetime_format},
6594 {"construct_internal_locale(string)", ves_icall_System_Globalization_CultureInfo_construct_internal_locale},
6595 {"construct_internal_locale_from_current_locale", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_current_locale},
6596 {"construct_internal_locale_from_lcid", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_lcid},
6597 {"construct_internal_locale_from_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name},
6598 {"construct_internal_locale_from_specific_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_specific_name},
6599 {"construct_number_format", ves_icall_System_Globalization_CultureInfo_construct_number_format},
6600 {"internal_get_cultures", ves_icall_System_Globalization_CultureInfo_internal_get_cultures},
6601 {"internal_is_lcid_neutral", ves_icall_System_Globalization_CultureInfo_internal_is_lcid_neutral}
6604 static const IcallEntry regioninfo_icalls [] = {
6605 {"construct_internal_region_from_lcid", ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_lcid},
6606 {"construct_internal_region_from_name", ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_name}
6609 static const IcallEntry compareinfo_icalls [] = {
6610 {"assign_sortkey(object,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_assign_sortkey},
6611 {"construct_compareinfo(string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
6612 {"free_internal_collator()", ves_icall_System_Globalization_CompareInfo_free_internal_collator},
6613 {"internal_compare(string,int,int,string,int,int,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_internal_compare},
6614 {"internal_index(string,int,int,char,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index_char},
6615 {"internal_index(string,int,int,string,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index}
6618 static const IcallEntry gc_icalls [] = {
6619 {"GetTotalMemory", ves_icall_System_GC_GetTotalMemory},
6620 {"InternalCollect", ves_icall_System_GC_InternalCollect},
6621 {"KeepAlive", ves_icall_System_GC_KeepAlive},
6622 {"ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize},
6623 {"SuppressFinalize", ves_icall_System_GC_SuppressFinalize},
6624 {"WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers}
6627 static const IcallEntry famwatcher_icalls [] = {
6628 {"InternalFAMNextEvent", ves_icall_System_IO_FAMW_InternalFAMNextEvent}
6631 static const IcallEntry filewatcher_icalls [] = {
6632 {"InternalCloseDirectory", ves_icall_System_IO_FSW_CloseDirectory},
6633 {"InternalOpenDirectory", ves_icall_System_IO_FSW_OpenDirectory},
6634 {"InternalReadDirectoryChanges", ves_icall_System_IO_FSW_ReadDirectoryChanges},
6635 {"InternalSupportsFSW", ves_icall_System_IO_FSW_SupportsFSW}
6638 static const IcallEntry path_icalls [] = {
6639 {"get_temp_path", ves_icall_System_IO_get_temp_path}
6642 static const IcallEntry monoio_icalls [] = {
6643 {"Close(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Close},
6644 {"CopyFile(string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CopyFile},
6645 {"CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CreateDirectory},
6646 {"CreatePipe(intptr&,intptr&)", ves_icall_System_IO_MonoIO_CreatePipe},
6647 {"DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile},
6648 {"Flush(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush},
6649 {"GetCurrentDirectory(System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetCurrentDirectory},
6650 {"GetFileAttributes(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileAttributes},
6651 {"GetFileStat(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileStat},
6652 {"GetFileSystemEntries", ves_icall_System_IO_MonoIO_GetFileSystemEntries},
6653 {"GetFileType(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType},
6654 {"GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength},
6655 {"GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath},
6656 {"Lock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Lock},
6657 {"MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile},
6658 {"Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,System.IO.FileOptions,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open},
6659 {"Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read},
6660 {"RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory},
6661 {"Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek},
6662 {"SetCurrentDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetCurrentDirectory},
6663 {"SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes},
6664 {"SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime},
6665 {"SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength},
6666 {"Unlock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Unlock},
6667 {"Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write},
6668 {"get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar},
6669 {"get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError},
6670 {"get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput},
6671 {"get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput},
6672 {"get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar},
6673 {"get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars},
6674 {"get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator},
6675 {"get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar}
6678 static const IcallEntry math_icalls [] = {
6679 {"Acos", ves_icall_System_Math_Acos},
6680 {"Asin", ves_icall_System_Math_Asin},
6681 {"Atan", ves_icall_System_Math_Atan},
6682 {"Atan2", ves_icall_System_Math_Atan2},
6683 {"Cos", ves_icall_System_Math_Cos},
6684 {"Cosh", ves_icall_System_Math_Cosh},
6685 {"Exp", ves_icall_System_Math_Exp},
6686 {"Floor", ves_icall_System_Math_Floor},
6687 {"Log", ves_icall_System_Math_Log},
6688 {"Log10", ves_icall_System_Math_Log10},
6689 {"Pow", ves_icall_System_Math_Pow},
6690 {"Round", ves_icall_System_Math_Round},
6691 {"Round2", ves_icall_System_Math_Round2},
6692 {"Sin", ves_icall_System_Math_Sin},
6693 {"Sinh", ves_icall_System_Math_Sinh},
6694 {"Sqrt", ves_icall_System_Math_Sqrt},
6695 {"Tan", ves_icall_System_Math_Tan},
6696 {"Tanh", ves_icall_System_Math_Tanh}
6699 static const IcallEntry customattrs_icalls [] = {
6700 {"GetCustomAttributesDataInternal", mono_reflection_get_custom_attrs_data},
6701 {"GetCustomAttributesInternal", custom_attrs_get_by_type},
6702 {"IsDefinedInternal", custom_attrs_defined_internal}
6705 static const IcallEntry enuminfo_icalls [] = {
6706 {"get_enum_info", ves_icall_get_enum_info}
6709 static const IcallEntry fieldinfo_icalls [] = {
6710 {"GetUnmanagedMarshal", ves_icall_System_Reflection_FieldInfo_GetUnmanagedMarshal},
6711 {"internal_from_handle", ves_icall_System_Reflection_FieldInfo_internal_from_handle}
6714 static const IcallEntry memberinfo_icalls [] = {
6715 {"get_MetadataToken", mono_reflection_get_token}
6718 static const IcallEntry monotype_icalls [] = {
6719 {"GetArrayRank", ves_icall_MonoType_GetArrayRank},
6720 {"GetConstructors", ves_icall_Type_GetConstructors_internal},
6721 {"GetConstructors_internal", ves_icall_Type_GetConstructors_internal},
6722 {"GetCorrespondingInflatedConstructor", ves_icall_MonoType_GetCorrespondingInflatedMethod},
6723 {"GetCorrespondingInflatedMethod", ves_icall_MonoType_GetCorrespondingInflatedMethod},
6724 {"GetElementType", ves_icall_MonoType_GetElementType},
6725 {"GetEvents_internal", ves_icall_Type_GetEvents_internal},
6726 {"GetField", ves_icall_Type_GetField},
6727 {"GetFields_internal", ves_icall_Type_GetFields_internal},
6728 {"GetGenericArguments", ves_icall_MonoType_GetGenericArguments},
6729 {"GetInterfaces", ves_icall_Type_GetInterfaces},
6730 {"GetMethodsByName", ves_icall_Type_GetMethodsByName},
6731 {"GetNestedType", ves_icall_Type_GetNestedType},
6732 {"GetNestedTypes", ves_icall_Type_GetNestedTypes},
6733 {"GetPropertiesByName", ves_icall_Type_GetPropertiesByName},
6734 {"InternalGetEvent", ves_icall_MonoType_GetEvent},
6735 {"IsByRefImpl", ves_icall_type_isbyref},
6736 {"IsPointerImpl", ves_icall_type_ispointer},
6737 {"IsPrimitiveImpl", ves_icall_type_isprimitive},
6738 {"getFullName", ves_icall_System_MonoType_getFullName},
6739 {"get_Assembly", ves_icall_MonoType_get_Assembly},
6740 {"get_BaseType", ves_icall_get_type_parent},
6741 {"get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod},
6742 {"get_DeclaringType", ves_icall_MonoType_get_DeclaringType},
6743 {"get_IsGenericParameter", ves_icall_MonoType_get_IsGenericParameter},
6744 {"get_Module", ves_icall_MonoType_get_Module},
6745 {"get_Name", ves_icall_MonoType_get_Name},
6746 {"get_Namespace", ves_icall_MonoType_get_Namespace},
6747 {"get_UnderlyingSystemType", ves_icall_MonoType_get_UnderlyingSystemType},
6748 {"get_attributes", ves_icall_get_attributes},
6749 {"type_from_obj", mono_type_type_from_obj}
6752 static const IcallEntry assembly_icalls [] = {
6753 {"FillName", ves_icall_System_Reflection_Assembly_FillName},
6754 {"GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly},
6755 {"GetEntryAssembly", ves_icall_System_Reflection_Assembly_GetEntryAssembly},
6756 {"GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly},
6757 {"GetFilesInternal", ves_icall_System_Reflection_Assembly_GetFilesInternal},
6758 {"GetManifestResourceInfoInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal},
6759 {"GetManifestResourceInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInternal},
6760 {"GetManifestResourceNames", ves_icall_System_Reflection_Assembly_GetManifestResourceNames},
6761 {"GetModulesInternal", ves_icall_System_Reflection_Assembly_GetModulesInternal},
6762 {"GetNamespaces", ves_icall_System_Reflection_Assembly_GetNamespaces},
6763 {"GetReferencedAssemblies", ves_icall_System_Reflection_Assembly_GetReferencedAssemblies},
6764 {"GetTypes", ves_icall_System_Reflection_Assembly_GetTypes},
6765 {"InternalGetAssemblyName", ves_icall_System_Reflection_Assembly_InternalGetAssemblyName},
6766 {"InternalGetType", ves_icall_System_Reflection_Assembly_InternalGetType},
6767 {"InternalImageRuntimeVersion", ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion},
6768 {"LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom},
6769 {"LoadPermissions", ves_icall_System_Reflection_Assembly_LoadPermissions},
6771 * Private icalls for the Mono Debugger
6773 {"MonoDebugger_GetMethodToken", ves_icall_MonoDebugger_GetMethodToken},
6775 /* normal icalls again */
6776 {"get_EntryPoint", ves_icall_System_Reflection_Assembly_get_EntryPoint},
6777 {"get_ManifestModule", ves_icall_System_Reflection_Assembly_get_ManifestModule},
6778 {"get_ReflectionOnly", ves_icall_System_Reflection_Assembly_get_ReflectionOnly},
6779 {"get_code_base", ves_icall_System_Reflection_Assembly_get_code_base},
6780 {"get_global_assembly_cache", ves_icall_System_Reflection_Assembly_get_global_assembly_cache},
6781 {"get_location", ves_icall_System_Reflection_Assembly_get_location},
6782 {"load_with_partial_name", ves_icall_System_Reflection_Assembly_load_with_partial_name}
6785 static const IcallEntry assembly_name_icalls [] = {
6786 {"ParseName", ves_icall_System_Reflection_AssemblyName_ParseName}
6789 static const IcallEntry methodbase_icalls [] = {
6790 {"GetCurrentMethod", ves_icall_GetCurrentMethod},
6791 {"GetMethodBodyInternal", ves_icall_System_Reflection_MethodBase_GetMethodBodyInternal},
6792 {"GetMethodFromHandleInternal", ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternal}
6795 static const IcallEntry module_icalls [] = {
6796 {"Close", ves_icall_System_Reflection_Module_Close},
6797 {"GetGlobalType", ves_icall_System_Reflection_Module_GetGlobalType},
6798 {"GetGuidInternal", ves_icall_System_Reflection_Module_GetGuidInternal},
6799 {"GetPEKind", ves_icall_System_Reflection_Module_GetPEKind},
6800 {"InternalGetTypes", ves_icall_System_Reflection_Module_InternalGetTypes},
6801 {"ResolveFieldToken", ves_icall_System_Reflection_Module_ResolveFieldToken},
6802 {"ResolveMemberToken", ves_icall_System_Reflection_Module_ResolveMemberToken},
6803 {"ResolveMethodToken", ves_icall_System_Reflection_Module_ResolveMethodToken},
6804 {"ResolveStringToken", ves_icall_System_Reflection_Module_ResolveStringToken},
6805 {"ResolveTypeToken", ves_icall_System_Reflection_Module_ResolveTypeToken},
6806 {"get_MDStreamVersion", ves_icall_System_Reflection_Module_get_MDStreamVersion},
6807 {"get_MetadataToken", mono_reflection_get_token}
6810 static const IcallEntry monocmethod_icalls [] = {
6811 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
6812 {"InternalInvoke", ves_icall_InternalInvoke},
6815 static const IcallEntry monoeventinfo_icalls [] = {
6816 {"get_event_info", ves_icall_get_event_info}
6819 static const IcallEntry monofield_icalls [] = {
6820 {"GetFieldOffset", ves_icall_MonoField_GetFieldOffset},
6821 {"GetParentType", ves_icall_MonoField_GetParentType},
6822 {"GetValueInternal", ves_icall_MonoField_GetValueInternal},
6823 {"SetValueInternal", ves_icall_FieldInfo_SetValueInternal}
6826 static const IcallEntry monogenericclass_icalls [] = {
6827 {"GetConstructors_internal", ves_icall_MonoGenericClass_GetConstructors},
6828 {"GetCorrespondingInflatedConstructor", ves_icall_MonoGenericClass_GetCorrespondingInflatedConstructor},
6829 {"GetCorrespondingInflatedField", ves_icall_MonoGenericClass_GetCorrespondingInflatedField},
6830 {"GetCorrespondingInflatedMethod", ves_icall_MonoGenericClass_GetCorrespondingInflatedMethod},
6831 {"GetEvents_internal", ves_icall_MonoGenericClass_GetEvents},
6832 {"GetFields_internal", ves_icall_MonoGenericClass_GetFields},
6833 {"GetInterfaces_internal", ves_icall_MonoGenericClass_GetInterfaces},
6834 {"GetMethods_internal", ves_icall_MonoGenericClass_GetMethods},
6835 {"GetParentType", ves_icall_MonoGenericClass_GetParentType},
6836 {"GetProperties_internal", ves_icall_MonoGenericClass_GetProperties},
6837 {"initialize", mono_reflection_generic_class_initialize}
6840 static const IcallEntry monogenericmethod_icalls [] = {
6841 {"get_ReflectedType", ves_icall_MonoGenericMethod_get_ReflectedType}
6844 static const IcallEntry generictypeparambuilder_icalls [] = {
6845 {"initialize", mono_reflection_initialize_generic_parameter}
6848 static const IcallEntry monomethod_icalls [] = {
6849 {"GetDllImportAttribute", ves_icall_MonoMethod_GetDllImportAttribute},
6850 {"GetGenericArguments", ves_icall_MonoMethod_GetGenericArguments},
6851 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
6852 {"InternalInvoke", ves_icall_InternalInvoke},
6853 {"MakeGenericMethod_impl", mono_reflection_bind_generic_method_parameters},
6854 {"get_IsGenericMethod", ves_icall_MonoMethod_get_IsGenericMethod},
6855 {"get_IsGenericMethodDefinition", ves_icall_MonoMethod_get_IsGenericMethodDefinition},
6856 {"get_base_definition", ves_icall_MonoMethod_get_base_definition}
6859 static const IcallEntry monomethodinfo_icalls [] = {
6860 {"get_method_info", ves_icall_get_method_info},
6861 {"get_parameter_info", ves_icall_get_parameter_info},
6862 {"get_retval_marshal", ves_icall_System_MonoMethodInfo_get_retval_marshal}
6865 static const IcallEntry monopropertyinfo_icalls [] = {
6866 {"get_property_info", ves_icall_get_property_info}
6869 static const IcallEntry parameterinfo_icalls [] = {
6870 {"get_MetadataToken", mono_reflection_get_token}
6873 static const IcallEntry dns_icalls [] = {
6874 {"GetHostByAddr_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByAddr_internal},
6875 {"GetHostByName_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByName_internal},
6876 {"GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal}
6879 static const IcallEntry socket_icalls [] = {
6880 {"Accept_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Accept_internal},
6881 {"Available_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Available_internal},
6882 {"Bind_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Bind_internal},
6883 {"Blocking_internal(intptr,bool,int&)", ves_icall_System_Net_Sockets_Socket_Blocking_internal},
6884 {"Close_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Close_internal},
6885 {"Connect_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Connect_internal},
6886 {"GetSocketOption_arr_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,byte[]&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal},
6887 {"GetSocketOption_obj_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal},
6888 {"Listen_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_Listen_internal},
6889 {"LocalEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal},
6890 {"Poll_internal", ves_icall_System_Net_Sockets_Socket_Poll_internal},
6891 {"Receive_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Receive_internal},
6892 {"RecvFrom_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal},
6893 {"RemoteEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal},
6894 {"Select_internal(System.Net.Sockets.Socket[]&,int,int&)", ves_icall_System_Net_Sockets_Socket_Select_internal},
6895 {"SendTo_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_SendTo_internal},
6896 {"Send_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Send_internal},
6897 {"SetSocketOption_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object,byte[],int,int&)", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal},
6898 {"Shutdown_internal(intptr,System.Net.Sockets.SocketShutdown,int&)", ves_icall_System_Net_Sockets_Socket_Shutdown_internal},
6899 {"Socket_internal(System.Net.Sockets.AddressFamily,System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,int&)", ves_icall_System_Net_Sockets_Socket_Socket_internal},
6900 {"WSAIoctl(intptr,int,byte[],byte[],int&)", ves_icall_System_Net_Sockets_Socket_WSAIoctl}
6903 static const IcallEntry socketex_icalls [] = {
6904 {"WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal}
6907 static const IcallEntry object_icalls [] = {
6908 {"GetType", ves_icall_System_Object_GetType},
6909 {"InternalGetHashCode", mono_object_hash},
6910 {"MemberwiseClone", ves_icall_System_Object_MemberwiseClone},
6911 {"obj_address", ves_icall_System_Object_obj_address}
6914 static const IcallEntry assemblybuilder_icalls[] = {
6915 {"InternalAddModule", mono_image_load_module},
6916 {"basic_init", mono_image_basic_init}
6919 static const IcallEntry customattrbuilder_icalls [] = {
6920 {"GetBlob", mono_reflection_get_custom_attrs_blob}
6923 static const IcallEntry dynamicmethod_icalls [] = {
6924 {"create_dynamic_method", mono_reflection_create_dynamic_method}
6927 static const IcallEntry methodbuilder_icalls [] = {
6928 {"MakeGenericMethod", mono_reflection_bind_generic_method_parameters}
6931 static const IcallEntry modulebuilder_icalls [] = {
6932 {"WriteToFile", ves_icall_ModuleBuilder_WriteToFile},
6933 {"basic_init", mono_image_module_basic_init},
6934 {"build_metadata", ves_icall_ModuleBuilder_build_metadata},
6935 {"create_modified_type", ves_icall_ModuleBuilder_create_modified_type},
6936 {"getMethodToken", ves_icall_ModuleBuilder_getMethodToken},
6937 {"getToken", ves_icall_ModuleBuilder_getToken},
6938 {"getUSIndex", mono_image_insert_string}
6941 static const IcallEntry signaturehelper_icalls [] = {
6942 {"get_signature_field", mono_reflection_sighelper_get_signature_field},
6943 {"get_signature_local", mono_reflection_sighelper_get_signature_local}
6946 static const IcallEntry typebuilder_icalls [] = {
6947 {"create_generic_class", mono_reflection_create_generic_class},
6948 {"create_internal_class", mono_reflection_create_internal_class},
6949 {"create_runtime_class", mono_reflection_create_runtime_class},
6950 {"get_IsGenericParameter", ves_icall_TypeBuilder_get_IsGenericParameter},
6951 {"get_event_info", mono_reflection_event_builder_get_event_info},
6952 {"setup_generic_class", mono_reflection_setup_generic_class},
6953 {"setup_internal_class", mono_reflection_setup_internal_class}
6956 static const IcallEntry enumbuilder_icalls [] = {
6957 {"setup_enum_type", ves_icall_EnumBuilder_setup_enum_type}
6960 static const IcallEntry runtimehelpers_icalls [] = {
6961 {"GetObjectValue", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue},
6962 /* REMOVEME: no longer needed, just so we dont break things when not needed */
6963 {"GetOffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData},
6964 {"InitializeArray", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray},
6965 {"RunClassConstructor", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor},
6966 {"get_OffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData}
6969 static const IcallEntry gchandle_icalls [] = {
6970 {"CheckCurrentDomain", GCHandle_CheckCurrentDomain},
6971 {"FreeHandle", ves_icall_System_GCHandle_FreeHandle},
6972 {"GetAddrOfPinnedObject", ves_icall_System_GCHandle_GetAddrOfPinnedObject},
6973 {"GetTarget", ves_icall_System_GCHandle_GetTarget},
6974 {"GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle}
6977 static const IcallEntry marshal_icalls [] = {
6978 {"AllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem},
6979 {"AllocHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_AllocHGlobal},
6980 {"DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure},
6981 {"FreeBSTR", ves_icall_System_Runtime_InteropServices_Marshal_FreeBSTR},
6982 {"FreeCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem},
6983 {"FreeHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_FreeHGlobal},
6984 {"GetComSlotForMethodInfoInternal", ves_icall_System_Runtime_InteropServices_Marshal_GetComSlotForMethodInfoInternal},
6985 {"GetDelegateForFunctionPointerInternal", ves_icall_System_Runtime_InteropServices_Marshal_GetDelegateForFunctionPointerInternal},
6986 {"GetFunctionPointerForDelegateInternal", mono_delegate_to_ftnptr},
6987 {"GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error},
6988 {"OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf},
6989 {"Prelink", ves_icall_System_Runtime_InteropServices_Marshal_Prelink},
6990 {"PrelinkAll", ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll},
6991 {"PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
6992 {"PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
6993 {"PtrToStringAuto(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
6994 {"PtrToStringAuto(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
6995 {"PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR},
6996 {"PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni},
6997 {"PtrToStringUni(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len},
6998 {"PtrToStructure(intptr,System.Type)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type},
6999 {"PtrToStructure(intptr,object)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure},
7000 {"ReAllocHGlobal", mono_marshal_realloc},
7001 {"ReadByte", ves_icall_System_Runtime_InteropServices_Marshal_ReadByte},
7002 {"ReadInt16", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt16},
7003 {"ReadInt32", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt32},
7004 {"ReadInt64", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64},
7005 {"ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr},
7006 {"SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf},
7007 {"StringToBSTR", ves_icall_System_Runtime_InteropServices_Marshal_StringToBSTR},
7008 {"StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
7009 {"StringToHGlobalAuto", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
7010 {"StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni},
7011 {"StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr},
7012 {"UnsafeAddrOfPinnedArrayElement", ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement},
7013 {"WriteByte", ves_icall_System_Runtime_InteropServices_Marshal_WriteByte},
7014 {"WriteInt16", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt16},
7015 {"WriteInt32", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt32},
7016 {"WriteInt64", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt64},
7017 {"WriteIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_WriteIntPtr},
7018 {"copy_from_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged},
7019 {"copy_to_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged}
7022 static const IcallEntry activationservices_icalls [] = {
7023 {"AllocateUninitializedClassInstance", ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance},
7024 {"EnableProxyActivation", ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation}
7027 static const IcallEntry monomethodmessage_icalls [] = {
7028 {"InitMessage", ves_icall_MonoMethodMessage_InitMessage}
7031 static const IcallEntry realproxy_icalls [] = {
7032 {"InternalGetProxyType", ves_icall_Remoting_RealProxy_InternalGetProxyType},
7033 {"InternalGetTransparentProxy", ves_icall_Remoting_RealProxy_GetTransparentProxy}
7036 static const IcallEntry remotingservices_icalls [] = {
7037 {"InternalExecute", ves_icall_InternalExecute},
7038 {"IsTransparentProxy", ves_icall_IsTransparentProxy}
7041 static const IcallEntry rng_icalls [] = {
7042 {"RngClose", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose},
7043 {"RngGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes},
7044 {"RngInitialize", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize},
7045 {"RngOpen", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngOpen}
7048 static const IcallEntry methodhandle_icalls [] = {
7049 {"GetFunctionPointer", ves_icall_RuntimeMethod_GetFunctionPointer}
7052 static const IcallEntry string_icalls [] = {
7053 {".ctor(char*)", ves_icall_System_String_ctor_charp},
7054 {".ctor(char*,int,int)", ves_icall_System_String_ctor_charp_int_int},
7055 {".ctor(char,int)", ves_icall_System_String_ctor_char_int},
7056 {".ctor(char[])", ves_icall_System_String_ctor_chara},
7057 {".ctor(char[],int,int)", ves_icall_System_String_ctor_chara_int_int},
7058 {".ctor(sbyte*)", ves_icall_System_String_ctor_sbytep},
7059 {".ctor(sbyte*,int,int)", ves_icall_System_String_ctor_sbytep_int_int},
7060 {".ctor(sbyte*,int,int,System.Text.Encoding)", ves_icall_System_String_ctor_encoding},
7061 {"InternalAllocateStr", ves_icall_System_String_InternalAllocateStr},
7062 {"InternalCharCopy", ves_icall_System_String_InternalCharCopy},
7063 {"InternalCopyTo", ves_icall_System_String_InternalCopyTo},
7064 {"InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny},
7065 {"InternalInsert", ves_icall_System_String_InternalInsert},
7066 {"InternalIntern", ves_icall_System_String_InternalIntern},
7067 {"InternalIsInterned", ves_icall_System_String_InternalIsInterned},
7068 {"InternalJoin", ves_icall_System_String_InternalJoin},
7069 {"InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny},
7070 {"InternalPad", ves_icall_System_String_InternalPad},
7071 {"InternalRemove", ves_icall_System_String_InternalRemove},
7072 {"InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char},
7073 {"InternalReplace(string,string,System.Globalization.CompareInfo)", ves_icall_System_String_InternalReplace_Str_Comp},
7074 {"InternalSplit", ves_icall_System_String_InternalSplit},
7075 {"InternalStrcpy(string,int,char[])", ves_icall_System_String_InternalStrcpy_Chars},
7076 {"InternalStrcpy(string,int,char[],int,int)", ves_icall_System_String_InternalStrcpy_CharsN},
7077 {"InternalStrcpy(string,int,string)", ves_icall_System_String_InternalStrcpy_Str},
7078 {"InternalStrcpy(string,int,string,int,int)", ves_icall_System_String_InternalStrcpy_StrN},
7079 {"InternalTrim", ves_icall_System_String_InternalTrim},
7080 {"get_Chars", ves_icall_System_String_get_Chars}
7083 static const IcallEntry encoding_icalls [] = {
7084 {"InternalCodePage", ves_icall_System_Text_Encoding_InternalCodePage}
7087 static const IcallEntry monitor_icalls [] = {
7088 {"Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit},
7089 {"Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse},
7090 {"Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all},
7091 {"Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner},
7092 {"Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised},
7093 {"Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter},
7094 {"Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait}
7097 static const IcallEntry interlocked_icalls [] = {
7098 {"Add(int&,int)", ves_icall_System_Threading_Interlocked_Add_Int},
7099 {"Add(long&,long)", ves_icall_System_Threading_Interlocked_Add_Long},
7100 {"CompareExchange(T&,T,T)", ves_icall_System_Threading_Interlocked_CompareExchange_T},
7101 {"CompareExchange(double&,double,double)", ves_icall_System_Threading_Interlocked_CompareExchange_Double},
7102 {"CompareExchange(int&,int,int)", ves_icall_System_Threading_Interlocked_CompareExchange_Int},
7103 {"CompareExchange(intptr&,intptr,intptr)", ves_icall_System_Threading_Interlocked_CompareExchange_Object},
7104 {"CompareExchange(long&,long,long)", ves_icall_System_Threading_Interlocked_CompareExchange_Long},
7105 {"CompareExchange(object&,object,object)", ves_icall_System_Threading_Interlocked_CompareExchange_Object},
7106 {"CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single},
7107 {"Decrement(int&)", ves_icall_System_Threading_Interlocked_Decrement_Int},
7108 {"Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long},
7109 {"Exchange(T&,T)", ves_icall_System_Threading_Interlocked_Exchange_T},
7110 {"Exchange(double&,double)", ves_icall_System_Threading_Interlocked_Exchange_Double},
7111 {"Exchange(int&,int)", ves_icall_System_Threading_Interlocked_Exchange_Int},
7112 {"Exchange(intptr&,intptr)", ves_icall_System_Threading_Interlocked_Exchange_Object},
7113 {"Exchange(long&,long)", ves_icall_System_Threading_Interlocked_Exchange_Long},
7114 {"Exchange(object&,object)", ves_icall_System_Threading_Interlocked_Exchange_Object},
7115 {"Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single},
7116 {"Increment(int&)", ves_icall_System_Threading_Interlocked_Increment_Int},
7117 {"Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long},
7118 {"Read(long&)", ves_icall_System_Threading_Interlocked_Read_Long}
7121 static const IcallEntry mutex_icalls [] = {
7122 {"CreateMutex_internal(bool,string,bool&)", ves_icall_System_Threading_Mutex_CreateMutex_internal},
7123 {"OpenMutex_internal(string,System.Security.AccessControl.MutexRights,System.IO.MonoIOError&)", ves_icall_System_Threading_Mutex_OpenMutex_internal},
7124 {"ReleaseMutex_internal(intptr)", ves_icall_System_Threading_Mutex_ReleaseMutex_internal}
7127 static const IcallEntry semaphore_icalls [] = {
7128 {"CreateSemaphore_internal(int,int,string,bool&)", ves_icall_System_Threading_Semaphore_CreateSemaphore_internal},
7129 {"OpenSemaphore_internal(string,System.Security.AccessControl.SemaphoreRights,System.IO.MonoIOError&)", ves_icall_System_Threading_Semaphore_OpenSemaphore_internal},
7130 {"ReleaseSemaphore_internal(intptr,int,bool&)", ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal}
7133 static const IcallEntry nativeevents_icalls [] = {
7134 {"CloseEvent_internal", ves_icall_System_Threading_Events_CloseEvent_internal},
7135 {"CreateEvent_internal(bool,bool,string,bool&)", ves_icall_System_Threading_Events_CreateEvent_internal},
7136 {"OpenEvent_internal(string,System.Security.AccessControl.EventWaitHandleRights,System.IO.MonoIOError&)", ves_icall_System_Threading_Events_OpenEvent_internal},
7137 {"ResetEvent_internal", ves_icall_System_Threading_Events_ResetEvent_internal},
7138 {"SetEvent_internal", ves_icall_System_Threading_Events_SetEvent_internal}
7141 static const IcallEntry thread_icalls [] = {
7142 {"Abort_internal(object)", ves_icall_System_Threading_Thread_Abort},
7143 {"ClrState", ves_icall_System_Threading_Thread_ClrState},
7144 {"CurrentThread_internal", mono_thread_current},
7145 {"FreeLocalSlotValues", mono_thread_free_local_slot_values},
7146 {"GetCachedCurrentCulture", ves_icall_System_Threading_Thread_GetCachedCurrentCulture},
7147 {"GetCachedCurrentUICulture", ves_icall_System_Threading_Thread_GetCachedCurrentUICulture},
7148 {"GetDomainID", ves_icall_System_Threading_Thread_GetDomainID},
7149 {"GetName_internal", ves_icall_System_Threading_Thread_GetName_internal},
7150 {"GetSerializedCurrentCulture", ves_icall_System_Threading_Thread_GetSerializedCurrentCulture},
7151 {"GetSerializedCurrentUICulture", ves_icall_System_Threading_Thread_GetSerializedCurrentUICulture},
7152 {"GetState", ves_icall_System_Threading_Thread_GetState},
7153 {"Join_internal", ves_icall_System_Threading_Thread_Join_internal},
7154 {"MemoryBarrier", ves_icall_System_Threading_Thread_MemoryBarrier},
7155 {"ResetAbort_internal()", ves_icall_System_Threading_Thread_ResetAbort},
7156 {"Resume_internal()", ves_icall_System_Threading_Thread_Resume},
7157 {"SetCachedCurrentCulture", ves_icall_System_Threading_Thread_SetCachedCurrentCulture},
7158 {"SetCachedCurrentUICulture", ves_icall_System_Threading_Thread_SetCachedCurrentUICulture},
7159 {"SetName_internal", ves_icall_System_Threading_Thread_SetName_internal},
7160 {"SetSerializedCurrentCulture", ves_icall_System_Threading_Thread_SetSerializedCurrentCulture},
7161 {"SetSerializedCurrentUICulture", ves_icall_System_Threading_Thread_SetSerializedCurrentUICulture},
7162 {"SetState", ves_icall_System_Threading_Thread_SetState},
7163 {"Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal},
7164 {"Suspend_internal", ves_icall_System_Threading_Thread_Suspend},
7165 {"Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal},
7166 {"Thread_internal", ves_icall_System_Threading_Thread_Thread_internal},
7167 {"VolatileRead(byte&)", ves_icall_System_Threading_Thread_VolatileRead1},
7168 {"VolatileRead(double&)", ves_icall_System_Threading_Thread_VolatileRead8},
7169 {"VolatileRead(int&)", ves_icall_System_Threading_Thread_VolatileRead4},
7170 {"VolatileRead(int16&)", ves_icall_System_Threading_Thread_VolatileRead2},
7171 {"VolatileRead(intptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
7172 {"VolatileRead(long&)", ves_icall_System_Threading_Thread_VolatileRead8},
7173 {"VolatileRead(object&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
7174 {"VolatileRead(sbyte&)", ves_icall_System_Threading_Thread_VolatileRead1},
7175 {"VolatileRead(single&)", ves_icall_System_Threading_Thread_VolatileRead4},
7176 {"VolatileRead(uint&)", ves_icall_System_Threading_Thread_VolatileRead2},
7177 {"VolatileRead(uint16&)", ves_icall_System_Threading_Thread_VolatileRead2},
7178 {"VolatileRead(uintptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
7179 {"VolatileRead(ulong&)", ves_icall_System_Threading_Thread_VolatileRead8},
7180 {"VolatileWrite(byte&,byte)", ves_icall_System_Threading_Thread_VolatileWrite1},
7181 {"VolatileWrite(double&,double)", ves_icall_System_Threading_Thread_VolatileWrite8},
7182 {"VolatileWrite(int&,int)", ves_icall_System_Threading_Thread_VolatileWrite4},
7183 {"VolatileWrite(int16&,int16)", ves_icall_System_Threading_Thread_VolatileWrite2},
7184 {"VolatileWrite(intptr&,intptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
7185 {"VolatileWrite(long&,long)", ves_icall_System_Threading_Thread_VolatileWrite8},
7186 {"VolatileWrite(object&,object)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
7187 {"VolatileWrite(sbyte&,sbyte)", ves_icall_System_Threading_Thread_VolatileWrite1},
7188 {"VolatileWrite(single&,single)", ves_icall_System_Threading_Thread_VolatileWrite4},
7189 {"VolatileWrite(uint&,uint)", ves_icall_System_Threading_Thread_VolatileWrite2},
7190 {"VolatileWrite(uint16&,uint16)", ves_icall_System_Threading_Thread_VolatileWrite2},
7191 {"VolatileWrite(uintptr&,uintptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
7192 {"VolatileWrite(ulong&,ulong)", ves_icall_System_Threading_Thread_VolatileWrite8},
7193 {"current_lcid()", ves_icall_System_Threading_Thread_current_lcid}
7196 static const IcallEntry threadpool_icalls [] = {
7197 {"GetAvailableThreads", ves_icall_System_Threading_ThreadPool_GetAvailableThreads},
7198 {"GetMaxThreads", ves_icall_System_Threading_ThreadPool_GetMaxThreads},
7199 {"GetMinThreads", ves_icall_System_Threading_ThreadPool_GetMinThreads},
7200 {"SetMinThreads", ves_icall_System_Threading_ThreadPool_SetMinThreads}
7203 static const IcallEntry waithandle_icalls [] = {
7204 {"WaitAll_internal", ves_icall_System_Threading_WaitHandle_WaitAll_internal},
7205 {"WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny_internal},
7206 {"WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal}
7209 static const IcallEntry type_icalls [] = {
7210 {"Equals", ves_icall_type_Equals},
7211 {"GetGenericParameterAttributes", ves_icall_Type_GetGenericParameterAttributes},
7212 {"GetGenericParameterConstraints_impl", ves_icall_Type_GetGenericParameterConstraints},
7213 {"GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition},
7214 {"GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl},
7215 {"GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData},
7216 {"GetPacking", ves_icall_Type_GetPacking},
7217 {"GetTypeCode", ves_icall_type_GetTypeCodeInternal},
7218 {"GetTypeCodeInternal", ves_icall_type_GetTypeCodeInternal},
7219 {"IsArrayImpl", ves_icall_Type_IsArrayImpl},
7220 {"IsInstanceOfType", ves_icall_type_IsInstanceOfType},
7221 {"MakeGenericType", ves_icall_Type_MakeGenericType},
7222 {"MakePointerType", ves_icall_Type_MakePointerType},
7223 {"get_IsGenericInstance", ves_icall_Type_get_IsGenericInstance},
7224 {"get_IsGenericType", ves_icall_Type_get_IsGenericType},
7225 {"get_IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition},
7226 {"internal_from_handle", ves_icall_type_from_handle},
7227 {"internal_from_name", ves_icall_type_from_name},
7228 {"make_array_type", ves_icall_Type_make_array_type},
7229 {"make_byref_type", ves_icall_Type_make_byref_type},
7230 {"type_is_assignable_from", ves_icall_type_is_assignable_from},
7231 {"type_is_subtype_of", ves_icall_type_is_subtype_of}
7234 static const IcallEntry typedref_icalls [] = {
7235 {"ToObject", mono_TypedReference_ToObject},
7236 {"ToObjectInternal", mono_TypedReference_ToObjectInternal}
7239 static const IcallEntry valuetype_icalls [] = {
7240 {"InternalEquals", ves_icall_System_ValueType_Equals},
7241 {"InternalGetHashCode", ves_icall_System_ValueType_InternalGetHashCode}
7244 static const IcallEntry web_icalls [] = {
7245 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
7246 {"GetMachineInstallDirectory", ves_icall_System_Web_Util_ICalls_get_machine_install_dir}
7249 static const IcallEntry identity_icalls [] = {
7250 {"GetCurrentToken", ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken},
7251 {"GetTokenName", ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName},
7252 {"GetUserToken", ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken},
7253 {"_GetRoles", ves_icall_System_Security_Principal_WindowsIdentity_GetRoles}
7256 static const IcallEntry impersonation_icalls [] = {
7257 {"CloseToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_CloseToken},
7258 {"DuplicateToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_DuplicateToken},
7259 {"RevertToSelf", ves_icall_System_Security_Principal_WindowsImpersonationContext_RevertToSelf},
7260 {"SetCurrentToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_SetCurrentToken}
7263 static const IcallEntry principal_icalls [] = {
7264 {"IsMemberOfGroupId", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupId},
7265 {"IsMemberOfGroupName", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupName}
7268 static const IcallEntry keypair_icalls [] = {
7269 {"_CanSecure", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_CanSecure},
7270 {"_IsMachineProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsMachineProtected},
7271 {"_IsUserProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsUserProtected},
7272 {"_ProtectMachine", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectMachine},
7273 {"_ProtectUser", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectUser}
7276 static const IcallEntry evidence_icalls [] = {
7277 {"IsAuthenticodePresent", ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent}
7280 static const IcallEntry securitymanager_icalls [] = {
7281 {"GetLinkDemandSecurity", ves_icall_System_Security_SecurityManager_GetLinkDemandSecurity},
7282 {"get_CheckExecutionRights", ves_icall_System_Security_SecurityManager_get_CheckExecutionRights},
7283 {"get_SecurityEnabled", ves_icall_System_Security_SecurityManager_get_SecurityEnabled},
7284 {"set_CheckExecutionRights", ves_icall_System_Security_SecurityManager_set_CheckExecutionRights},
7285 {"set_SecurityEnabled", ves_icall_System_Security_SecurityManager_set_SecurityEnabled}
7288 static const IcallEntry generic_array_icalls [] = {
7289 {"GetGenericValueImpl", ves_icall_System_Array_InternalArray_GetGenericValueImpl}
7293 static const IcallEntry array_icalls [] = {
7298 /* keep the entries all sorted */
7299 static const IcallMap icall_entries [] = {
7300 {"Mono.Runtime", runtime_icalls, G_N_ELEMENTS (runtime_icalls)},
7301 {"Mono.Security.Cryptography.KeyPairPersistence", keypair_icalls, G_N_ELEMENTS (keypair_icalls)},
7302 {"System.Activator", activator_icalls, G_N_ELEMENTS (activator_icalls)},
7303 {"System.AppDomain", appdomain_icalls, G_N_ELEMENTS (appdomain_icalls)},
7304 {"System.ArgIterator", argiterator_icalls, G_N_ELEMENTS (argiterator_icalls)},
7305 {"System.Array", array_icalls, G_N_ELEMENTS (array_icalls)},
7306 {"System.Array/InternalArray`1", generic_array_icalls, G_N_ELEMENTS (generic_array_icalls)},
7307 {"System.Buffer", buffer_icalls, G_N_ELEMENTS (buffer_icalls)},
7308 {"System.Char", char_icalls, G_N_ELEMENTS (char_icalls)},
7309 {"System.Configuration.DefaultConfig", defaultconf_icalls, G_N_ELEMENTS (defaultconf_icalls)},
7310 {"System.ConsoleDriver", consoledriver_icalls, G_N_ELEMENTS (consoledriver_icalls)},
7311 {"System.Convert", convert_icalls, G_N_ELEMENTS (convert_icalls)},
7312 {"System.CurrentSystemTimeZone", timezone_icalls, G_N_ELEMENTS (timezone_icalls)},
7313 {"System.DateTime", datetime_icalls, G_N_ELEMENTS (datetime_icalls)},
7314 #ifndef DISABLE_DECIMAL
7315 {"System.Decimal", decimal_icalls, G_N_ELEMENTS (decimal_icalls)},
7317 {"System.Delegate", delegate_icalls, G_N_ELEMENTS (delegate_icalls)},
7318 {"System.Diagnostics.DefaultTraceListener", tracelist_icalls, G_N_ELEMENTS (tracelist_icalls)},
7319 {"System.Diagnostics.FileVersionInfo", fileversion_icalls, G_N_ELEMENTS (fileversion_icalls)},
7320 {"System.Diagnostics.Process", process_icalls, G_N_ELEMENTS (process_icalls)},
7321 {"System.Double", double_icalls, G_N_ELEMENTS (double_icalls)},
7322 {"System.Enum", enum_icalls, G_N_ELEMENTS (enum_icalls)},
7323 {"System.Environment", environment_icalls, G_N_ELEMENTS (environment_icalls)},
7324 {"System.GC", gc_icalls, G_N_ELEMENTS (gc_icalls)},
7325 {"System.Globalization.CompareInfo", compareinfo_icalls, G_N_ELEMENTS (compareinfo_icalls)},
7326 {"System.Globalization.CultureInfo", cultureinfo_icalls, G_N_ELEMENTS (cultureinfo_icalls)},
7327 {"System.Globalization.RegionInfo", regioninfo_icalls, G_N_ELEMENTS (regioninfo_icalls)},
7328 {"System.IO.FAMWatcher", famwatcher_icalls, G_N_ELEMENTS (famwatcher_icalls)},
7329 {"System.IO.FileSystemWatcher", filewatcher_icalls, G_N_ELEMENTS (filewatcher_icalls)},
7330 {"System.IO.MonoIO", monoio_icalls, G_N_ELEMENTS (monoio_icalls)},
7331 {"System.IO.Path", path_icalls, G_N_ELEMENTS (path_icalls)},
7332 {"System.Math", math_icalls, G_N_ELEMENTS (math_icalls)},
7333 {"System.MonoCustomAttrs", customattrs_icalls, G_N_ELEMENTS (customattrs_icalls)},
7334 {"System.MonoEnumInfo", enuminfo_icalls, G_N_ELEMENTS (enuminfo_icalls)},
7335 {"System.MonoType", monotype_icalls, G_N_ELEMENTS (monotype_icalls)},
7336 {"System.Net.Dns", dns_icalls, G_N_ELEMENTS (dns_icalls)},
7337 {"System.Net.Sockets.Socket", socket_icalls, G_N_ELEMENTS (socket_icalls)},
7338 {"System.Net.Sockets.SocketException", socketex_icalls, G_N_ELEMENTS (socketex_icalls)},
7339 {"System.Object", object_icalls, G_N_ELEMENTS (object_icalls)},
7340 {"System.Reflection.Assembly", assembly_icalls, G_N_ELEMENTS (assembly_icalls)},
7341 {"System.Reflection.AssemblyName", assembly_name_icalls, G_N_ELEMENTS (assembly_name_icalls)},
7342 {"System.Reflection.Emit.AssemblyBuilder", assemblybuilder_icalls, G_N_ELEMENTS (assemblybuilder_icalls)},
7343 {"System.Reflection.Emit.CustomAttributeBuilder", customattrbuilder_icalls, G_N_ELEMENTS (customattrbuilder_icalls)},
7344 {"System.Reflection.Emit.DynamicMethod", dynamicmethod_icalls, G_N_ELEMENTS (dynamicmethod_icalls)},
7345 {"System.Reflection.Emit.EnumBuilder", enumbuilder_icalls, G_N_ELEMENTS (enumbuilder_icalls)},
7346 {"System.Reflection.Emit.GenericTypeParameterBuilder", generictypeparambuilder_icalls, G_N_ELEMENTS (generictypeparambuilder_icalls)},
7347 {"System.Reflection.Emit.MethodBuilder", methodbuilder_icalls, G_N_ELEMENTS (methodbuilder_icalls)},
7348 {"System.Reflection.Emit.ModuleBuilder", modulebuilder_icalls, G_N_ELEMENTS (modulebuilder_icalls)},
7349 {"System.Reflection.Emit.SignatureHelper", signaturehelper_icalls, G_N_ELEMENTS (signaturehelper_icalls)},
7350 {"System.Reflection.Emit.TypeBuilder", typebuilder_icalls, G_N_ELEMENTS (typebuilder_icalls)},
7351 {"System.Reflection.FieldInfo", fieldinfo_icalls, G_N_ELEMENTS (fieldinfo_icalls)},
7352 {"System.Reflection.MemberInfo", memberinfo_icalls, G_N_ELEMENTS (memberinfo_icalls)},
7353 {"System.Reflection.MethodBase", methodbase_icalls, G_N_ELEMENTS (methodbase_icalls)},
7354 {"System.Reflection.Module", module_icalls, G_N_ELEMENTS (module_icalls)},
7355 {"System.Reflection.MonoCMethod", monocmethod_icalls, G_N_ELEMENTS (monocmethod_icalls)},
7356 {"System.Reflection.MonoEventInfo", monoeventinfo_icalls, G_N_ELEMENTS (monoeventinfo_icalls)},
7357 {"System.Reflection.MonoField", monofield_icalls, G_N_ELEMENTS (monofield_icalls)},
7358 {"System.Reflection.MonoGenericCMethod", monogenericmethod_icalls, G_N_ELEMENTS (monogenericmethod_icalls)},
7359 {"System.Reflection.MonoGenericClass", monogenericclass_icalls, G_N_ELEMENTS (monogenericclass_icalls)},
7360 {"System.Reflection.MonoGenericMethod", monogenericmethod_icalls, G_N_ELEMENTS (monogenericmethod_icalls)},
7361 {"System.Reflection.MonoMethod", monomethod_icalls, G_N_ELEMENTS (monomethod_icalls)},
7362 {"System.Reflection.MonoMethodInfo", monomethodinfo_icalls, G_N_ELEMENTS (monomethodinfo_icalls)},
7363 {"System.Reflection.MonoPropertyInfo", monopropertyinfo_icalls, G_N_ELEMENTS (monopropertyinfo_icalls)},
7364 {"System.Reflection.ParameterInfo", parameterinfo_icalls, G_N_ELEMENTS (parameterinfo_icalls)},
7365 {"System.Runtime.CompilerServices.RuntimeHelpers", runtimehelpers_icalls, G_N_ELEMENTS (runtimehelpers_icalls)},
7366 {"System.Runtime.InteropServices.GCHandle", gchandle_icalls, G_N_ELEMENTS (gchandle_icalls)},
7367 {"System.Runtime.InteropServices.Marshal", marshal_icalls, G_N_ELEMENTS (marshal_icalls)},
7368 {"System.Runtime.Remoting.Activation.ActivationServices", activationservices_icalls, G_N_ELEMENTS (activationservices_icalls)},
7369 {"System.Runtime.Remoting.Messaging.MonoMethodMessage", monomethodmessage_icalls, G_N_ELEMENTS (monomethodmessage_icalls)},
7370 {"System.Runtime.Remoting.Proxies.RealProxy", realproxy_icalls, G_N_ELEMENTS (realproxy_icalls)},
7371 {"System.Runtime.Remoting.RemotingServices", remotingservices_icalls, G_N_ELEMENTS (remotingservices_icalls)},
7372 {"System.RuntimeMethodHandle", methodhandle_icalls, G_N_ELEMENTS (methodhandle_icalls)},
7373 {"System.Security.Cryptography.RNGCryptoServiceProvider", rng_icalls, G_N_ELEMENTS (rng_icalls)},
7374 {"System.Security.Policy.Evidence", evidence_icalls, G_N_ELEMENTS (evidence_icalls)},
7375 {"System.Security.Principal.WindowsIdentity", identity_icalls, G_N_ELEMENTS (identity_icalls)},
7376 {"System.Security.Principal.WindowsImpersonationContext", impersonation_icalls, G_N_ELEMENTS (impersonation_icalls)},
7377 {"System.Security.Principal.WindowsPrincipal", principal_icalls, G_N_ELEMENTS (principal_icalls)},
7378 {"System.Security.SecurityManager", securitymanager_icalls, G_N_ELEMENTS (securitymanager_icalls)},
7379 {"System.String", string_icalls, G_N_ELEMENTS (string_icalls)},
7380 {"System.Text.Encoding", encoding_icalls, G_N_ELEMENTS (encoding_icalls)},
7381 {"System.Threading.Interlocked", interlocked_icalls, G_N_ELEMENTS (interlocked_icalls)},
7382 {"System.Threading.Monitor", monitor_icalls, G_N_ELEMENTS (monitor_icalls)},
7383 {"System.Threading.Mutex", mutex_icalls, G_N_ELEMENTS (mutex_icalls)},
7384 {"System.Threading.NativeEventCalls", nativeevents_icalls, G_N_ELEMENTS (nativeevents_icalls)},
7385 {"System.Threading.Semaphore", semaphore_icalls, G_N_ELEMENTS (semaphore_icalls)},
7386 {"System.Threading.Thread", thread_icalls, G_N_ELEMENTS (thread_icalls)},
7387 {"System.Threading.ThreadPool", threadpool_icalls, G_N_ELEMENTS (threadpool_icalls)},
7388 {"System.Threading.WaitHandle", waithandle_icalls, G_N_ELEMENTS (waithandle_icalls)},
7389 {"System.Type", type_icalls, G_N_ELEMENTS (type_icalls)},
7390 {"System.TypedReference", typedref_icalls, G_N_ELEMENTS (typedref_icalls)},
7391 {"System.ValueType", valuetype_icalls, G_N_ELEMENTS (valuetype_icalls)},
7392 {"System.Web.Util.ICalls", web_icalls, G_N_ELEMENTS (web_icalls)}
7395 static GHashTable *icall_hash = NULL;
7396 static GHashTable *jit_icall_hash_name = NULL;
7397 static GHashTable *jit_icall_hash_addr = NULL;
7400 mono_icall_init (void)
7404 /* check that tables are sorted: disable in release */
7407 const IcallMap *imap;
7408 const IcallEntry *ientry;
7409 const char *prev_class = NULL;
7410 const char *prev_method;
7412 for (i = 0; i < G_N_ELEMENTS (icall_entries); ++i) {
7413 imap = &icall_entries [i];
7415 if (prev_class && strcmp (prev_class, imap->klass) >= 0)
7416 g_print ("class %s should come before class %s\n", imap->klass, prev_class);
7417 prev_class = imap->klass;
7418 for (j = 0; j < imap->size; ++j) {
7419 ientry = &imap->icalls [j];
7420 if (prev_method && strcmp (prev_method, ientry->method) >= 0)
7421 g_print ("method %s should come before method %s\n", ientry->method, prev_method);
7422 prev_method = ientry->method;
7427 icall_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
7431 mono_icall_cleanup (void)
7433 g_hash_table_destroy (icall_hash);
7434 g_hash_table_destroy (jit_icall_hash_name);
7435 g_hash_table_destroy (jit_icall_hash_addr);
7439 mono_add_internal_call (const char *name, gconstpointer method)
7441 mono_loader_lock ();
7443 g_hash_table_insert (icall_hash, g_strdup (name), (gpointer) method);
7445 mono_loader_unlock ();
7449 compare_class_imap (const void *key, const void *elem)
7451 const IcallMap* imap = (const IcallMap*)elem;
7452 return strcmp (key, imap->klass);
7455 static const IcallMap*
7456 find_class_icalls (const char *name)
7458 return (const IcallMap*) bsearch (name, icall_entries, G_N_ELEMENTS (icall_entries), sizeof (IcallMap), compare_class_imap);
7462 compare_method_imap (const void *key, const void *elem)
7464 const IcallEntry* ientry = (const IcallEntry*)elem;
7465 return strcmp (key, ientry->method);
7469 find_method_icall (const IcallMap *imap, const char *name)
7471 const IcallEntry *ientry = (const IcallEntry*) bsearch (name, imap->icalls, imap->size, sizeof (IcallEntry), compare_method_imap);
7473 return (void*)ientry->func;
7478 * we should probably export this as an helper (handle nested types).
7479 * Returns the number of chars written in buf.
7482 concat_class_name (char *buf, int bufsize, MonoClass *klass)
7484 int nspacelen, cnamelen;
7485 nspacelen = strlen (klass->name_space);
7486 cnamelen = strlen (klass->name);
7487 if (nspacelen + cnamelen + 2 > bufsize)
7490 memcpy (buf, klass->name_space, nspacelen);
7491 buf [nspacelen ++] = '.';
7493 memcpy (buf + nspacelen, klass->name, cnamelen);
7494 buf [nspacelen + cnamelen] = 0;
7495 return nspacelen + cnamelen;
7499 mono_lookup_internal_call (MonoMethod *method)
7504 int typelen = 0, mlen, siglen;
7506 const IcallMap *imap;
7508 g_assert (method != NULL);
7510 if (method->is_inflated)
7511 method = ((MonoMethodInflated *) method)->declaring;
7513 if (method->klass->nested_in) {
7514 int pos = concat_class_name (mname, sizeof (mname)-2, method->klass->nested_in);
7518 mname [pos++] = '/';
7521 typelen = concat_class_name (mname+pos, sizeof (mname)-pos-1, method->klass);
7527 typelen = concat_class_name (mname, sizeof (mname), method->klass);
7532 imap = find_class_icalls (mname);
7534 mname [typelen] = ':';
7535 mname [typelen + 1] = ':';
7537 mlen = strlen (method->name);
7538 memcpy (mname + typelen + 2, method->name, mlen);
7539 sigstart = mname + typelen + 2 + mlen;
7542 tmpsig = mono_signature_get_desc (mono_method_signature (method), TRUE);
7543 siglen = strlen (tmpsig);
7544 if (typelen + mlen + siglen + 6 > sizeof (mname))
7547 memcpy (sigstart + 1, tmpsig, siglen);
7548 sigstart [siglen + 1] = ')';
7549 sigstart [siglen + 2] = 0;
7552 mono_loader_lock ();
7554 res = g_hash_table_lookup (icall_hash, mname);
7556 mono_loader_unlock ();
7559 /* try without signature */
7561 res = g_hash_table_lookup (icall_hash, mname);
7563 mono_loader_unlock ();
7567 /* it wasn't found in the static call tables */
7569 mono_loader_unlock ();
7572 res = find_method_icall (imap, sigstart - mlen);
7574 mono_loader_unlock ();
7577 /* try _with_ signature */
7579 res = find_method_icall (imap, sigstart - mlen);
7581 mono_loader_unlock ();
7585 g_warning ("cant resolve internal call to \"%s\" (tested without signature also)", mname);
7586 g_print ("\nYour mono runtime and class libraries are out of sync.\n");
7587 g_print ("The out of sync library is: %s\n", method->klass->image->name);
7588 g_print ("\nWhen you update one from cvs you need to update, compile and install\nthe other too.\n");
7589 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");
7590 g_print ("If you see other errors or faults after this message they are probably related\n");
7591 g_print ("and you need to fix your mono install first.\n");
7593 mono_loader_unlock ();
7599 type_from_typename (char *typename)
7601 MonoClass *klass = NULL; /* assignment to shut GCC warning up */
7603 if (!strcmp (typename, "int"))
7604 klass = mono_defaults.int_class;
7605 else if (!strcmp (typename, "ptr"))
7606 klass = mono_defaults.int_class;
7607 else if (!strcmp (typename, "void"))
7608 klass = mono_defaults.void_class;
7609 else if (!strcmp (typename, "int32"))
7610 klass = mono_defaults.int32_class;
7611 else if (!strcmp (typename, "uint32"))
7612 klass = mono_defaults.uint32_class;
7613 else if (!strcmp (typename, "long"))
7614 klass = mono_defaults.int64_class;
7615 else if (!strcmp (typename, "ulong"))
7616 klass = mono_defaults.uint64_class;
7617 else if (!strcmp (typename, "float"))
7618 klass = mono_defaults.single_class;
7619 else if (!strcmp (typename, "double"))
7620 klass = mono_defaults.double_class;
7621 else if (!strcmp (typename, "object"))
7622 klass = mono_defaults.object_class;
7623 else if (!strcmp (typename, "obj"))
7624 klass = mono_defaults.object_class;
7627 g_assert_not_reached ();
7629 return &klass->byval_arg;
7632 MonoMethodSignature*
7633 mono_create_icall_signature (const char *sigstr)
7638 MonoMethodSignature *res;
7640 mono_loader_lock ();
7641 res = g_hash_table_lookup (mono_defaults.corlib->helper_signatures, sigstr);
7643 mono_loader_unlock ();
7647 parts = g_strsplit (sigstr, " ", 256);
7656 res = mono_metadata_signature_alloc (mono_defaults.corlib, len - 1);
7659 #ifdef PLATFORM_WIN32
7661 * Under windows, the default pinvoke calling convention is STDCALL but
7664 res->call_convention = MONO_CALL_C;
7667 res->ret = type_from_typename (parts [0]);
7668 for (i = 1; i < len; ++i) {
7669 res->params [i - 1] = type_from_typename (parts [i]);
7674 g_hash_table_insert (mono_defaults.corlib->helper_signatures, (gpointer)sigstr, res);
7676 mono_loader_unlock ();
7682 mono_find_jit_icall_by_name (const char *name)
7684 MonoJitICallInfo *info;
7685 g_assert (jit_icall_hash_name);
7687 mono_loader_lock ();
7688 info = g_hash_table_lookup (jit_icall_hash_name, name);
7689 mono_loader_unlock ();
7694 mono_find_jit_icall_by_addr (gconstpointer addr)
7696 MonoJitICallInfo *info;
7697 g_assert (jit_icall_hash_addr);
7699 mono_loader_lock ();
7700 info = g_hash_table_lookup (jit_icall_hash_addr, (gpointer)addr);
7701 mono_loader_unlock ();
7707 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper)
7709 mono_loader_lock ();
7710 g_hash_table_insert (jit_icall_hash_addr, (gpointer)wrapper, info);
7711 mono_loader_unlock ();
7715 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save)
7717 MonoJitICallInfo *info;
7722 mono_loader_lock ();
7724 if (!jit_icall_hash_name) {
7725 jit_icall_hash_name = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
7726 jit_icall_hash_addr = g_hash_table_new (NULL, NULL);
7729 if (g_hash_table_lookup (jit_icall_hash_name, name)) {
7730 g_warning ("jit icall already defined \"%s\"\n", name);
7731 g_assert_not_reached ();
7734 info = g_new0 (MonoJitICallInfo, 1);
7741 info->wrapper = func;
7743 info->wrapper = NULL;
7746 g_hash_table_insert (jit_icall_hash_name, (gpointer)info->name, info);
7747 g_hash_table_insert (jit_icall_hash_addr, (gpointer)func, info);
7749 mono_loader_unlock ();