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;
105 error = mono_loader_get_last_error ();
106 g_assert (error != NULL);
108 ex = mono_loader_error_prepare_exception (error);
109 mono_raise_exception (ex);
114 ves_icall_System_Double_AssertEndianity (double *value)
118 MONO_DOUBLE_ASSERT_ENDIANITY (value);
122 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
131 ao = (MonoArray *)this;
132 ac = (MonoClass *)ao->obj.vtable->klass;
134 esize = mono_array_element_size (ac);
135 ea = (gpointer*)((char*)ao->vector + (pos * esize));
137 if (ac->element_class->valuetype)
138 return mono_value_box (this->vtable->domain, ac->element_class, ea);
144 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
152 MONO_CHECK_ARG_NULL (idxs);
154 io = (MonoArray *)idxs;
155 ic = (MonoClass *)io->obj.vtable->klass;
157 ao = (MonoArray *)this;
158 ac = (MonoClass *)ao->obj.vtable->klass;
160 g_assert (ic->rank == 1);
161 if (io->bounds != NULL || io->max_length != ac->rank)
162 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
164 ind = (gint32 *)io->vector;
166 if (ao->bounds == NULL) {
167 if (*ind < 0 || *ind >= ao->max_length)
168 mono_raise_exception (mono_get_exception_index_out_of_range ());
170 return ves_icall_System_Array_GetValueImpl (this, *ind);
173 for (i = 0; i < ac->rank; i++)
174 if ((ind [i] < ao->bounds [i].lower_bound) ||
175 (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
176 mono_raise_exception (mono_get_exception_index_out_of_range ());
178 pos = ind [0] - ao->bounds [0].lower_bound;
179 for (i = 1; i < ac->rank; i++)
180 pos = pos*ao->bounds [i].length + ind [i] -
181 ao->bounds [i].lower_bound;
183 return ves_icall_System_Array_GetValueImpl (this, pos);
187 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
189 MonoClass *ac, *vc, *ec;
200 vc = value->vtable->klass;
204 ac = this->obj.vtable->klass;
205 ec = ac->element_class;
207 esize = mono_array_element_size (ac);
208 ea = (gpointer*)((char*)this->vector + (pos * esize));
209 va = (gpointer*)((char*)value + sizeof (MonoObject));
212 memset (ea, 0, esize);
216 #define NO_WIDENING_CONVERSION G_STMT_START{\
217 mono_raise_exception (mono_get_exception_argument ( \
218 "value", "not a widening conversion")); \
221 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
222 if (esize < vsize + (extra)) \
223 mono_raise_exception (mono_get_exception_argument ( \
224 "value", "not a widening conversion")); \
227 #define INVALID_CAST G_STMT_START{\
228 mono_raise_exception (mono_get_exception_invalid_cast ()); \
231 /* Check element (destination) type. */
232 switch (ec->byval_arg.type) {
233 case MONO_TYPE_STRING:
234 switch (vc->byval_arg.type) {
235 case MONO_TYPE_STRING:
241 case MONO_TYPE_BOOLEAN:
242 switch (vc->byval_arg.type) {
243 case MONO_TYPE_BOOLEAN:
256 NO_WIDENING_CONVERSION;
263 if (!ec->valuetype) {
264 if (!mono_object_isinst (value, ec))
266 *ea = (gpointer)value;
270 if (mono_object_isinst (value, ec)) {
271 memcpy (ea, (char *)value + sizeof (MonoObject), esize);
278 vsize = mono_class_instance_size (vc) - sizeof (MonoObject);
280 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
281 switch (vc->byval_arg.type) { \
286 case MONO_TYPE_CHAR: \
287 CHECK_WIDENING_CONVERSION(0); \
288 *(etype *) ea = (etype) u64; \
290 /* You can't assign a signed value to an unsigned array. */ \
295 /* You can't assign a floating point number to an integer array. */ \
298 NO_WIDENING_CONVERSION; \
302 #define ASSIGN_SIGNED(etype) G_STMT_START{\
303 switch (vc->byval_arg.type) { \
308 CHECK_WIDENING_CONVERSION(0); \
309 *(etype *) ea = (etype) i64; \
311 /* You can assign an unsigned value to a signed array if the array's */ \
312 /* element size is larger than the value size. */ \
317 case MONO_TYPE_CHAR: \
318 CHECK_WIDENING_CONVERSION(1); \
319 *(etype *) ea = (etype) u64; \
321 /* You can't assign a floating point number to an integer array. */ \
324 NO_WIDENING_CONVERSION; \
328 #define ASSIGN_REAL(etype) G_STMT_START{\
329 switch (vc->byval_arg.type) { \
332 CHECK_WIDENING_CONVERSION(0); \
333 *(etype *) ea = (etype) r64; \
335 /* All integer values fit into a floating point array, so we don't */ \
336 /* need to CHECK_WIDENING_CONVERSION here. */ \
341 *(etype *) ea = (etype) i64; \
347 case MONO_TYPE_CHAR: \
348 *(etype *) ea = (etype) u64; \
353 switch (vc->byval_arg.type) {
355 u64 = *(guint8 *) va;
358 u64 = *(guint16 *) va;
361 u64 = *(guint32 *) va;
364 u64 = *(guint64 *) va;
370 i64 = *(gint16 *) va;
373 i64 = *(gint32 *) va;
376 i64 = *(gint64 *) va;
379 r64 = *(gfloat *) va;
382 r64 = *(gdouble *) va;
385 u64 = *(guint16 *) va;
387 case MONO_TYPE_BOOLEAN:
388 /* Boolean is only compatible with itself. */
389 switch (ec->byval_arg.type) {
401 NO_WIDENING_CONVERSION;
408 /* If we can't do a direct copy, let's try a widening conversion. */
409 switch (ec->byval_arg.type) {
411 ASSIGN_UNSIGNED (guint16);
413 ASSIGN_UNSIGNED (guint8);
415 ASSIGN_UNSIGNED (guint16);
417 ASSIGN_UNSIGNED (guint32);
419 ASSIGN_UNSIGNED (guint64);
421 ASSIGN_SIGNED (gint8);
423 ASSIGN_SIGNED (gint16);
425 ASSIGN_SIGNED (gint32);
427 ASSIGN_SIGNED (gint64);
429 ASSIGN_REAL (gfloat);
431 ASSIGN_REAL (gdouble);
435 /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
439 #undef NO_WIDENING_CONVERSION
440 #undef CHECK_WIDENING_CONVERSION
441 #undef ASSIGN_UNSIGNED
447 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
455 MONO_CHECK_ARG_NULL (idxs);
457 ic = idxs->obj.vtable->klass;
458 ac = this->obj.vtable->klass;
460 g_assert (ic->rank == 1);
461 if (idxs->bounds != NULL || idxs->max_length != ac->rank)
462 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
464 ind = (gint32 *)idxs->vector;
466 if (this->bounds == NULL) {
467 if (*ind < 0 || *ind >= this->max_length)
468 mono_raise_exception (mono_get_exception_index_out_of_range ());
470 ves_icall_System_Array_SetValueImpl (this, value, *ind);
474 for (i = 0; i < ac->rank; i++)
475 if ((ind [i] < this->bounds [i].lower_bound) ||
476 (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
477 mono_raise_exception (mono_get_exception_index_out_of_range ());
479 pos = ind [0] - this->bounds [0].lower_bound;
480 for (i = 1; i < ac->rank; i++)
481 pos = pos * this->bounds [i].length + ind [i] -
482 this->bounds [i].lower_bound;
484 ves_icall_System_Array_SetValueImpl (this, value, pos);
488 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
493 gboolean bounded = FALSE;
497 MONO_CHECK_ARG_NULL (type);
498 MONO_CHECK_ARG_NULL (lengths);
500 MONO_CHECK_ARG (lengths, mono_array_length (lengths) > 0);
502 MONO_CHECK_ARG (bounds, mono_array_length (lengths) == mono_array_length (bounds));
504 for (i = 0; i < mono_array_length (lengths); i++)
505 if (mono_array_get (lengths, gint32, i) < 0)
506 mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
508 if (bounds && (mono_array_length (bounds) == 1) && (mono_array_get (bounds, gint32, 0) != 0))
509 /* vectors are not the same as one dimensional arrays with no-zero bounds */
514 aklass = mono_bounded_array_class_get (mono_class_from_mono_type (type->type), mono_array_length (lengths), bounded);
516 sizes = alloca (aklass->rank * sizeof(guint32) * 2);
517 for (i = 0; i < aklass->rank; ++i) {
518 sizes [i] = mono_array_get (lengths, guint32, i);
520 sizes [i + aklass->rank] = mono_array_get (bounds, guint32, i);
522 sizes [i + aklass->rank] = 0;
525 array = mono_array_new_full (mono_object_domain (type), aklass, sizes, sizes + aklass->rank);
531 ves_icall_System_Array_GetRank (MonoObject *this)
535 return this->vtable->klass->rank;
539 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
541 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
545 if ((dimension < 0) || (dimension >= rank))
546 mono_raise_exception (mono_get_exception_index_out_of_range ());
548 if (this->bounds == NULL)
549 return this->max_length;
551 return this->bounds [dimension].length;
555 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
557 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
561 if ((dimension < 0) || (dimension >= rank))
562 mono_raise_exception (mono_get_exception_index_out_of_range ());
564 if (this->bounds == NULL)
567 return this->bounds [dimension].lower_bound;
571 ves_icall_System_Array_ClearInternal (MonoArray *arr, int idx, int length)
573 int sz = mono_array_element_size (mono_object_class (arr));
574 memset (mono_array_addr_with_size (arr, sz, idx), 0, length * sz);
578 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
583 MonoClass *src_class;
584 MonoClass *dest_class;
589 if (source->obj.vtable->klass->rank != dest->obj.vtable->klass->rank)
592 if (source->bounds || dest->bounds)
595 if ((dest_idx + length > mono_array_length (dest)) ||
596 (source_idx + length > mono_array_length (source)))
599 src_class = source->obj.vtable->klass->element_class;
600 dest_class = dest->obj.vtable->klass->element_class;
603 * Handle common cases.
606 /* Case1: object[] -> valuetype[] (ArrayList::ToArray) */
607 if (src_class == mono_defaults.object_class && dest_class->valuetype) {
608 int has_refs = dest_class->has_references;
609 for (i = source_idx; i < source_idx + length; ++i) {
610 MonoObject *elem = mono_array_get (source, MonoObject*, i);
611 if (elem && !mono_object_isinst (elem, dest_class))
615 element_size = mono_array_element_size (dest->obj.vtable->klass);
616 memset (mono_array_addr_with_size (dest, element_size, dest_idx), 0, element_size * length);
617 for (i = 0; i < length; ++i) {
618 MonoObject *elem = mono_array_get (source, MonoObject*, source_idx + i);
619 void *addr = mono_array_addr_with_size (dest, element_size, dest_idx + i);
623 mono_value_copy (addr, (char *)elem + sizeof (MonoObject), dest_class);
625 memcpy (addr, (char *)elem + sizeof (MonoObject), element_size);
630 /* Check if we're copying a char[] <==> (u)short[] */
631 if (src_class != dest_class) {
632 if (dest_class->valuetype || dest_class->enumtype || src_class->valuetype || src_class->enumtype)
635 if (mono_class_is_subclass_of (src_class, dest_class, FALSE))
637 /* Case2: object[] -> reftype[] (ArrayList::ToArray) */
638 else if (mono_class_is_subclass_of (dest_class, src_class, FALSE))
639 for (i = source_idx; i < source_idx + length; ++i) {
640 MonoObject *elem = mono_array_get (source, MonoObject*, i);
641 if (elem && !mono_object_isinst (elem, dest_class))
648 if (dest_class->valuetype) {
649 element_size = mono_array_element_size (source->obj.vtable->klass);
650 source_addr = mono_array_addr_with_size (source, element_size, source_idx);
651 if (dest_class->has_references) {
652 mono_value_copy_array (dest, dest_idx, source_addr, length);
654 dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
655 memmove (dest_addr, source_addr, element_size * length);
658 mono_array_memcpy_refs (dest, dest_idx, source, source_idx, length);
665 ves_icall_System_Array_InternalArray_GetGenericValueImpl (MonoObject *this, guint32 pos,
675 ao = (MonoArray *)this;
676 ac = (MonoClass *)ao->obj.vtable->klass;
678 esize = mono_array_element_size (ac);
679 ea = (gpointer*)((char*)ao->vector + (pos * esize));
681 memcpy (value, ea, esize);
685 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArray *array, MonoClassField *field_handle)
687 MonoClass *klass = array->obj.vtable->klass;
688 guint32 size = mono_array_element_size (klass);
693 if (array->bounds == NULL)
694 size *= array->max_length;
696 for (i = 0; i < klass->rank; ++i)
697 size *= array->bounds [i].length;
699 memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
701 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
705 guint ## n *data = (guint ## n *) mono_array_addr (array, char, 0); \
707 for (i = 0; i < size; i += n/8, data++) { \
708 tmp = read ## n (data); \
713 /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
715 switch (mono_type_get_underlying_type (&klass->element_class->byval_arg)->type) {
735 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
739 return offsetof (MonoString, chars);
743 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject *obj)
747 if ((obj == NULL) || (! (obj->vtable->klass->valuetype)))
750 return mono_object_clone (obj);
754 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
760 MONO_CHECK_ARG_NULL (handle);
762 klass = mono_class_from_mono_type (handle);
763 MONO_CHECK_ARG (handle, klass);
765 /* This will call the type constructor */
766 if (! (klass->flags & TYPE_ATTRIBUTE_INTERFACE))
767 mono_runtime_class_init (mono_class_vtable (mono_domain_get (), klass));
771 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
775 return mono_object_clone (this);
779 ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fields)
782 MonoObject **values = NULL;
786 MonoClassField* field;
791 klass = mono_object_class (this);
793 if (mono_class_num_fields (klass) == 0)
794 return mono_object_hash (this);
797 * Compute the starting value of the hashcode for fields of primitive
798 * types, and return the remaining fields in an array to the managed side.
799 * This way, we can avoid costly reflection operations in managed code.
802 while ((field = mono_class_get_fields (klass, &iter))) {
803 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
805 if (mono_field_is_deleted (field))
807 /* FIXME: Add more types */
808 switch (field->type->type) {
810 result ^= *(gint32*)((guint8*)this + field->offset);
812 case MONO_TYPE_STRING: {
814 s = *(MonoString**)((guint8*)this + field->offset);
816 result ^= mono_string_hash (s);
821 values = g_newa (MonoObject*, mono_class_num_fields (klass));
822 o = mono_field_get_value_object (mono_object_domain (this), field, this);
823 values [count++] = o;
829 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
830 for (i = 0; i < count; ++i)
831 mono_array_setref (*fields, i, values [i]);
839 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that, MonoArray **fields)
842 MonoObject **values = NULL;
844 MonoClassField* field;
850 MONO_CHECK_ARG_NULL (that);
852 if (this->vtable != that->vtable)
855 klass = mono_object_class (this);
858 * Do the comparison for fields of primitive type and return a result if
859 * possible. Otherwise, return the remaining fields in an array to the
860 * managed side. This way, we can avoid costly reflection operations in
865 while ((field = mono_class_get_fields (klass, &iter))) {
866 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
868 if (mono_field_is_deleted (field))
870 /* FIXME: Add more types */
871 switch (field->type->type) {
873 if (*(gint32*)((guint8*)this + field->offset) != *(gint32*)((guint8*)that + field->offset))
876 case MONO_TYPE_STRING: {
878 guint32 s1len, s2len;
879 s1 = *(MonoString**)((guint8*)this + field->offset);
880 s2 = *(MonoString**)((guint8*)that + field->offset);
883 if ((s1 == NULL) || (s2 == NULL))
885 s1len = mono_string_length (s1);
886 s2len = mono_string_length (s2);
890 if (memcmp (mono_string_chars (s1), mono_string_chars (s2), s1len * sizeof (gunichar2)) != 0)
896 values = g_newa (MonoObject*, mono_class_num_fields (klass) * 2);
897 o = mono_field_get_value_object (mono_object_domain (this), field, this);
898 values [count++] = o;
899 o = mono_field_get_value_object (mono_object_domain (this), field, that);
900 values [count++] = o;
906 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
907 for (i = 0; i < count; ++i)
908 mono_array_setref (*fields, i, values [i]);
915 static MonoReflectionType *
916 ves_icall_System_Object_GetType (MonoObject *obj)
920 if (obj->vtable->klass != mono_defaults.transparent_proxy_class)
921 return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
923 return mono_type_get_object (mono_object_domain (obj), &((MonoTransparentProxy*)obj)->remote_class->proxy_class->byval_arg);
927 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
931 mtype->type = &obj->vtable->klass->byval_arg;
932 g_assert (mtype->type->type);
936 ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj)
940 MONO_CHECK_ARG_NULL (obj);
942 return mono_image_create_token (mb->dynamic_image, obj, TRUE);
946 ves_icall_ModuleBuilder_getMethodToken (MonoReflectionModuleBuilder *mb,
947 MonoReflectionMethod *method,
948 MonoArray *opt_param_types)
952 MONO_CHECK_ARG_NULL (method);
954 return mono_image_create_method_token (
955 mb->dynamic_image, (MonoObject *) method, opt_param_types);
959 ves_icall_ModuleBuilder_WriteToFile (MonoReflectionModuleBuilder *mb, HANDLE file)
963 mono_image_create_pefile (mb, file);
967 ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
971 mono_image_build_metadata (mb);
975 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
977 MonoMethod **dest = data;
979 /* skip unmanaged frames */
994 static MonoReflectionType *
995 type_from_name (const char *str, MonoBoolean ignoreCase)
997 MonoType *type = NULL;
998 MonoAssembly *assembly = NULL;
999 MonoTypeNameParse info;
1000 char *temp_str = g_strdup (str);
1001 gboolean type_resolve = FALSE;
1003 MONO_ARCH_SAVE_REGS;
1005 /* mono_reflection_parse_type() mangles the string */
1006 if (!mono_reflection_parse_type (temp_str, &info)) {
1007 g_list_free (info.modifiers);
1008 g_list_free (info.nested);
1013 if (info.assembly.name) {
1014 assembly = mono_assembly_load (&info.assembly, NULL, NULL);
1016 MonoMethod *m = mono_method_get_last_managed ();
1017 MonoMethod *dest = m;
1019 mono_stack_walk_no_il (get_caller, &dest);
1024 * FIXME: mono_method_get_last_managed() sometimes returns NULL, thus
1025 * causing ves_icall_System_Reflection_Assembly_GetCallingAssembly()
1026 * to crash. This only seems to happen in some strange remoting
1027 * scenarios and I was unable to figure out what's happening there.
1028 * Dec 10, 2005 - Martin.
1032 assembly = dest->klass->image->assembly;
1034 g_warning (G_STRLOC);
1039 type = mono_reflection_get_type (assembly->image, &info, ignoreCase, &type_resolve);
1041 if (!info.assembly.name && !type) /* try mscorlib */
1042 type = mono_reflection_get_type (NULL, &info, ignoreCase, &type_resolve);
1044 g_list_free (info.modifiers);
1045 g_list_free (info.nested);
1051 return mono_type_get_object (mono_domain_get (), type);
1055 MonoReflectionType *
1056 mono_type_get (const char *str)
1058 char *copy = g_strdup (str);
1059 MonoReflectionType *type = type_from_name (copy, FALSE);
1066 static MonoReflectionType*
1067 ves_icall_type_from_name (MonoString *name,
1068 MonoBoolean throwOnError,
1069 MonoBoolean ignoreCase)
1071 char *str = mono_string_to_utf8 (name);
1072 MonoReflectionType *type;
1074 type = type_from_name (str, ignoreCase);
1078 mono_raise_exception (mono_get_exception_type_load (name, NULL));
1085 static MonoReflectionType*
1086 ves_icall_type_from_handle (MonoType *handle)
1088 MonoDomain *domain = mono_domain_get ();
1089 MonoClass *klass = mono_class_from_mono_type (handle);
1091 MONO_ARCH_SAVE_REGS;
1093 mono_class_init (klass);
1094 return mono_type_get_object (domain, handle);
1098 ves_icall_type_Equals (MonoReflectionType *type, MonoReflectionType *c)
1100 MONO_ARCH_SAVE_REGS;
1102 if (c && type->type && c->type)
1103 return mono_metadata_type_equal (type->type, c->type);
1108 /* System.TypeCode */
1127 TYPECODE_STRING = 18
1131 ves_icall_type_GetTypeCodeInternal (MonoReflectionType *type)
1133 int t = type->type->type;
1135 MONO_ARCH_SAVE_REGS;
1137 if (type->type->byref)
1138 return TYPECODE_OBJECT;
1142 case MONO_TYPE_VOID:
1143 return TYPECODE_OBJECT;
1144 case MONO_TYPE_BOOLEAN:
1145 return TYPECODE_BOOLEAN;
1147 return TYPECODE_BYTE;
1149 return TYPECODE_SBYTE;
1151 return TYPECODE_UINT16;
1153 return TYPECODE_INT16;
1154 case MONO_TYPE_CHAR:
1155 return TYPECODE_CHAR;
1159 return TYPECODE_OBJECT;
1161 return TYPECODE_UINT32;
1163 return TYPECODE_INT32;
1165 return TYPECODE_UINT64;
1167 return TYPECODE_INT64;
1169 return TYPECODE_SINGLE;
1171 return TYPECODE_DOUBLE;
1172 case MONO_TYPE_VALUETYPE:
1173 if (type->type->data.klass->enumtype) {
1174 t = type->type->data.klass->enum_basetype->type;
1177 MonoClass *k = type->type->data.klass;
1178 if (strcmp (k->name_space, "System") == 0) {
1179 if (strcmp (k->name, "Decimal") == 0)
1180 return TYPECODE_DECIMAL;
1181 else if (strcmp (k->name, "DateTime") == 0)
1182 return TYPECODE_DATETIME;
1185 return TYPECODE_OBJECT;
1186 case MONO_TYPE_STRING:
1187 return TYPECODE_STRING;
1188 case MONO_TYPE_SZARRAY:
1189 case MONO_TYPE_ARRAY:
1190 case MONO_TYPE_OBJECT:
1192 case MONO_TYPE_MVAR:
1193 case MONO_TYPE_TYPEDBYREF:
1194 return TYPECODE_OBJECT;
1195 case MONO_TYPE_CLASS:
1197 MonoClass *k = type->type->data.klass;
1198 if (strcmp (k->name_space, "System") == 0) {
1199 if (strcmp (k->name, "DBNull") == 0)
1200 return TYPECODE_DBNULL;
1203 return TYPECODE_OBJECT;
1204 case MONO_TYPE_GENERICINST:
1205 return TYPECODE_OBJECT;
1207 g_error ("type 0x%02x not handled in GetTypeCode()", t);
1213 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
1219 MONO_ARCH_SAVE_REGS;
1221 g_assert (type != NULL);
1223 domain = ((MonoObject *)type)->vtable->domain;
1225 if (!c) /* FIXME: dont know what do do here */
1228 klass = mono_class_from_mono_type (type->type);
1229 klassc = mono_class_from_mono_type (c->type);
1231 if (type->type->byref)
1232 return klassc == mono_defaults.object_class;
1234 return mono_class_is_subclass_of (klass, klassc, check_interfaces);
1238 ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
1244 MONO_ARCH_SAVE_REGS;
1246 g_assert (type != NULL);
1248 domain = ((MonoObject *)type)->vtable->domain;
1250 klass = mono_class_from_mono_type (type->type);
1251 klassc = mono_class_from_mono_type (c->type);
1253 if (type->type->byref && !c->type->byref)
1256 return mono_class_is_assignable_from (klass, klassc);
1260 ves_icall_type_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
1262 MonoClass *klass = mono_class_from_mono_type (type->type);
1263 return mono_object_isinst (obj, klass) != NULL;
1267 ves_icall_get_attributes (MonoReflectionType *type)
1269 MonoClass *klass = mono_class_from_mono_type (type->type);
1271 MONO_ARCH_SAVE_REGS;
1273 return klass->flags;
1276 static MonoReflectionMarshal*
1277 ves_icall_System_Reflection_FieldInfo_GetUnmanagedMarshal (MonoReflectionField *field)
1279 MonoClass *klass = field->field->parent;
1280 MonoMarshalType *info;
1283 if (klass->generic_container ||
1284 (klass->generic_class && klass->generic_class->inst->is_open))
1287 info = mono_marshal_load_type_info (klass);
1289 for (i = 0; i < info->num_fields; ++i) {
1290 if (info->fields [i].field == field->field) {
1291 if (!info->fields [i].mspec)
1294 return mono_reflection_marshal_from_marshal_spec (field->object.vtable->domain, klass, info->fields [i].mspec);
1301 static MonoReflectionField*
1302 ves_icall_System_Reflection_FieldInfo_internal_from_handle (MonoClassField *handle)
1304 MONO_ARCH_SAVE_REGS;
1308 return mono_field_get_object (mono_domain_get (), handle->parent, handle);
1312 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
1314 MonoDomain *domain = mono_domain_get ();
1315 MonoMethodSignature* sig;
1316 MONO_ARCH_SAVE_REGS;
1318 if (method->is_inflated)
1319 method = mono_get_inflated_method (method);
1321 sig = mono_method_signature (method);
1323 info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
1324 info->ret = mono_type_get_object (domain, sig->ret);
1325 info->attrs = method->flags;
1326 info->implattrs = method->iflags;
1327 if (sig->call_convention == MONO_CALL_DEFAULT)
1330 if (sig->call_convention == MONO_CALL_VARARG)
1335 info->callconv |= (sig->hasthis << 5) | (sig->explicit_this << 6);
1339 ves_icall_get_parameter_info (MonoMethod *method)
1341 MonoDomain *domain = mono_domain_get ();
1343 MONO_ARCH_SAVE_REGS;
1345 if (method->is_inflated)
1346 method = mono_get_inflated_method (method);
1348 return mono_param_get_objects (domain, method);
1351 static MonoReflectionMarshal*
1352 ves_icall_System_MonoMethodInfo_get_retval_marshal (MonoMethod *method)
1354 MonoDomain *domain = mono_domain_get ();
1355 MonoReflectionMarshal* res = NULL;
1356 MonoMarshalSpec **mspecs;
1359 MONO_ARCH_SAVE_REGS;
1361 if (method->is_inflated)
1362 method = mono_get_inflated_method (method);
1364 mspecs = g_new (MonoMarshalSpec*, mono_method_signature (method)->param_count + 1);
1365 mono_method_get_marshal_info (method, mspecs);
1368 res = mono_reflection_marshal_from_marshal_spec (domain, method->klass, mspecs [0]);
1370 for (i = mono_method_signature (method)->param_count; i >= 0; i--)
1372 mono_metadata_free_marshal_spec (mspecs [i]);
1379 ves_icall_MonoField_GetFieldOffset (MonoReflectionField *field)
1381 return field->field->offset - sizeof (MonoObject);
1384 static MonoReflectionType*
1385 ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean declaring)
1388 MONO_ARCH_SAVE_REGS;
1390 parent = declaring? field->field->parent: field->klass;
1392 return mono_type_get_object (mono_object_domain (field), &parent->byval_arg);
1396 ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *obj)
1399 MonoClassField *cf = field->field;
1403 MonoDomain *domain = mono_object_domain (field);
1405 gboolean is_static = FALSE;
1406 gboolean is_ref = FALSE;
1408 MONO_ARCH_SAVE_REGS;
1410 if (field->klass->image->assembly->ref_only)
1411 mono_raise_exception (mono_get_exception_invalid_operation (
1412 "It is illegal to get the value on a field on a type loaded using the ReflectionOnly methods."));
1414 mono_class_init (field->klass);
1416 t = mono_type_get_underlying_type (cf->type);
1418 case MONO_TYPE_STRING:
1419 case MONO_TYPE_OBJECT:
1420 case MONO_TYPE_CLASS:
1421 case MONO_TYPE_ARRAY:
1422 case MONO_TYPE_SZARRAY:
1427 case MONO_TYPE_BOOLEAN:
1430 case MONO_TYPE_CHAR:
1439 case MONO_TYPE_VALUETYPE:
1442 case MONO_TYPE_GENERICINST:
1443 if (mono_type_generic_inst_is_valuetype (t)) {
1450 g_error ("type 0x%x not handled in "
1451 "ves_icall_Monofield_GetValue", t->type);
1456 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1458 vtable = mono_class_vtable (domain, field->klass);
1459 if (!vtable->initialized && !(cf->type->attrs & FIELD_ATTRIBUTE_LITERAL))
1460 mono_runtime_class_init (vtable);
1465 mono_field_static_get_value (vtable, cf, &o);
1467 mono_field_get_value (obj, cf, &o);
1472 if (mono_class_is_nullable (mono_class_from_mono_type (cf->type))) {
1473 MonoClass *nklass = mono_class_from_mono_type (cf->type);
1476 /* Convert the Nullable structure into a boxed vtype */
1478 buf = (guint8*)vtable->data + cf->offset;
1480 buf = (guint8*)obj + cf->offset;
1482 return mono_nullable_box (buf, nklass);
1485 /* boxed value type */
1486 klass = mono_class_from_mono_type (cf->type);
1487 o = mono_object_new (domain, klass);
1488 v = ((gchar *) o) + sizeof (MonoObject);
1490 mono_field_static_get_value (vtable, cf, v);
1492 mono_field_get_value (obj, cf, v);
1499 ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
1501 MonoClassField *cf = field->field;
1504 MONO_ARCH_SAVE_REGS;
1506 if (field->klass->image->assembly->ref_only)
1507 mono_raise_exception (mono_get_exception_invalid_operation (
1508 "It is illegal to set the value on a field on a type loaded using the ReflectionOnly methods."));
1510 v = (gchar *) value;
1511 if (!cf->type->byref) {
1512 switch (cf->type->type) {
1515 case MONO_TYPE_BOOLEAN:
1518 case MONO_TYPE_CHAR:
1527 case MONO_TYPE_VALUETYPE:
1529 v += sizeof (MonoObject);
1531 case MONO_TYPE_STRING:
1532 case MONO_TYPE_OBJECT:
1533 case MONO_TYPE_CLASS:
1534 case MONO_TYPE_ARRAY:
1535 case MONO_TYPE_SZARRAY:
1538 case MONO_TYPE_GENERICINST: {
1539 MonoGenericClass *gclass = cf->type->data.generic_class;
1540 g_assert (!gclass->inst->is_open);
1542 if (mono_class_is_nullable (mono_class_from_mono_type (cf->type))) {
1543 MonoClass *nklass = mono_class_from_mono_type (cf->type);
1547 * Convert the boxed vtype into a Nullable structure.
1548 * This is complicated by the fact that Nullables have
1549 * a variable structure.
1551 /* Allocate using alloca so it gets GC tracking */
1552 buf = alloca (nklass->instance_size);
1554 mono_nullable_init (buf, value, nklass);
1559 if (gclass->container_class->valuetype && (v != NULL))
1560 v += sizeof (MonoObject);
1564 g_error ("type 0x%x not handled in "
1565 "ves_icall_FieldInfo_SetValueInternal", cf->type->type);
1570 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1571 MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), field->klass);
1572 if (!vtable->initialized)
1573 mono_runtime_class_init (vtable);
1574 mono_field_static_set_value (vtable, cf, v);
1576 mono_field_set_value (obj, cf, v);
1580 static MonoReflectionType*
1581 ves_icall_MonoGenericMethod_get_ReflectedType (MonoReflectionGenericMethod *rmethod)
1583 MonoMethod *method = mono_get_inflated_method (rmethod->method.method);
1585 return mono_type_get_object (mono_object_domain (rmethod), &method->klass->byval_arg);
1588 /* From MonoProperty.cs */
1590 PInfo_Attributes = 1,
1591 PInfo_GetMethod = 1 << 1,
1592 PInfo_SetMethod = 1 << 2,
1593 PInfo_ReflectedType = 1 << 3,
1594 PInfo_DeclaringType = 1 << 4,
1599 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info)
1601 MonoDomain *domain = mono_object_domain (property);
1603 MONO_ARCH_SAVE_REGS;
1605 if ((req_info & PInfo_ReflectedType) != 0)
1606 info->parent = mono_type_get_object (domain, &property->klass->byval_arg);
1607 else if ((req_info & PInfo_DeclaringType) != 0)
1608 info->parent = mono_type_get_object (domain, &property->property->parent->byval_arg);
1610 if ((req_info & PInfo_Name) != 0)
1611 info->name = mono_string_new (domain, property->property->name);
1613 if ((req_info & PInfo_Attributes) != 0)
1614 info->attrs = property->property->attrs;
1616 if ((req_info & PInfo_GetMethod) != 0)
1617 info->get = property->property->get ?
1618 mono_method_get_object (domain, property->property->get, NULL): NULL;
1620 if ((req_info & PInfo_SetMethod) != 0)
1621 info->set = property->property->set ?
1622 mono_method_get_object (domain, property->property->set, NULL): NULL;
1624 * There may be other methods defined for properties, though, it seems they are not exposed
1625 * in the reflection API
1630 ves_icall_get_event_info (MonoReflectionEvent *event, MonoEventInfo *info)
1632 MonoDomain *domain = mono_object_domain (event);
1634 MONO_ARCH_SAVE_REGS;
1636 info->reflected_type = mono_type_get_object (domain, &event->klass->byval_arg);
1637 info->declaring_type = mono_type_get_object (domain, &event->event->parent->byval_arg);
1639 info->name = mono_string_new (domain, event->event->name);
1640 info->attrs = event->event->attrs;
1641 info->add_method = event->event->add ? mono_method_get_object (domain, event->event->add, NULL): NULL;
1642 info->remove_method = event->event->remove ? mono_method_get_object (domain, event->event->remove, NULL): NULL;
1643 info->raise_method = event->event->raise ? mono_method_get_object (domain, event->event->raise, NULL): NULL;
1645 if (event->event->other) {
1647 while (event->event->other [n])
1649 info->other_methods = mono_array_new (domain, mono_defaults.method_info_class, n);
1651 for (i = 0; i < n; i++)
1652 mono_array_setref (info->other_methods, i, mono_method_get_object (domain, event->event->other [i], NULL));
1657 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
1659 MonoDomain *domain = mono_object_domain (type);
1661 GPtrArray *ifaces = NULL;
1663 MonoClass *class = mono_class_from_mono_type (type->type);
1666 MonoGenericContext *context = NULL;
1668 MONO_ARCH_SAVE_REGS;
1670 /* open generic-instance classes can share their interface_id */
1671 if (class->generic_class && class->generic_class->inst->is_open) {
1672 context = class->generic_class->context;
1673 class = class->generic_class->container_class;
1676 mono_class_setup_vtable (class);
1678 slots = mono_bitset_new (class->max_interface_id + 1, 0);
1681 /* GetInterfaces() returns an empty array in MS.NET (this may be a bug) */
1682 mono_bitset_free (slots);
1683 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1686 for (parent = class; parent; parent = parent->parent) {
1687 GPtrArray *tmp_ifaces = mono_class_get_implemented_interfaces (parent);
1689 for (i = 0; i < tmp_ifaces->len; ++i) {
1690 MonoClass *ic = g_ptr_array_index (tmp_ifaces, i);
1692 if (mono_bitset_test (slots, ic->interface_id))
1695 mono_bitset_set (slots, ic->interface_id);
1697 ifaces = g_ptr_array_new ();
1698 g_ptr_array_add (ifaces, ic);
1700 g_ptr_array_free (tmp_ifaces, TRUE);
1703 mono_bitset_free (slots);
1706 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1708 intf = mono_array_new (domain, mono_defaults.monotype_class, ifaces->len);
1709 for (i = 0; i < ifaces->len; ++i) {
1710 MonoClass *ic = g_ptr_array_index (ifaces, i);
1711 MonoType *ret = &ic->byval_arg;
1712 if (context && ic->generic_class && ic->generic_class->inst->is_open)
1713 ret = mono_class_inflate_generic_type (ret, context);
1715 mono_array_setref (intf, i, mono_type_get_object (domain, ret));
1717 g_ptr_array_free (ifaces, TRUE);
1723 ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
1725 MonoClass *class = mono_class_from_mono_type (type->type);
1726 MonoClass *iclass = mono_class_from_mono_type (iface->type);
1727 MonoReflectionMethod *member;
1730 int i = 0, len, ioffset;
1733 MONO_ARCH_SAVE_REGS;
1735 mono_class_setup_vtable (class);
1737 /* type doesn't implement iface: the exception is thrown in managed code */
1738 if ((iclass->interface_id > class->max_interface_id) || !class->interface_offsets [iclass->interface_id])
1741 len = mono_class_num_methods (iclass);
1742 ioffset = class->interface_offsets [iclass->interface_id];
1743 domain = mono_object_domain (type);
1744 *targets = mono_array_new (domain, mono_defaults.method_info_class, len);
1745 *methods = mono_array_new (domain, mono_defaults.method_info_class, len);
1748 while ((method = mono_class_get_methods (iclass, &iter))) {
1749 member = mono_method_get_object (domain, method, iclass);
1750 mono_array_setref (*methods, i, member);
1751 member = mono_method_get_object (domain, class->vtable [i + ioffset], class);
1752 mono_array_setref (*targets, i, member);
1759 ves_icall_Type_GetPacking (MonoReflectionType *type, guint32 *packing, guint32 *size)
1761 MonoClass *klass = mono_class_from_mono_type (type->type);
1763 g_assert (!klass->image->dynamic);
1765 mono_metadata_packing_from_typedef (klass->image, klass->type_token, packing, size);
1768 static MonoReflectionType*
1769 ves_icall_MonoType_GetElementType (MonoReflectionType *type)
1771 MonoClass *class = mono_class_from_mono_type (type->type);
1773 MONO_ARCH_SAVE_REGS;
1775 // GelElementType should only return a type for:
1776 // Array Pointer PassedByRef
1777 if (type->type->byref)
1778 return mono_type_get_object (mono_object_domain (type), &class->byval_arg);
1779 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1780 return mono_type_get_object (mono_object_domain (type), class->enum_basetype);
1781 else if (class->element_class && MONO_CLASS_IS_ARRAY (class))
1782 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1783 else if (class->element_class && type->type->type == MONO_TYPE_PTR)
1784 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1789 static MonoReflectionType*
1790 ves_icall_get_type_parent (MonoReflectionType *type)
1792 MonoClass *class = mono_class_from_mono_type (type->type);
1794 MONO_ARCH_SAVE_REGS;
1796 return class->parent ? mono_type_get_object (mono_object_domain (type), &class->parent->byval_arg): NULL;
1800 ves_icall_type_ispointer (MonoReflectionType *type)
1802 MONO_ARCH_SAVE_REGS;
1804 return type->type->type == MONO_TYPE_PTR;
1808 ves_icall_type_isprimitive (MonoReflectionType *type)
1810 MONO_ARCH_SAVE_REGS;
1812 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)));
1816 ves_icall_type_isbyref (MonoReflectionType *type)
1818 MONO_ARCH_SAVE_REGS;
1820 return type->type->byref;
1824 ves_icall_type_iscomobject (MonoReflectionType *type)
1826 MonoClass *klass = mono_class_from_mono_type (type->type);
1827 MONO_ARCH_SAVE_REGS;
1829 return (klass && klass->is_com_object);
1832 static MonoReflectionModule*
1833 ves_icall_MonoType_get_Module (MonoReflectionType *type)
1835 MonoClass *class = mono_class_from_mono_type (type->type);
1837 MONO_ARCH_SAVE_REGS;
1839 return mono_module_get_object (mono_object_domain (type), class->image);
1842 static MonoReflectionAssembly*
1843 ves_icall_MonoType_get_Assembly (MonoReflectionType *type)
1845 MonoDomain *domain = mono_domain_get ();
1846 MonoClass *class = mono_class_from_mono_type (type->type);
1848 MONO_ARCH_SAVE_REGS;
1850 return mono_assembly_get_object (domain, class->image->assembly);
1853 static MonoReflectionType*
1854 ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
1856 MonoDomain *domain = mono_domain_get ();
1859 MONO_ARCH_SAVE_REGS;
1861 if (type->type->byref)
1863 if (type->type->type == MONO_TYPE_VAR)
1864 class = type->type->data.generic_param->owner->klass;
1865 else if (type->type->type == MONO_TYPE_MVAR)
1866 class = type->type->data.generic_param->method->klass;
1868 class = mono_class_from_mono_type (type->type)->nested_in;
1870 return class ? mono_type_get_object (domain, &class->byval_arg) : NULL;
1873 static MonoReflectionType*
1874 ves_icall_MonoType_get_UnderlyingSystemType (MonoReflectionType *type)
1876 MonoDomain *domain = mono_domain_get ();
1877 MonoClass *class = mono_class_from_mono_type (type->type);
1879 MONO_ARCH_SAVE_REGS;
1881 if (class->enumtype && class->enum_basetype) /* types that are modified typebuilders may not have enum_basetype set */
1882 return mono_type_get_object (domain, class->enum_basetype);
1883 else if (class->element_class)
1884 return mono_type_get_object (domain, &class->element_class->byval_arg);
1890 ves_icall_MonoType_get_Name (MonoReflectionType *type)
1892 MonoDomain *domain = mono_domain_get ();
1893 MonoClass *class = mono_class_from_mono_type (type->type);
1895 MONO_ARCH_SAVE_REGS;
1897 return mono_string_new (domain, class->name);
1901 ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
1903 MonoDomain *domain = mono_domain_get ();
1904 MonoClass *class = mono_class_from_mono_type (type->type);
1906 MONO_ARCH_SAVE_REGS;
1908 while (class->nested_in)
1909 class = class->nested_in;
1911 if (class->name_space [0] == '\0')
1914 return mono_string_new (domain, class->name_space);
1918 ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
1920 MonoClass *class = mono_class_from_mono_type (type->type);
1922 MONO_ARCH_SAVE_REGS;
1928 ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type)
1931 MonoClass *klass, *pklass;
1933 MONO_ARCH_SAVE_REGS;
1935 klass = mono_class_from_mono_type (type->type);
1937 if (klass->generic_container) {
1938 MonoGenericContainer *container = klass->generic_container;
1939 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, container->type_argc);
1940 for (i = 0; i < container->type_argc; ++i) {
1941 pklass = mono_class_from_generic_parameter (&container->type_params [i], klass->image, FALSE);
1942 mono_array_setref (res, i, mono_type_get_object (mono_object_domain (type), &pklass->byval_arg));
1944 } else if (klass->generic_class) {
1945 MonoGenericInst *inst = klass->generic_class->inst;
1946 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, inst->type_argc);
1947 for (i = 0; i < inst->type_argc; ++i)
1948 mono_array_setref (res, i, mono_type_get_object (mono_object_domain (type), inst->type_argv [i]));
1950 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1956 ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
1959 MONO_ARCH_SAVE_REGS;
1961 klass = mono_class_from_mono_type (type->type);
1963 return klass->generic_container != NULL;
1966 static MonoReflectionType*
1967 ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
1970 MONO_ARCH_SAVE_REGS;
1972 klass = mono_class_from_mono_type (type->type);
1973 if (klass->generic_container) {
1974 return type; /* check this one */
1976 if (klass->generic_class) {
1977 MonoClass *generic_class = klass->generic_class->container_class;
1979 if (generic_class->wastypebuilder && generic_class->reflection_info)
1980 return generic_class->reflection_info;
1982 return mono_type_get_object (mono_object_domain (type), &generic_class->byval_arg);
1987 static MonoReflectionType*
1988 ves_icall_Type_MakeGenericType (MonoReflectionType *type, MonoArray *type_array)
1990 MonoType *geninst, **types;
1993 MONO_ARCH_SAVE_REGS;
1995 count = mono_array_length (type_array);
1996 types = g_new0 (MonoType *, count);
1998 for (i = 0; i < count; i++) {
1999 MonoReflectionType *t = mono_array_get (type_array, gpointer, i);
2000 types [i] = t->type;
2003 geninst = mono_reflection_bind_generic_parameters (type, count, types);
2007 return mono_type_get_object (mono_object_domain (type), geninst);
2011 ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
2014 MONO_ARCH_SAVE_REGS;
2016 klass = mono_class_from_mono_type (type->type);
2017 return klass->generic_class != NULL;
2021 ves_icall_Type_get_IsGenericType (MonoReflectionType *type)
2024 MONO_ARCH_SAVE_REGS;
2026 klass = mono_class_from_mono_type (type->type);
2027 return klass->generic_class != NULL || klass->generic_container != NULL;
2031 ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
2033 MONO_ARCH_SAVE_REGS;
2035 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
2036 return type->type->data.generic_param->num;
2040 static GenericParameterAttributes
2041 ves_icall_Type_GetGenericParameterAttributes (MonoReflectionType *type)
2043 MONO_ARCH_SAVE_REGS;
2044 return type->type->data.generic_param->flags;
2048 ves_icall_Type_GetGenericParameterConstraints (MonoReflectionType *type)
2050 MonoGenericParam *param;
2056 MONO_ARCH_SAVE_REGS;
2058 domain = mono_object_domain (type);
2059 param = type->type->data.generic_param;
2060 for (count = 0, ptr = param->constraints; ptr && *ptr; ptr++, count++)
2063 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2064 for (i = 0; i < count; i++)
2065 mono_array_setref (res, i, mono_type_get_object (domain, ¶m->constraints [i]->byval_arg));
2072 ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
2074 MONO_ARCH_SAVE_REGS;
2076 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
2077 return !type->type->byref;
2082 ves_icall_TypeBuilder_get_IsGenericParameter (MonoReflectionTypeBuilder *tb)
2084 MONO_ARCH_SAVE_REGS;
2086 if (tb->type.type->type == MONO_TYPE_VAR || tb->type.type->type == MONO_TYPE_MVAR)
2087 return !tb->type.type->byref;
2092 ves_icall_EnumBuilder_setup_enum_type (MonoReflectionType *enumtype,
2093 MonoReflectionType *t)
2095 enumtype->type = t->type;
2098 static MonoReflectionType*
2099 ves_icall_MonoGenericClass_GetParentType (MonoReflectionGenericClass *type)
2101 MonoDynamicGenericClass *gclass;
2102 MonoReflectionType *parent = NULL;
2107 MONO_ARCH_SAVE_REGS;
2109 g_assert (type->type.type->data.generic_class->is_dynamic);
2110 gclass = (MonoDynamicGenericClass *) type->type.type->data.generic_class;
2112 domain = mono_object_domain (type);
2113 klass = mono_class_from_mono_type (type->generic_type->type);
2115 if (!klass->generic_class && !klass->generic_container)
2118 if (!strcmp (type->generic_type->object.vtable->klass->name, "TypeBuilder")) {
2119 MonoReflectionTypeBuilder *tb = (MonoReflectionTypeBuilder *) type->generic_type;
2120 parent = tb->parent;
2121 } else if (klass->wastypebuilder) {
2122 MonoReflectionTypeBuilder *tb = (MonoReflectionTypeBuilder *) type->generic_type;
2123 parent = tb->parent;
2125 MonoClass *pklass = klass->parent;
2127 parent = mono_type_get_object (domain, &pklass->byval_arg);
2130 if (!parent || (parent->type->type != MONO_TYPE_GENERICINST))
2133 inflated = mono_class_inflate_generic_type (
2134 parent->type, gclass->generic_class.generic_class.context);
2136 return mono_type_get_object (domain, inflated);
2140 ves_icall_MonoGenericClass_GetInterfaces (MonoReflectionGenericClass *type)
2142 static MonoClass *System_Reflection_MonoGenericClass;
2143 MonoDynamicGenericClass *gclass;
2144 MonoReflectionTypeBuilder *tb = NULL;
2145 MonoClass *klass = NULL;
2150 MONO_ARCH_SAVE_REGS;
2152 if (!System_Reflection_MonoGenericClass) {
2153 System_Reflection_MonoGenericClass = mono_class_from_name (
2154 mono_defaults.corlib, "System.Reflection", "MonoGenericClass");
2155 g_assert (System_Reflection_MonoGenericClass);
2158 domain = mono_object_domain (type);
2160 g_assert (type->type.type->data.generic_class->is_dynamic);
2161 gclass = (MonoDynamicGenericClass *) type->type.type->data.generic_class;
2163 if (!strcmp (type->generic_type->object.vtable->klass->name, "TypeBuilder")) {
2164 tb = (MonoReflectionTypeBuilder *) type->generic_type;
2165 icount = tb->interfaces ? mono_array_length (tb->interfaces) : 0;
2167 klass = gclass->generic_class.generic_class.container_class;
2168 mono_class_init (klass);
2169 icount = klass->interface_count;
2172 res = mono_array_new (domain, System_Reflection_MonoGenericClass, icount);
2174 for (i = 0; i < icount; i++) {
2175 MonoReflectionType *iface;
2179 iface = mono_array_get (tb->interfaces, MonoReflectionType *, i);
2182 it = &klass->interfaces [i]->byval_arg;
2184 it = mono_class_inflate_generic_type (
2185 it, gclass->generic_class.generic_class.context);
2187 iface = mono_type_get_object (domain, it);
2188 mono_array_setref (res, i, iface);
2194 static MonoReflectionMethod*
2195 ves_icall_MonoGenericClass_GetCorrespondingInflatedMethod (MonoReflectionGenericClass *type,
2196 MonoReflectionMethod* generic)
2198 MonoGenericClass *gclass;
2199 MonoDynamicGenericClass *dgclass;
2203 MONO_ARCH_SAVE_REGS;
2205 gclass = type->type.type->data.generic_class;
2206 g_assert (gclass->is_dynamic);
2208 dgclass = (MonoDynamicGenericClass *) gclass;
2210 domain = mono_object_domain (type);
2212 for (i = 0; i < dgclass->count_methods; i++)
2213 if (generic->method->token == dgclass->methods [i]->token)
2214 return mono_method_get_object (domain, dgclass->methods [i], NULL);
2219 static MonoReflectionMethod*
2220 ves_icall_MonoGenericClass_GetCorrespondingInflatedConstructor (MonoReflectionGenericClass *type,
2221 MonoReflectionMethod* generic)
2223 MonoGenericClass *gclass;
2224 MonoDynamicGenericClass *dgclass;
2228 MONO_ARCH_SAVE_REGS;
2230 gclass = type->type.type->data.generic_class;
2231 g_assert (gclass->is_dynamic);
2233 dgclass = (MonoDynamicGenericClass *) gclass;
2235 domain = mono_object_domain (type);
2237 for (i = 0; i < dgclass->count_ctors; i++)
2238 if (generic->method->token == dgclass->ctors [i]->token)
2239 return mono_method_get_object (domain, dgclass->ctors [i], NULL);
2245 static MonoReflectionField*
2246 ves_icall_MonoGenericClass_GetCorrespondingInflatedField (MonoReflectionGenericClass *type,
2247 MonoString* generic_name)
2249 MonoGenericClass *gclass;
2250 MonoDynamicGenericClass *dgclass;
2252 MonoClass *refclass;
2253 char *utf8_name = mono_string_to_utf8 (generic_name);
2256 MONO_ARCH_SAVE_REGS;
2258 gclass = type->type.type->data.generic_class;
2259 g_assert (gclass->is_dynamic);
2261 dgclass = (MonoDynamicGenericClass *) gclass;
2263 refclass = mono_class_from_mono_type (type->type.type);
2265 domain = mono_object_domain (type);
2267 for (i = 0; i < dgclass->count_fields; i++)
2268 if (strcmp (utf8_name, dgclass->fields [i].name) == 0) {
2270 return mono_field_get_object (domain, refclass, &dgclass->fields [i]);
2279 static MonoReflectionMethod*
2280 ves_icall_MonoType_GetCorrespondingInflatedMethod (MonoReflectionType *type,
2281 MonoReflectionMethod* generic)
2288 MONO_ARCH_SAVE_REGS;
2290 domain = ((MonoObject *)type)->vtable->domain;
2292 klass = mono_class_from_mono_type (type->type);
2295 while ((method = mono_class_get_methods (klass, &iter))) {
2296 if (method->token == generic->method->token)
2297 return mono_method_get_object (domain, method, klass);
2304 ves_icall_MonoGenericClass_GetMethods (MonoReflectionGenericClass *type,
2305 MonoReflectionType *reflected_type)
2307 MonoGenericClass *gclass;
2308 MonoDynamicGenericClass *dgclass;
2310 MonoClass *refclass;
2314 MONO_ARCH_SAVE_REGS;
2316 gclass = type->type.type->data.generic_class;
2317 g_assert (gclass->is_dynamic);
2318 dgclass = (MonoDynamicGenericClass *) gclass;
2320 refclass = mono_class_from_mono_type (reflected_type->type);
2322 domain = mono_object_domain (type);
2323 res = mono_array_new (domain, mono_defaults.method_info_class, dgclass->count_methods);
2325 for (i = 0; i < dgclass->count_methods; i++)
2326 mono_array_setref (res, i, mono_method_get_object (domain, dgclass->methods [i], refclass));
2332 ves_icall_MonoGenericClass_GetConstructors (MonoReflectionGenericClass *type,
2333 MonoReflectionType *reflected_type)
2335 static MonoClass *System_Reflection_ConstructorInfo;
2336 MonoGenericClass *gclass;
2337 MonoDynamicGenericClass *dgclass;
2339 MonoClass *refclass;
2343 MONO_ARCH_SAVE_REGS;
2345 if (!System_Reflection_ConstructorInfo)
2346 System_Reflection_ConstructorInfo = mono_class_from_name (
2347 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
2349 gclass = type->type.type->data.generic_class;
2350 g_assert (gclass->is_dynamic);
2351 dgclass = (MonoDynamicGenericClass *) gclass;
2353 refclass = mono_class_from_mono_type (reflected_type->type);
2355 domain = mono_object_domain (type);
2356 res = mono_array_new (domain, System_Reflection_ConstructorInfo, dgclass->count_ctors);
2358 for (i = 0; i < dgclass->count_ctors; i++)
2359 mono_array_setref (res, i, mono_method_get_object (domain, dgclass->ctors [i], refclass));
2365 ves_icall_MonoGenericClass_GetFields (MonoReflectionGenericClass *type,
2366 MonoReflectionType *reflected_type)
2368 MonoGenericClass *gclass;
2369 MonoDynamicGenericClass *dgclass;
2371 MonoClass *refclass;
2375 MONO_ARCH_SAVE_REGS;
2377 gclass = type->type.type->data.generic_class;
2378 g_assert (gclass->is_dynamic);
2379 dgclass = (MonoDynamicGenericClass *) gclass;
2381 refclass = mono_class_from_mono_type (reflected_type->type);
2383 domain = mono_object_domain (type);
2384 res = mono_array_new (domain, mono_defaults.field_info_class, dgclass->count_fields);
2386 for (i = 0; i < dgclass->count_fields; i++)
2387 mono_array_setref (res, i, mono_field_get_object (domain, refclass, &dgclass->fields [i]));
2393 ves_icall_MonoGenericClass_GetProperties (MonoReflectionGenericClass *type,
2394 MonoReflectionType *reflected_type)
2396 static MonoClass *System_Reflection_PropertyInfo;
2397 MonoGenericClass *gclass;
2398 MonoDynamicGenericClass *dgclass;
2400 MonoClass *refclass;
2404 MONO_ARCH_SAVE_REGS;
2406 if (!System_Reflection_PropertyInfo)
2407 System_Reflection_PropertyInfo = mono_class_from_name (
2408 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
2410 gclass = type->type.type->data.generic_class;
2411 g_assert (gclass->is_dynamic);
2412 dgclass = (MonoDynamicGenericClass *) gclass;
2414 refclass = mono_class_from_mono_type (reflected_type->type);
2416 domain = mono_object_domain (type);
2417 res = mono_array_new (domain, System_Reflection_PropertyInfo, dgclass->count_properties);
2419 for (i = 0; i < dgclass->count_properties; i++)
2420 mono_array_setref (res, i, mono_property_get_object (domain, refclass, &dgclass->properties [i]));
2426 ves_icall_MonoGenericClass_GetEvents (MonoReflectionGenericClass *type,
2427 MonoReflectionType *reflected_type)
2429 static MonoClass *System_Reflection_EventInfo;
2430 MonoGenericClass *gclass;
2431 MonoDynamicGenericClass *dgclass;
2433 MonoClass *refclass;
2437 MONO_ARCH_SAVE_REGS;
2439 if (!System_Reflection_EventInfo)
2440 System_Reflection_EventInfo = mono_class_from_name (
2441 mono_defaults.corlib, "System.Reflection", "EventInfo");
2443 gclass = type->type.type->data.generic_class;
2444 g_assert (gclass->is_dynamic);
2445 dgclass = (MonoDynamicGenericClass *) gclass;
2447 refclass = mono_class_from_mono_type (reflected_type->type);
2449 domain = mono_object_domain (type);
2450 res = mono_array_new (domain, System_Reflection_EventInfo, dgclass->count_events);
2452 for (i = 0; i < dgclass->count_events; i++)
2453 mono_array_setref (res, i, mono_event_get_object (domain, refclass, &dgclass->events [i]));
2458 static MonoReflectionMethod *
2459 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *type)
2464 MONO_ARCH_SAVE_REGS;
2466 if (type->type->byref || type->type->type != MONO_TYPE_MVAR)
2469 method = type->type->data.generic_param->method;
2471 klass = mono_class_from_mono_type (type->type);
2472 return mono_method_get_object (mono_object_domain (type), method, klass);
2475 static MonoReflectionDllImportAttribute*
2476 ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
2478 static MonoClass *DllImportAttributeClass = NULL;
2479 MonoDomain *domain = mono_domain_get ();
2480 MonoReflectionDllImportAttribute *attr;
2481 MonoImage *image = method->klass->image;
2482 MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)method;
2483 MonoTableInfo *tables = image->tables;
2484 MonoTableInfo *im = &tables [MONO_TABLE_IMPLMAP];
2485 MonoTableInfo *mr = &tables [MONO_TABLE_MODULEREF];
2486 guint32 im_cols [MONO_IMPLMAP_SIZE];
2487 guint32 scope_token;
2488 const char *import = NULL;
2489 const char *scope = NULL;
2492 if (!method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
2495 if (!DllImportAttributeClass) {
2496 DllImportAttributeClass =
2497 mono_class_from_name (mono_defaults.corlib,
2498 "System.Runtime.InteropServices", "DllImportAttribute");
2499 g_assert (DllImportAttributeClass);
2502 if (method->klass->image->dynamic) {
2503 MonoReflectionMethodAux *method_aux =
2504 g_hash_table_lookup (
2505 ((MonoDynamicImage*)method->klass->image)->method_aux_hash, method);
2507 import = method_aux->dllentry;
2508 scope = method_aux->dll;
2512 if (piinfo->implmap_idx) {
2513 mono_metadata_decode_row (im, piinfo->implmap_idx - 1, im_cols, MONO_IMPLMAP_SIZE);
2515 piinfo->piflags = im_cols [MONO_IMPLMAP_FLAGS];
2516 import = mono_metadata_string_heap (image, im_cols [MONO_IMPLMAP_NAME]);
2517 scope_token = mono_metadata_decode_row_col (mr, im_cols [MONO_IMPLMAP_SCOPE] - 1, MONO_MODULEREF_NAME);
2518 scope = mono_metadata_string_heap (image, scope_token);
2521 flags = piinfo->piflags;
2523 attr = (MonoReflectionDllImportAttribute*)mono_object_new (domain, DllImportAttributeClass);
2525 MONO_OBJECT_SETREF (attr, dll, mono_string_new (domain, scope));
2526 MONO_OBJECT_SETREF (attr, entry_point, mono_string_new (domain, import));
2527 attr->call_conv = (flags & 0x700) >> 8;
2528 attr->charset = ((flags & 0x6) >> 1) + 1;
2529 if (attr->charset == 1)
2531 attr->exact_spelling = (flags & 0x1) != 0;
2532 attr->set_last_error = (flags & 0x40) != 0;
2533 attr->best_fit_mapping = (flags & 0x30) == 0x10;
2534 attr->throw_on_unmappable = (flags & 0x3000) == 0x1000;
2535 attr->preserve_sig = FALSE;
2540 static MonoReflectionMethod *
2541 ves_icall_MonoMethod_GetGenericMethodDefinition (MonoReflectionMethod *method)
2543 MonoMethodInflated *imethod;
2545 MONO_ARCH_SAVE_REGS;
2547 if (!method->method->is_inflated) {
2548 if (mono_method_signature (method->method)->generic_param_count)
2554 imethod = (MonoMethodInflated *) method->method;
2555 if (imethod->context->gmethod && imethod->context->gmethod->reflection_info)
2556 return imethod->context->gmethod->reflection_info;
2558 return mono_method_get_object (
2559 mono_object_domain (method), imethod->declaring, NULL);
2563 ves_icall_MonoMethod_get_IsGenericMethod (MonoReflectionMethod *method)
2565 MONO_ARCH_SAVE_REGS;
2567 return mono_method_signature (method->method)->generic_param_count != 0;
2571 ves_icall_MonoMethod_get_IsGenericMethodDefinition (MonoReflectionMethod *method)
2573 MONO_ARCH_SAVE_REGS;
2575 return !method->method->is_inflated &&
2576 (mono_method_signature (method->method)->generic_param_count != 0);
2580 ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method)
2585 MONO_ARCH_SAVE_REGS;
2587 domain = mono_object_domain (method);
2589 if (method->method->is_inflated) {
2590 MonoMethodInflated *imethod = (MonoMethodInflated *) method->method;
2591 MonoGenericMethod *gmethod = imethod->context->gmethod;
2594 count = gmethod->inst->type_argc;
2595 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2597 for (i = 0; i < count; i++)
2598 mono_array_setref (res, i, mono_type_get_object (domain, gmethod->inst->type_argv [i]));
2604 count = mono_method_signature (method->method)->generic_param_count;
2605 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2607 for (i = 0; i < count; i++) {
2608 MonoGenericParam *param = &method->method->generic_container->type_params [i];
2609 MonoClass *pklass = mono_class_from_generic_parameter (
2610 param, method->method->klass->image, TRUE);
2611 mono_array_setref (res, i,
2612 mono_type_get_object (domain, &pklass->byval_arg));
2619 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
2622 * Invoke from reflection is supposed to always be a virtual call (the API
2623 * is stupid), mono_runtime_invoke_*() calls the provided method, allowing
2624 * greater flexibility.
2626 MonoMethod *m = mono_get_inflated_method (method->method);
2630 MONO_ARCH_SAVE_REGS;
2632 if (!(m->flags & METHOD_ATTRIBUTE_STATIC)) {
2634 if (!mono_object_isinst (this, m->klass))
2635 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2636 m = mono_object_get_virtual_method (this, m);
2637 /* must pass the pointer to the value for valuetype methods */
2638 if (m->klass->valuetype)
2639 obj = mono_object_unbox (this);
2640 } else if (strcmp (m->name, ".ctor") && !m->wrapper_type)
2641 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2644 pcount = params? mono_array_length (params): 0;
2645 if (pcount != mono_method_signature (m)->param_count)
2646 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetParameterCountException"));
2648 if ((m->klass->flags & TYPE_ATTRIBUTE_ABSTRACT) && !strcmp (m->name, ".ctor"))
2649 mono_raise_exception (mono_exception_from_name_msg (mono_defaults.corlib, "System", "MethodAccessException", "Cannot invoke constructor of an abstract class."));
2651 if (m->klass->image->assembly->ref_only)
2652 mono_raise_exception (mono_get_exception_invalid_operation ("It is illegal to invoke a method on a type loaded using the ReflectionOnly api."));
2654 if (m->klass->rank && !strcmp (m->name, ".ctor")) {
2657 guint32 *lower_bounds;
2658 pcount = mono_array_length (params);
2659 lengths = alloca (sizeof (guint32) * pcount);
2660 for (i = 0; i < pcount; ++i)
2661 lengths [i] = *(gint32*) ((char*)mono_array_get (params, gpointer, i) + sizeof (MonoObject));
2663 if (m->klass->rank == pcount) {
2664 /* Only lengths provided. */
2665 lower_bounds = NULL;
2667 g_assert (pcount == (m->klass->rank * 2));
2668 /* lower bounds are first. */
2669 lower_bounds = lengths;
2670 lengths += m->klass->rank;
2673 return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
2675 return mono_runtime_invoke_array (m, obj, params, NULL);
2679 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs)
2681 MonoDomain *domain = mono_object_domain (method);
2682 MonoMethod *m = method->method;
2683 MonoMethodSignature *sig = mono_method_signature (m);
2684 MonoArray *out_args;
2686 int i, j, outarg_count = 0;
2688 MONO_ARCH_SAVE_REGS;
2690 if (m->klass == mono_defaults.object_class) {
2692 if (!strcmp (m->name, "FieldGetter")) {
2693 MonoClass *k = this->vtable->klass;
2697 /* If this is a proxy, then it must be a CBO */
2698 if (k == mono_defaults.transparent_proxy_class) {
2699 MonoTransparentProxy *tp = (MonoTransparentProxy*) this;
2700 this = tp->rp->unwrapped_server;
2702 k = this->vtable->klass;
2705 name = mono_array_get (params, MonoString *, 1);
2706 str = mono_string_to_utf8 (name);
2709 MonoClassField* field = mono_class_get_field_from_name (k, str);
2711 MonoClass *field_klass = mono_class_from_mono_type (field->type);
2712 if (field_klass->valuetype)
2713 result = mono_value_box (domain, field_klass, (char *)this + field->offset);
2715 result = *((gpointer *)((char *)this + field->offset));
2717 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
2718 *outArgs = out_args;
2719 mono_array_setref (out_args, 0, result);
2727 g_assert_not_reached ();
2729 } else if (!strcmp (m->name, "FieldSetter")) {
2730 MonoClass *k = this->vtable->klass;
2735 /* If this is a proxy, then it must be a CBO */
2736 if (k == mono_defaults.transparent_proxy_class) {
2737 MonoTransparentProxy *tp = (MonoTransparentProxy*) this;
2738 this = tp->rp->unwrapped_server;
2740 k = this->vtable->klass;
2743 name = mono_array_get (params, MonoString *, 1);
2744 str = mono_string_to_utf8 (name);
2747 MonoClassField* field = mono_class_get_field_from_name (k, str);
2749 MonoClass *field_klass = mono_class_from_mono_type (field->type);
2750 MonoObject *val = mono_array_get (params, gpointer, 2);
2752 if (field_klass->valuetype) {
2753 size = mono_type_size (field->type, &align);
2754 memcpy ((char *)this + field->offset,
2755 ((char *)val) + sizeof (MonoObject), size);
2757 *(MonoObject**)((char *)this + field->offset) = val;
2759 out_args = mono_array_new (domain, mono_defaults.object_class, 0);
2760 *outArgs = out_args;
2770 g_assert_not_reached ();
2775 for (i = 0; i < mono_array_length (params); i++) {
2776 if (sig->params [i]->byref)
2780 out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
2782 /* handle constructors only for objects already allocated */
2783 if (!strcmp (method->method->name, ".ctor"))
2786 /* This can be called only on MBR objects, so no need to unbox for valuetypes. */
2787 g_assert (!method->method->klass->valuetype);
2788 result = mono_runtime_invoke_array (method->method, this, params, NULL);
2790 for (i = 0, j = 0; i < mono_array_length (params); i++) {
2791 if (sig->params [i]->byref) {
2793 arg = mono_array_get (params, gpointer, i);
2794 mono_array_setref (out_args, j, arg);
2799 *outArgs = out_args;
2805 read_enum_value (char *mem, int type)
2809 return *(guint8*)mem;
2811 return *(gint8*)mem;
2813 return *(guint16*)mem;
2815 return *(gint16*)mem;
2817 return *(guint32*)mem;
2819 return *(gint32*)mem;
2821 return *(guint64*)mem;
2823 return *(gint64*)mem;
2825 g_assert_not_reached ();
2831 write_enum_value (char *mem, int type, guint64 value)
2835 case MONO_TYPE_I1: {
2836 guint8 *p = (guint8*)mem;
2841 case MONO_TYPE_I2: {
2842 guint16 *p = (void*)mem;
2847 case MONO_TYPE_I4: {
2848 guint32 *p = (void*)mem;
2853 case MONO_TYPE_I8: {
2854 guint64 *p = (void*)mem;
2859 g_assert_not_reached ();
2865 ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
2868 MonoClass *enumc, *objc;
2872 MONO_ARCH_SAVE_REGS;
2874 MONO_CHECK_ARG_NULL (type);
2875 MONO_CHECK_ARG_NULL (obj);
2877 domain = mono_object_domain (type);
2878 enumc = mono_class_from_mono_type (type->type);
2879 objc = obj->vtable->klass;
2881 if (!enumc->enumtype)
2882 mono_raise_exception (mono_get_exception_argument ("enumType", "Type provided must be an Enum."));
2883 if (!((objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 && objc->byval_arg.type <= MONO_TYPE_U8)))
2884 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."));
2886 res = mono_object_new (domain, enumc);
2887 val = read_enum_value ((char *)obj + sizeof (MonoObject), objc->enumtype? objc->enum_basetype->type: objc->byval_arg.type);
2888 write_enum_value ((char *)res + sizeof (MonoObject), enumc->enum_basetype->type, val);
2894 ves_icall_System_Enum_get_value (MonoObject *this)
2902 MONO_ARCH_SAVE_REGS;
2907 g_assert (this->vtable->klass->enumtype);
2909 enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
2910 res = mono_object_new (mono_object_domain (this), enumc);
2911 dst = (char *)res + sizeof (MonoObject);
2912 src = (char *)this + sizeof (MonoObject);
2913 size = mono_class_value_size (enumc, NULL);
2915 memcpy (dst, src, size);
2921 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
2923 MonoDomain *domain = mono_object_domain (type);
2924 MonoClass *enumc = mono_class_from_mono_type (type->type);
2925 guint j = 0, nvalues, crow;
2927 MonoClassField *field;
2929 MONO_ARCH_SAVE_REGS;
2931 info->utype = mono_type_get_object (domain, enumc->enum_basetype);
2932 nvalues = mono_class_num_fields (enumc) ? mono_class_num_fields (enumc) - 1 : 0;
2933 info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
2934 info->values = mono_array_new (domain, enumc, nvalues);
2938 while ((field = mono_class_get_fields (enumc, &iter))) {
2942 if (strcmp ("value__", field->name) == 0)
2944 if (mono_field_is_deleted (field))
2946 mono_array_setref (info->names, j, mono_string_new (domain, field->name));
2949 crow = mono_metadata_get_constant_index (enumc->image, mono_class_get_field_token (field), crow + 1);
2950 field->def_type = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_TYPE);
2951 crow = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_VALUE);
2952 field->data = (gpointer)mono_metadata_blob_heap (enumc->image, crow);
2956 len = mono_metadata_decode_blob_size (p, &p);
2957 switch (enumc->enum_basetype->type) {
2960 mono_array_set (info->values, gchar, j, *p);
2962 case MONO_TYPE_CHAR:
2965 mono_array_set (info->values, gint16, j, read16 (p));
2969 mono_array_set (info->values, gint32, j, read32 (p));
2973 mono_array_set (info->values, gint64, j, read64 (p));
2976 g_error ("Implement type 0x%02x in get_enum_info", enumc->enum_basetype->type);
2983 BFLAGS_IgnoreCase = 1,
2984 BFLAGS_DeclaredOnly = 2,
2985 BFLAGS_Instance = 4,
2987 BFLAGS_Public = 0x10,
2988 BFLAGS_NonPublic = 0x20,
2989 BFLAGS_FlattenHierarchy = 0x40,
2990 BFLAGS_InvokeMethod = 0x100,
2991 BFLAGS_CreateInstance = 0x200,
2992 BFLAGS_GetField = 0x400,
2993 BFLAGS_SetField = 0x800,
2994 BFLAGS_GetProperty = 0x1000,
2995 BFLAGS_SetProperty = 0x2000,
2996 BFLAGS_ExactBinding = 0x10000,
2997 BFLAGS_SuppressChangeType = 0x20000,
2998 BFLAGS_OptionalParamBinding = 0x40000
3001 static MonoReflectionField *
3002 ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
3005 MonoClass *startklass, *klass;
3007 MonoClassField *field;
3010 int (*compare_func) (const char *s1, const char *s2) = NULL;
3011 domain = ((MonoObject *)type)->vtable->domain;
3012 klass = startklass = mono_class_from_mono_type (type->type);
3014 MONO_ARCH_SAVE_REGS;
3017 mono_raise_exception (mono_get_exception_argument_null ("name"));
3018 if (type->type->byref)
3021 compare_func = (bflags & BFLAGS_IgnoreCase) ? g_strcasecmp : strcmp;
3025 while ((field = mono_class_get_fields (klass, &iter))) {
3027 if (mono_field_is_deleted (field))
3029 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
3030 if (bflags & BFLAGS_Public)
3033 if (bflags & BFLAGS_NonPublic)
3039 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
3040 if (bflags & BFLAGS_Static)
3041 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3044 if (bflags & BFLAGS_Instance)
3051 utf8_name = mono_string_to_utf8 (name);
3053 if (compare_func (field->name, utf8_name)) {
3059 return mono_field_get_object (domain, klass, field);
3061 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3068 ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
3071 MonoClass *startklass, *klass, *refklass;
3076 MonoClassField *field;
3078 MONO_ARCH_SAVE_REGS;
3080 domain = ((MonoObject *)type)->vtable->domain;
3081 if (type->type->byref)
3082 return mono_array_new (domain, mono_defaults.field_info_class, 0);
3083 klass = startklass = mono_class_from_mono_type (type->type);
3084 refklass = mono_class_from_mono_type (reftype->type);
3088 res = mono_array_new (domain, mono_defaults.field_info_class, len);
3091 while ((field = mono_class_get_fields (klass, &iter))) {
3093 if (mono_field_is_deleted (field))
3095 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
3096 if (bflags & BFLAGS_Public)
3099 if (bflags & BFLAGS_NonPublic)
3105 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
3106 if (bflags & BFLAGS_Static)
3107 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3110 if (bflags & BFLAGS_Instance)
3116 member = (MonoObject*)mono_field_get_object (domain, refklass, field);
3118 MonoArray *new_res = mono_array_new (domain, mono_defaults.field_info_class, len * 2);
3119 mono_array_memcpy_refs (new_res, 0, res, 0, len);
3123 mono_array_setref (res, i, member);
3126 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3129 MonoArray *new_res = mono_array_new (domain, mono_defaults.field_info_class, i);
3130 mono_array_memcpy_refs (new_res, 0, res, 0, i);
3133 * Better solution for the new GC.
3134 * res->max_length = i;
3141 ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
3144 MonoClass *startklass, *klass, *refklass;
3149 int i, len, match, nslots;
3150 guint32 method_slots_default [8];
3151 guint32 *method_slots;
3152 gchar *mname = NULL;
3153 int (*compare_func) (const char *s1, const char *s2) = NULL;
3155 MONO_ARCH_SAVE_REGS;
3157 domain = ((MonoObject *)type)->vtable->domain;
3158 if (type->type->byref)
3159 return mono_array_new (domain, mono_defaults.method_info_class, 0);
3160 klass = startklass = mono_class_from_mono_type (type->type);
3161 refklass = mono_class_from_mono_type (reftype->type);
3164 mname = mono_string_to_utf8 (name);
3165 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
3168 mono_class_setup_vtable (klass);
3170 nslots = MONO_CLASS_IS_INTERFACE (klass) ? mono_class_num_methods (klass) : klass->vtable_size;
3171 if (nslots >= sizeof (method_slots_default) * 8) {
3172 method_slots = g_new0 (guint32, nslots / 32 + 1);
3174 method_slots = method_slots_default;
3175 memset (method_slots, 0, sizeof (method_slots_default));
3179 res = mono_array_new (domain, mono_defaults.method_info_class, len);
3181 mono_class_setup_vtable (klass);
3183 while ((method = mono_class_get_methods (klass, &iter))) {
3185 if (method->name [0] == '.' && (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0))
3187 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
3188 if (bflags & BFLAGS_Public)
3191 if (bflags & BFLAGS_NonPublic)
3197 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
3198 if (bflags & BFLAGS_Static)
3199 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3202 if (bflags & BFLAGS_Instance)
3210 if (compare_func (mname, method->name))
3215 if (method->slot != -1) {
3216 g_assert (method->slot < nslots);
3217 if (method_slots [method->slot >> 5] & (1 << (method->slot & 0x1f)))
3219 method_slots [method->slot >> 5] |= 1 << (method->slot & 0x1f);
3222 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
3225 MonoArray *new_res = mono_array_new (domain, mono_defaults.method_info_class, len * 2);
3226 mono_array_memcpy_refs (new_res, 0, res, 0, len);
3230 mono_array_setref (res, i, member);
3233 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3237 if (method_slots != method_slots_default)
3238 g_free (method_slots);
3240 MonoArray *new_res = mono_array_new (domain, mono_defaults.method_info_class, i);
3241 mono_array_memcpy_refs (new_res, 0, res, 0, i);
3244 * Better solution for the new GC.
3245 * res->max_length = i;
3252 ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
3255 static MonoClass *System_Reflection_ConstructorInfo;
3256 MonoClass *startklass, *klass, *refklass;
3261 gpointer iter = NULL;
3263 MONO_ARCH_SAVE_REGS;
3265 domain = ((MonoObject *)type)->vtable->domain;
3266 if (type->type->byref)
3267 return mono_array_new (domain, mono_defaults.method_info_class, 0);
3268 klass = startklass = mono_class_from_mono_type (type->type);
3269 refklass = mono_class_from_mono_type (reftype->type);
3271 if (!System_Reflection_ConstructorInfo)
3272 System_Reflection_ConstructorInfo = mono_class_from_name (
3273 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
3277 res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
3279 while ((method = mono_class_get_methods (klass, &iter))) {
3281 if (strcmp (method->name, ".ctor") && strcmp (method->name, ".cctor"))
3283 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
3284 if (bflags & BFLAGS_Public)
3287 if (bflags & BFLAGS_NonPublic)
3293 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
3294 if (bflags & BFLAGS_Static)
3295 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3298 if (bflags & BFLAGS_Instance)
3304 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
3307 MonoArray *new_res = mono_array_new (domain, System_Reflection_ConstructorInfo, len * 2);
3308 mono_array_memcpy_refs (new_res, 0, res, 0, len);
3312 mono_array_setref (res, i, member);
3316 MonoArray *new_res = mono_array_new (domain, System_Reflection_ConstructorInfo, i);
3317 mono_array_memcpy_refs (new_res, 0, res, 0, i);
3320 * Better solution for the new GC.
3321 * res->max_length = i;
3328 ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
3331 static MonoClass *System_Reflection_PropertyInfo;
3332 MonoClass *startklass, *klass;
3336 int i, match, nslots;
3339 guint32 method_slots_default [8];
3340 guint32 *method_slots;
3341 gchar *propname = NULL;
3342 int (*compare_func) (const char *s1, const char *s2) = NULL;
3345 MONO_ARCH_SAVE_REGS;
3347 if (!System_Reflection_PropertyInfo)
3348 System_Reflection_PropertyInfo = mono_class_from_name (
3349 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
3351 domain = ((MonoObject *)type)->vtable->domain;
3352 if (type->type->byref)
3353 return mono_array_new (domain, System_Reflection_PropertyInfo, 0);
3354 klass = startklass = mono_class_from_mono_type (type->type);
3356 propname = mono_string_to_utf8 (name);
3357 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
3360 mono_class_setup_vtable (klass);
3362 nslots = MONO_CLASS_IS_INTERFACE (klass) ? mono_class_num_methods (klass) : klass->vtable_size;
3363 if (nslots >= sizeof (method_slots_default) * 8) {
3364 method_slots = g_new0 (guint32, nslots / 32 + 1);
3366 method_slots = method_slots_default;
3367 memset (method_slots, 0, sizeof (method_slots_default));
3371 res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
3373 mono_class_setup_vtable (klass);
3375 while ((prop = mono_class_get_properties (klass, &iter))) {
3381 flags = method->flags;
3384 if ((prop->get && ((prop->get->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC)) ||
3385 (prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC))) {
3386 if (bflags & BFLAGS_Public)
3389 if (bflags & BFLAGS_NonPublic)
3395 if (flags & METHOD_ATTRIBUTE_STATIC) {
3396 if (bflags & BFLAGS_Static)
3397 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3400 if (bflags & BFLAGS_Instance)
3409 if (compare_func (propname, prop->name))
3413 if (prop->get && prop->get->slot != -1) {
3414 if (method_slots [prop->get->slot >> 5] & (1 << (prop->get->slot & 0x1f)))
3416 method_slots [prop->get->slot >> 5] |= 1 << (prop->get->slot & 0x1f);
3418 if (prop->set && prop->set->slot != -1) {
3419 if (method_slots [prop->set->slot >> 5] & (1 << (prop->set->slot & 0x1f)))
3421 method_slots [prop->set->slot >> 5] |= 1 << (prop->set->slot & 0x1f);
3425 MonoArray *new_res = mono_array_new (domain, System_Reflection_PropertyInfo, len * 2);
3426 mono_array_memcpy_refs (new_res, 0, res, 0, len);
3430 mono_array_setref (res, i, mono_property_get_object (domain, startklass, prop));
3433 if ((!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
3437 if (method_slots != method_slots_default)
3438 g_free (method_slots);
3440 MonoArray *new_res = mono_array_new (domain, System_Reflection_PropertyInfo, i);
3441 mono_array_memcpy_refs (new_res, 0, res, 0, i);
3444 * Better solution for the new GC.
3445 * res->max_length = i;
3451 static MonoReflectionEvent *
3452 ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
3455 MonoClass *klass, *startklass;
3461 MONO_ARCH_SAVE_REGS;
3463 event_name = mono_string_to_utf8 (name);
3464 if (type->type->byref)
3466 klass = startklass = mono_class_from_mono_type (type->type);
3467 domain = mono_object_domain (type);
3471 while ((event = mono_class_get_events (klass, &iter))) {
3472 if (strcmp (event->name, event_name))
3475 method = event->add;
3477 method = event->remove;
3479 method = event->raise;
3481 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
3482 if (!(bflags & BFLAGS_Public))
3485 if (!(bflags & BFLAGS_NonPublic))
3490 if (!(bflags & BFLAGS_NonPublic))
3493 g_free (event_name);
3494 return mono_event_get_object (domain, startklass, event);
3497 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3500 g_free (event_name);
3505 ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
3508 static MonoClass *System_Reflection_EventInfo;
3509 MonoClass *startklass, *klass;
3516 MONO_ARCH_SAVE_REGS;
3518 if (!System_Reflection_EventInfo)
3519 System_Reflection_EventInfo = mono_class_from_name (
3520 mono_defaults.corlib, "System.Reflection", "EventInfo");
3522 domain = mono_object_domain (type);
3523 if (type->type->byref)
3524 return mono_array_new (domain, System_Reflection_EventInfo, 0);
3525 klass = startklass = mono_class_from_mono_type (type->type);
3529 res = mono_array_new (domain, System_Reflection_EventInfo, len);
3532 while ((event = mono_class_get_events (klass, &iter))) {
3534 method = event->add;
3536 method = event->remove;
3538 method = event->raise;
3540 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
3541 if (bflags & BFLAGS_Public)
3544 if (bflags & BFLAGS_NonPublic)
3549 if (bflags & BFLAGS_NonPublic)
3555 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
3556 if (bflags & BFLAGS_Static)
3557 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3560 if (bflags & BFLAGS_Instance)
3565 if (bflags & BFLAGS_Instance)
3571 MonoArray *new_res = mono_array_new (domain, System_Reflection_EventInfo, len * 2);
3572 mono_array_memcpy_refs (new_res, 0, res, 0, len);
3576 mono_array_setref (res, i, mono_event_get_object (domain, startklass, event));
3579 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3582 MonoArray *new_res = mono_array_new (domain, System_Reflection_EventInfo, i);
3583 mono_array_memcpy_refs (new_res, 0, res, 0, i);
3586 * Better solution for the new GC.
3587 * res->max_length = i;
3593 static MonoReflectionType *
3594 ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
3597 MonoClass *startklass, *klass;
3602 MONO_ARCH_SAVE_REGS;
3604 domain = ((MonoObject *)type)->vtable->domain;
3605 if (type->type->byref)
3607 klass = startklass = mono_class_from_mono_type (type->type);
3608 str = mono_string_to_utf8 (name);
3611 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
3613 nested = tmpn->data;
3614 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
3615 if (bflags & BFLAGS_Public)
3618 if (bflags & BFLAGS_NonPublic)
3623 if (strcmp (nested->name, str) == 0){
3625 return mono_type_get_object (domain, &nested->byval_arg);
3628 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3635 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
3639 MonoClass *startklass, *klass;
3645 MONO_ARCH_SAVE_REGS;
3647 domain = ((MonoObject *)type)->vtable->domain;
3648 if (type->type->byref)
3649 return mono_array_new (domain, mono_defaults.monotype_class, 0);
3650 klass = startklass = mono_class_from_mono_type (type->type);
3654 res = mono_array_new (domain, mono_defaults.monotype_class, len);
3655 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
3657 nested = tmpn->data;
3658 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
3659 if (bflags & BFLAGS_Public)
3662 if (bflags & BFLAGS_NonPublic)
3667 member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
3669 MonoArray *new_res = mono_array_new (domain, mono_defaults.monotype_class, len * 2);
3670 mono_array_memcpy_refs (new_res, 0, res, 0, len);
3674 mono_array_setref (res, i, member);
3678 MonoArray *new_res = mono_array_new (domain, mono_defaults.monotype_class, i);
3679 mono_array_memcpy_refs (new_res, 0, res, 0, i);
3682 * Better solution for the new GC.
3683 * res->max_length = i;
3689 static MonoReflectionType*
3690 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoReflectionModule *module, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
3693 MonoType *type = NULL;
3694 MonoTypeNameParse info;
3695 gboolean type_resolve;
3697 MONO_ARCH_SAVE_REGS;
3699 /* On MS.NET, this does not fire a TypeResolve event */
3700 type_resolve = TRUE;
3701 str = mono_string_to_utf8 (name);
3702 /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
3703 if (!mono_reflection_parse_type (str, &info)) {
3705 g_list_free (info.modifiers);
3706 g_list_free (info.nested);
3707 if (throwOnError) /* uhm: this is a parse error, though... */
3708 mono_raise_exception (mono_get_exception_type_load (name, NULL));
3709 /*g_print ("failed parse\n");*/
3713 if (module != NULL) {
3715 type = mono_reflection_get_type (module->image, &info, ignoreCase, &type_resolve);
3720 if (assembly->assembly->dynamic) {
3721 /* Enumerate all modules */
3722 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
3726 if (abuilder->modules) {
3727 for (i = 0; i < mono_array_length (abuilder->modules); ++i) {
3728 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
3729 type = mono_reflection_get_type (&mb->dynamic_image->image, &info, ignoreCase, &type_resolve);
3735 if (!type && abuilder->loaded_modules) {
3736 for (i = 0; i < mono_array_length (abuilder->loaded_modules); ++i) {
3737 MonoReflectionModule *mod = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
3738 type = mono_reflection_get_type (mod->image, &info, ignoreCase, &type_resolve);
3745 type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase, &type_resolve);
3747 g_list_free (info.modifiers);
3748 g_list_free (info.nested);
3751 mono_raise_exception (mono_get_exception_type_load (name, NULL));
3752 /* g_print ("failed find\n"); */
3756 if (type->type == MONO_TYPE_CLASS) {
3757 MonoClass *klass = mono_type_get_class (type);
3758 /* need to report exceptions ? */
3759 if (throwOnError && klass->exception_type) {
3760 /* report SecurityException (or others) that occured when loading the assembly */
3761 MonoException *exc = mono_class_get_exception_for_failure (klass);
3762 mono_raise_exception (exc);
3763 } else if (klass->exception_type == MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND) {
3768 /* g_print ("got it\n"); */
3769 return mono_type_get_object (mono_object_domain (assembly), type);
3773 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly, MonoBoolean escaped)
3775 MonoDomain *domain = mono_object_domain (assembly);
3776 MonoAssembly *mass = assembly->assembly;
3777 MonoString *res = NULL;
3781 MONO_ARCH_SAVE_REGS;
3783 absolute = g_build_filename (mass->basedir, mass->image->module_name, NULL);
3787 for (i = strlen (absolute) - 1; i >= 0; i--)
3788 if (absolute [i] == '\\')
3793 uri = g_filename_to_uri (absolute, NULL, NULL);
3795 uri = g_strconcat ("file://", absolute, NULL);
3799 res = mono_string_new (domain, uri);
3807 ves_icall_System_Reflection_Assembly_get_global_assembly_cache (MonoReflectionAssembly *assembly)
3809 MonoAssembly *mass = assembly->assembly;
3811 MONO_ARCH_SAVE_REGS;
3813 return mass->in_gac;
3816 static MonoReflectionAssembly*
3817 ves_icall_System_Reflection_Assembly_load_with_partial_name (MonoString *mname, MonoObject *evidence)
3821 MonoImageOpenStatus status;
3823 MONO_ARCH_SAVE_REGS;
3825 name = mono_string_to_utf8 (mname);
3826 res = mono_assembly_load_with_partial_name (name, &status);
3832 return mono_assembly_get_object (mono_domain_get (), res);
3836 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assembly)
3838 MonoDomain *domain = mono_object_domain (assembly);
3841 MONO_ARCH_SAVE_REGS;
3843 res = mono_string_new (domain, mono_image_get_filename (assembly->assembly->image));
3849 ves_icall_System_Reflection_Assembly_get_ReflectionOnly (MonoReflectionAssembly *assembly)
3851 MONO_ARCH_SAVE_REGS;
3853 return assembly->assembly->ref_only;
3857 ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflectionAssembly *assembly)
3859 MonoDomain *domain = mono_object_domain (assembly);
3861 MONO_ARCH_SAVE_REGS;
3863 return mono_string_new (domain, assembly->assembly->image->version);
3866 static MonoReflectionMethod*
3867 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly)
3869 guint32 token = mono_image_get_entry_point (assembly->assembly->image);
3871 MONO_ARCH_SAVE_REGS;
3875 return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL), NULL);
3878 static MonoReflectionModule*
3879 ves_icall_System_Reflection_Assembly_get_ManifestModule (MonoReflectionAssembly *assembly)
3881 return mono_module_get_object (mono_object_domain (assembly), assembly->assembly->image);
3885 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly)
3887 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3888 MonoArray *result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3892 MONO_ARCH_SAVE_REGS;
3894 for (i = 0; i < table->rows; ++i) {
3895 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_MANIFEST_NAME));
3896 mono_array_setref (result, i, mono_string_new (mono_object_domain (assembly), val));
3902 create_version (MonoDomain *domain, guint32 major, guint32 minor, guint32 build, guint32 revision)
3904 static MonoClass *System_Version = NULL;
3905 static MonoMethod *create_version = NULL;
3909 if (!System_Version) {
3910 System_Version = mono_class_from_name (mono_defaults.corlib, "System", "Version");
3911 g_assert (System_Version);
3914 if (!create_version) {
3915 MonoMethodDesc *desc = mono_method_desc_new (":.ctor(int,int,int,int)", FALSE);
3916 create_version = mono_method_desc_search_in_class (desc, System_Version);
3917 g_assert (create_version);
3918 mono_method_desc_free (desc);
3924 args [3] = &revision;
3925 result = mono_object_new (domain, System_Version);
3926 mono_runtime_invoke (create_version, result, args, NULL);
3932 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly)
3934 static MonoClass *System_Reflection_AssemblyName;
3936 MonoDomain *domain = mono_object_domain (assembly);
3938 static MonoMethod *create_culture = NULL;
3939 MonoImage *image = assembly->assembly->image;
3942 MONO_ARCH_SAVE_REGS;
3944 if (!System_Reflection_AssemblyName)
3945 System_Reflection_AssemblyName = mono_class_from_name (
3946 mono_defaults.corlib, "System.Reflection", "AssemblyName");
3948 t = &assembly->assembly->image->tables [MONO_TABLE_ASSEMBLYREF];
3951 result = mono_array_new (domain, System_Reflection_AssemblyName, count);
3954 MonoMethodDesc *desc = mono_method_desc_new (
3955 "System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3956 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3957 g_assert (create_culture);
3958 mono_method_desc_free (desc);
3961 for (i = 0; i < count; i++) {
3962 MonoReflectionAssemblyName *aname;
3963 guint32 cols [MONO_ASSEMBLYREF_SIZE];
3965 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
3967 aname = (MonoReflectionAssemblyName *) mono_object_new (
3968 domain, System_Reflection_AssemblyName);
3970 MONO_OBJECT_SETREF (aname, name, mono_string_new (domain, mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_NAME])));
3972 aname->major = cols [MONO_ASSEMBLYREF_MAJOR_VERSION];
3973 aname->minor = cols [MONO_ASSEMBLYREF_MINOR_VERSION];
3974 aname->build = cols [MONO_ASSEMBLYREF_BUILD_NUMBER];
3975 aname->revision = cols [MONO_ASSEMBLYREF_REV_NUMBER];
3976 aname->flags = cols [MONO_ASSEMBLYREF_FLAGS];
3977 aname->versioncompat = 1; /* SameMachine (default) */
3978 aname->hashalg = ASSEMBLY_HASH_SHA1; /* SHA1 (default) */
3979 MONO_OBJECT_SETREF (aname, version, create_version (domain, aname->major, aname->minor, aname->build, aname->revision));
3981 if (create_culture) {
3983 args [0] = mono_string_new (domain, mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_CULTURE]));
3984 MONO_OBJECT_SETREF (aname, cultureInfo, mono_runtime_invoke (create_culture, NULL, args, NULL));
3987 if (cols [MONO_ASSEMBLYREF_PUBLIC_KEY]) {
3988 const gchar *pkey_ptr = mono_metadata_blob_heap (image, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
3989 guint32 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3991 if ((cols [MONO_ASSEMBLYREF_FLAGS] & ASSEMBLYREF_FULL_PUBLIC_KEY_FLAG)) {
3992 /* public key token isn't copied - the class library will
3993 automatically generate it from the public key if required */
3994 MONO_OBJECT_SETREF (aname, publicKey, mono_array_new (domain, mono_defaults.byte_class, pkey_len));
3995 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3997 MONO_OBJECT_SETREF (aname, keyToken, mono_array_new (domain, mono_defaults.byte_class, pkey_len));
3998 memcpy (mono_array_addr (aname->keyToken, guint8, 0), pkey_ptr, pkey_len);
4002 /* note: this function doesn't return the codebase on purpose (i.e. it can
4003 be used under partial trust as path information isn't present). */
4005 mono_array_setref (result, i, aname);
4016 foreach_namespace (const char* key, gconstpointer val, NameSpaceInfo *info)
4018 MonoString *name = mono_string_new (mono_object_domain (info->res), key);
4020 mono_array_setref (info->res, info->idx, name);
4025 ves_icall_System_Reflection_Assembly_GetNamespaces (MonoReflectionAssembly *assembly)
4027 MonoImage *img = assembly->assembly->image;
4031 MONO_ARCH_SAVE_REGS;
4033 res = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, g_hash_table_size (img->name_cache));
4036 g_hash_table_foreach (img->name_cache, (GHFunc)foreach_namespace, &info);
4041 /* move this in some file in mono/util/ */
4043 g_concat_dir_and_file (const char *dir, const char *file)
4045 g_return_val_if_fail (dir != NULL, NULL);
4046 g_return_val_if_fail (file != NULL, NULL);
4049 * If the directory name doesn't have a / on the end, we need
4050 * to add one so we get a proper path to the file
4052 if (dir [strlen(dir) - 1] != G_DIR_SEPARATOR)
4053 return g_strconcat (dir, G_DIR_SEPARATOR_S, file, NULL);
4055 return g_strconcat (dir, file, NULL);
4059 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name, gint32 *size, MonoReflectionModule **ref_module)
4061 char *n = mono_string_to_utf8 (name);
4062 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
4064 guint32 cols [MONO_MANIFEST_SIZE];
4065 guint32 impl, file_idx;
4069 MONO_ARCH_SAVE_REGS;
4071 for (i = 0; i < table->rows; ++i) {
4072 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
4073 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
4074 if (strcmp (val, n) == 0)
4078 if (i == table->rows)
4081 impl = cols [MONO_MANIFEST_IMPLEMENTATION];
4084 * this code should only be called after obtaining the
4085 * ResourceInfo and handling the other cases.
4087 g_assert ((impl & MONO_IMPLEMENTATION_MASK) == MONO_IMPLEMENTATION_FILE);
4088 file_idx = impl >> MONO_IMPLEMENTATION_BITS;
4090 module = mono_image_load_file_for_image (assembly->assembly->image, file_idx);
4095 module = assembly->assembly->image;
4097 *ref_module = mono_module_get_object (mono_domain_get (), module);
4099 return (void*)mono_image_get_resource (module, cols [MONO_MANIFEST_OFFSET], (guint32*)size);
4103 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoManifestResourceInfo *info)
4105 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
4107 guint32 cols [MONO_MANIFEST_SIZE];
4108 guint32 file_cols [MONO_FILE_SIZE];
4112 MONO_ARCH_SAVE_REGS;
4114 n = mono_string_to_utf8 (name);
4115 for (i = 0; i < table->rows; ++i) {
4116 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
4117 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
4118 if (strcmp (val, n) == 0)
4122 if (i == table->rows)
4125 if (!cols [MONO_MANIFEST_IMPLEMENTATION]) {
4126 info->location = RESOURCE_LOCATION_EMBEDDED | RESOURCE_LOCATION_IN_MANIFEST;
4129 switch (cols [MONO_MANIFEST_IMPLEMENTATION] & MONO_IMPLEMENTATION_MASK) {
4130 case MONO_IMPLEMENTATION_FILE:
4131 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> MONO_IMPLEMENTATION_BITS;
4132 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
4133 mono_metadata_decode_row (table, i - 1, file_cols, MONO_FILE_SIZE);
4134 val = mono_metadata_string_heap (assembly->assembly->image, file_cols [MONO_FILE_NAME]);
4135 MONO_OBJECT_SETREF (info, filename, mono_string_new (mono_object_domain (assembly), val));
4136 if (file_cols [MONO_FILE_FLAGS] && FILE_CONTAINS_NO_METADATA)
4139 info->location = RESOURCE_LOCATION_EMBEDDED;
4142 case MONO_IMPLEMENTATION_ASSEMBLYREF:
4143 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> MONO_IMPLEMENTATION_BITS;
4144 mono_assembly_load_reference (assembly->assembly->image, i - 1);
4145 if (assembly->assembly->image->references [i - 1] == (gpointer)-1) {
4146 char *msg = g_strdup_printf ("Assembly %d referenced from assembly %s not found ", i - 1, assembly->assembly->image->name);
4147 MonoException *ex = mono_get_exception_file_not_found2 (msg, NULL);
4149 mono_raise_exception (ex);
4151 MONO_OBJECT_SETREF (info, assembly, mono_assembly_get_object (mono_domain_get (), assembly->assembly->image->references [i - 1]));
4153 /* Obtain info recursively */
4154 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (info->assembly, name, info);
4155 info->location |= RESOURCE_LOCATION_ANOTHER_ASSEMBLY;
4158 case MONO_IMPLEMENTATION_EXP_TYPE:
4159 g_assert_not_reached ();
4168 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoBoolean resource_modules)
4170 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
4171 MonoArray *result = NULL;
4176 MONO_ARCH_SAVE_REGS;
4178 /* check hash if needed */
4180 n = mono_string_to_utf8 (name);
4181 for (i = 0; i < table->rows; ++i) {
4182 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
4183 if (strcmp (val, n) == 0) {
4186 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
4187 fn = mono_string_new (mono_object_domain (assembly), n);
4189 return (MonoObject*)fn;
4197 for (i = 0; i < table->rows; ++i) {
4198 if (resource_modules || !(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA))
4202 result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, count);
4205 for (i = 0; i < table->rows; ++i) {
4206 if (resource_modules || !(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
4207 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
4208 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
4209 mono_array_setref (result, count, mono_string_new (mono_object_domain (assembly), n));
4214 return (MonoObject*)result;
4218 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly *assembly)
4220 MonoDomain *domain = mono_domain_get();
4223 int i, j, file_count = 0;
4224 MonoImage **modules;
4225 guint32 module_count, real_module_count;
4226 MonoTableInfo *table;
4228 g_assert (assembly->assembly->image != NULL);
4230 if (assembly->assembly->dynamic) {
4231 MonoReflectionAssemblyBuilder *assemblyb = (MonoReflectionAssemblyBuilder*)assembly;
4233 if (assemblyb->modules)
4234 module_count = mono_array_length (assemblyb->modules);
4237 real_module_count = module_count;
4239 modules = g_new0 (MonoImage*, module_count);
4240 if (assemblyb->modules) {
4241 for (i = 0; i < mono_array_length (assemblyb->modules); ++i) {
4243 mono_array_get (assemblyb->modules, MonoReflectionModuleBuilder*, i)->module.image;
4248 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
4249 file_count = table->rows;
4251 modules = assembly->assembly->image->modules;
4252 module_count = assembly->assembly->image->module_count;
4254 real_module_count = 0;
4255 for (i = 0; i < module_count; ++i)
4257 real_module_count ++;
4260 klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "Module");
4261 res = mono_array_new (domain, klass, 1 + real_module_count + file_count);
4263 mono_array_setref (res, 0, mono_module_get_object (domain, assembly->assembly->image));
4265 for (i = 0; i < module_count; ++i)
4267 mono_array_setref (res, j, mono_module_get_object (domain, modules[i]));
4271 for (i = 0; i < file_count; ++i, ++j)
4272 mono_array_setref (res, j, mono_module_file_get_object (domain, assembly->assembly->image, i));
4274 if (assembly->assembly->dynamic)
4280 static MonoReflectionMethod*
4281 ves_icall_GetCurrentMethod (void)
4283 MonoMethod *m = mono_method_get_last_managed ();
4285 MONO_ARCH_SAVE_REGS;
4287 return mono_method_get_object (mono_domain_get (), m, NULL);
4290 static MonoReflectionMethod*
4291 ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternal (MonoMethod *method)
4293 return mono_method_get_object (mono_domain_get (), method, NULL);
4296 static MonoReflectionMethodBody*
4297 ves_icall_System_Reflection_MethodBase_GetMethodBodyInternal (MonoMethod *method)
4299 return mono_method_body_get_object (mono_domain_get (), method);
4302 static MonoReflectionAssembly*
4303 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
4305 MonoMethod *m = mono_method_get_last_managed ();
4307 MONO_ARCH_SAVE_REGS;
4309 return mono_assembly_get_object (mono_domain_get (), m->klass->image->assembly);
4313 static MonoReflectionAssembly*
4314 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
4316 MonoDomain* domain = mono_domain_get ();
4318 MONO_ARCH_SAVE_REGS;
4320 if (!domain->entry_assembly)
4323 return mono_assembly_get_object (domain, domain->entry_assembly);
4326 static MonoReflectionAssembly*
4327 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
4329 MonoMethod *m = mono_method_get_last_managed ();
4330 MonoMethod *dest = m;
4332 MONO_ARCH_SAVE_REGS;
4334 mono_stack_walk_no_il (get_caller, &dest);
4337 return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
4341 ves_icall_System_MonoType_getFullName (MonoReflectionType *object, gboolean full_name,
4342 gboolean assembly_qualified)
4344 MonoDomain *domain = mono_object_domain (object);
4345 MonoTypeNameFormat format;
4349 MONO_ARCH_SAVE_REGS;
4351 format = assembly_qualified ?
4352 MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED :
4353 MONO_TYPE_NAME_FORMAT_FULL_NAME;
4355 format = MONO_TYPE_NAME_FORMAT_REFLECTION;
4357 name = mono_type_get_name_full (object->type, format);
4361 if (full_name && (object->type->type == MONO_TYPE_VAR || object->type->type == MONO_TYPE_MVAR))
4364 res = mono_string_new (domain, name);
4371 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute, gboolean by_default_version)
4373 static MonoMethod *create_culture = NULL;
4376 const char *pkey_ptr;
4379 MONO_ARCH_SAVE_REGS;
4381 MONO_OBJECT_SETREF (aname, name, mono_string_new (domain, name->name));
4382 aname->major = name->major;
4383 aname->minor = name->minor;
4384 aname->build = name->build;
4385 aname->revision = name->revision;
4386 aname->hashalg = name->hash_alg;
4387 if (by_default_version)
4388 MONO_OBJECT_SETREF (aname, version, create_version (domain, name->major, name->minor, name->build, name->revision));
4390 codebase = g_filename_to_uri (absolute, NULL, NULL);
4392 MONO_OBJECT_SETREF (aname, codebase, mono_string_new (domain, codebase));
4396 if (!create_culture) {
4397 MonoMethodDesc *desc = mono_method_desc_new ("System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
4398 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
4399 g_assert (create_culture);
4400 mono_method_desc_free (desc);
4403 if (name->culture) {
4404 args [0] = mono_string_new (domain, name->culture);
4405 MONO_OBJECT_SETREF (aname, cultureInfo, mono_runtime_invoke (create_culture, NULL, args, NULL));
4408 if (name->public_key) {
4409 pkey_ptr = (char*)name->public_key;
4410 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
4412 MONO_OBJECT_SETREF (aname, publicKey, mono_array_new (domain, mono_defaults.byte_class, pkey_len));
4413 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
4416 /* MonoAssemblyName keeps the public key token as an hexadecimal string */
4417 if (name->public_key_token [0]) {
4421 MONO_OBJECT_SETREF (aname, keyToken, mono_array_new (domain, mono_defaults.byte_class, 8));
4422 p = mono_array_addr (aname->keyToken, char, 0);
4424 for (i = 0, j = 0; i < 8; i++) {
4425 *p = g_ascii_xdigit_value (name->public_key_token [j++]) << 4;
4426 *p |= g_ascii_xdigit_value (name->public_key_token [j++]);
4433 ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
4437 MONO_ARCH_SAVE_REGS;
4439 absolute = g_build_filename (assembly->assembly->basedir, assembly->assembly->image->module_name, NULL);
4441 fill_reflection_assembly_name (mono_object_domain (assembly), aname,
4442 &assembly->assembly->aname, absolute, TRUE);
4448 ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname, MonoReflectionAssemblyName *aname)
4451 MonoImageOpenStatus status = MONO_IMAGE_OK;
4454 MonoAssemblyName name;
4456 MONO_ARCH_SAVE_REGS;
4458 filename = mono_string_to_utf8 (fname);
4460 image = mono_image_open (filename, &status);
4466 exc = mono_get_exception_file_not_found (fname);
4467 mono_raise_exception (exc);
4470 res = mono_assembly_fill_assembly_name (image, &name);
4472 mono_image_close (image);
4474 mono_raise_exception (mono_get_exception_argument ("assemblyFile", "The file does not contain a manifest"));
4477 fill_reflection_assembly_name (mono_domain_get (), aname, &name, filename, TRUE);
4480 mono_image_close (image);
4484 ves_icall_System_Reflection_Assembly_LoadPermissions (MonoReflectionAssembly *assembly,
4485 char **minimum, guint32 *minLength, char **optional, guint32 *optLength, char **refused, guint32 *refLength)
4487 MonoBoolean result = FALSE;
4488 MonoDeclSecurityEntry entry;
4490 /* SecurityAction.RequestMinimum */
4491 if (mono_declsec_get_assembly_action (assembly->assembly, SECURITY_ACTION_REQMIN, &entry)) {
4492 *minimum = entry.blob;
4493 *minLength = entry.size;
4496 /* SecurityAction.RequestOptional */
4497 if (mono_declsec_get_assembly_action (assembly->assembly, SECURITY_ACTION_REQOPT, &entry)) {
4498 *optional = entry.blob;
4499 *optLength = entry.size;
4502 /* SecurityAction.RequestRefuse */
4503 if (mono_declsec_get_assembly_action (assembly->assembly, SECURITY_ACTION_REQREFUSE, &entry)) {
4504 *refused = entry.blob;
4505 *refLength = entry.size;
4513 mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoBoolean exportedOnly)
4517 MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF];
4519 guint32 attrs, visibility;
4521 /* we start the count from 1 because we skip the special type <Module> */
4524 for (i = 1; i < tdef->rows; ++i) {
4525 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
4526 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
4527 if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
4531 count = tdef->rows - 1;
4533 res = mono_array_new (domain, mono_defaults.monotype_class, count);
4535 for (i = 1; i < tdef->rows; ++i) {
4536 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
4537 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
4538 if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
4539 klass = mono_class_get_throw (image, (i + 1) | MONO_TOKEN_TYPE_DEF);
4540 if (mono_loader_get_last_error ())
4541 mono_loader_clear_error ();
4542 mono_array_setref (res, count, mono_type_get_object (domain, &klass->byval_arg));
4551 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
4553 MonoArray *res = NULL;
4554 MonoImage *image = NULL;
4555 MonoTableInfo *table = NULL;
4560 MONO_ARCH_SAVE_REGS;
4562 domain = mono_object_domain (assembly);
4564 if (assembly->assembly->dynamic) {
4565 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
4566 if (abuilder->modules) {
4567 for (i = 0; i < mono_array_length(abuilder->modules); i++) {
4568 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
4569 MonoArray *append = mb->types;
4570 /* The types array might not be fully filled up */
4571 if (append && mb->num_types > 0) {
4574 len1 = res ? mono_array_length (res) : 0;
4575 len2 = mb->num_types;
4576 new = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
4578 mono_array_memcpy_refs (new, 0, res, 0, len1);
4579 mono_array_memcpy_refs (new, len1, append, 0, len2);
4585 * Replace TypeBuilders with the created types to be compatible
4589 for (i = 0; i < mono_array_length (res); ++i) {
4590 MonoReflectionTypeBuilder *tb = mono_array_get (res, MonoReflectionTypeBuilder*, i);
4592 mono_array_setref (res, i, tb->created);
4597 if (abuilder->loaded_modules)
4598 for (i = 0; i < mono_array_length(abuilder->loaded_modules); i++) {
4599 MonoReflectionModule *rm = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
4600 MonoArray *append = mono_module_get_types (domain, rm->image, exportedOnly);
4601 if (append && mono_array_length (append) > 0) {
4604 len1 = res ? mono_array_length (res) : 0;
4605 len2 = mono_array_length (append);
4606 new = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
4608 mono_array_memcpy_refs (new, 0, res, 0, len1);
4609 mono_array_memcpy_refs (new, len1, append, 0, len2);
4616 return mono_array_new (domain, mono_defaults.monotype_class, 0);
4618 image = assembly->assembly->image;
4619 table = &image->tables [MONO_TABLE_FILE];
4620 res = mono_module_get_types (domain, image, exportedOnly);
4622 /* Append data from all modules in the assembly */
4623 for (i = 0; i < table->rows; ++i) {
4624 if (!(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
4625 MonoImage *loaded_image = mono_assembly_load_module (image->assembly, i + 1);
4627 MonoArray *res2 = mono_module_get_types (domain, loaded_image, exportedOnly);
4628 /* Append the new types to the end of the array */
4629 if (mono_array_length (res2) > 0) {
4633 len1 = mono_array_length (res);
4634 len2 = mono_array_length (res2);
4635 res3 = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
4636 mono_array_memcpy_refs (res3, 0, res, 0, len1);
4637 mono_array_memcpy_refs (res3, len1, res2, 0, len2);
4644 /* the ReflectionTypeLoadException must have all the types (Types property),
4645 * NULL replacing types which throws an exception. The LoaderException must
4646 * contain all exceptions for NULL items.
4649 len = mono_array_length (res);
4651 for (i = 0; i < len; i++) {
4652 MonoReflectionType *t = mono_array_get (res, gpointer, i);
4653 MonoClass *klass = mono_type_get_class (t->type);
4654 if ((klass != NULL) && klass->exception_type) {
4655 /* keep the class in the list */
4656 list = g_list_append (list, klass);
4657 /* and replace Type with NULL */
4658 mono_array_setref (res, i, NULL);
4664 MonoException *exc = NULL;
4665 MonoArray *exl = NULL;
4666 int length = g_list_length (list);
4668 mono_loader_clear_error ();
4670 exl = mono_array_new (domain, mono_defaults.exception_class, length);
4671 for (i = 0, tmp = list; i < length; i++, tmp = tmp->next) {
4672 MonoException *exc = mono_class_get_exception_for_failure (tmp->data);
4673 mono_array_setref (exl, i, exc);
4678 exc = mono_get_exception_reflection_type_load (res, exl);
4679 mono_raise_exception (exc);
4686 ves_icall_System_Reflection_AssemblyName_ParseName (MonoReflectionAssemblyName *name, MonoString *assname)
4688 MonoAssemblyName aname;
4689 MonoDomain *domain = mono_object_domain (name);
4691 gboolean is_version_defined;
4693 val = mono_string_to_utf8 (assname);
4694 if (!mono_assembly_name_parse_full (val, &aname, TRUE, &is_version_defined))
4697 fill_reflection_assembly_name (domain, name, &aname, "", is_version_defined);
4699 mono_assembly_name_free (&aname);
4700 g_free ((guint8*) aname.public_key);
4706 static MonoReflectionType*
4707 ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module)
4709 MonoDomain *domain = mono_object_domain (module);
4712 MONO_ARCH_SAVE_REGS;
4714 g_assert (module->image);
4716 if (module->image->dynamic && ((MonoDynamicImage*)(module->image))->initial_image)
4717 /* These images do not have a global type */
4720 klass = mono_class_get (module->image, 1 | MONO_TOKEN_TYPE_DEF);
4721 return mono_type_get_object (domain, &klass->byval_arg);
4725 ves_icall_System_Reflection_Module_Close (MonoReflectionModule *module)
4727 /*if (module->image)
4728 mono_image_close (module->image);*/
4732 ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module)
4734 MonoDomain *domain = mono_object_domain (module);
4736 MONO_ARCH_SAVE_REGS;
4738 g_assert (module->image);
4739 return mono_string_new (domain, module->image->guid);
4743 ves_icall_System_Reflection_Module_GetPEKind (MonoImage *image, gint32 *pe_kind, gint32 *machine)
4745 if (image->dynamic) {
4746 MonoDynamicImage *dyn = (MonoDynamicImage*)image;
4747 *pe_kind = dyn->pe_kind;
4748 *machine = dyn->machine;
4751 *pe_kind = ((MonoCLIImageInfo*)(image->image_info))->cli_cli_header.ch_flags & 0x3;
4752 *machine = ((MonoCLIImageInfo*)(image->image_info))->cli_header.coff.coff_machine;
4757 ves_icall_System_Reflection_Module_get_MDStreamVersion (MonoReflectionModule *module)
4759 MonoImage *image = module->image;
4762 mono_raise_exception (mono_get_exception_not_supported (""));
4764 return (image->md_version_major << 16) | (image->md_version_minor);
4768 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *module)
4770 MONO_ARCH_SAVE_REGS;
4773 return mono_array_new (mono_object_domain (module), mono_defaults.monotype_class, 0);
4775 return mono_module_get_types (mono_object_domain (module), module->image, FALSE);
4779 mono_metadata_memberref_is_method (MonoImage *image, guint32 token)
4781 guint32 cols [MONO_MEMBERREF_SIZE];
4783 mono_metadata_decode_row (&image->tables [MONO_TABLE_MEMBERREF], mono_metadata_token_index (token) - 1, cols, MONO_MEMBERREF_SIZE);
4784 sig = mono_metadata_blob_heap (image, cols [MONO_MEMBERREF_SIGNATURE]);
4785 mono_metadata_decode_blob_size (sig, &sig);
4786 return (*sig != 0x6);
4790 ves_icall_System_Reflection_Module_ResolveTypeToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4793 int table = mono_metadata_token_table (token);
4794 int index = mono_metadata_token_index (token);
4796 *error = ResolveTokenError_Other;
4798 /* Validate token */
4799 if ((table != MONO_TABLE_TYPEDEF) && (table != MONO_TABLE_TYPEREF) &&
4800 (table != MONO_TABLE_TYPESPEC)) {
4801 *error = ResolveTokenError_BadTable;
4806 return mono_lookup_dynamic_token (image, token);
4808 if ((index <= 0) || (index > image->tables [table].rows)) {
4809 *error = ResolveTokenError_OutOfRange;
4813 klass = mono_class_get (image, token);
4815 return &klass->byval_arg;
4821 ves_icall_System_Reflection_Module_ResolveMethodToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4823 int table = mono_metadata_token_table (token);
4824 int index = mono_metadata_token_index (token);
4826 *error = ResolveTokenError_Other;
4828 /* Validate token */
4829 if ((table != MONO_TABLE_METHOD) && (table != MONO_TABLE_METHODSPEC) &&
4830 (table != MONO_TABLE_MEMBERREF)) {
4831 *error = ResolveTokenError_BadTable;
4836 /* FIXME: validate memberref token type */
4837 return mono_lookup_dynamic_token (image, token);
4839 if ((index <= 0) || (index > image->tables [table].rows)) {
4840 *error = ResolveTokenError_OutOfRange;
4843 if ((table == MONO_TABLE_MEMBERREF) && (!mono_metadata_memberref_is_method (image, token))) {
4844 *error = ResolveTokenError_BadTable;
4848 return mono_get_method (image, token, NULL);
4852 ves_icall_System_Reflection_Module_ResolveStringToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4854 int index = mono_metadata_token_index (token);
4856 *error = ResolveTokenError_Other;
4858 /* Validate token */
4859 if (mono_metadata_token_code (token) != MONO_TOKEN_STRING) {
4860 *error = ResolveTokenError_BadTable;
4865 return mono_lookup_dynamic_token (image, token);
4867 if ((index <= 0) || (index >= image->heap_us.size)) {
4868 *error = ResolveTokenError_OutOfRange;
4872 /* FIXME: What to do if the index points into the middle of a string ? */
4874 return mono_ldstr (mono_domain_get (), image, index);
4877 static MonoClassField*
4878 ves_icall_System_Reflection_Module_ResolveFieldToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4881 int table = mono_metadata_token_table (token);
4882 int index = mono_metadata_token_index (token);
4884 *error = ResolveTokenError_Other;
4886 /* Validate token */
4887 if ((table != MONO_TABLE_FIELD) && (table != MONO_TABLE_MEMBERREF)) {
4888 *error = ResolveTokenError_BadTable;
4893 /* FIXME: validate memberref token type */
4894 return mono_lookup_dynamic_token (image, token);
4896 if ((index <= 0) || (index > image->tables [table].rows)) {
4897 *error = ResolveTokenError_OutOfRange;
4900 if ((table == MONO_TABLE_MEMBERREF) && (mono_metadata_memberref_is_method (image, token))) {
4901 *error = ResolveTokenError_BadTable;
4905 return mono_field_from_token (image, token, &klass, NULL);
4910 ves_icall_System_Reflection_Module_ResolveMemberToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4912 int table = mono_metadata_token_table (token);
4914 *error = ResolveTokenError_Other;
4917 case MONO_TABLE_TYPEDEF:
4918 case MONO_TABLE_TYPEREF:
4919 case MONO_TABLE_TYPESPEC: {
4920 MonoType *t = ves_icall_System_Reflection_Module_ResolveTypeToken (image, token, error);
4922 return (MonoObject*)mono_type_get_object (mono_domain_get (), t);
4926 case MONO_TABLE_METHOD:
4927 case MONO_TABLE_METHODSPEC: {
4928 MonoMethod *m = ves_icall_System_Reflection_Module_ResolveMethodToken (image, token, error);
4930 return (MonoObject*)mono_method_get_object (mono_domain_get (), m, m->klass);
4934 case MONO_TABLE_FIELD: {
4935 MonoClassField *f = ves_icall_System_Reflection_Module_ResolveFieldToken (image, token, error);
4937 return (MonoObject*)mono_field_get_object (mono_domain_get (), f->parent, f);
4941 case MONO_TABLE_MEMBERREF:
4942 if (mono_metadata_memberref_is_method (image, token)) {
4943 MonoMethod *m = ves_icall_System_Reflection_Module_ResolveMethodToken (image, token, error);
4945 return (MonoObject*)mono_method_get_object (mono_domain_get (), m, m->klass);
4950 MonoClassField *f = ves_icall_System_Reflection_Module_ResolveFieldToken (image, token, error);
4952 return (MonoObject*)mono_field_get_object (mono_domain_get (), f->parent, f);
4959 *error = ResolveTokenError_BadTable;
4965 static MonoReflectionType*
4966 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
4969 int isbyref = 0, rank;
4970 char *str = mono_string_to_utf8 (smodifiers);
4973 MONO_ARCH_SAVE_REGS;
4975 klass = mono_class_from_mono_type (tb->type.type);
4977 /* logic taken from mono_reflection_parse_type(): keep in sync */
4981 if (isbyref) { /* only one level allowed by the spec */
4988 return mono_type_get_object (mono_object_domain (tb), &klass->this_arg);
4991 klass = mono_ptr_class_get (&klass->byval_arg);
4992 mono_class_init (klass);
5003 else if (*p != '*') { /* '*' means unknown lower bound */
5014 klass = mono_array_class_get (klass, rank);
5015 mono_class_init (klass);
5022 return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
5026 ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
5031 MONO_ARCH_SAVE_REGS;
5034 res = !type->byref && (type->type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY);
5039 static MonoReflectionType *
5040 ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
5042 MonoClass *klass, *aklass;
5044 MONO_ARCH_SAVE_REGS;
5046 klass = mono_class_from_mono_type (type->type);
5047 aklass = mono_array_class_get (klass, rank);
5049 return mono_type_get_object (mono_object_domain (type), &aklass->byval_arg);
5052 static MonoReflectionType *
5053 ves_icall_Type_make_byref_type (MonoReflectionType *type)
5057 MONO_ARCH_SAVE_REGS;
5059 klass = mono_class_from_mono_type (type->type);
5061 return mono_type_get_object (mono_object_domain (type), &klass->this_arg);
5064 static MonoReflectionType *
5065 ves_icall_Type_MakePointerType (MonoReflectionType *type)
5069 MONO_ARCH_SAVE_REGS;
5071 pklass = mono_ptr_class_get (type->type);
5073 return mono_type_get_object (mono_object_domain (type), &pklass->byval_arg);
5077 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target,
5078 MonoReflectionMethod *info)
5080 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
5081 MonoObject *delegate;
5084 MONO_ARCH_SAVE_REGS;
5086 mono_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
5088 delegate = mono_object_new (mono_object_domain (type), delegate_class);
5090 func = mono_compile_method (info->method);
5092 mono_delegate_ctor (delegate, target, func);
5098 ves_icall_System_Delegate_FreeTrampoline (MonoDelegate *this)
5101 Delegates have a finalizer only when needed, now.
5102 mono_delegate_free_ftnptr (this);*/
5106 * Magic number to convert a time which is relative to
5107 * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
5109 #define EPOCH_ADJUST ((guint64)62135596800LL)
5112 * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
5114 #define FILETIME_ADJUST ((guint64)504911232000000000LL)
5117 * This returns Now in UTC
5120 ves_icall_System_DateTime_GetNow (void)
5122 #ifdef PLATFORM_WIN32
5126 GetSystemTime (&st);
5127 SystemTimeToFileTime (&st, &ft);
5128 return (gint64) FILETIME_ADJUST + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
5130 /* FIXME: put this in io-layer and call it GetLocalTime */
5134 MONO_ARCH_SAVE_REGS;
5136 if (gettimeofday (&tv, NULL) == 0) {
5137 res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
5140 /* fixme: raise exception */
5145 #ifdef PLATFORM_WIN32
5146 /* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
5148 convert_to_absolute_date(SYSTEMTIME *date)
5150 #define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
5151 static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
5152 static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
5153 /* from the calendar FAQ */
5154 int a = (14 - date->wMonth) / 12;
5155 int y = date->wYear - a;
5156 int m = date->wMonth + 12 * a - 2;
5157 int d = (1 + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
5159 /* d is now the day of the week for the first of the month (0 == Sunday) */
5161 int day_of_week = date->wDayOfWeek;
5163 /* set day_in_month to the first day in the month which falls on day_of_week */
5164 int day_in_month = 1 + (day_of_week - d);
5165 if (day_in_month <= 0)
5168 /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
5169 date->wDay = day_in_month + (date->wDay - 1) * 7;
5170 if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
5175 #ifndef PLATFORM_WIN32
5177 * Return's the offset from GMT of a local time.
5179 * tm is a local time
5180 * t is the same local time as seconds.
5183 gmt_offset(struct tm *tm, time_t t)
5185 #if defined (HAVE_TM_GMTOFF)
5186 return tm->tm_gmtoff;
5191 g.tm_isdst = tm->tm_isdst;
5193 return (int)difftime(t, t2);
5198 * This is heavily based on zdump.c from glibc 2.2.
5200 * * data[0]: start of daylight saving time (in DateTime ticks).
5201 * * data[1]: end of daylight saving time (in DateTime ticks).
5202 * * data[2]: utcoffset (in TimeSpan ticks).
5203 * * data[3]: additional offset when daylight saving (in TimeSpan ticks).
5204 * * name[0]: name of this timezone when not daylight saving.
5205 * * name[1]: name of this timezone when daylight saving.
5207 * FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
5208 * the class library allows years between 1 and 9999.
5210 * Returns true on success and zero on failure.
5213 ves_icall_System_CurrentSystemTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
5215 #ifndef PLATFORM_WIN32
5216 MonoDomain *domain = mono_domain_get ();
5217 struct tm start, tt;
5221 int is_daylight = 0, day;
5224 MONO_ARCH_SAVE_REGS;
5226 MONO_CHECK_ARG_NULL (data);
5227 MONO_CHECK_ARG_NULL (names);
5229 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
5230 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
5233 * no info is better than crashing: we'll need our own tz data
5234 * to make this work properly, anyway. The range is probably
5235 * reduced to 1970 .. 2037 because that is what mktime is
5236 * guaranteed to support (we get into an infinite loop
5240 memset (&start, 0, sizeof (start));
5243 start.tm_year = year-1900;
5245 t = mktime (&start);
5247 if ((year < 1970) || (year > 2037) || (t == -1)) {
5249 tt = *localtime (&t);
5250 strftime (tzone, sizeof (tzone), "%Z", &tt);
5251 mono_array_setref ((*names), 0, mono_string_new (domain, tzone));
5252 mono_array_setref ((*names), 1, mono_string_new (domain, tzone));
5256 gmtoff = gmt_offset (&start, t);
5258 /* For each day of the year, calculate the tm_gmtoff. */
5259 for (day = 0; day < 365; day++) {
5262 tt = *localtime (&t);
5264 /* Daylight saving starts or ends here. */
5265 if (gmt_offset (&tt, t) != gmtoff) {
5269 /* Try to find the exact hour when daylight saving starts/ends. */
5273 tt1 = *localtime (&t1);
5274 } while (gmt_offset (&tt1, t1) != gmtoff);
5276 /* Try to find the exact minute when daylight saving starts/ends. */
5279 tt1 = *localtime (&t1);
5280 } while (gmt_offset (&tt1, t1) == gmtoff);
5282 strftime (tzone, sizeof (tzone), "%Z", &tt);
5284 /* Write data, if we're already in daylight saving, we're done. */
5286 mono_array_setref ((*names), 0, mono_string_new (domain, tzone));
5287 mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
5290 mono_array_setref ((*names), 1, mono_string_new (domain, tzone));
5291 mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
5295 /* This is only set once when we enter daylight saving. */
5296 mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
5297 mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (&tt, t) - gmtoff) * 10000000L);
5299 gmtoff = gmt_offset (&tt, t);
5304 strftime (tzone, sizeof (tzone), "%Z", &tt);
5305 mono_array_setref ((*names), 0, mono_string_new (domain, tzone));
5306 mono_array_setref ((*names), 1, mono_string_new (domain, tzone));
5307 mono_array_set ((*data), gint64, 0, 0);
5308 mono_array_set ((*data), gint64, 1, 0);
5309 mono_array_set ((*data), gint64, 2, (gint64) gmtoff * 10000000L);
5310 mono_array_set ((*data), gint64, 3, 0);
5315 MonoDomain *domain = mono_domain_get ();
5316 TIME_ZONE_INFORMATION tz_info;
5321 tz_id = GetTimeZoneInformation (&tz_info);
5322 if (tz_id == TIME_ZONE_ID_INVALID)
5325 MONO_CHECK_ARG_NULL (data);
5326 MONO_CHECK_ARG_NULL (names);
5328 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
5329 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
5331 for (i = 0; i < 32; ++i)
5332 if (!tz_info.DaylightName [i])
5334 mono_array_setref ((*names), 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
5335 for (i = 0; i < 32; ++i)
5336 if (!tz_info.StandardName [i])
5338 mono_array_setref ((*names), 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
5340 if ((year <= 1601) || (year > 30827)) {
5342 * According to MSDN, the MS time functions can't handle dates outside
5348 /* even if the timezone has no daylight savings it may have Bias (e.g. GMT+13 it seems) */
5349 if (tz_id != TIME_ZONE_ID_UNKNOWN) {
5350 tz_info.StandardDate.wYear = year;
5351 convert_to_absolute_date(&tz_info.StandardDate);
5352 err = SystemTimeToFileTime (&tz_info.StandardDate, &ft);
5354 mono_array_set ((*data), gint64, 1, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
5355 tz_info.DaylightDate.wYear = year;
5356 convert_to_absolute_date(&tz_info.DaylightDate);
5357 err = SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
5359 mono_array_set ((*data), gint64, 0, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
5361 mono_array_set ((*data), gint64, 2, (tz_info.Bias + tz_info.StandardBias) * -600000000LL);
5362 mono_array_set ((*data), gint64, 3, (tz_info.DaylightBias - tz_info.StandardBias) * -600000000LL);
5369 ves_icall_System_Object_obj_address (MonoObject *this)
5371 MONO_ARCH_SAVE_REGS;
5378 static inline gint32
5379 mono_array_get_byte_length (MonoArray *array)
5385 klass = array->obj.vtable->klass;
5387 if (array->bounds == NULL)
5388 length = array->max_length;
5391 for (i = 0; i < klass->rank; ++ i)
5392 length *= array->bounds [i].length;
5395 switch (klass->element_class->byval_arg.type) {
5398 case MONO_TYPE_BOOLEAN:
5402 case MONO_TYPE_CHAR:
5410 return length * sizeof (gpointer);
5421 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
5423 MONO_ARCH_SAVE_REGS;
5425 return mono_array_get_byte_length (array);
5429 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx)
5431 MONO_ARCH_SAVE_REGS;
5433 return mono_array_get (array, gint8, idx);
5437 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value)
5439 MONO_ARCH_SAVE_REGS;
5441 mono_array_set (array, gint8, idx, value);
5445 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count)
5447 guint8 *src_buf, *dest_buf;
5449 MONO_ARCH_SAVE_REGS;
5451 /* watch out for integer overflow */
5452 if ((src_offset > mono_array_get_byte_length (src) - count) || (dest_offset > mono_array_get_byte_length (dest) - count))
5455 src_buf = (guint8 *)src->vector + src_offset;
5456 dest_buf = (guint8 *)dest->vector + dest_offset;
5459 memcpy (dest_buf, src_buf, count);
5461 memmove (dest_buf, src_buf, count); /* Source and dest are the same array */
5467 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this, MonoString *class_name)
5469 MonoDomain *domain = mono_object_domain (this);
5471 MonoRealProxy *rp = ((MonoRealProxy *)this);
5472 MonoTransparentProxy *tp;
5476 MONO_ARCH_SAVE_REGS;
5478 res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
5479 tp = (MonoTransparentProxy*) res;
5481 MONO_OBJECT_SETREF (tp, rp, rp);
5482 type = ((MonoReflectionType *)rp->class_to_proxy)->type;
5483 klass = mono_class_from_mono_type (type);
5485 tp->custom_type_info = (mono_object_isinst (this, mono_defaults.iremotingtypeinfo_class) != NULL);
5486 tp->remote_class = mono_remote_class (domain, class_name, klass);
5488 res->vtable = mono_remote_class_vtable (domain, tp->remote_class, rp);
5492 static MonoReflectionType *
5493 ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy *tp)
5495 return mono_type_get_object (mono_object_domain (tp), &tp->remote_class->proxy_class->byval_arg);
5498 /* System.Environment */
5501 ves_icall_System_Environment_get_MachineName (void)
5503 #if defined (PLATFORM_WIN32)
5508 len = MAX_COMPUTERNAME_LENGTH + 1;
5509 buf = g_new (gunichar2, len);
5512 if (GetComputerName (buf, (PDWORD) &len))
5513 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
5521 if (gethostname (buf, sizeof (buf)) == 0)
5522 result = mono_string_new (mono_domain_get (), buf);
5531 ves_icall_System_Environment_get_Platform (void)
5533 MONO_ARCH_SAVE_REGS;
5535 #if defined (PLATFORM_WIN32)
5545 ves_icall_System_Environment_get_NewLine (void)
5547 MONO_ARCH_SAVE_REGS;
5549 #if defined (PLATFORM_WIN32)
5550 return mono_string_new (mono_domain_get (), "\r\n");
5552 return mono_string_new (mono_domain_get (), "\n");
5557 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
5562 MONO_ARCH_SAVE_REGS;
5567 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
5568 value = g_getenv (utf8_name);
5575 return mono_string_new (mono_domain_get (), value);
5579 * There is no standard way to get at environ.
5587 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
5595 MONO_ARCH_SAVE_REGS;
5598 for (e = environ; *e != 0; ++ e)
5601 domain = mono_domain_get ();
5602 names = mono_array_new (domain, mono_defaults.string_class, n);
5605 for (e = environ; *e != 0; ++ e) {
5606 parts = g_strsplit (*e, "=", 2);
5608 str = mono_string_new (domain, *parts);
5609 mono_array_setref (names, n, str);
5621 * If your platform lacks setenv/unsetenv, you must upgrade your glib.
5623 #if !GLIB_CHECK_VERSION(2,4,0)
5624 #define g_setenv(a,b,c) setenv(a,b,c)
5625 #define g_unsetenv(a) unsetenv(a)
5629 ves_icall_System_Environment_InternalSetEnvironmentVariable (MonoString *name, MonoString *value)
5631 #ifdef PLATFORM_WIN32
5632 gunichar2 *utf16_name, *utf16_value;
5634 gchar *utf8_name, *utf8_value;
5637 MONO_ARCH_SAVE_REGS;
5639 #ifdef PLATFORM_WIN32
5640 utf16_name = mono_string_to_utf16 (name);
5641 if ((value == NULL) || (mono_string_length (value) == 0) || (mono_string_chars (value)[0] == 0)) {
5642 SetEnvironmentVariable (utf16_name, NULL);
5643 g_free (utf16_name);
5647 utf16_value = mono_string_to_utf16 (value);
5649 SetEnvironmentVariable (utf16_name, utf16_value);
5651 g_free (utf16_name);
5652 g_free (utf16_value);
5654 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
5656 if ((value == NULL) || (mono_string_length (value) == 0) || (mono_string_chars (value)[0] == 0)) {
5657 g_unsetenv (utf8_name);
5662 utf8_value = mono_string_to_utf8 (value);
5663 g_setenv (utf8_name, utf8_value, TRUE);
5666 g_free (utf8_value);
5671 * Returns: the number of milliseconds elapsed since the system started.
5674 ves_icall_System_Environment_get_TickCount (void)
5676 return GetTickCount ();
5681 ves_icall_System_Environment_Exit (int result)
5683 MONO_ARCH_SAVE_REGS;
5685 mono_runtime_set_shutting_down ();
5687 /* Suspend all managed threads since the runtime is going away */
5688 mono_thread_suspend_all_other_threads ();
5690 mono_runtime_quit ();
5692 /* we may need to do some cleanup here... */
5697 ves_icall_System_Environment_GetGacPath (void)
5699 return mono_string_new (mono_domain_get (), mono_assembly_getrootdir ());
5703 ves_icall_System_Environment_GetWindowsFolderPath (int folder)
5705 #if defined (PLATFORM_WIN32)
5706 #ifndef CSIDL_FLAG_CREATE
5707 #define CSIDL_FLAG_CREATE 0x8000
5710 WCHAR path [MAX_PATH];
5711 /* Create directory if no existing */
5712 if (SUCCEEDED (SHGetFolderPathW (NULL, folder | CSIDL_FLAG_CREATE, NULL, 0, path))) {
5716 return mono_string_new_utf16 (mono_domain_get (), path, len);
5719 g_warning ("ves_icall_System_Environment_GetWindowsFolderPath should only be called on Windows!");
5721 return mono_string_new (mono_domain_get (), "");
5725 ves_icall_System_Environment_GetLogicalDrives (void)
5727 gunichar2 buf [128], *ptr, *dname;
5729 gint initial_size = 127, size = 128;
5732 MonoString *drivestr;
5733 MonoDomain *domain = mono_domain_get ();
5736 MONO_ARCH_SAVE_REGS;
5741 while (size > initial_size) {
5742 size = GetLogicalDriveStrings (initial_size, ptr);
5743 if (size > initial_size) {
5746 ptr = g_malloc0 ((size + 1) * sizeof (gunichar2));
5747 initial_size = size;
5761 result = mono_array_new (domain, mono_defaults.string_class, ndrives);
5766 while (*u16) { u16++; len ++; }
5767 drivestr = mono_string_new_utf16 (domain, dname, len);
5768 mono_array_setref (result, ndrives++, drivestr);
5779 ves_icall_System_Environment_InternalGetHome (void)
5781 MONO_ARCH_SAVE_REGS;
5783 return mono_string_new (mono_domain_get (), g_get_home_dir ());
5786 static const char *encodings [] = {
5788 "ascii", "us_ascii", "us", "ansi_x3.4_1968",
5789 "ansi_x3.4_1986", "cp367", "csascii", "ibm367",
5790 "iso_ir_6", "iso646_us", "iso_646.irv:1991",
5792 "utf_7", "csunicode11utf7", "unicode_1_1_utf_7",
5793 "unicode_2_0_utf_7", "x_unicode_1_1_utf_7",
5794 "x_unicode_2_0_utf_7",
5796 "utf_8", "unicode_1_1_utf_8", "unicode_2_0_utf_8",
5797 "x_unicode_1_1_utf_8", "x_unicode_2_0_utf_8",
5799 "utf_16", "UTF_16LE", "ucs_2", "unicode",
5802 "unicodefffe", "utf_16be",
5809 * Returns the internal codepage, if the value of "int_code_page" is
5810 * 1 at entry, and we can not compute a suitable code page number,
5811 * returns the code page as a string
5814 ves_icall_System_Text_Encoding_InternalCodePage (gint32 *int_code_page)
5819 char *codepage = NULL;
5821 int want_name = *int_code_page;
5824 *int_code_page = -1;
5825 MONO_ARCH_SAVE_REGS;
5827 g_get_charset (&cset);
5828 c = codepage = strdup (cset);
5829 for (c = codepage; *c; c++){
5830 if (isascii (*c) && isalpha (*c))
5835 /* g_print ("charset: %s\n", cset); */
5837 /* handle some common aliases */
5840 for (i = 0; p != 0; ){
5841 if ((gssize) p < 7){
5843 p = encodings [++i];
5846 if (strcmp (p, codepage) == 0){
5847 *int_code_page = code;
5850 p = encodings [++i];
5853 if (strstr (codepage, "utf_8") != NULL)
5854 *int_code_page |= 0x10000000;
5857 if (want_name && *int_code_page == -1)
5858 return mono_string_new (mono_domain_get (), cset);
5864 ves_icall_System_Environment_get_HasShutdownStarted (void)
5866 if (mono_runtime_is_shutting_down ())
5869 if (mono_domain_is_unloading (mono_domain_get ()))
5876 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
5877 MonoReflectionMethod *method,
5878 MonoArray *out_args)
5880 MONO_ARCH_SAVE_REGS;
5882 mono_message_init (mono_object_domain (this), this, method, out_args);
5886 ves_icall_IsTransparentProxy (MonoObject *proxy)
5888 MONO_ARCH_SAVE_REGS;
5893 if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
5900 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
5905 MONO_ARCH_SAVE_REGS;
5907 klass = mono_class_from_mono_type (type->type);
5908 vtable = mono_class_vtable (mono_domain_get (), klass);
5910 if (enable) vtable->remote = 1;
5911 else vtable->remote = 0;
5915 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType *type)
5920 MONO_ARCH_SAVE_REGS;
5922 domain = mono_object_domain (type);
5923 klass = mono_class_from_mono_type (type->type);
5925 if (klass->rank >= 1) {
5926 g_assert (klass->rank == 1);
5927 return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
5929 /* Bypass remoting object creation check */
5930 return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
5935 ves_icall_System_IO_get_temp_path (void)
5937 MONO_ARCH_SAVE_REGS;
5939 return mono_string_new (mono_domain_get (), g_get_tmp_dir ());
5943 ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
5945 MONO_ARCH_SAVE_REGS;
5947 return mono_compile_method (method);
5951 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
5956 MONO_ARCH_SAVE_REGS;
5958 path = g_build_path (G_DIR_SEPARATOR_S, mono_get_config_dir (), "mono", mono_get_runtime_info ()->framework_version, "machine.config", NULL);
5960 #if defined (PLATFORM_WIN32)
5961 /* Avoid mixing '/' and '\\' */
5964 for (i = strlen (path) - 1; i >= 0; i--)
5965 if (path [i] == '/')
5969 mcpath = mono_string_new (mono_domain_get (), path);
5976 ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
5981 MONO_ARCH_SAVE_REGS;
5983 path = g_path_get_dirname (mono_get_config_dir ());
5985 #if defined (PLATFORM_WIN32)
5986 /* Avoid mixing '/' and '\\' */
5989 for (i = strlen (path) - 1; i >= 0; i--)
5990 if (path [i] == '/')
5994 ipath = mono_string_new (mono_domain_get (), path);
6001 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
6003 #if defined (PLATFORM_WIN32)
6004 static void (*output_debug) (gunichar2 *);
6005 static gboolean tried_loading = FALSE;
6007 MONO_ARCH_SAVE_REGS;
6009 if (!tried_loading && output_debug == NULL) {
6012 tried_loading = TRUE;
6013 k32 = g_module_open ("kernel32", G_MODULE_BIND_LAZY);
6015 gchar *error = g_strdup (g_module_error ());
6016 g_warning ("Failed to load kernel32.dll: %s\n", error);
6021 g_module_symbol (k32, "OutputDebugStringW", (gpointer *) &output_debug);
6022 if (!output_debug) {
6023 gchar *error = g_strdup (g_module_error ());
6024 g_warning ("Failed to load OutputDebugStringW: %s\n", error);
6030 if (output_debug == NULL)
6033 output_debug (mono_string_chars (message));
6035 g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
6039 /* Only used for value types */
6041 ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
6046 MONO_ARCH_SAVE_REGS;
6048 domain = mono_object_domain (type);
6049 klass = mono_class_from_mono_type (type->type);
6051 if (mono_class_is_nullable (klass))
6052 /* No arguments -> null */
6055 return mono_object_new (domain, klass);
6058 static MonoReflectionMethod *
6059 ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
6061 MonoClass *klass, *parent;
6062 MonoMethod *method = m->method;
6063 MonoMethod *result = NULL;
6065 MONO_ARCH_SAVE_REGS;
6067 if (method->klass == NULL)
6070 if (!(method->flags & METHOD_ATTRIBUTE_VIRTUAL) ||
6071 MONO_CLASS_IS_INTERFACE (method->klass) ||
6072 method->flags & METHOD_ATTRIBUTE_NEW_SLOT)
6075 klass = method->klass;
6076 if (klass->generic_class)
6077 klass = klass->generic_class->container_class;
6079 /* At the end of the loop, klass points to the eldest class that has this virtual function slot. */
6080 for (parent = klass->parent; parent != NULL; parent = parent->parent) {
6081 mono_class_setup_vtable (parent);
6082 if (parent->vtable_size <= method->slot)
6087 if (klass == method->klass)
6090 result = klass->vtable [method->slot];
6091 if (result == NULL) {
6092 /* It is an abstract method */
6093 gpointer iter = NULL;
6094 while ((result = mono_class_get_methods (klass, &iter)))
6095 if (result->slot == method->slot)
6102 return mono_method_get_object (mono_domain_get (), result, NULL);
6106 mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
6108 MONO_ARCH_SAVE_REGS;
6110 iter->sig = *(MonoMethodSignature**)argsp;
6112 g_assert (iter->sig->sentinelpos <= iter->sig->param_count);
6113 g_assert (iter->sig->call_convention == MONO_CALL_VARARG);
6116 /* FIXME: it's not documented what start is exactly... */
6120 int i, align, arg_size;
6121 iter->args = argsp + sizeof (gpointer);
6122 #ifndef MONO_ARCH_REGPARMS
6123 for (i = 0; i < iter->sig->sentinelpos; ++i) {
6124 arg_size = mono_type_stack_size (iter->sig->params [i], &align);
6125 iter->args = (char*)iter->args + arg_size;
6129 iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
6131 /* g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos); */
6135 mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
6137 gint i, align, arg_size;
6139 MONO_ARCH_SAVE_REGS;
6141 i = iter->sig->sentinelpos + iter->next_arg;
6143 g_assert (i < iter->sig->param_count);
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;
6153 /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
6159 mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
6161 gint i, align, arg_size;
6163 MONO_ARCH_SAVE_REGS;
6165 i = iter->sig->sentinelpos + iter->next_arg;
6167 g_assert (i < iter->sig->param_count);
6169 while (i < iter->sig->param_count) {
6170 if (!mono_metadata_type_equal (type, iter->sig->params [i]))
6172 res.type = iter->sig->params [i];
6173 res.klass = mono_class_from_mono_type (res.type);
6174 /* FIXME: endianess issue... */
6175 res.value = iter->args;
6176 arg_size = mono_type_stack_size (res.type, &align);
6177 iter->args = (char*)iter->args + arg_size;
6179 /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
6182 /* g_print ("arg type 0x%02x not found\n", res.type->type); */
6191 mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
6194 MONO_ARCH_SAVE_REGS;
6196 i = iter->sig->sentinelpos + iter->next_arg;
6198 g_assert (i < iter->sig->param_count);
6200 return iter->sig->params [i];
6204 mono_TypedReference_ToObject (MonoTypedRef tref)
6206 MONO_ARCH_SAVE_REGS;
6208 if (MONO_TYPE_IS_REFERENCE (tref.type)) {
6209 MonoObject** objp = tref.value;
6213 return mono_value_box (mono_domain_get (), tref.klass, tref.value);
6217 mono_TypedReference_ToObjectInternal (MonoType *type, gpointer value, MonoClass *klass)
6219 MONO_ARCH_SAVE_REGS;
6221 if (MONO_TYPE_IS_REFERENCE (type)) {
6222 MonoObject** objp = value;
6226 return mono_value_box (mono_domain_get (), klass, value);
6230 prelink_method (MonoMethod *method)
6232 const char *exc_class, *exc_arg;
6233 if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
6235 mono_lookup_pinvoke_call (method, &exc_class, &exc_arg);
6237 mono_raise_exception(
6238 mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg ) );
6240 /* create the wrapper, too? */
6244 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod *method)
6246 MONO_ARCH_SAVE_REGS;
6247 prelink_method (method->method);
6251 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType *type)
6253 MonoClass *klass = mono_class_from_mono_type (type->type);
6255 gpointer iter = NULL;
6256 MONO_ARCH_SAVE_REGS;
6258 while ((m = mono_class_get_methods (klass, &iter)))
6262 /* These parameters are "readonly" in corlib/System/Char.cs */
6264 ves_icall_System_Char_GetDataTablePointers (guint8 const **category_data,
6265 guint8 const **numeric_data,
6266 gdouble const **numeric_data_values,
6267 guint16 const **to_lower_data_low,
6268 guint16 const **to_lower_data_high,
6269 guint16 const **to_upper_data_low,
6270 guint16 const **to_upper_data_high)
6272 *category_data = CategoryData;
6273 *numeric_data = NumericData;
6274 *numeric_data_values = NumericDataValues;
6275 *to_lower_data_low = ToLowerDataLow;
6276 *to_lower_data_high = ToLowerDataHigh;
6277 *to_upper_data_low = ToUpperDataLow;
6278 *to_upper_data_high = ToUpperDataHigh;
6282 ves_icall_MonoDebugger_GetMethodToken (MonoReflectionMethod *method)
6284 return method->method->token;
6288 custom_attrs_defined_internal (MonoObject *obj, MonoReflectionType *attr_type)
6290 MonoCustomAttrInfo *cinfo;
6293 cinfo = mono_reflection_get_custom_attrs_info (obj);
6296 found = mono_custom_attrs_has_attr (cinfo, mono_class_from_mono_type (attr_type->type));
6298 mono_custom_attrs_free (cinfo);
6303 custom_attrs_get_by_type (MonoObject *obj, MonoReflectionType *attr_type)
6305 return mono_reflection_get_custom_attrs_by_type (obj, attr_type ? mono_class_from_mono_type (attr_type->type) : NULL);
6309 GCHandle_CheckCurrentDomain (guint32 gchandle)
6311 return mono_gchandle_is_in_domain (gchandle, mono_domain_get ());
6315 ves_icall_Mono_Runtime_GetDisplayName (void)
6317 static const char display_name_str [] = "Mono " VERSION;
6318 MonoString *display_name = mono_string_new (mono_domain_get (), display_name_str);
6319 return display_name;
6324 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
6325 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
6326 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 62, 128, 128, 128, 63,
6327 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 128, 128, 128, 0, 128, 128,
6328 128, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
6329 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 128, 128, 128, 128, 128,
6330 128, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
6331 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
6335 base64_to_byte_array (gunichar2 *start, gint ilength, MonoBoolean allowWhitespaceOnly)
6340 gunichar2 last, prev_last;
6348 last = prev_last = 0;
6349 for (i = 0; i < ilength; i++) {
6351 if (c >= sizeof (dbase64)) {
6352 exc = mono_exception_from_name_msg (mono_get_corlib (),
6353 "System", "FormatException",
6354 "Invalid character found.");
6355 mono_raise_exception (exc);
6356 } else if (isspace (c)) {
6364 olength = ilength - ignored;
6366 if (allowWhitespaceOnly && olength == 0) {
6367 return mono_array_new (mono_domain_get (), mono_defaults.byte_class, 0);
6370 if ((olength & 3) != 0 || olength <= 0) {
6371 exc = mono_exception_from_name_msg (mono_get_corlib (), "System",
6372 "FormatException", "Invalid length.");
6373 mono_raise_exception (exc);
6376 olength = (olength * 3) / 4;
6380 if (prev_last == '=')
6383 result = mono_array_new (mono_domain_get (), mono_defaults.byte_class, olength);
6384 res_ptr = mono_array_addr (result, guchar, 0);
6385 for (i = 0; i < ilength; ) {
6388 for (k = 0; k < 4 && i < ilength;) {
6394 if (((b [k] = dbase64 [c]) & 0x80) != 0) {
6395 exc = mono_exception_from_name_msg (mono_get_corlib (),
6396 "System", "FormatException",
6397 "Invalid character found.");
6398 mono_raise_exception (exc);
6403 *res_ptr++ = (b [0] << 2) | (b [1] >> 4);
6405 *res_ptr++ = (b [1] << 4) | (b [2] >> 2);
6407 *res_ptr++ = (b [2] << 6) | b [3];
6409 while (i < ilength && isspace (start [i]))
6417 InternalFromBase64String (MonoString *str, MonoBoolean allowWhitespaceOnly)
6419 MONO_ARCH_SAVE_REGS;
6421 return base64_to_byte_array (mono_string_chars (str),
6422 mono_string_length (str), allowWhitespaceOnly);
6426 InternalFromBase64CharArray (MonoArray *input, gint offset, gint length)
6428 MONO_ARCH_SAVE_REGS;
6430 return base64_to_byte_array (mono_array_addr (input, gunichar2, offset),
6442 const IcallEntry *icalls;
6446 static const IcallEntry runtime_icalls [] = {
6447 {"GetDisplayName", ves_icall_Mono_Runtime_GetDisplayName}
6450 static const IcallEntry activator_icalls [] = {
6451 {"CreateInstanceInternal", ves_icall_System_Activator_CreateInstanceInternal}
6453 static const IcallEntry appdomain_icalls [] = {
6454 {"ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly},
6455 {"GetAssemblies", ves_icall_System_AppDomain_GetAssemblies},
6456 {"GetData", ves_icall_System_AppDomain_GetData},
6457 {"InternalGetContext", ves_icall_System_AppDomain_InternalGetContext},
6458 {"InternalGetDefaultContext", ves_icall_System_AppDomain_InternalGetDefaultContext},
6459 {"InternalGetProcessGuid", ves_icall_System_AppDomain_InternalGetProcessGuid},
6460 {"InternalIsFinalizingForUnload", ves_icall_System_AppDomain_InternalIsFinalizingForUnload},
6461 {"InternalPopDomainRef", ves_icall_System_AppDomain_InternalPopDomainRef},
6462 {"InternalPushDomainRef", ves_icall_System_AppDomain_InternalPushDomainRef},
6463 {"InternalPushDomainRefByID", ves_icall_System_AppDomain_InternalPushDomainRefByID},
6464 {"InternalSetContext", ves_icall_System_AppDomain_InternalSetContext},
6465 {"InternalSetDomain", ves_icall_System_AppDomain_InternalSetDomain},
6466 {"InternalSetDomainByID", ves_icall_System_AppDomain_InternalSetDomainByID},
6467 {"InternalUnload", ves_icall_System_AppDomain_InternalUnload},
6468 {"LoadAssembly", ves_icall_System_AppDomain_LoadAssembly},
6469 {"LoadAssemblyRaw", ves_icall_System_AppDomain_LoadAssemblyRaw},
6470 {"SetData", ves_icall_System_AppDomain_SetData},
6471 {"createDomain", ves_icall_System_AppDomain_createDomain},
6472 {"getCurDomain", ves_icall_System_AppDomain_getCurDomain},
6473 {"getFriendlyName", ves_icall_System_AppDomain_getFriendlyName},
6474 {"getRootDomain", ves_icall_System_AppDomain_getRootDomain},
6475 {"getSetup", ves_icall_System_AppDomain_getSetup}
6478 static const IcallEntry argiterator_icalls [] = {
6479 {"IntGetNextArg()", mono_ArgIterator_IntGetNextArg},
6480 {"IntGetNextArg(intptr)", mono_ArgIterator_IntGetNextArgT},
6481 {"IntGetNextArgType", mono_ArgIterator_IntGetNextArgType},
6482 {"Setup", mono_ArgIterator_Setup}
6485 static const IcallEntry array_icalls [] = {
6486 {"ClearInternal", ves_icall_System_Array_ClearInternal},
6487 {"Clone", mono_array_clone},
6488 {"CreateInstanceImpl", ves_icall_System_Array_CreateInstanceImpl},
6489 {"FastCopy", ves_icall_System_Array_FastCopy},
6490 {"GetLength", ves_icall_System_Array_GetLength},
6491 {"GetLowerBound", ves_icall_System_Array_GetLowerBound},
6492 {"GetRank", ves_icall_System_Array_GetRank},
6493 {"GetValue", ves_icall_System_Array_GetValue},
6494 {"GetValueImpl", ves_icall_System_Array_GetValueImpl},
6495 {"SetValue", ves_icall_System_Array_SetValue},
6496 {"SetValueImpl", ves_icall_System_Array_SetValueImpl}
6499 static const IcallEntry buffer_icalls [] = {
6500 {"BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal},
6501 {"ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal},
6502 {"GetByteInternal", ves_icall_System_Buffer_GetByteInternal},
6503 {"SetByteInternal", ves_icall_System_Buffer_SetByteInternal}
6506 static const IcallEntry char_icalls [] = {
6507 {"GetDataTablePointers", ves_icall_System_Char_GetDataTablePointers}
6510 static const IcallEntry defaultconf_icalls [] = {
6511 {"get_machine_config_path", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path}
6514 static const IcallEntry consoledriver_icalls [] = {
6515 {"GetTtySize", ves_icall_System_ConsoleDriver_GetTtySize },
6516 {"InternalKeyAvailable", ves_icall_System_ConsoleDriver_InternalKeyAvailable },
6517 {"Isatty", ves_icall_System_ConsoleDriver_Isatty },
6518 {"SetBreak", ves_icall_System_ConsoleDriver_SetBreak },
6519 {"SetEcho", ves_icall_System_ConsoleDriver_SetEcho },
6520 {"TtySetup", ves_icall_System_ConsoleDriver_TtySetup }
6523 static const IcallEntry convert_icalls [] = {
6524 {"InternalFromBase64CharArray", InternalFromBase64CharArray },
6525 {"InternalFromBase64String", InternalFromBase64String }
6528 static const IcallEntry timezone_icalls [] = {
6529 {"GetTimeZoneData", ves_icall_System_CurrentSystemTimeZone_GetTimeZoneData}
6532 static const IcallEntry datetime_icalls [] = {
6533 {"GetNow", ves_icall_System_DateTime_GetNow}
6536 #ifndef DISABLE_DECIMAL
6537 static const IcallEntry decimal_icalls [] = {
6538 {"decimal2Int64", mono_decimal2Int64},
6539 {"decimal2UInt64", mono_decimal2UInt64},
6540 {"decimal2double", mono_decimal2double},
6541 {"decimal2string", mono_decimal2string},
6542 {"decimalCompare", mono_decimalCompare},
6543 {"decimalDiv", mono_decimalDiv},
6544 {"decimalFloorAndTrunc", mono_decimalFloorAndTrunc},
6545 {"decimalIncr", mono_decimalIncr},
6546 {"decimalIntDiv", mono_decimalIntDiv},
6547 {"decimalMult", mono_decimalMult},
6548 {"decimalRound", mono_decimalRound},
6549 {"decimalSetExponent", mono_decimalSetExponent},
6550 {"double2decimal", mono_double2decimal}, /* FIXME: wrong signature. */
6551 {"string2decimal", mono_string2decimal}
6555 static const IcallEntry delegate_icalls [] = {
6556 {"CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal},
6557 {"FreeTrampoline", ves_icall_System_Delegate_FreeTrampoline}
6560 static const IcallEntry tracelist_icalls [] = {
6561 {"WriteWindowsDebugString", ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString}
6564 static const IcallEntry fileversion_icalls [] = {
6565 {"GetVersionInfo_internal(string)", ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal}
6568 static const IcallEntry process_icalls [] = {
6569 {"CreateProcess_internal(System.Diagnostics.ProcessStartInfo,intptr,intptr,intptr,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_CreateProcess_internal},
6570 {"ExitCode_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitCode_internal},
6571 {"ExitTime_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitTime_internal},
6572 {"GetModules_internal()", ves_icall_System_Diagnostics_Process_GetModules_internal},
6573 {"GetPid_internal()", ves_icall_System_Diagnostics_Process_GetPid_internal},
6574 {"GetProcess_internal(int)", ves_icall_System_Diagnostics_Process_GetProcess_internal},
6575 {"GetProcesses_internal()", ves_icall_System_Diagnostics_Process_GetProcesses_internal},
6576 {"GetWorkingSet_internal(intptr,int&,int&)", ves_icall_System_Diagnostics_Process_GetWorkingSet_internal},
6577 {"Kill_internal", ves_icall_System_Diagnostics_Process_Kill_internal},
6578 {"ProcessName_internal(intptr)", ves_icall_System_Diagnostics_Process_ProcessName_internal},
6579 {"Process_free_internal(intptr)", ves_icall_System_Diagnostics_Process_Process_free_internal},
6580 {"SetWorkingSet_internal(intptr,int,int,bool)", ves_icall_System_Diagnostics_Process_SetWorkingSet_internal},
6581 {"ShellExecuteEx_internal(System.Diagnostics.ProcessStartInfo,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal},
6582 {"StartTime_internal(intptr)", ves_icall_System_Diagnostics_Process_StartTime_internal},
6583 {"WaitForExit_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForExit_internal}
6586 static const IcallEntry double_icalls [] = {
6587 {"AssertEndianity", ves_icall_System_Double_AssertEndianity},
6588 {"ParseImpl", mono_double_ParseImpl}
6591 static const IcallEntry enum_icalls [] = {
6592 {"ToObject", ves_icall_System_Enum_ToObject},
6593 {"get_value", ves_icall_System_Enum_get_value}
6596 static const IcallEntry environment_icalls [] = {
6597 {"Exit", ves_icall_System_Environment_Exit},
6598 {"GetCommandLineArgs", mono_runtime_get_main_args},
6599 {"GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames},
6600 {"GetLogicalDrivesInternal", ves_icall_System_Environment_GetLogicalDrives },
6601 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
6602 {"GetOSVersionString", ves_icall_System_Environment_GetOSVersionString},
6603 {"GetWindowsFolderPath", ves_icall_System_Environment_GetWindowsFolderPath},
6604 {"InternalSetEnvironmentVariable", ves_icall_System_Environment_InternalSetEnvironmentVariable},
6605 {"get_ExitCode", mono_environment_exitcode_get},
6606 {"get_HasShutdownStarted", ves_icall_System_Environment_get_HasShutdownStarted},
6607 {"get_MachineName", ves_icall_System_Environment_get_MachineName},
6608 {"get_NewLine", ves_icall_System_Environment_get_NewLine},
6609 {"get_Platform", ves_icall_System_Environment_get_Platform},
6610 {"get_TickCount", ves_icall_System_Environment_get_TickCount},
6611 {"get_UserName", ves_icall_System_Environment_get_UserName},
6612 {"internalGetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable},
6613 {"internalGetGacPath", ves_icall_System_Environment_GetGacPath},
6614 {"internalGetHome", ves_icall_System_Environment_InternalGetHome},
6615 {"set_ExitCode", mono_environment_exitcode_set}
6618 static const IcallEntry cultureinfo_icalls [] = {
6619 {"construct_compareinfo(object,string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
6620 {"construct_datetime_format", ves_icall_System_Globalization_CultureInfo_construct_datetime_format},
6621 {"construct_internal_locale(string)", ves_icall_System_Globalization_CultureInfo_construct_internal_locale},
6622 {"construct_internal_locale_from_current_locale", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_current_locale},
6623 {"construct_internal_locale_from_lcid", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_lcid},
6624 {"construct_internal_locale_from_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name},
6625 {"construct_internal_locale_from_specific_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_specific_name},
6626 {"construct_number_format", ves_icall_System_Globalization_CultureInfo_construct_number_format},
6627 {"internal_get_cultures", ves_icall_System_Globalization_CultureInfo_internal_get_cultures},
6628 {"internal_is_lcid_neutral", ves_icall_System_Globalization_CultureInfo_internal_is_lcid_neutral}
6631 static const IcallEntry regioninfo_icalls [] = {
6632 {"construct_internal_region_from_lcid", ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_lcid},
6633 {"construct_internal_region_from_name", ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_name}
6636 static const IcallEntry compareinfo_icalls [] = {
6637 {"assign_sortkey(object,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_assign_sortkey},
6638 {"construct_compareinfo(string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
6639 {"free_internal_collator()", ves_icall_System_Globalization_CompareInfo_free_internal_collator},
6640 {"internal_compare(string,int,int,string,int,int,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_internal_compare},
6641 {"internal_index(string,int,int,char,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index_char},
6642 {"internal_index(string,int,int,string,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index}
6645 static const IcallEntry normalization_icalls [] = {
6646 {"load_normalization_resource(intptr&,intptr&,intptr&,intptr&,intptr&,intptr&)", load_normalization_resource}
6649 static const IcallEntry gc_icalls [] = {
6650 {"GetTotalMemory", ves_icall_System_GC_GetTotalMemory},
6651 {"InternalCollect", ves_icall_System_GC_InternalCollect},
6652 {"KeepAlive", ves_icall_System_GC_KeepAlive},
6653 {"ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize},
6654 {"SuppressFinalize", ves_icall_System_GC_SuppressFinalize},
6655 {"WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers}
6658 static const IcallEntry famwatcher_icalls [] = {
6659 {"InternalFAMNextEvent", ves_icall_System_IO_FAMW_InternalFAMNextEvent}
6662 static const IcallEntry inotifywatcher_icalls [] = {
6663 {"AddWatch", ves_icall_System_IO_InotifyWatcher_AddWatch},
6664 {"GetInotifyInstance", ves_icall_System_IO_InotifyWatcher_GetInotifyInstance},
6665 {"RemoveWatch", ves_icall_System_IO_InotifyWatcher_RemoveWatch}
6668 static const IcallEntry filewatcher_icalls [] = {
6669 {"InternalCloseDirectory", ves_icall_System_IO_FSW_CloseDirectory},
6670 {"InternalOpenDirectory", ves_icall_System_IO_FSW_OpenDirectory},
6671 {"InternalReadDirectoryChanges", ves_icall_System_IO_FSW_ReadDirectoryChanges},
6672 {"InternalSupportsFSW", ves_icall_System_IO_FSW_SupportsFSW}
6675 static const IcallEntry path_icalls [] = {
6676 {"get_temp_path", ves_icall_System_IO_get_temp_path}
6679 static const IcallEntry monoio_icalls [] = {
6680 {"Close(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Close},
6681 {"CopyFile(string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CopyFile},
6682 {"CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CreateDirectory},
6683 {"CreatePipe(intptr&,intptr&)", ves_icall_System_IO_MonoIO_CreatePipe},
6684 {"DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile},
6685 {"Flush(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush},
6686 {"GetCurrentDirectory(System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetCurrentDirectory},
6687 {"GetFileAttributes(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileAttributes},
6688 {"GetFileStat(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileStat},
6689 {"GetFileSystemEntries", ves_icall_System_IO_MonoIO_GetFileSystemEntries},
6690 {"GetFileType(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType},
6691 {"GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength},
6692 {"GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath},
6693 {"Lock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Lock},
6694 {"MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile},
6695 {"Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,System.IO.FileOptions,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open},
6696 {"Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read},
6697 {"RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory},
6698 {"Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek},
6699 {"SetCurrentDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetCurrentDirectory},
6700 {"SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes},
6701 {"SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime},
6702 {"SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength},
6703 {"Unlock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Unlock},
6704 {"Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write},
6705 {"get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar},
6706 {"get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError},
6707 {"get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput},
6708 {"get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput},
6709 {"get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar},
6710 {"get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars},
6711 {"get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator},
6712 {"get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar}
6715 static const IcallEntry math_icalls [] = {
6716 {"Acos", ves_icall_System_Math_Acos},
6717 {"Asin", ves_icall_System_Math_Asin},
6718 {"Atan", ves_icall_System_Math_Atan},
6719 {"Atan2", ves_icall_System_Math_Atan2},
6720 {"Cos", ves_icall_System_Math_Cos},
6721 {"Cosh", ves_icall_System_Math_Cosh},
6722 {"Exp", ves_icall_System_Math_Exp},
6723 {"Floor", ves_icall_System_Math_Floor},
6724 {"Log", ves_icall_System_Math_Log},
6725 {"Log10", ves_icall_System_Math_Log10},
6726 {"Pow", ves_icall_System_Math_Pow},
6727 {"Round", ves_icall_System_Math_Round},
6728 {"Round2", ves_icall_System_Math_Round2},
6729 {"Sin", ves_icall_System_Math_Sin},
6730 {"Sinh", ves_icall_System_Math_Sinh},
6731 {"Sqrt", ves_icall_System_Math_Sqrt},
6732 {"Tan", ves_icall_System_Math_Tan},
6733 {"Tanh", ves_icall_System_Math_Tanh}
6736 static const IcallEntry customattrs_icalls [] = {
6737 {"GetCustomAttributesDataInternal", mono_reflection_get_custom_attrs_data},
6738 {"GetCustomAttributesInternal", custom_attrs_get_by_type},
6739 {"IsDefinedInternal", custom_attrs_defined_internal}
6742 static const IcallEntry enuminfo_icalls [] = {
6743 {"get_enum_info", ves_icall_get_enum_info}
6746 static const IcallEntry fieldinfo_icalls [] = {
6747 {"GetUnmanagedMarshal", ves_icall_System_Reflection_FieldInfo_GetUnmanagedMarshal},
6748 {"internal_from_handle", ves_icall_System_Reflection_FieldInfo_internal_from_handle}
6751 static const IcallEntry memberinfo_icalls [] = {
6752 {"get_MetadataToken", mono_reflection_get_token}
6755 static const IcallEntry monotype_icalls [] = {
6756 {"GetArrayRank", ves_icall_MonoType_GetArrayRank},
6757 {"GetConstructors", ves_icall_Type_GetConstructors_internal},
6758 {"GetConstructors_internal", ves_icall_Type_GetConstructors_internal},
6759 {"GetCorrespondingInflatedConstructor", ves_icall_MonoType_GetCorrespondingInflatedMethod},
6760 {"GetCorrespondingInflatedMethod", ves_icall_MonoType_GetCorrespondingInflatedMethod},
6761 {"GetElementType", ves_icall_MonoType_GetElementType},
6762 {"GetEvents_internal", ves_icall_Type_GetEvents_internal},
6763 {"GetField", ves_icall_Type_GetField},
6764 {"GetFields_internal", ves_icall_Type_GetFields_internal},
6765 {"GetGenericArguments", ves_icall_MonoType_GetGenericArguments},
6766 {"GetInterfaces", ves_icall_Type_GetInterfaces},
6767 {"GetMethodsByName", ves_icall_Type_GetMethodsByName},
6768 {"GetNestedType", ves_icall_Type_GetNestedType},
6769 {"GetNestedTypes", ves_icall_Type_GetNestedTypes},
6770 {"GetPropertiesByName", ves_icall_Type_GetPropertiesByName},
6771 {"InternalGetEvent", ves_icall_MonoType_GetEvent},
6772 {"IsByRefImpl", ves_icall_type_isbyref},
6773 {"IsCOMObjectImpl", ves_icall_type_iscomobject},
6774 {"IsPointerImpl", ves_icall_type_ispointer},
6775 {"IsPrimitiveImpl", ves_icall_type_isprimitive},
6776 {"getFullName", ves_icall_System_MonoType_getFullName},
6777 {"get_Assembly", ves_icall_MonoType_get_Assembly},
6778 {"get_BaseType", ves_icall_get_type_parent},
6779 {"get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod},
6780 {"get_DeclaringType", ves_icall_MonoType_get_DeclaringType},
6781 {"get_IsGenericParameter", ves_icall_MonoType_get_IsGenericParameter},
6782 {"get_Module", ves_icall_MonoType_get_Module},
6783 {"get_Name", ves_icall_MonoType_get_Name},
6784 {"get_Namespace", ves_icall_MonoType_get_Namespace},
6785 {"get_UnderlyingSystemType", ves_icall_MonoType_get_UnderlyingSystemType},
6786 {"get_attributes", ves_icall_get_attributes},
6787 {"type_from_obj", mono_type_type_from_obj}
6790 static const IcallEntry assembly_icalls [] = {
6791 {"FillName", ves_icall_System_Reflection_Assembly_FillName},
6792 {"GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly},
6793 {"GetEntryAssembly", ves_icall_System_Reflection_Assembly_GetEntryAssembly},
6794 {"GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly},
6795 {"GetFilesInternal", ves_icall_System_Reflection_Assembly_GetFilesInternal},
6796 {"GetManifestResourceInfoInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal},
6797 {"GetManifestResourceInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInternal},
6798 {"GetManifestResourceNames", ves_icall_System_Reflection_Assembly_GetManifestResourceNames},
6799 {"GetModulesInternal", ves_icall_System_Reflection_Assembly_GetModulesInternal},
6800 {"GetNamespaces", ves_icall_System_Reflection_Assembly_GetNamespaces},
6801 {"GetReferencedAssemblies", ves_icall_System_Reflection_Assembly_GetReferencedAssemblies},
6802 {"GetTypes", ves_icall_System_Reflection_Assembly_GetTypes},
6803 {"InternalGetAssemblyName", ves_icall_System_Reflection_Assembly_InternalGetAssemblyName},
6804 {"InternalGetType", ves_icall_System_Reflection_Assembly_InternalGetType},
6805 {"InternalImageRuntimeVersion", ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion},
6806 {"LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom},
6807 {"LoadPermissions", ves_icall_System_Reflection_Assembly_LoadPermissions},
6809 * Private icalls for the Mono Debugger
6811 {"MonoDebugger_GetMethodToken", ves_icall_MonoDebugger_GetMethodToken},
6813 /* normal icalls again */
6814 {"get_EntryPoint", ves_icall_System_Reflection_Assembly_get_EntryPoint},
6815 {"get_ManifestModule", ves_icall_System_Reflection_Assembly_get_ManifestModule},
6816 {"get_ReflectionOnly", ves_icall_System_Reflection_Assembly_get_ReflectionOnly},
6817 {"get_code_base", ves_icall_System_Reflection_Assembly_get_code_base},
6818 {"get_global_assembly_cache", ves_icall_System_Reflection_Assembly_get_global_assembly_cache},
6819 {"get_location", ves_icall_System_Reflection_Assembly_get_location},
6820 {"load_with_partial_name", ves_icall_System_Reflection_Assembly_load_with_partial_name}
6823 static const IcallEntry assembly_name_icalls [] = {
6824 {"ParseName", ves_icall_System_Reflection_AssemblyName_ParseName}
6827 static const IcallEntry methodbase_icalls [] = {
6828 {"GetCurrentMethod", ves_icall_GetCurrentMethod},
6829 {"GetMethodBodyInternal", ves_icall_System_Reflection_MethodBase_GetMethodBodyInternal},
6830 {"GetMethodFromHandleInternal", ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternal}
6833 static const IcallEntry module_icalls [] = {
6834 {"Close", ves_icall_System_Reflection_Module_Close},
6835 {"GetGlobalType", ves_icall_System_Reflection_Module_GetGlobalType},
6836 {"GetGuidInternal", ves_icall_System_Reflection_Module_GetGuidInternal},
6837 {"GetPEKind", ves_icall_System_Reflection_Module_GetPEKind},
6838 {"InternalGetTypes", ves_icall_System_Reflection_Module_InternalGetTypes},
6839 {"ResolveFieldToken", ves_icall_System_Reflection_Module_ResolveFieldToken},
6840 {"ResolveMemberToken", ves_icall_System_Reflection_Module_ResolveMemberToken},
6841 {"ResolveMethodToken", ves_icall_System_Reflection_Module_ResolveMethodToken},
6842 {"ResolveStringToken", ves_icall_System_Reflection_Module_ResolveStringToken},
6843 {"ResolveTypeToken", ves_icall_System_Reflection_Module_ResolveTypeToken},
6844 {"get_MDStreamVersion", ves_icall_System_Reflection_Module_get_MDStreamVersion},
6845 {"get_MetadataToken", mono_reflection_get_token}
6848 static const IcallEntry monocmethod_icalls [] = {
6849 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
6850 {"InternalInvoke", ves_icall_InternalInvoke},
6853 static const IcallEntry monoeventinfo_icalls [] = {
6854 {"get_event_info", ves_icall_get_event_info}
6857 static const IcallEntry monofield_icalls [] = {
6858 {"GetFieldOffset", ves_icall_MonoField_GetFieldOffset},
6859 {"GetParentType", ves_icall_MonoField_GetParentType},
6860 {"GetValueInternal", ves_icall_MonoField_GetValueInternal},
6861 {"SetValueInternal", ves_icall_FieldInfo_SetValueInternal}
6864 static const IcallEntry monogenericclass_icalls [] = {
6865 {"GetConstructors_internal", ves_icall_MonoGenericClass_GetConstructors},
6866 {"GetCorrespondingInflatedConstructor", ves_icall_MonoGenericClass_GetCorrespondingInflatedConstructor},
6867 {"GetCorrespondingInflatedField", ves_icall_MonoGenericClass_GetCorrespondingInflatedField},
6868 {"GetCorrespondingInflatedMethod", ves_icall_MonoGenericClass_GetCorrespondingInflatedMethod},
6869 {"GetEvents_internal", ves_icall_MonoGenericClass_GetEvents},
6870 {"GetFields_internal", ves_icall_MonoGenericClass_GetFields},
6871 {"GetInterfaces_internal", ves_icall_MonoGenericClass_GetInterfaces},
6872 {"GetMethods_internal", ves_icall_MonoGenericClass_GetMethods},
6873 {"GetParentType", ves_icall_MonoGenericClass_GetParentType},
6874 {"GetProperties_internal", ves_icall_MonoGenericClass_GetProperties},
6875 {"initialize", mono_reflection_generic_class_initialize}
6878 static const IcallEntry monogenericmethod_icalls [] = {
6879 {"get_ReflectedType", ves_icall_MonoGenericMethod_get_ReflectedType}
6882 static const IcallEntry generictypeparambuilder_icalls [] = {
6883 {"initialize", mono_reflection_initialize_generic_parameter}
6886 static const IcallEntry monomethod_icalls [] = {
6887 {"GetDllImportAttribute", ves_icall_MonoMethod_GetDllImportAttribute},
6888 {"GetGenericArguments", ves_icall_MonoMethod_GetGenericArguments},
6889 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
6890 {"InternalInvoke", ves_icall_InternalInvoke},
6891 {"MakeGenericMethod_impl", mono_reflection_bind_generic_method_parameters},
6892 {"get_IsGenericMethod", ves_icall_MonoMethod_get_IsGenericMethod},
6893 {"get_IsGenericMethodDefinition", ves_icall_MonoMethod_get_IsGenericMethodDefinition},
6894 {"get_base_definition", ves_icall_MonoMethod_get_base_definition}
6897 static const IcallEntry monomethodinfo_icalls [] = {
6898 {"get_method_info", ves_icall_get_method_info},
6899 {"get_parameter_info", ves_icall_get_parameter_info},
6900 {"get_retval_marshal", ves_icall_System_MonoMethodInfo_get_retval_marshal}
6903 static const IcallEntry monopropertyinfo_icalls [] = {
6904 {"get_property_info", ves_icall_get_property_info}
6907 static const IcallEntry parameterinfo_icalls [] = {
6908 {"get_MetadataToken", mono_reflection_get_token}
6911 static const IcallEntry dns_icalls [] = {
6912 {"GetHostByAddr_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByAddr_internal},
6913 {"GetHostByName_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByName_internal},
6914 {"GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal}
6917 static const IcallEntry socket_icalls [] = {
6918 {"Accept_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Accept_internal},
6919 {"Available_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Available_internal},
6920 {"Bind_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Bind_internal},
6921 {"Blocking_internal(intptr,bool,int&)", ves_icall_System_Net_Sockets_Socket_Blocking_internal},
6922 {"Close_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Close_internal},
6923 {"Connect_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Connect_internal},
6924 {"GetSocketOption_arr_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,byte[]&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal},
6925 {"GetSocketOption_obj_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal},
6926 {"Listen_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_Listen_internal},
6927 {"LocalEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal},
6928 {"Poll_internal", ves_icall_System_Net_Sockets_Socket_Poll_internal},
6929 {"Receive_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Receive_internal},
6930 {"RecvFrom_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal},
6931 {"RemoteEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal},
6932 {"Select_internal(System.Net.Sockets.Socket[]&,int,int&)", ves_icall_System_Net_Sockets_Socket_Select_internal},
6933 {"SendTo_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_SendTo_internal},
6934 {"Send_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Send_internal},
6935 {"SetSocketOption_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object,byte[],int,int&)", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal},
6936 {"Shutdown_internal(intptr,System.Net.Sockets.SocketShutdown,int&)", ves_icall_System_Net_Sockets_Socket_Shutdown_internal},
6937 {"Socket_internal(System.Net.Sockets.AddressFamily,System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,int&)", ves_icall_System_Net_Sockets_Socket_Socket_internal},
6938 {"WSAIoctl(intptr,int,byte[],byte[],int&)", ves_icall_System_Net_Sockets_Socket_WSAIoctl}
6941 static const IcallEntry socketex_icalls [] = {
6942 {"WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal}
6945 static const IcallEntry object_icalls [] = {
6946 {"GetType", ves_icall_System_Object_GetType},
6947 {"InternalGetHashCode", mono_object_hash},
6948 {"MemberwiseClone", ves_icall_System_Object_MemberwiseClone},
6949 {"obj_address", ves_icall_System_Object_obj_address}
6952 static const IcallEntry assemblybuilder_icalls[] = {
6953 {"InternalAddModule", mono_image_load_module},
6954 {"basic_init", mono_image_basic_init}
6957 static const IcallEntry customattrbuilder_icalls [] = {
6958 {"GetBlob", mono_reflection_get_custom_attrs_blob}
6961 static const IcallEntry dynamicmethod_icalls [] = {
6962 {"create_dynamic_method", mono_reflection_create_dynamic_method}
6965 static const IcallEntry methodbuilder_icalls [] = {
6966 {"MakeGenericMethod", mono_reflection_bind_generic_method_parameters}
6969 static const IcallEntry modulebuilder_icalls [] = {
6970 {"WriteToFile", ves_icall_ModuleBuilder_WriteToFile},
6971 {"basic_init", mono_image_module_basic_init},
6972 {"build_metadata", ves_icall_ModuleBuilder_build_metadata},
6973 {"create_modified_type", ves_icall_ModuleBuilder_create_modified_type},
6974 {"getMethodToken", ves_icall_ModuleBuilder_getMethodToken},
6975 {"getToken", ves_icall_ModuleBuilder_getToken},
6976 {"getUSIndex", mono_image_insert_string}
6979 static const IcallEntry signaturehelper_icalls [] = {
6980 {"get_signature_field", mono_reflection_sighelper_get_signature_field},
6981 {"get_signature_local", mono_reflection_sighelper_get_signature_local}
6984 static const IcallEntry typebuilder_icalls [] = {
6985 {"create_generic_class", mono_reflection_create_generic_class},
6986 {"create_internal_class", mono_reflection_create_internal_class},
6987 {"create_runtime_class", mono_reflection_create_runtime_class},
6988 {"get_IsGenericParameter", ves_icall_TypeBuilder_get_IsGenericParameter},
6989 {"get_event_info", mono_reflection_event_builder_get_event_info},
6990 {"setup_generic_class", mono_reflection_setup_generic_class},
6991 {"setup_internal_class", mono_reflection_setup_internal_class}
6994 static const IcallEntry enumbuilder_icalls [] = {
6995 {"setup_enum_type", ves_icall_EnumBuilder_setup_enum_type}
6998 static const IcallEntry runtimehelpers_icalls [] = {
6999 {"GetObjectValue", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue},
7000 /* REMOVEME: no longer needed, just so we dont break things when not needed */
7001 {"GetOffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData},
7002 {"InitializeArray", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray},
7003 {"RunClassConstructor", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor},
7004 {"get_OffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData}
7007 static const IcallEntry gchandle_icalls [] = {
7008 {"CheckCurrentDomain", GCHandle_CheckCurrentDomain},
7009 {"FreeHandle", ves_icall_System_GCHandle_FreeHandle},
7010 {"GetAddrOfPinnedObject", ves_icall_System_GCHandle_GetAddrOfPinnedObject},
7011 {"GetTarget", ves_icall_System_GCHandle_GetTarget},
7012 {"GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle}
7015 static const IcallEntry marshal_icalls [] = {
7016 {"AddRef", ves_icall_System_Runtime_InteropServices_Marshal_AddRef},
7017 {"AllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem},
7018 {"AllocHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_AllocHGlobal},
7019 {"DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure},
7020 {"FreeBSTR", ves_icall_System_Runtime_InteropServices_Marshal_FreeBSTR},
7021 {"FreeCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem},
7022 {"FreeHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_FreeHGlobal},
7023 {"GetComSlotForMethodInfoInternal", ves_icall_System_Runtime_InteropServices_Marshal_GetComSlotForMethodInfoInternal},
7024 {"GetDelegateForFunctionPointerInternal", ves_icall_System_Runtime_InteropServices_Marshal_GetDelegateForFunctionPointerInternal},
7025 {"GetFunctionPointerForDelegateInternal", mono_delegate_to_ftnptr},
7026 {"GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error},
7027 {"OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf},
7028 {"Prelink", ves_icall_System_Runtime_InteropServices_Marshal_Prelink},
7029 {"PrelinkAll", ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll},
7030 {"PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
7031 {"PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
7032 {"PtrToStringAuto(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
7033 {"PtrToStringAuto(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
7034 {"PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR},
7035 {"PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni},
7036 {"PtrToStringUni(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len},
7037 {"PtrToStructure(intptr,System.Type)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type},
7038 {"PtrToStructure(intptr,object)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure},
7039 {"QueryInterface", ves_icall_System_Runtime_InteropServices_Marshal_QueryInterface},
7040 {"ReAllocHGlobal", mono_marshal_realloc},
7041 {"ReadByte", ves_icall_System_Runtime_InteropServices_Marshal_ReadByte},
7042 {"ReadInt16", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt16},
7043 {"ReadInt32", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt32},
7044 {"ReadInt64", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64},
7045 {"ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr},
7046 {"Release", ves_icall_System_Runtime_InteropServices_Marshal_Release},
7047 {"SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf},
7048 {"StringToBSTR", ves_icall_System_Runtime_InteropServices_Marshal_StringToBSTR},
7049 {"StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
7050 {"StringToHGlobalAuto", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
7051 {"StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni},
7052 {"StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr},
7053 {"UnsafeAddrOfPinnedArrayElement", ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement},
7054 {"WriteByte", ves_icall_System_Runtime_InteropServices_Marshal_WriteByte},
7055 {"WriteInt16", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt16},
7056 {"WriteInt32", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt32},
7057 {"WriteInt64", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt64},
7058 {"WriteIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_WriteIntPtr},
7059 {"copy_from_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged},
7060 {"copy_to_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged}
7063 static const IcallEntry activationservices_icalls [] = {
7064 {"AllocateUninitializedClassInstance", ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance},
7065 {"EnableProxyActivation", ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation}
7068 static const IcallEntry monomethodmessage_icalls [] = {
7069 {"InitMessage", ves_icall_MonoMethodMessage_InitMessage}
7072 static const IcallEntry realproxy_icalls [] = {
7073 {"InternalGetProxyType", ves_icall_Remoting_RealProxy_InternalGetProxyType},
7074 {"InternalGetTransparentProxy", ves_icall_Remoting_RealProxy_GetTransparentProxy}
7077 static const IcallEntry remotingservices_icalls [] = {
7078 {"InternalExecute", ves_icall_InternalExecute},
7079 {"IsTransparentProxy", ves_icall_IsTransparentProxy}
7082 static const IcallEntry rng_icalls [] = {
7083 {"RngClose", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose},
7084 {"RngGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes},
7085 {"RngInitialize", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize},
7086 {"RngOpen", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngOpen}
7089 static const IcallEntry methodhandle_icalls [] = {
7090 {"GetFunctionPointer", ves_icall_RuntimeMethod_GetFunctionPointer}
7093 static const IcallEntry string_icalls [] = {
7094 {".ctor(char*)", ves_icall_System_String_ctor_charp},
7095 {".ctor(char*,int,int)", ves_icall_System_String_ctor_charp_int_int},
7096 {".ctor(char,int)", ves_icall_System_String_ctor_char_int},
7097 {".ctor(char[])", ves_icall_System_String_ctor_chara},
7098 {".ctor(char[],int,int)", ves_icall_System_String_ctor_chara_int_int},
7099 {".ctor(sbyte*)", ves_icall_System_String_ctor_RedirectToCreateString},
7100 {".ctor(sbyte*,int,int)", ves_icall_System_String_ctor_RedirectToCreateString},
7101 {".ctor(sbyte*,int,int,System.Text.Encoding)", ves_icall_System_String_ctor_RedirectToCreateString},
7102 {"InternalAllocateStr", ves_icall_System_String_InternalAllocateStr},
7103 {"InternalCharCopy", ves_icall_System_String_InternalCharCopy},
7104 {"InternalCopyTo", ves_icall_System_String_InternalCopyTo},
7105 {"InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny},
7106 {"InternalInsert", ves_icall_System_String_InternalInsert},
7107 {"InternalIntern", ves_icall_System_String_InternalIntern},
7108 {"InternalIsInterned", ves_icall_System_String_InternalIsInterned},
7109 {"InternalJoin", ves_icall_System_String_InternalJoin},
7110 {"InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny},
7111 {"InternalPad", ves_icall_System_String_InternalPad},
7112 {"InternalRemove", ves_icall_System_String_InternalRemove},
7113 {"InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char},
7114 {"InternalReplace(string,string,System.Globalization.CompareInfo)", ves_icall_System_String_InternalReplace_Str_Comp},
7115 {"InternalSplit", ves_icall_System_String_InternalSplit},
7116 {"InternalStrcpy(string,int,char[])", ves_icall_System_String_InternalStrcpy_Chars},
7117 {"InternalStrcpy(string,int,char[],int,int)", ves_icall_System_String_InternalStrcpy_CharsN},
7118 {"InternalStrcpy(string,int,string)", ves_icall_System_String_InternalStrcpy_Str},
7119 {"InternalStrcpy(string,int,string,int,int)", ves_icall_System_String_InternalStrcpy_StrN},
7120 {"InternalTrim", ves_icall_System_String_InternalTrim},
7121 {"get_Chars", ves_icall_System_String_get_Chars}
7124 static const IcallEntry encoding_icalls [] = {
7125 {"InternalCodePage", ves_icall_System_Text_Encoding_InternalCodePage}
7128 static const IcallEntry monitor_icalls [] = {
7129 {"Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit},
7130 {"Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse},
7131 {"Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all},
7132 {"Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner},
7133 {"Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised},
7134 {"Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter},
7135 {"Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait}
7138 static const IcallEntry interlocked_icalls [] = {
7139 {"Add(int&,int)", ves_icall_System_Threading_Interlocked_Add_Int},
7140 {"Add(long&,long)", ves_icall_System_Threading_Interlocked_Add_Long},
7141 {"CompareExchange(T&,T,T)", ves_icall_System_Threading_Interlocked_CompareExchange_T},
7142 {"CompareExchange(double&,double,double)", ves_icall_System_Threading_Interlocked_CompareExchange_Double},
7143 {"CompareExchange(int&,int,int)", ves_icall_System_Threading_Interlocked_CompareExchange_Int},
7144 {"CompareExchange(intptr&,intptr,intptr)", ves_icall_System_Threading_Interlocked_CompareExchange_Object},
7145 {"CompareExchange(long&,long,long)", ves_icall_System_Threading_Interlocked_CompareExchange_Long},
7146 {"CompareExchange(object&,object,object)", ves_icall_System_Threading_Interlocked_CompareExchange_Object},
7147 {"CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single},
7148 {"Decrement(int&)", ves_icall_System_Threading_Interlocked_Decrement_Int},
7149 {"Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long},
7150 {"Exchange(T&,T)", ves_icall_System_Threading_Interlocked_Exchange_T},
7151 {"Exchange(double&,double)", ves_icall_System_Threading_Interlocked_Exchange_Double},
7152 {"Exchange(int&,int)", ves_icall_System_Threading_Interlocked_Exchange_Int},
7153 {"Exchange(intptr&,intptr)", ves_icall_System_Threading_Interlocked_Exchange_Object},
7154 {"Exchange(long&,long)", ves_icall_System_Threading_Interlocked_Exchange_Long},
7155 {"Exchange(object&,object)", ves_icall_System_Threading_Interlocked_Exchange_Object},
7156 {"Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single},
7157 {"Increment(int&)", ves_icall_System_Threading_Interlocked_Increment_Int},
7158 {"Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long},
7159 {"Read(long&)", ves_icall_System_Threading_Interlocked_Read_Long}
7162 static const IcallEntry mutex_icalls [] = {
7163 {"CreateMutex_internal(bool,string,bool&)", ves_icall_System_Threading_Mutex_CreateMutex_internal},
7164 {"OpenMutex_internal(string,System.Security.AccessControl.MutexRights,System.IO.MonoIOError&)", ves_icall_System_Threading_Mutex_OpenMutex_internal},
7165 {"ReleaseMutex_internal(intptr)", ves_icall_System_Threading_Mutex_ReleaseMutex_internal}
7168 static const IcallEntry semaphore_icalls [] = {
7169 {"CreateSemaphore_internal(int,int,string,bool&)", ves_icall_System_Threading_Semaphore_CreateSemaphore_internal},
7170 {"OpenSemaphore_internal(string,System.Security.AccessControl.SemaphoreRights,System.IO.MonoIOError&)", ves_icall_System_Threading_Semaphore_OpenSemaphore_internal},
7171 {"ReleaseSemaphore_internal(intptr,int,bool&)", ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal}
7174 static const IcallEntry nativeevents_icalls [] = {
7175 {"CloseEvent_internal", ves_icall_System_Threading_Events_CloseEvent_internal},
7176 {"CreateEvent_internal(bool,bool,string,bool&)", ves_icall_System_Threading_Events_CreateEvent_internal},
7177 {"OpenEvent_internal(string,System.Security.AccessControl.EventWaitHandleRights,System.IO.MonoIOError&)", ves_icall_System_Threading_Events_OpenEvent_internal},
7178 {"ResetEvent_internal", ves_icall_System_Threading_Events_ResetEvent_internal},
7179 {"SetEvent_internal", ves_icall_System_Threading_Events_SetEvent_internal}
7182 static const IcallEntry thread_icalls [] = {
7183 {"Abort_internal(object)", ves_icall_System_Threading_Thread_Abort},
7184 {"ClrState", ves_icall_System_Threading_Thread_ClrState},
7185 {"CurrentThread_internal", mono_thread_current},
7186 {"FreeLocalSlotValues", mono_thread_free_local_slot_values},
7187 {"GetCachedCurrentCulture", ves_icall_System_Threading_Thread_GetCachedCurrentCulture},
7188 {"GetCachedCurrentUICulture", ves_icall_System_Threading_Thread_GetCachedCurrentUICulture},
7189 {"GetDomainID", ves_icall_System_Threading_Thread_GetDomainID},
7190 {"GetName_internal", ves_icall_System_Threading_Thread_GetName_internal},
7191 {"GetSerializedCurrentCulture", ves_icall_System_Threading_Thread_GetSerializedCurrentCulture},
7192 {"GetSerializedCurrentUICulture", ves_icall_System_Threading_Thread_GetSerializedCurrentUICulture},
7193 {"GetState", ves_icall_System_Threading_Thread_GetState},
7194 {"Join_internal", ves_icall_System_Threading_Thread_Join_internal},
7195 {"MemoryBarrier", ves_icall_System_Threading_Thread_MemoryBarrier},
7196 {"ResetAbort_internal()", ves_icall_System_Threading_Thread_ResetAbort},
7197 {"Resume_internal()", ves_icall_System_Threading_Thread_Resume},
7198 {"SetCachedCurrentCulture", ves_icall_System_Threading_Thread_SetCachedCurrentCulture},
7199 {"SetCachedCurrentUICulture", ves_icall_System_Threading_Thread_SetCachedCurrentUICulture},
7200 {"SetName_internal", ves_icall_System_Threading_Thread_SetName_internal},
7201 {"SetSerializedCurrentCulture", ves_icall_System_Threading_Thread_SetSerializedCurrentCulture},
7202 {"SetSerializedCurrentUICulture", ves_icall_System_Threading_Thread_SetSerializedCurrentUICulture},
7203 {"SetState", ves_icall_System_Threading_Thread_SetState},
7204 {"Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal},
7205 {"Suspend_internal", ves_icall_System_Threading_Thread_Suspend},
7206 {"Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal},
7207 {"Thread_internal", ves_icall_System_Threading_Thread_Thread_internal},
7208 {"VolatileRead(byte&)", ves_icall_System_Threading_Thread_VolatileRead1},
7209 {"VolatileRead(double&)", ves_icall_System_Threading_Thread_VolatileRead8},
7210 {"VolatileRead(int&)", ves_icall_System_Threading_Thread_VolatileRead4},
7211 {"VolatileRead(int16&)", ves_icall_System_Threading_Thread_VolatileRead2},
7212 {"VolatileRead(intptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
7213 {"VolatileRead(long&)", ves_icall_System_Threading_Thread_VolatileRead8},
7214 {"VolatileRead(object&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
7215 {"VolatileRead(sbyte&)", ves_icall_System_Threading_Thread_VolatileRead1},
7216 {"VolatileRead(single&)", ves_icall_System_Threading_Thread_VolatileRead4},
7217 {"VolatileRead(uint&)", ves_icall_System_Threading_Thread_VolatileRead2},
7218 {"VolatileRead(uint16&)", ves_icall_System_Threading_Thread_VolatileRead2},
7219 {"VolatileRead(uintptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
7220 {"VolatileRead(ulong&)", ves_icall_System_Threading_Thread_VolatileRead8},
7221 {"VolatileWrite(byte&,byte)", ves_icall_System_Threading_Thread_VolatileWrite1},
7222 {"VolatileWrite(double&,double)", ves_icall_System_Threading_Thread_VolatileWrite8},
7223 {"VolatileWrite(int&,int)", ves_icall_System_Threading_Thread_VolatileWrite4},
7224 {"VolatileWrite(int16&,int16)", ves_icall_System_Threading_Thread_VolatileWrite2},
7225 {"VolatileWrite(intptr&,intptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
7226 {"VolatileWrite(long&,long)", ves_icall_System_Threading_Thread_VolatileWrite8},
7227 {"VolatileWrite(object&,object)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
7228 {"VolatileWrite(sbyte&,sbyte)", ves_icall_System_Threading_Thread_VolatileWrite1},
7229 {"VolatileWrite(single&,single)", ves_icall_System_Threading_Thread_VolatileWrite4},
7230 {"VolatileWrite(uint&,uint)", ves_icall_System_Threading_Thread_VolatileWrite2},
7231 {"VolatileWrite(uint16&,uint16)", ves_icall_System_Threading_Thread_VolatileWrite2},
7232 {"VolatileWrite(uintptr&,uintptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
7233 {"VolatileWrite(ulong&,ulong)", ves_icall_System_Threading_Thread_VolatileWrite8},
7234 {"current_lcid()", ves_icall_System_Threading_Thread_current_lcid}
7237 static const IcallEntry threadpool_icalls [] = {
7238 {"GetAvailableThreads", ves_icall_System_Threading_ThreadPool_GetAvailableThreads},
7239 {"GetMaxThreads", ves_icall_System_Threading_ThreadPool_GetMaxThreads},
7240 {"GetMinThreads", ves_icall_System_Threading_ThreadPool_GetMinThreads},
7241 {"SetMinThreads", ves_icall_System_Threading_ThreadPool_SetMinThreads}
7244 static const IcallEntry waithandle_icalls [] = {
7245 {"WaitAll_internal", ves_icall_System_Threading_WaitHandle_WaitAll_internal},
7246 {"WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny_internal},
7247 {"WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal}
7250 static const IcallEntry type_icalls [] = {
7251 {"Equals", ves_icall_type_Equals},
7252 {"GetGenericParameterAttributes", ves_icall_Type_GetGenericParameterAttributes},
7253 {"GetGenericParameterConstraints_impl", ves_icall_Type_GetGenericParameterConstraints},
7254 {"GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition},
7255 {"GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl},
7256 {"GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData},
7257 {"GetPacking", ves_icall_Type_GetPacking},
7258 {"GetTypeCode", ves_icall_type_GetTypeCodeInternal},
7259 {"GetTypeCodeInternal", ves_icall_type_GetTypeCodeInternal},
7260 {"IsArrayImpl", ves_icall_Type_IsArrayImpl},
7261 {"IsInstanceOfType", ves_icall_type_IsInstanceOfType},
7262 {"MakeGenericType", ves_icall_Type_MakeGenericType},
7263 {"MakePointerType", ves_icall_Type_MakePointerType},
7264 {"get_IsGenericInstance", ves_icall_Type_get_IsGenericInstance},
7265 {"get_IsGenericType", ves_icall_Type_get_IsGenericType},
7266 {"get_IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition},
7267 {"internal_from_handle", ves_icall_type_from_handle},
7268 {"internal_from_name", ves_icall_type_from_name},
7269 {"make_array_type", ves_icall_Type_make_array_type},
7270 {"make_byref_type", ves_icall_Type_make_byref_type},
7271 {"type_is_assignable_from", ves_icall_type_is_assignable_from},
7272 {"type_is_subtype_of", ves_icall_type_is_subtype_of}
7275 static const IcallEntry typedref_icalls [] = {
7276 {"ToObject", mono_TypedReference_ToObject},
7277 {"ToObjectInternal", mono_TypedReference_ToObjectInternal}
7280 static const IcallEntry valuetype_icalls [] = {
7281 {"InternalEquals", ves_icall_System_ValueType_Equals},
7282 {"InternalGetHashCode", ves_icall_System_ValueType_InternalGetHashCode}
7285 static const IcallEntry web_icalls [] = {
7286 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
7287 {"GetMachineInstallDirectory", ves_icall_System_Web_Util_ICalls_get_machine_install_dir}
7290 static const IcallEntry identity_icalls [] = {
7291 {"GetCurrentToken", ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken},
7292 {"GetTokenName", ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName},
7293 {"GetUserToken", ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken},
7294 {"_GetRoles", ves_icall_System_Security_Principal_WindowsIdentity_GetRoles}
7297 static const IcallEntry impersonation_icalls [] = {
7298 {"CloseToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_CloseToken},
7299 {"DuplicateToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_DuplicateToken},
7300 {"RevertToSelf", ves_icall_System_Security_Principal_WindowsImpersonationContext_RevertToSelf},
7301 {"SetCurrentToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_SetCurrentToken}
7304 static const IcallEntry principal_icalls [] = {
7305 {"IsMemberOfGroupId", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupId},
7306 {"IsMemberOfGroupName", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupName}
7309 static const IcallEntry keypair_icalls [] = {
7310 {"_CanSecure", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_CanSecure},
7311 {"_IsMachineProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsMachineProtected},
7312 {"_IsUserProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsUserProtected},
7313 {"_ProtectMachine", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectMachine},
7314 {"_ProtectUser", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectUser}
7317 static const IcallEntry evidence_icalls [] = {
7318 {"IsAuthenticodePresent", ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent}
7321 static const IcallEntry securitymanager_icalls [] = {
7322 {"GetLinkDemandSecurity", ves_icall_System_Security_SecurityManager_GetLinkDemandSecurity},
7323 {"get_CheckExecutionRights", ves_icall_System_Security_SecurityManager_get_CheckExecutionRights},
7324 {"get_SecurityEnabled", ves_icall_System_Security_SecurityManager_get_SecurityEnabled},
7325 {"set_CheckExecutionRights", ves_icall_System_Security_SecurityManager_set_CheckExecutionRights},
7326 {"set_SecurityEnabled", ves_icall_System_Security_SecurityManager_set_SecurityEnabled}
7329 static const IcallEntry generic_array_icalls [] = {
7330 {"GetGenericValueImpl", ves_icall_System_Array_InternalArray_GetGenericValueImpl}
7333 static const IcallEntry comobject_icalls [] = {
7334 {"CacheInterface", ves_icall_System_ComObject_CacheInterface},
7335 {"CreateRCW", ves_icall_System_ComObject_CreateRCW},
7336 {"Finalizer", ves_icall_System_ComObject_Finalizer},
7337 {"FindInterface", ves_icall_System_ComObject_FindInterface},
7338 {"GetIUnknown", ves_icall_System_ComObject_GetIUnknown},
7339 {"SetIUnknown", ves_icall_System_ComObject_SetIUnknown},
7343 static const IcallEntry array_icalls [] = {
7348 /* keep the entries all sorted */
7349 static const IcallMap icall_entries [] = {
7350 {"Mono.Globalization.Unicode.Normalization", normalization_icalls, G_N_ELEMENTS (normalization_icalls)},
7351 {"Mono.Runtime", runtime_icalls, G_N_ELEMENTS (runtime_icalls)},
7352 {"Mono.Security.Cryptography.KeyPairPersistence", keypair_icalls, G_N_ELEMENTS (keypair_icalls)},
7353 {"System.Activator", activator_icalls, G_N_ELEMENTS (activator_icalls)},
7354 {"System.AppDomain", appdomain_icalls, G_N_ELEMENTS (appdomain_icalls)},
7355 {"System.ArgIterator", argiterator_icalls, G_N_ELEMENTS (argiterator_icalls)},
7356 {"System.Array", array_icalls, G_N_ELEMENTS (array_icalls)},
7357 {"System.Array/InternalArray`1", generic_array_icalls, G_N_ELEMENTS (generic_array_icalls)},
7358 {"System.Buffer", buffer_icalls, G_N_ELEMENTS (buffer_icalls)},
7359 {"System.Char", char_icalls, G_N_ELEMENTS (char_icalls)},
7360 {"System.Configuration.DefaultConfig", defaultconf_icalls, G_N_ELEMENTS (defaultconf_icalls)},
7361 {"System.ConsoleDriver", consoledriver_icalls, G_N_ELEMENTS (consoledriver_icalls)},
7362 {"System.Convert", convert_icalls, G_N_ELEMENTS (convert_icalls)},
7363 {"System.CurrentSystemTimeZone", timezone_icalls, G_N_ELEMENTS (timezone_icalls)},
7364 {"System.DateTime", datetime_icalls, G_N_ELEMENTS (datetime_icalls)},
7365 #ifndef DISABLE_DECIMAL
7366 {"System.Decimal", decimal_icalls, G_N_ELEMENTS (decimal_icalls)},
7368 {"System.Delegate", delegate_icalls, G_N_ELEMENTS (delegate_icalls)},
7369 {"System.Diagnostics.DefaultTraceListener", tracelist_icalls, G_N_ELEMENTS (tracelist_icalls)},
7370 {"System.Diagnostics.FileVersionInfo", fileversion_icalls, G_N_ELEMENTS (fileversion_icalls)},
7371 {"System.Diagnostics.Process", process_icalls, G_N_ELEMENTS (process_icalls)},
7372 {"System.Double", double_icalls, G_N_ELEMENTS (double_icalls)},
7373 {"System.Enum", enum_icalls, G_N_ELEMENTS (enum_icalls)},
7374 {"System.Environment", environment_icalls, G_N_ELEMENTS (environment_icalls)},
7375 {"System.GC", gc_icalls, G_N_ELEMENTS (gc_icalls)},
7376 {"System.Globalization.CompareInfo", compareinfo_icalls, G_N_ELEMENTS (compareinfo_icalls)},
7377 {"System.Globalization.CultureInfo", cultureinfo_icalls, G_N_ELEMENTS (cultureinfo_icalls)},
7378 {"System.Globalization.RegionInfo", regioninfo_icalls, G_N_ELEMENTS (regioninfo_icalls)},
7379 {"System.IO.FAMWatcher", famwatcher_icalls, G_N_ELEMENTS (famwatcher_icalls)},
7380 {"System.IO.FileSystemWatcher", filewatcher_icalls, G_N_ELEMENTS (filewatcher_icalls)},
7381 {"System.IO.InotifyWatcher", inotifywatcher_icalls, G_N_ELEMENTS (inotifywatcher_icalls)},
7382 {"System.IO.MonoIO", monoio_icalls, G_N_ELEMENTS (monoio_icalls)},
7383 {"System.IO.Path", path_icalls, G_N_ELEMENTS (path_icalls)},
7384 {"System.Math", math_icalls, G_N_ELEMENTS (math_icalls)},
7385 {"System.MonoCustomAttrs", customattrs_icalls, G_N_ELEMENTS (customattrs_icalls)},
7386 {"System.MonoEnumInfo", enuminfo_icalls, G_N_ELEMENTS (enuminfo_icalls)},
7387 {"System.MonoType", monotype_icalls, G_N_ELEMENTS (monotype_icalls)},
7388 {"System.Net.Dns", dns_icalls, G_N_ELEMENTS (dns_icalls)},
7389 {"System.Net.Sockets.Socket", socket_icalls, G_N_ELEMENTS (socket_icalls)},
7390 {"System.Net.Sockets.SocketException", socketex_icalls, G_N_ELEMENTS (socketex_icalls)},
7391 {"System.Object", object_icalls, G_N_ELEMENTS (object_icalls)},
7392 {"System.Reflection.Assembly", assembly_icalls, G_N_ELEMENTS (assembly_icalls)},
7393 {"System.Reflection.AssemblyName", assembly_name_icalls, G_N_ELEMENTS (assembly_name_icalls)},
7394 {"System.Reflection.Emit.AssemblyBuilder", assemblybuilder_icalls, G_N_ELEMENTS (assemblybuilder_icalls)},
7395 {"System.Reflection.Emit.CustomAttributeBuilder", customattrbuilder_icalls, G_N_ELEMENTS (customattrbuilder_icalls)},
7396 {"System.Reflection.Emit.DynamicMethod", dynamicmethod_icalls, G_N_ELEMENTS (dynamicmethod_icalls)},
7397 {"System.Reflection.Emit.EnumBuilder", enumbuilder_icalls, G_N_ELEMENTS (enumbuilder_icalls)},
7398 {"System.Reflection.Emit.GenericTypeParameterBuilder", generictypeparambuilder_icalls, G_N_ELEMENTS (generictypeparambuilder_icalls)},
7399 {"System.Reflection.Emit.MethodBuilder", methodbuilder_icalls, G_N_ELEMENTS (methodbuilder_icalls)},
7400 {"System.Reflection.Emit.ModuleBuilder", modulebuilder_icalls, G_N_ELEMENTS (modulebuilder_icalls)},
7401 {"System.Reflection.Emit.SignatureHelper", signaturehelper_icalls, G_N_ELEMENTS (signaturehelper_icalls)},
7402 {"System.Reflection.Emit.TypeBuilder", typebuilder_icalls, G_N_ELEMENTS (typebuilder_icalls)},
7403 {"System.Reflection.FieldInfo", fieldinfo_icalls, G_N_ELEMENTS (fieldinfo_icalls)},
7404 {"System.Reflection.MemberInfo", memberinfo_icalls, G_N_ELEMENTS (memberinfo_icalls)},
7405 {"System.Reflection.MethodBase", methodbase_icalls, G_N_ELEMENTS (methodbase_icalls)},
7406 {"System.Reflection.Module", module_icalls, G_N_ELEMENTS (module_icalls)},
7407 {"System.Reflection.MonoCMethod", monocmethod_icalls, G_N_ELEMENTS (monocmethod_icalls)},
7408 {"System.Reflection.MonoEventInfo", monoeventinfo_icalls, G_N_ELEMENTS (monoeventinfo_icalls)},
7409 {"System.Reflection.MonoField", monofield_icalls, G_N_ELEMENTS (monofield_icalls)},
7410 {"System.Reflection.MonoGenericCMethod", monogenericmethod_icalls, G_N_ELEMENTS (monogenericmethod_icalls)},
7411 {"System.Reflection.MonoGenericClass", monogenericclass_icalls, G_N_ELEMENTS (monogenericclass_icalls)},
7412 {"System.Reflection.MonoGenericMethod", monogenericmethod_icalls, G_N_ELEMENTS (monogenericmethod_icalls)},
7413 {"System.Reflection.MonoMethod", monomethod_icalls, G_N_ELEMENTS (monomethod_icalls)},
7414 {"System.Reflection.MonoMethodInfo", monomethodinfo_icalls, G_N_ELEMENTS (monomethodinfo_icalls)},
7415 {"System.Reflection.MonoPropertyInfo", monopropertyinfo_icalls, G_N_ELEMENTS (monopropertyinfo_icalls)},
7416 {"System.Reflection.ParameterInfo", parameterinfo_icalls, G_N_ELEMENTS (parameterinfo_icalls)},
7417 {"System.Runtime.CompilerServices.RuntimeHelpers", runtimehelpers_icalls, G_N_ELEMENTS (runtimehelpers_icalls)},
7418 {"System.Runtime.InteropServices.GCHandle", gchandle_icalls, G_N_ELEMENTS (gchandle_icalls)},
7419 {"System.Runtime.InteropServices.Marshal", marshal_icalls, G_N_ELEMENTS (marshal_icalls)},
7420 {"System.Runtime.Remoting.Activation.ActivationServices", activationservices_icalls, G_N_ELEMENTS (activationservices_icalls)},
7421 {"System.Runtime.Remoting.Messaging.MonoMethodMessage", monomethodmessage_icalls, G_N_ELEMENTS (monomethodmessage_icalls)},
7422 {"System.Runtime.Remoting.Proxies.RealProxy", realproxy_icalls, G_N_ELEMENTS (realproxy_icalls)},
7423 {"System.Runtime.Remoting.RemotingServices", remotingservices_icalls, G_N_ELEMENTS (remotingservices_icalls)},
7424 {"System.RuntimeMethodHandle", methodhandle_icalls, G_N_ELEMENTS (methodhandle_icalls)},
7425 {"System.Security.Cryptography.RNGCryptoServiceProvider", rng_icalls, G_N_ELEMENTS (rng_icalls)},
7426 {"System.Security.Policy.Evidence", evidence_icalls, G_N_ELEMENTS (evidence_icalls)},
7427 {"System.Security.Principal.WindowsIdentity", identity_icalls, G_N_ELEMENTS (identity_icalls)},
7428 {"System.Security.Principal.WindowsImpersonationContext", impersonation_icalls, G_N_ELEMENTS (impersonation_icalls)},
7429 {"System.Security.Principal.WindowsPrincipal", principal_icalls, G_N_ELEMENTS (principal_icalls)},
7430 {"System.Security.SecurityManager", securitymanager_icalls, G_N_ELEMENTS (securitymanager_icalls)},
7431 {"System.String", string_icalls, G_N_ELEMENTS (string_icalls)},
7432 {"System.Text.Encoding", encoding_icalls, G_N_ELEMENTS (encoding_icalls)},
7433 {"System.Threading.Interlocked", interlocked_icalls, G_N_ELEMENTS (interlocked_icalls)},
7434 {"System.Threading.Monitor", monitor_icalls, G_N_ELEMENTS (monitor_icalls)},
7435 {"System.Threading.Mutex", mutex_icalls, G_N_ELEMENTS (mutex_icalls)},
7436 {"System.Threading.NativeEventCalls", nativeevents_icalls, G_N_ELEMENTS (nativeevents_icalls)},
7437 {"System.Threading.Semaphore", semaphore_icalls, G_N_ELEMENTS (semaphore_icalls)},
7438 {"System.Threading.Thread", thread_icalls, G_N_ELEMENTS (thread_icalls)},
7439 {"System.Threading.ThreadPool", threadpool_icalls, G_N_ELEMENTS (threadpool_icalls)},
7440 {"System.Threading.WaitHandle", waithandle_icalls, G_N_ELEMENTS (waithandle_icalls)},
7441 {"System.Type", type_icalls, G_N_ELEMENTS (type_icalls)},
7442 {"System.TypedReference", typedref_icalls, G_N_ELEMENTS (typedref_icalls)},
7443 {"System.ValueType", valuetype_icalls, G_N_ELEMENTS (valuetype_icalls)},
7444 {"System.Web.Util.ICalls", web_icalls, G_N_ELEMENTS (web_icalls)},
7445 {"System.__ComObject", comobject_icalls, G_N_ELEMENTS (comobject_icalls)}
7448 static GHashTable *icall_hash = NULL;
7449 static GHashTable *jit_icall_hash_name = NULL;
7450 static GHashTable *jit_icall_hash_addr = NULL;
7453 mono_icall_init (void)
7457 /* check that tables are sorted: disable in release */
7460 const IcallMap *imap;
7461 const IcallEntry *ientry;
7462 const char *prev_class = NULL;
7463 const char *prev_method;
7465 for (i = 0; i < G_N_ELEMENTS (icall_entries); ++i) {
7466 imap = &icall_entries [i];
7468 if (prev_class && strcmp (prev_class, imap->klass) >= 0)
7469 g_print ("class %s should come before class %s\n", imap->klass, prev_class);
7470 prev_class = imap->klass;
7471 for (j = 0; j < imap->size; ++j) {
7472 ientry = &imap->icalls [j];
7473 if (prev_method && strcmp (prev_method, ientry->method) >= 0)
7474 g_print ("method %s should come before method %s\n", ientry->method, prev_method);
7475 prev_method = ientry->method;
7480 icall_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
7484 mono_icall_cleanup (void)
7486 g_hash_table_destroy (icall_hash);
7487 g_hash_table_destroy (jit_icall_hash_name);
7488 g_hash_table_destroy (jit_icall_hash_addr);
7492 mono_add_internal_call (const char *name, gconstpointer method)
7494 mono_loader_lock ();
7496 g_hash_table_insert (icall_hash, g_strdup (name), (gpointer) method);
7498 mono_loader_unlock ();
7502 compare_class_imap (const void *key, const void *elem)
7504 const IcallMap* imap = (const IcallMap*)elem;
7505 return strcmp (key, imap->klass);
7508 static const IcallMap*
7509 find_class_icalls (const char *name)
7511 return (const IcallMap*) bsearch (name, icall_entries, G_N_ELEMENTS (icall_entries), sizeof (IcallMap), compare_class_imap);
7515 compare_method_imap (const void *key, const void *elem)
7517 const IcallEntry* ientry = (const IcallEntry*)elem;
7518 return strcmp (key, ientry->method);
7522 find_method_icall (const IcallMap *imap, const char *name)
7524 const IcallEntry *ientry = (const IcallEntry*) bsearch (name, imap->icalls, imap->size, sizeof (IcallEntry), compare_method_imap);
7526 return (void*)ientry->func;
7531 * we should probably export this as an helper (handle nested types).
7532 * Returns the number of chars written in buf.
7535 concat_class_name (char *buf, int bufsize, MonoClass *klass)
7537 int nspacelen, cnamelen;
7538 nspacelen = strlen (klass->name_space);
7539 cnamelen = strlen (klass->name);
7540 if (nspacelen + cnamelen + 2 > bufsize)
7543 memcpy (buf, klass->name_space, nspacelen);
7544 buf [nspacelen ++] = '.';
7546 memcpy (buf + nspacelen, klass->name, cnamelen);
7547 buf [nspacelen + cnamelen] = 0;
7548 return nspacelen + cnamelen;
7552 mono_lookup_internal_call (MonoMethod *method)
7557 int typelen = 0, mlen, siglen;
7559 const IcallMap *imap;
7561 g_assert (method != NULL);
7563 if (method->is_inflated)
7564 method = ((MonoMethodInflated *) method)->declaring;
7566 if (method->klass->nested_in) {
7567 int pos = concat_class_name (mname, sizeof (mname)-2, method->klass->nested_in);
7571 mname [pos++] = '/';
7574 typelen = concat_class_name (mname+pos, sizeof (mname)-pos-1, method->klass);
7580 typelen = concat_class_name (mname, sizeof (mname), method->klass);
7585 imap = find_class_icalls (mname);
7587 mname [typelen] = ':';
7588 mname [typelen + 1] = ':';
7590 mlen = strlen (method->name);
7591 memcpy (mname + typelen + 2, method->name, mlen);
7592 sigstart = mname + typelen + 2 + mlen;
7595 tmpsig = mono_signature_get_desc (mono_method_signature (method), TRUE);
7596 siglen = strlen (tmpsig);
7597 if (typelen + mlen + siglen + 6 > sizeof (mname))
7600 memcpy (sigstart + 1, tmpsig, siglen);
7601 sigstart [siglen + 1] = ')';
7602 sigstart [siglen + 2] = 0;
7605 mono_loader_lock ();
7607 res = g_hash_table_lookup (icall_hash, mname);
7609 mono_loader_unlock ();
7612 /* try without signature */
7614 res = g_hash_table_lookup (icall_hash, mname);
7616 mono_loader_unlock ();
7620 /* it wasn't found in the static call tables */
7622 mono_loader_unlock ();
7625 res = find_method_icall (imap, sigstart - mlen);
7627 mono_loader_unlock ();
7630 /* try _with_ signature */
7632 res = find_method_icall (imap, sigstart - mlen);
7634 mono_loader_unlock ();
7638 g_warning ("cant resolve internal call to \"%s\" (tested without signature also)", mname);
7639 g_print ("\nYour mono runtime and class libraries are out of sync.\n");
7640 g_print ("The out of sync library is: %s\n", method->klass->image->name);
7641 g_print ("\nWhen you update one from cvs you need to update, compile and install\nthe other too.\n");
7642 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");
7643 g_print ("If you see other errors or faults after this message they are probably related\n");
7644 g_print ("and you need to fix your mono install first.\n");
7646 mono_loader_unlock ();
7652 type_from_typename (char *typename)
7654 MonoClass *klass = NULL; /* assignment to shut GCC warning up */
7656 if (!strcmp (typename, "int"))
7657 klass = mono_defaults.int_class;
7658 else if (!strcmp (typename, "ptr"))
7659 klass = mono_defaults.int_class;
7660 else if (!strcmp (typename, "void"))
7661 klass = mono_defaults.void_class;
7662 else if (!strcmp (typename, "int32"))
7663 klass = mono_defaults.int32_class;
7664 else if (!strcmp (typename, "uint32"))
7665 klass = mono_defaults.uint32_class;
7666 else if (!strcmp (typename, "long"))
7667 klass = mono_defaults.int64_class;
7668 else if (!strcmp (typename, "ulong"))
7669 klass = mono_defaults.uint64_class;
7670 else if (!strcmp (typename, "float"))
7671 klass = mono_defaults.single_class;
7672 else if (!strcmp (typename, "double"))
7673 klass = mono_defaults.double_class;
7674 else if (!strcmp (typename, "object"))
7675 klass = mono_defaults.object_class;
7676 else if (!strcmp (typename, "obj"))
7677 klass = mono_defaults.object_class;
7680 g_assert_not_reached ();
7682 return &klass->byval_arg;
7685 MonoMethodSignature*
7686 mono_create_icall_signature (const char *sigstr)
7691 MonoMethodSignature *res;
7693 mono_loader_lock ();
7694 res = g_hash_table_lookup (mono_defaults.corlib->helper_signatures, sigstr);
7696 mono_loader_unlock ();
7700 parts = g_strsplit (sigstr, " ", 256);
7709 res = mono_metadata_signature_alloc (mono_defaults.corlib, len - 1);
7712 #ifdef PLATFORM_WIN32
7714 * Under windows, the default pinvoke calling convention is STDCALL but
7717 res->call_convention = MONO_CALL_C;
7720 res->ret = type_from_typename (parts [0]);
7721 for (i = 1; i < len; ++i) {
7722 res->params [i - 1] = type_from_typename (parts [i]);
7727 g_hash_table_insert (mono_defaults.corlib->helper_signatures, (gpointer)sigstr, res);
7729 mono_loader_unlock ();
7735 mono_find_jit_icall_by_name (const char *name)
7737 MonoJitICallInfo *info;
7738 g_assert (jit_icall_hash_name);
7740 mono_loader_lock ();
7741 info = g_hash_table_lookup (jit_icall_hash_name, name);
7742 mono_loader_unlock ();
7747 mono_find_jit_icall_by_addr (gconstpointer addr)
7749 MonoJitICallInfo *info;
7750 g_assert (jit_icall_hash_addr);
7752 mono_loader_lock ();
7753 info = g_hash_table_lookup (jit_icall_hash_addr, (gpointer)addr);
7754 mono_loader_unlock ();
7760 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper)
7762 mono_loader_lock ();
7763 g_hash_table_insert (jit_icall_hash_addr, (gpointer)wrapper, info);
7764 mono_loader_unlock ();
7768 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save)
7770 MonoJitICallInfo *info;
7775 mono_loader_lock ();
7777 if (!jit_icall_hash_name) {
7778 jit_icall_hash_name = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
7779 jit_icall_hash_addr = g_hash_table_new (NULL, NULL);
7782 if (g_hash_table_lookup (jit_icall_hash_name, name)) {
7783 g_warning ("jit icall already defined \"%s\"\n", name);
7784 g_assert_not_reached ();
7787 info = g_new0 (MonoJitICallInfo, 1);
7794 info->wrapper = func;
7796 info->wrapper = NULL;
7799 g_hash_table_insert (jit_icall_hash_name, (gpointer)info->name, info);
7800 g_hash_table_insert (jit_icall_hash_addr, (gpointer)func, info);
7802 mono_loader_unlock ();