5 * Dietmar Maurer (dietmar@ximian.com)
6 * Paolo Molaro (lupus@ximian.com)
7 * Patrik Torstensson (patrik.torstensson@labs2.com)
9 * (C) 2001 Ximian, Inc.
18 #if defined (PLATFORM_WIN32)
22 #include <mono/metadata/object.h>
23 #include <mono/metadata/threads.h>
24 #include <mono/metadata/reflection.h>
25 #include <mono/metadata/assembly.h>
26 #include <mono/metadata/tabledefs.h>
27 #include <mono/metadata/exception.h>
28 #include <mono/metadata/file-io.h>
29 #include <mono/metadata/socket-io.h>
30 #include <mono/metadata/mono-endian.h>
31 #include <mono/metadata/tokentype.h>
32 #include <mono/metadata/unicode.h>
33 #include <mono/metadata/appdomain.h>
34 #include <mono/metadata/marshal.h>
35 #include <mono/metadata/gc-internal.h>
36 #include <mono/metadata/rand.h>
37 #include <mono/metadata/sysmath.h>
38 #include <mono/metadata/string-icalls.h>
39 #include <mono/metadata/debug-mono-symfile.h>
40 #include <mono/metadata/process.h>
41 #include <mono/io-layer/io-layer.h>
42 #include <mono/utils/strtod.h>
44 #if defined (PLATFORM_WIN32)
50 mono_double_ToStringImpl (double value)
52 /* FIXME: Handle formats, etc. */
58 retVal = g_strdup_printf ("%.15g", value);
59 s = mono_string_new (mono_domain_get (), retVal);
65 * We expect a pointer to a char, not a string
68 mono_double_ParseImpl (char *ptr)
72 return bsd_strtod (ptr, NULL);
76 mono_float_ToStringImpl (float value)
80 return mono_double_ToStringImpl (value);
84 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
93 ao = (MonoArray *)this;
94 ac = (MonoClass *)ao->obj.vtable->klass;
96 esize = mono_array_element_size (ac);
97 ea = (gpointer*)((char*)ao->vector + (pos * esize));
99 if (ac->element_class->valuetype)
100 return mono_value_box (this->vtable->domain, ac->element_class, ea);
106 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
114 MONO_CHECK_ARG_NULL (idxs);
116 io = (MonoArray *)idxs;
117 ic = (MonoClass *)io->obj.vtable->klass;
119 ao = (MonoArray *)this;
120 ac = (MonoClass *)ao->obj.vtable->klass;
122 g_assert (ic->rank == 1);
123 if (io->bounds != NULL || io->max_length != ac->rank)
124 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
126 ind = (guint32 *)io->vector;
128 if (ao->bounds == NULL) {
129 if (*ind < 0 || *ind >= ao->max_length)
130 mono_raise_exception (mono_get_exception_index_out_of_range ());
132 return ves_icall_System_Array_GetValueImpl (this, *ind);
135 for (i = 0; i < ac->rank; i++)
136 if ((ind [i] < ao->bounds [i].lower_bound) ||
137 (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
138 mono_raise_exception (mono_get_exception_index_out_of_range ());
140 pos = ind [0] - ao->bounds [0].lower_bound;
141 for (i = 1; i < ac->rank; i++)
142 pos = pos*ao->bounds [i].length + ind [i] -
143 ao->bounds [i].lower_bound;
145 return ves_icall_System_Array_GetValueImpl (this, pos);
149 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
151 MonoClass *ac, *vc, *ec;
162 vc = value->vtable->klass;
166 ac = this->obj.vtable->klass;
167 ec = ac->element_class;
169 esize = mono_array_element_size (ac);
170 ea = (gpointer*)((char*)this->vector + (pos * esize));
171 va = (gpointer*)((char*)value + sizeof (MonoObject));
174 memset (ea, 0, esize);
178 #define NO_WIDENING_CONVERSION G_STMT_START{\
179 mono_raise_exception (mono_get_exception_argument ( \
180 "value", "not a widening conversion")); \
183 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
184 if (esize < vsize + (extra)) \
185 mono_raise_exception (mono_get_exception_argument ( \
186 "value", "not a widening conversion")); \
189 #define INVALID_CAST G_STMT_START{\
190 mono_raise_exception (mono_get_exception_invalid_cast ()); \
193 /* Check element (destination) type. */
194 switch (ec->byval_arg.type) {
195 case MONO_TYPE_STRING:
196 switch (vc->byval_arg.type) {
197 case MONO_TYPE_STRING:
203 case MONO_TYPE_BOOLEAN:
204 switch (vc->byval_arg.type) {
205 case MONO_TYPE_BOOLEAN:
218 NO_WIDENING_CONVERSION;
225 if (!ec->valuetype) {
226 *ea = (gpointer)value;
230 if (mono_object_isinst (value, ec)) {
231 memcpy (ea, (char *)value + sizeof (MonoObject), esize);
238 vsize = mono_class_instance_size (vc) - sizeof (MonoObject);
241 g_message (G_STRLOC ": %d (%d) <= %d (%d)",
242 ec->byval_arg.type, esize,
243 vc->byval_arg.type, vsize);
246 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
247 switch (vc->byval_arg.type) { \
252 case MONO_TYPE_CHAR: \
253 CHECK_WIDENING_CONVERSION(0); \
254 *(etype *) ea = (etype) u64; \
256 /* You can't assign a signed value to an unsigned array. */ \
261 /* You can't assign a floating point number to an integer array. */ \
264 NO_WIDENING_CONVERSION; \
268 #define ASSIGN_SIGNED(etype) G_STMT_START{\
269 switch (vc->byval_arg.type) { \
274 CHECK_WIDENING_CONVERSION(0); \
275 *(etype *) ea = (etype) i64; \
277 /* You can assign an unsigned value to a signed array if the array's */ \
278 /* element size is larger than the value size. */ \
283 case MONO_TYPE_CHAR: \
284 CHECK_WIDENING_CONVERSION(1); \
285 *(etype *) ea = (etype) u64; \
287 /* You can't assign a floating point number to an integer array. */ \
290 NO_WIDENING_CONVERSION; \
294 #define ASSIGN_REAL(etype) G_STMT_START{\
295 switch (vc->byval_arg.type) { \
298 CHECK_WIDENING_CONVERSION(0); \
299 *(etype *) ea = (etype) r64; \
301 /* All integer values fit into a floating point array, so we don't */ \
302 /* need to CHECK_WIDENING_CONVERSION here. */ \
307 *(etype *) ea = (etype) i64; \
313 case MONO_TYPE_CHAR: \
314 *(etype *) ea = (etype) u64; \
319 switch (vc->byval_arg.type) {
321 u64 = *(guint8 *) va;
324 u64 = *(guint16 *) va;
327 u64 = *(guint32 *) va;
330 u64 = *(guint64 *) va;
336 i64 = *(gint16 *) va;
339 i64 = *(gint32 *) va;
342 i64 = *(gint64 *) va;
345 r64 = *(gfloat *) va;
348 r64 = *(gdouble *) va;
351 u64 = *(guint16 *) va;
353 case MONO_TYPE_BOOLEAN:
354 /* Boolean is only compatible with itself. */
355 switch (ec->byval_arg.type) {
367 NO_WIDENING_CONVERSION;
374 /* If we can't do a direct copy, let's try a widening conversion. */
375 switch (ec->byval_arg.type) {
377 ASSIGN_UNSIGNED (guint16);
379 ASSIGN_UNSIGNED (guint8);
381 ASSIGN_UNSIGNED (guint16);
383 ASSIGN_UNSIGNED (guint32);
385 ASSIGN_UNSIGNED (guint64);
387 ASSIGN_SIGNED (gint8);
389 ASSIGN_SIGNED (gint16);
391 ASSIGN_SIGNED (gint32);
393 ASSIGN_SIGNED (gint64);
395 ASSIGN_REAL (gfloat);
397 ASSIGN_REAL (gdouble);
401 /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
405 #undef NO_WIDENING_CONVERSION
406 #undef CHECK_WIDENING_CONVERSION
407 #undef ASSIGN_UNSIGNED
413 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
421 MONO_CHECK_ARG_NULL (idxs);
423 ic = idxs->obj.vtable->klass;
424 ac = this->obj.vtable->klass;
426 g_assert (ic->rank == 1);
427 if (idxs->bounds != NULL || idxs->max_length != ac->rank)
428 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
430 ind = (guint32 *)idxs->vector;
432 if (this->bounds == NULL) {
433 if (*ind < 0 || *ind >= this->max_length)
434 mono_raise_exception (mono_get_exception_index_out_of_range ());
436 ves_icall_System_Array_SetValueImpl (this, value, *ind);
440 for (i = 0; i < ac->rank; i++)
441 if ((ind [i] < this->bounds [i].lower_bound) ||
442 (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
443 mono_raise_exception (mono_get_exception_index_out_of_range ());
445 pos = ind [0] - this->bounds [0].lower_bound;
446 for (i = 1; i < ac->rank; i++)
447 pos = pos * this->bounds [i].length + ind [i] -
448 this->bounds [i].lower_bound;
450 ves_icall_System_Array_SetValueImpl (this, value, pos);
454 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
462 MONO_CHECK_ARG_NULL (type);
463 MONO_CHECK_ARG_NULL (lengths);
465 MONO_CHECK_ARG (lengths, mono_array_length (lengths) > 0);
467 MONO_CHECK_ARG (bounds, mono_array_length (lengths) == mono_array_length (bounds));
469 for (i = 0; i < mono_array_length (lengths); i++)
470 if (mono_array_get (lengths, gint32, i) < 0)
471 mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
473 aklass = mono_array_class_get (type->type, mono_array_length (lengths));
475 sizes = alloca (aklass->rank * sizeof(guint32) * 2);
476 for (i = 0; i < aklass->rank; ++i) {
477 sizes [i] = mono_array_get (lengths, gint32, i);
479 sizes [i + aklass->rank] = mono_array_get (bounds, gint32, i);
481 sizes [i + aklass->rank] = 0;
484 array = mono_array_new_full (mono_object_domain (type), aklass, sizes, sizes + aklass->rank);
490 ves_icall_System_Array_GetRank (MonoObject *this)
494 return this->vtable->klass->rank;
498 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
500 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
504 if ((dimension < 0) || (dimension >= rank))
505 mono_raise_exception (mono_get_exception_index_out_of_range ());
507 if (this->bounds == NULL)
508 return this->max_length;
510 return this->bounds [dimension].length;
514 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
516 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
520 if ((dimension < 0) || (dimension >= rank))
521 mono_raise_exception (mono_get_exception_index_out_of_range ());
523 if (this->bounds == NULL)
526 return this->bounds [dimension].lower_bound;
530 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
532 int element_size = mono_array_element_size (source->obj.vtable->klass);
533 void * dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
534 void * source_addr = mono_array_addr_with_size (source, element_size, source_idx);
538 g_assert (dest_idx + length <= mono_array_length (dest));
539 g_assert (source_idx + length <= mono_array_length (source));
540 memmove (dest_addr, source_addr, element_size * length);
544 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArray *array, MonoClassField *field_handle)
546 MonoClass *klass = array->obj.vtable->klass;
547 guint32 size = mono_array_element_size (klass);
552 if (array->bounds == NULL)
553 size *= array->max_length;
555 for (i = 0; i < klass->rank; ++i)
556 size *= array->bounds [i].length;
558 memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
560 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
564 guint ## n *data = (guint ## n *) mono_array_addr (array, char, 0); \
566 for (i = 0; i < size; i += n/8, data++) { \
567 tmp = read ## n (data); \
572 /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
574 switch (klass->element_class->byval_arg.type) {
594 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
598 return offsetof (MonoString, chars);
602 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject *obj)
606 if ((obj == NULL) || (! (obj->vtable->klass->valuetype)))
609 return mono_object_clone (obj);
613 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
619 MONO_CHECK_ARG_NULL (handle);
621 klass = mono_class_from_mono_type (handle);
622 MONO_CHECK_ARG (handle, klass);
624 /* This will call the type constructor */
625 mono_class_vtable (mono_domain_get (), klass);
629 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
633 return mono_object_clone (this);
637 #define MONO_OBJECT_ALIGNMENT_SHIFT 3
639 #define MONO_OBJECT_ALIGNMENT_SHIFT 2
643 * Return hashcode based on object address. This function will need to be
644 * smarter in the presence of a moving garbage collector, which will cache
645 * the address hash before relocating the object.
647 * Wang's address-based hash function:
648 * http://www.concentric.net/~Ttwang/tech/addrhash.htm
651 ves_icall_System_Object_GetHashCode (MonoObject *this)
653 register guint32 key;
657 key = (GPOINTER_TO_UINT (this) >> MONO_OBJECT_ALIGNMENT_SHIFT) * 2654435761u;
659 return key & 0x7fffffff;
663 * A hash function for value types. I have no idea if this is a good hash
664 * function (its similar to g_str_hash).
667 ves_icall_System_ValueType_GetHashCode (MonoObject *this)
675 MONO_CHECK_ARG_NULL (this);
677 size = this->vtable->klass->instance_size - sizeof (MonoObject);
679 p = (const char *)this + sizeof (MonoObject);
681 for (i = 0; i < size; i++) {
682 h = (h << 5) - h + *p;
690 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that)
697 MONO_CHECK_ARG_NULL (that);
699 if (this->vtable != that->vtable)
702 size = this->vtable->klass->instance_size - sizeof (MonoObject);
704 p = (const char *)this + sizeof (MonoObject);
705 s = (const char *)that + sizeof (MonoObject);
707 return memcmp (p, s, size)? FALSE: TRUE;
710 static MonoReflectionType *
711 ves_icall_System_Object_GetType (MonoObject *obj)
715 return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
719 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
723 mtype->type = &obj->vtable->klass->byval_arg;
724 g_assert (mtype->type->type);
728 ves_icall_AssemblyBuilder_getToken (MonoReflectionAssemblyBuilder *assb, MonoObject *obj)
732 return mono_image_create_token (assb->dynamic_assembly, obj);
736 ves_icall_AssemblyBuilder_getDataChunk (MonoReflectionAssemblyBuilder *assb, MonoArray *buf, gint32 offset)
739 MonoDynamicAssembly *ass = assb->dynamic_assembly;
740 char *p = mono_array_addr (buf, char, 0);
744 mono_image_create_pefile (assb);
746 if (offset >= ass->pefile.index)
748 count = mono_array_length (buf);
749 count = MIN (count, ass->pefile.index - offset);
751 memcpy (p, ass->pefile.data + offset, count);
756 typedef struct getTypeInfo GetTypeInfo;
759 MonoTypeNameParse *info;
760 MonoBoolean ignoreCase;
764 try_get_type (gpointer key, gpointer value, gpointer user_data)
766 GetTypeInfo *gt_info = user_data;
767 MonoAssembly *assembly;
769 if (gt_info->type != NULL)
773 /* Weird, but the domain is locked and the assembly will not be freed */
774 memcpy (>_info->info->assembly, &assembly->aname, sizeof (MonoAssemblyName));
775 gt_info->type = mono_reflection_get_type (assembly->image,
777 gt_info->ignoreCase);
780 static MonoReflectionType*
781 ves_icall_type_from_name (MonoString *name,
782 MonoBoolean throwOnError,
783 MonoBoolean ignoreCase)
787 MonoAssembly *assembly = NULL;
788 MonoTypeNameParse info;
792 str = mono_string_to_utf8 (name);
793 if (!mono_reflection_parse_type (str, &info)) {
795 g_list_free (info.modifiers);
796 g_list_free (info.nested);
797 if (throwOnError) /* uhm: this is a parse error, though... */
798 mono_raise_exception (mono_get_exception_type_load ());
803 if (info.assembly.name) {
804 assembly = mono_assembly_load (&info.assembly, NULL, NULL);
808 g_list_free (info.modifiers);
809 g_list_free (info.nested);
811 mono_raise_exception (mono_get_exception_type_load ());
818 type = mono_reflection_get_type (assembly->image, &info, ignoreCase);
820 MonoDomain *domain = mono_domain_get ();
824 gt_info.info = &info;
825 gt_info.ignoreCase = ignoreCase;
827 mono_domain_lock (domain);
828 g_hash_table_foreach (domain->assemblies, try_get_type, >_info);
829 mono_domain_unlock (domain);
834 g_list_free (info.modifiers);
835 g_list_free (info.nested);
838 mono_raise_exception (mono_get_exception_type_load ());
843 return mono_type_get_object (mono_domain_get (), type);
846 static MonoReflectionType*
847 ves_icall_type_from_handle (MonoType *handle)
849 MonoDomain *domain = mono_domain_get ();
850 MonoClass *klass = mono_class_from_mono_type (handle);
854 mono_class_init (klass);
855 return mono_type_get_object (domain, handle);
859 ves_icall_type_Equals (MonoReflectionType *type, MonoReflectionType *c)
863 if (type->type && c->type)
864 return mono_metadata_type_equal (type->type, c->type);
865 g_print ("type equals\n");
869 /* System.TypeCode */
892 ves_icall_type_GetTypeCode (MonoReflectionType *type)
894 int t = type->type->type;
901 return TYPECODE_OBJECT;
902 case MONO_TYPE_BOOLEAN:
903 return TYPECODE_BOOLEAN;
905 return TYPECODE_BYTE;
907 return TYPECODE_SBYTE;
909 return TYPECODE_UINT16;
911 return TYPECODE_INT16;
913 return TYPECODE_CHAR;
917 return TYPECODE_OBJECT;
919 return TYPECODE_UINT32;
921 return TYPECODE_INT32;
923 return TYPECODE_UINT64;
925 return TYPECODE_INT64;
927 return TYPECODE_SINGLE;
929 return TYPECODE_DOUBLE;
930 case MONO_TYPE_VALUETYPE:
931 if (type->type->data.klass->enumtype) {
932 t = type->type->data.klass->enum_basetype->type;
935 MonoClass *k = type->type->data.klass;
936 if (strcmp (k->name_space, "System") == 0) {
937 if (strcmp (k->name, "Decimal") == 0)
938 return TYPECODE_DECIMAL;
939 else if (strcmp (k->name, "DateTime") == 0)
940 return TYPECODE_DATETIME;
941 else if (strcmp (k->name, "DBNull") == 0)
942 return TYPECODE_DBNULL;
945 /* handle datetime, dbnull.. */
946 return TYPECODE_OBJECT;
947 case MONO_TYPE_STRING:
948 return TYPECODE_STRING;
949 case MONO_TYPE_SZARRAY:
950 case MONO_TYPE_ARRAY:
951 case MONO_TYPE_OBJECT:
952 return TYPECODE_OBJECT;
953 case MONO_TYPE_CLASS:
954 return TYPECODE_OBJECT;
956 g_error ("type 0x%02x not handled in GetTypeCode()", t);
962 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
970 g_assert (type != NULL);
972 domain = ((MonoObject *)type)->vtable->domain;
974 if (!c) /* FIXME: dont know what do do here */
977 klass = mono_class_from_mono_type (type->type);
978 klassc = mono_class_from_mono_type (c->type);
980 /* cut&paste from mono_object_isinst (): keep in sync */
981 if (check_interfaces && (klassc->flags & TYPE_ATTRIBUTE_INTERFACE) && !(klass->flags & TYPE_ATTRIBUTE_INTERFACE)) {
982 MonoVTable *klass_vt = mono_class_vtable (domain, klass);
983 if ((klassc->interface_id <= klass->max_interface_id) &&
984 klass_vt->interface_offsets [klassc->interface_id])
986 } else if (check_interfaces && (klassc->flags & TYPE_ATTRIBUTE_INTERFACE) && (klass->flags & TYPE_ATTRIBUTE_INTERFACE)) {
989 for (i = 0; i < klass->interface_count; i ++) {
990 MonoClass *ic = klass->interfaces [i];
996 * klass->baseval is 0 for interfaces
998 if (klass->baseval && ((klass->baseval - klassc->baseval) <= klassc->diffval))
1005 ves_icall_get_attributes (MonoReflectionType *type)
1007 MonoClass *klass = mono_class_from_mono_type (type->type);
1009 MONO_ARCH_SAVE_REGS;
1011 return klass->flags;
1015 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
1017 MonoDomain *domain = mono_domain_get ();
1019 MONO_ARCH_SAVE_REGS;
1021 info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
1022 info->ret = mono_type_get_object (domain, method->signature->ret);
1023 info->attrs = method->flags;
1024 info->implattrs = method->iflags;
1028 ves_icall_get_parameter_info (MonoMethod *method)
1030 MonoDomain *domain = mono_domain_get ();
1032 static MonoClass *System_Reflection_ParameterInfo;
1033 MonoReflectionParameter** args;
1036 MONO_ARCH_SAVE_REGS;
1038 args = mono_param_get_objects (domain, method);
1039 if (!System_Reflection_ParameterInfo)
1040 System_Reflection_ParameterInfo = mono_class_from_name (
1041 mono_defaults.corlib, "System.Reflection", "ParameterInfo");
1042 res = mono_array_new (domain, System_Reflection_ParameterInfo, method->signature->param_count);
1043 for (i = 0; i < method->signature->param_count; ++i) {
1044 mono_array_set (res, gpointer, i, args [i]);
1050 ves_icall_get_field_info (MonoReflectionField *field, MonoFieldInfo *info)
1052 MonoDomain *domain = mono_object_domain (field);
1054 MONO_ARCH_SAVE_REGS;
1056 info->parent = mono_type_get_object (domain, &field->klass->byval_arg);
1057 info->type = mono_type_get_object (domain, field->field->type);
1058 info->name = mono_string_new (domain, field->field->name);
1059 info->attrs = field->field->type->attrs;
1063 ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *obj)
1066 MonoClassField *cf = field->field;
1069 MonoDomain *domain = mono_object_domain (field);
1071 gboolean is_static = FALSE;
1072 gboolean is_ref = FALSE;
1074 MONO_ARCH_SAVE_REGS;
1076 mono_class_init (field->klass);
1078 switch (cf->type->type) {
1079 case MONO_TYPE_STRING:
1080 case MONO_TYPE_OBJECT:
1081 case MONO_TYPE_CLASS:
1082 case MONO_TYPE_ARRAY:
1083 case MONO_TYPE_SZARRAY:
1088 case MONO_TYPE_BOOLEAN:
1091 case MONO_TYPE_CHAR:
1100 case MONO_TYPE_VALUETYPE:
1101 is_ref = cf->type->byref;
1104 g_error ("type 0x%x not handled in "
1105 "ves_icall_Monofield_GetValue", cf->type->type);
1109 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1111 vtable = mono_class_vtable (domain, field->klass);
1116 mono_field_static_get_value (vtable, cf, &o);
1118 mono_field_get_value (obj, cf, &o);
1123 /* boxed value type */
1124 klass = mono_class_from_mono_type (cf->type);
1125 o = mono_object_new (domain, klass);
1126 v = ((gchar *) o) + sizeof (MonoObject);
1128 mono_field_static_get_value (vtable, cf, v);
1130 mono_field_get_value (obj, cf, v);
1137 ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
1139 MonoClassField *cf = field->field;
1142 MONO_ARCH_SAVE_REGS;
1144 v = (gchar *) value;
1145 if (!cf->type->byref) {
1146 switch (cf->type->type) {
1149 case MONO_TYPE_BOOLEAN:
1152 case MONO_TYPE_CHAR:
1161 case MONO_TYPE_VALUETYPE:
1162 v += sizeof (MonoObject);
1164 case MONO_TYPE_STRING:
1165 case MONO_TYPE_OBJECT:
1166 case MONO_TYPE_CLASS:
1167 case MONO_TYPE_ARRAY:
1168 case MONO_TYPE_SZARRAY:
1172 g_error ("type 0x%x not handled in "
1173 "ves_icall_FieldInfo_SetValueInternal", cf->type->type);
1178 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1179 MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), field->klass);
1180 mono_field_static_set_value (vtable, cf, v);
1182 mono_field_set_value (obj, cf, v);
1187 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info)
1189 MonoDomain *domain = mono_object_domain (property);
1191 MONO_ARCH_SAVE_REGS;
1193 info->parent = mono_type_get_object (domain, &property->klass->byval_arg);
1194 info->name = mono_string_new (domain, property->property->name);
1195 info->attrs = property->property->attrs;
1196 info->get = property->property->get ? mono_method_get_object (domain, property->property->get, NULL): NULL;
1197 info->set = property->property->set ? mono_method_get_object (domain, property->property->set, NULL): NULL;
1199 * There may be other methods defined for properties, though, it seems they are not exposed
1200 * in the reflection API
1205 ves_icall_get_event_info (MonoReflectionEvent *event, MonoEventInfo *info)
1207 MonoDomain *domain = mono_object_domain (event);
1209 MONO_ARCH_SAVE_REGS;
1211 info->parent = mono_type_get_object (domain, &event->klass->byval_arg);
1212 info->name = mono_string_new (domain, event->event->name);
1213 info->attrs = event->event->attrs;
1214 info->add_method = event->event->add ? mono_method_get_object (domain, event->event->add, NULL): NULL;
1215 info->remove_method = event->event->remove ? mono_method_get_object (domain, event->event->remove, NULL): NULL;
1216 info->raise_method = event->event->raise ? mono_method_get_object (domain, event->event->raise, NULL): NULL;
1220 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
1222 MonoDomain *domain = mono_object_domain (type);
1225 MonoClass *class = mono_class_from_mono_type (type->type);
1228 MONO_ARCH_SAVE_REGS;
1231 for (parent = class; parent; parent = parent->parent) {
1232 ninterf += parent->interface_count;
1234 intf = mono_array_new (domain, mono_defaults.monotype_class, ninterf);
1236 for (parent = class; parent; parent = parent->parent) {
1237 for (i = 0; i < parent->interface_count; ++i) {
1238 mono_array_set (intf, gpointer, ninterf, mono_type_get_object (domain, &parent->interfaces [i]->byval_arg));
1246 ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
1248 MonoClass *class = mono_class_from_mono_type (type->type);
1249 MonoClass *iclass = mono_class_from_mono_type (iface->type);
1250 MonoReflectionMethod *member;
1251 int i, len, ioffset;
1254 MONO_ARCH_SAVE_REGS;
1256 /* type doesn't implement iface: the exception is thrown in managed code */
1257 if ((iclass->interface_id > class->max_interface_id) || !class->interface_offsets [iclass->interface_id])
1260 len = iclass->method.count;
1261 ioffset = class->interface_offsets [iclass->interface_id];
1262 domain = mono_object_domain (type);
1263 *targets = mono_array_new (domain, mono_defaults.method_info_class, len);
1264 *methods = mono_array_new (domain, mono_defaults.method_info_class, len);
1265 for (i = 0; i < len; ++i) {
1266 member = mono_method_get_object (domain, iclass->methods [i], iclass);
1267 mono_array_set (*methods, gpointer, i, member);
1268 member = mono_method_get_object (domain, class->vtable [i + ioffset], class);
1269 mono_array_set (*targets, gpointer, i, member);
1273 static MonoReflectionType*
1274 ves_icall_MonoType_GetElementType (MonoReflectionType *type)
1276 MonoClass *class = mono_class_from_mono_type (type->type);
1278 MONO_ARCH_SAVE_REGS;
1280 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1281 return mono_type_get_object (mono_object_domain (type), class->enum_basetype);
1282 else if (class->element_class)
1283 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1288 static MonoReflectionType*
1289 ves_icall_get_type_parent (MonoReflectionType *type)
1291 MonoClass *class = mono_class_from_mono_type (type->type);
1293 MONO_ARCH_SAVE_REGS;
1295 return class->parent ? mono_type_get_object (mono_object_domain (type), &class->parent->byval_arg): NULL;
1299 ves_icall_type_ispointer (MonoReflectionType *type)
1301 MONO_ARCH_SAVE_REGS;
1303 return type->type->type == MONO_TYPE_PTR;
1307 ves_icall_type_isbyref (MonoReflectionType *type)
1309 MONO_ARCH_SAVE_REGS;
1311 return type->type->byref;
1314 static MonoReflectionModule*
1315 ves_icall_MonoType_get_Module (MonoReflectionType *type)
1317 MonoClass *class = mono_class_from_mono_type (type->type);
1319 MONO_ARCH_SAVE_REGS;
1321 return mono_module_get_object (mono_object_domain (type), class->image);
1325 ves_icall_get_type_info (MonoType *type, MonoTypeInfo *info)
1327 MonoDomain *domain = mono_domain_get ();
1328 MonoClass *class = mono_class_from_mono_type (type);
1330 MONO_ARCH_SAVE_REGS;
1332 info->nested_in = class->nested_in ? mono_type_get_object (domain, &class->nested_in->byval_arg): NULL;
1333 info->name = mono_string_new (domain, class->name);
1334 info->name_space = mono_string_new (domain, class->name_space);
1335 info->rank = class->rank;
1336 info->assembly = mono_assembly_get_object (domain, class->image->assembly);
1337 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1338 info->etype = mono_type_get_object (domain, class->enum_basetype);
1339 else if (class->element_class)
1340 info->etype = mono_type_get_object (domain, &class->element_class->byval_arg);
1344 info->isprimitive = (type->type >= MONO_TYPE_BOOLEAN) && (type->type <= MONO_TYPE_R8);
1348 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
1351 * Invoke from reflection is supposed to always be a virtual call (the API
1352 * is stupid), mono_runtime_invoke_*() calls the provided method, allowing
1353 * greater flexibility.
1355 MonoMethod *m = method->method;
1358 MONO_ARCH_SAVE_REGS;
1361 if (!mono_object_isinst (this, m->klass))
1362 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
1363 m = mono_object_get_virtual_method (this, m);
1364 } else if (!(m->flags & METHOD_ATTRIBUTE_STATIC))
1365 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
1367 pcount = params? mono_array_length (params): 0;
1368 if (pcount != m->signature->param_count)
1369 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetParameterCountException"));
1371 return mono_runtime_invoke_array (m, this, params, NULL);
1375 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs)
1377 MonoDomain *domain = mono_object_domain (method);
1378 MonoMethod *m = method->method;
1379 MonoMethodSignature *sig = m->signature;
1380 MonoArray *out_args;
1382 int i, j, outarg_count = 0;
1384 MONO_ARCH_SAVE_REGS;
1386 if (m->klass == mono_defaults.object_class) {
1388 if (!strcmp (m->name, "FieldGetter")) {
1389 MonoClass *k = this->vtable->klass;
1390 MonoString *name = mono_array_get (params, MonoString *, 1);
1393 str = mono_string_to_utf8 (name);
1395 for (i = 0; i < k->field.count; i++) {
1396 if (!strcmp (k->fields [i].name, str)) {
1397 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
1398 if (field_klass->valuetype)
1399 result = mono_value_box (domain, field_klass,
1400 (char *)this + k->fields [i].offset);
1402 result = *((gpointer *)((char *)this + k->fields [i].offset));
1405 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
1406 *outArgs = out_args;
1407 mono_array_set (out_args, gpointer, 0, result);
1414 g_assert_not_reached ();
1416 } else if (!strcmp (m->name, "FieldSetter")) {
1417 MonoClass *k = this->vtable->klass;
1418 MonoString *name = mono_array_get (params, MonoString *, 1);
1422 str = mono_string_to_utf8 (name);
1424 for (i = 0; i < k->field.count; i++) {
1425 if (!strcmp (k->fields [i].name, str)) {
1426 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
1427 MonoObject *val = mono_array_get (params, gpointer, 2);
1429 if (field_klass->valuetype) {
1430 size = mono_type_size (k->fields [i].type, &align);
1431 memcpy ((char *)this + k->fields [i].offset,
1432 ((char *)val) + sizeof (MonoObject), size);
1434 *((gpointer *)this + k->fields [i].offset) = val;
1443 g_assert_not_reached ();
1448 for (i = 0; i < mono_array_length (params); i++) {
1449 if (sig->params [i]->byref)
1453 out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
1455 for (i = 0, j = 0; i < mono_array_length (params); i++) {
1456 if (sig->params [i]->byref) {
1458 arg = mono_array_get (params, gpointer, i);
1459 mono_array_set (out_args, gpointer, j, arg);
1464 /* fixme: handle constructors? */
1465 if (!strcmp (method->method->name, ".ctor"))
1466 g_assert_not_reached ();
1468 result = mono_runtime_invoke_array (method->method, this, params, NULL);
1470 *outArgs = out_args;
1476 ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
1479 MonoClass *enumc, *objc;
1483 MONO_ARCH_SAVE_REGS;
1485 MONO_CHECK_ARG_NULL (type);
1486 MONO_CHECK_ARG_NULL (obj);
1488 domain = mono_object_domain (type);
1489 enumc = mono_class_from_mono_type (type->type);
1490 objc = obj->vtable->klass;
1492 MONO_CHECK_ARG (obj, enumc->enumtype == TRUE);
1493 MONO_CHECK_ARG (obj, (objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 &&
1494 objc->byval_arg.type <= MONO_TYPE_U8));
1496 s1 = mono_class_value_size (enumc, NULL);
1497 s2 = mono_class_value_size (objc, NULL);
1499 res = mono_object_new (domain, enumc);
1501 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1502 memcpy ((char *)res + sizeof (MonoObject), (char *)obj + sizeof (MonoObject), MIN (s1, s2));
1504 memcpy ((char *)res + sizeof (MonoObject) + (s1 > s2 ? s1 - s2 : 0),
1505 (char *)obj + sizeof (MonoObject) + (s2 > s1 ? s2 - s1 : 0),
1512 ves_icall_System_Enum_get_value (MonoObject *this)
1520 MONO_ARCH_SAVE_REGS;
1525 g_assert (this->vtable->klass->enumtype);
1527 enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
1528 res = mono_object_new (mono_object_domain (this), enumc);
1529 dst = (char *)res + sizeof (MonoObject);
1530 src = (char *)this + sizeof (MonoObject);
1531 size = mono_class_value_size (enumc, NULL);
1533 memcpy (dst, src, size);
1539 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
1541 MonoDomain *domain = mono_object_domain (type);
1542 MonoClass *enumc = mono_class_from_mono_type (type->type);
1543 guint i, j, nvalues, crow;
1544 MonoClassField *field;
1546 MONO_ARCH_SAVE_REGS;
1548 info->utype = mono_type_get_object (domain, enumc->enum_basetype);
1549 nvalues = enumc->field.count - 1;
1550 info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
1551 info->values = mono_array_new (domain, enumc, nvalues);
1553 for (i = 0, j = 0; i < enumc->field.count; ++i) {
1554 field = &enumc->fields [i];
1555 if (strcmp ("value__", field->name) == 0)
1557 mono_array_set (info->names, gpointer, j, mono_string_new (domain, field->name));
1559 crow = mono_metadata_get_constant_index (enumc->image, MONO_TOKEN_FIELD_DEF | (i+enumc->field.first+1));
1560 crow = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_VALUE);
1561 /* 1 is the length of the blob */
1562 field->data = 1 + mono_metadata_blob_heap (enumc->image, crow);
1564 switch (enumc->enum_basetype->type) {
1567 mono_array_set (info->values, gchar, j, *field->data);
1569 case MONO_TYPE_CHAR:
1572 mono_array_set (info->values, gint16, j, read16 (field->data));
1576 mono_array_set (info->values, gint32, j, read32 (field->data));
1580 mono_array_set (info->values, gint64, j, read64 (field->data));
1583 g_error ("Implement type 0x%02x in get_enum_info", enumc->enum_basetype->type);
1590 BFLAGS_IgnoreCase = 1,
1591 BFLAGS_DeclaredOnly = 2,
1592 BFLAGS_Instance = 4,
1594 BFLAGS_Public = 0x10,
1595 BFLAGS_NonPublic = 0x20,
1596 BFLAGS_InvokeMethod = 0x100,
1597 BFLAGS_CreateInstance = 0x200,
1598 BFLAGS_GetField = 0x400,
1599 BFLAGS_SetField = 0x800,
1600 BFLAGS_GetProperty = 0x1000,
1601 BFLAGS_SetProperty = 0x2000,
1602 BFLAGS_ExactBinding = 0x10000,
1603 BFLAGS_SuppressChangeType = 0x20000,
1604 BFLAGS_OptionalParamBinding = 0x40000
1607 static MonoFieldInfo *
1608 ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
1611 MonoClass *startklass, *klass;
1613 MonoClassField *field;
1615 domain = ((MonoObject *)type)->vtable->domain;
1616 klass = startklass = mono_class_from_mono_type (type->type);
1618 MONO_ARCH_SAVE_REGS;
1624 for (i = 0; i < klass->field.count; ++i) {
1626 field = &klass->fields [i];
1627 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
1628 if (bflags & BFLAGS_Public)
1631 if (bflags & BFLAGS_NonPublic)
1637 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1638 if (bflags & BFLAGS_Static)
1641 if (bflags & BFLAGS_Instance)
1648 utf8_name = mono_string_to_utf8 (name);
1650 if (strcmp (field->name, utf8_name)) {
1656 return (MonoFieldInfo *)mono_field_get_object (domain, klass, field);
1658 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
1665 ves_icall_Type_GetFields (MonoReflectionType *type, guint32 bflags)
1668 GSList *l = NULL, *tmp;
1669 MonoClass *startklass, *klass;
1673 MonoClassField *field;
1675 MONO_ARCH_SAVE_REGS;
1677 domain = ((MonoObject *)type)->vtable->domain;
1678 klass = startklass = mono_class_from_mono_type (type->type);
1681 for (i = 0; i < klass->field.count; ++i) {
1683 field = &klass->fields [i];
1684 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
1685 if (bflags & BFLAGS_Public)
1688 if (bflags & BFLAGS_NonPublic)
1694 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1695 if (bflags & BFLAGS_Static)
1698 if (bflags & BFLAGS_Instance)
1704 member = (MonoObject*)mono_field_get_object (domain, klass, field);
1705 l = g_slist_prepend (l, member);
1707 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
1709 len = g_slist_length (l);
1710 res = mono_array_new (domain, mono_defaults.field_info_class, len);
1712 tmp = g_slist_reverse (l);
1713 for (; tmp; tmp = tmp->next, ++i)
1714 mono_array_set (res, gpointer, i, tmp->data);
1720 ves_icall_Type_GetMethods (MonoReflectionType *type, guint32 bflags)
1723 GSList *l = NULL, *tmp;
1724 MonoClass *startklass, *klass;
1729 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
1731 MONO_ARCH_SAVE_REGS;
1733 domain = ((MonoObject *)type)->vtable->domain;
1734 klass = startklass = mono_class_from_mono_type (type->type);
1738 for (i = 0; i < klass->method.count; ++i) {
1740 method = klass->methods [i];
1741 if (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0)
1743 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
1744 if (bflags & BFLAGS_Public)
1747 if (bflags & BFLAGS_NonPublic)
1753 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
1754 if (bflags & BFLAGS_Static)
1757 if (bflags & BFLAGS_Instance)
1764 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
1766 g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), method);
1767 member = (MonoObject*)mono_method_get_object (domain, method, startklass);
1769 l = g_slist_prepend (l, member);
1772 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
1774 res = mono_array_new (domain, mono_defaults.method_info_class, len);
1777 for (; tmp; tmp = tmp->next, ++i)
1778 mono_array_set (res, gpointer, i, tmp->data);
1780 g_hash_table_destroy (method_slots);
1785 ves_icall_Type_GetConstructors (MonoReflectionType *type, guint32 bflags)
1788 GSList *l = NULL, *tmp;
1789 static MonoClass *System_Reflection_ConstructorInfo;
1790 MonoClass *startklass, *klass;
1796 MONO_ARCH_SAVE_REGS;
1798 domain = ((MonoObject *)type)->vtable->domain;
1799 klass = startklass = mono_class_from_mono_type (type->type);
1801 for (i = 0; i < klass->method.count; ++i) {
1803 method = klass->methods [i];
1804 if (strcmp (method->name, ".ctor") && strcmp (method->name, ".cctor"))
1806 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
1807 if (bflags & BFLAGS_Public)
1810 if (bflags & BFLAGS_NonPublic)
1816 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
1817 if (bflags & BFLAGS_Static)
1820 if (bflags & BFLAGS_Instance)
1826 member = (MonoObject*)mono_method_get_object (domain, method, startklass);
1828 l = g_slist_prepend (l, member);
1830 len = g_slist_length (l);
1831 if (!System_Reflection_ConstructorInfo)
1832 System_Reflection_ConstructorInfo = mono_class_from_name (
1833 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
1834 res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
1836 tmp = g_slist_reverse (l);
1837 for (; tmp; tmp = tmp->next, ++i)
1838 mono_array_set (res, gpointer, i, tmp->data);
1844 ves_icall_Type_GetProperties (MonoReflectionType *type, guint32 bflags)
1847 GSList *l = NULL, *tmp;
1848 static MonoClass *System_Reflection_PropertyInfo;
1849 MonoClass *startklass, *klass;
1855 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
1857 MONO_ARCH_SAVE_REGS;
1859 domain = ((MonoObject *)type)->vtable->domain;
1860 klass = startklass = mono_class_from_mono_type (type->type);
1863 for (i = 0; i < klass->property.count; ++i) {
1864 prop = &klass->properties [i];
1869 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
1870 if (bflags & BFLAGS_Public)
1873 if (bflags & BFLAGS_NonPublic)
1879 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
1880 if (bflags & BFLAGS_Static)
1883 if (bflags & BFLAGS_Instance)
1891 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
1893 g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), prop);
1895 l = g_slist_prepend (l, mono_property_get_object (domain, klass, prop));
1898 if ((!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
1900 if (!System_Reflection_PropertyInfo)
1901 System_Reflection_PropertyInfo = mono_class_from_name (
1902 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
1903 res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
1906 for (; tmp; tmp = tmp->next, ++i)
1907 mono_array_set (res, gpointer, i, tmp->data);
1909 g_hash_table_destroy (method_slots);
1913 static MonoReflectionEvent *
1914 ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
1923 MONO_ARCH_SAVE_REGS;
1925 event_name = mono_string_to_utf8 (name);
1926 klass = mono_class_from_mono_type (type->type);
1927 domain = mono_object_domain (type);
1930 for (i = 0; i < klass->event.count; i++) {
1931 event = &klass->events [i];
1932 if (strcmp (event->name, event_name))
1935 method = event->add;
1937 method = event->remove;
1939 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
1940 if (!(bflags & BFLAGS_Public))
1943 if (!(bflags & BFLAGS_NonPublic))
1947 g_free (event_name);
1948 return mono_event_get_object (domain, klass, event);
1951 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
1954 g_free (event_name);
1959 ves_icall_Type_GetEvents (MonoReflectionType *type, guint32 bflags)
1962 GSList *l = NULL, *tmp;
1963 static MonoClass *System_Reflection_EventInfo;
1964 MonoClass *startklass, *klass;
1970 MONO_ARCH_SAVE_REGS;
1972 domain = ((MonoObject *)type)->vtable->domain;
1973 klass = startklass = mono_class_from_mono_type (type->type);
1976 for (i = 0; i < klass->event.count; ++i) {
1977 event = &klass->events [i];
1979 method = event->add;
1981 method = event->remove;
1982 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
1983 if (bflags & BFLAGS_Public)
1986 if (bflags & BFLAGS_NonPublic)
1992 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
1993 if (bflags & BFLAGS_Static)
1996 if (bflags & BFLAGS_Instance)
2003 l = g_slist_prepend (l, mono_event_get_object (domain, klass, event));
2005 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2007 len = g_slist_length (l);
2008 if (!System_Reflection_EventInfo)
2009 System_Reflection_EventInfo = mono_class_from_name (
2010 mono_defaults.corlib, "System.Reflection", "EventInfo");
2011 res = mono_array_new (domain, System_Reflection_EventInfo, len);
2014 for (; tmp; tmp = tmp->next, ++i)
2015 mono_array_set (res, gpointer, i, tmp->data);
2021 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
2024 GSList *l = NULL, *tmp;
2026 MonoClass *startklass, *klass;
2032 MONO_ARCH_SAVE_REGS;
2034 domain = ((MonoObject *)type)->vtable->domain;
2035 klass = startklass = mono_class_from_mono_type (type->type);
2037 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
2039 nested = tmpn->data;
2040 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
2041 if (bflags & BFLAGS_Public)
2044 if (bflags & BFLAGS_NonPublic)
2049 member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
2050 l = g_slist_prepend (l, member);
2052 len = g_slist_length (l);
2053 res = mono_array_new (domain, mono_defaults.monotype_class, len);
2055 tmp = g_slist_reverse (l);
2056 for (; tmp; tmp = tmp->next, ++i)
2057 mono_array_set (res, gpointer, i, tmp->data);
2062 static MonoReflectionType*
2063 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
2067 MonoTypeNameParse info;
2069 MONO_ARCH_SAVE_REGS;
2071 str = mono_string_to_utf8 (name);
2072 /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
2073 if (!mono_reflection_parse_type (str, &info)) {
2075 g_list_free (info.modifiers);
2076 g_list_free (info.nested);
2077 if (throwOnError) /* uhm: this is a parse error, though... */
2078 mono_raise_exception (mono_get_exception_type_load ());
2079 /*g_print ("failed parse\n");*/
2083 type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase);
2085 g_list_free (info.modifiers);
2086 g_list_free (info.nested);
2089 mono_raise_exception (mono_get_exception_type_load ());
2090 /* g_print ("failed find\n"); */
2093 /* g_print ("got it\n"); */
2094 return mono_type_get_object (mono_object_domain (assembly), type);
2099 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly)
2101 MonoDomain *domain = mono_object_domain (assembly);
2103 char *name = g_strconcat (
2104 "file://", assembly->assembly->image->name, NULL);
2106 MONO_ARCH_SAVE_REGS;
2108 res = mono_string_new (domain, name);
2114 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assembly)
2116 MonoDomain *domain = mono_object_domain (assembly);
2118 char *name = g_build_filename (
2119 assembly->assembly->basedir,
2120 assembly->assembly->image->module_name, NULL);
2122 MONO_ARCH_SAVE_REGS;
2124 res = mono_string_new (domain, name);
2129 static MonoReflectionMethod*
2130 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly)
2132 guint32 token = mono_image_get_entry_point (assembly->assembly->image);
2134 MONO_ARCH_SAVE_REGS;
2138 return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL), NULL);
2142 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly)
2144 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
2145 MonoArray *result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
2149 MONO_ARCH_SAVE_REGS;
2151 for (i = 0; i < table->rows; ++i) {
2152 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_MANIFEST_NAME));
2153 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), val));
2159 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly)
2161 static MonoClass *System_Reflection_AssemblyName;
2166 MONO_ARCH_SAVE_REGS;
2168 if (!System_Reflection_AssemblyName)
2169 System_Reflection_AssemblyName = mono_class_from_name (
2170 mono_defaults.corlib, "System.Reflection", "AssemblyName");
2172 for (ptr = assembly->assembly->image->references; ptr && *ptr; ptr++)
2175 result = mono_array_new (mono_object_domain (assembly), System_Reflection_AssemblyName, count);
2177 for (i = 0; i < count; i++) {
2178 MonoAssembly *assem = assembly->assembly->image->references [i];
2179 MonoReflectionAssemblyName *aname;
2181 aname = (MonoReflectionAssemblyName *) mono_object_new (
2182 mono_object_domain (assembly), System_Reflection_AssemblyName);
2184 if (strcmp (assem->aname.name, "corlib") == 0)
2185 aname->name = mono_string_new (mono_object_domain (assembly), "mscorlib");
2187 aname->name = mono_string_new (mono_object_domain (assembly), assem->aname.name);
2188 aname->major = assem->aname.major;
2190 mono_array_set (result, gpointer, i, aname);
2195 /* move this in some file in mono/util/ */
2197 g_concat_dir_and_file (const char *dir, const char *file)
2199 g_return_val_if_fail (dir != NULL, NULL);
2200 g_return_val_if_fail (file != NULL, NULL);
2203 * If the directory name doesn't have a / on the end, we need
2204 * to add one so we get a proper path to the file
2206 if (dir [strlen(dir) - 1] != G_DIR_SEPARATOR)
2207 return g_strconcat (dir, G_DIR_SEPARATOR_S, file, NULL);
2209 return g_strconcat (dir, file, NULL);
2213 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name)
2215 char *n = mono_string_to_utf8 (name);
2216 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
2218 guint32 cols [MONO_MANIFEST_SIZE];
2222 MONO_ARCH_SAVE_REGS;
2224 for (i = 0; i < table->rows; ++i) {
2225 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
2226 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
2227 if (strcmp (val, n) == 0)
2231 if (i == table->rows)
2234 if (!cols [MONO_MANIFEST_IMPLEMENTATION]) {
2237 val = mono_image_get_resource (assembly->assembly->image, cols [MONO_MANIFEST_OFFSET], &size);
2240 data = mono_array_new (mono_object_domain (assembly), mono_defaults.byte_class, size);
2241 memcpy (mono_array_addr (data, char, 0), val, size);
2242 return (MonoObject*)data;
2244 switch (cols [MONO_MANIFEST_IMPLEMENTATION] & IMPLEMENTATION_MASK) {
2245 case IMPLEMENTATION_FILE:
2246 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
2247 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
2248 i = mono_metadata_decode_row_col (table, i - 1, MONO_FILE_NAME);
2249 val = mono_metadata_string_heap (assembly->assembly->image, i);
2250 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
2251 result = (MonoObject*)mono_string_new (mono_object_domain (assembly), n);
2252 /* check hash if needed */
2255 case IMPLEMENTATION_ASSEMBLYREF:
2256 case IMPLEMENTATION_EXP_TYPE:
2264 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name)
2266 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
2272 MONO_ARCH_SAVE_REGS;
2274 /* check hash if needed */
2276 n = mono_string_to_utf8 (name);
2277 for (i = 0; i < table->rows; ++i) {
2278 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
2279 if (strcmp (val, n) == 0) {
2282 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
2283 fn = mono_string_new (mono_object_domain (assembly), n);
2285 return (MonoObject*)fn;
2292 for (i = 0; i < table->rows; ++i) {
2293 result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
2294 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
2295 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
2296 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), n));
2299 return (MonoObject*)result;
2302 static MonoReflectionMethod*
2303 ves_icall_GetCurrentMethod (void)
2305 MonoMethod *m = mono_method_get_last_managed ();
2307 MONO_ARCH_SAVE_REGS;
2309 return mono_method_get_object (mono_domain_get (), m, NULL);
2312 static MonoReflectionAssembly*
2313 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
2315 MonoMethod *m = mono_method_get_last_managed ();
2317 MONO_ARCH_SAVE_REGS;
2319 return mono_assembly_get_object (mono_domain_get (), m->klass->image->assembly);
2324 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
2326 MonoMethod **dest = data;
2328 /* skip unmanaged frames */
2343 static MonoReflectionAssembly*
2344 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
2346 MonoDomain* domain = mono_domain_get ();
2348 MONO_ARCH_SAVE_REGS;
2350 g_assert (domain->entry_assembly);
2351 return mono_assembly_get_object (domain, domain->entry_assembly);
2355 static MonoReflectionAssembly*
2356 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
2358 MonoMethod *m = mono_method_get_last_managed ();
2359 MonoMethod *dest = m;
2361 MONO_ARCH_SAVE_REGS;
2363 mono_stack_walk (get_caller, &dest);
2366 return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
2370 ves_icall_System_MonoType_getFullName (MonoReflectionType *object)
2372 MonoDomain *domain = mono_object_domain (object);
2376 MONO_ARCH_SAVE_REGS;
2378 name = mono_type_get_name (object->type);
2379 res = mono_string_new (domain, name);
2386 ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
2388 MonoAssemblyName *name = &assembly->assembly->aname;
2390 MONO_ARCH_SAVE_REGS;
2392 if (strcmp (name->name, "corlib") == 0)
2393 aname->name = mono_string_new (mono_object_domain (assembly), "mscorlib");
2395 aname->name = mono_string_new (mono_object_domain (assembly), name->name);
2397 aname->major = name->major;
2398 aname->minor = name->minor;
2399 aname->build = name->build;
2400 aname->revision = name->revision;
2404 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
2406 MonoDomain *domain = mono_object_domain (assembly);
2409 MonoTableInfo *tdef = &assembly->assembly->image->tables [MONO_TABLE_TYPEDEF];
2411 guint32 attrs, visibility;
2413 MONO_ARCH_SAVE_REGS;
2415 /* we start the count from 1 because we skip the special type <Module> */
2418 for (i = 1; i < tdef->rows; ++i) {
2419 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
2420 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
2421 if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
2425 count = tdef->rows - 1;
2427 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2429 for (i = 1; i < tdef->rows; ++i) {
2430 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
2431 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
2432 if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
2433 klass = mono_class_get (assembly->assembly->image, (i + 1) | MONO_TOKEN_TYPE_DEF);
2434 mono_array_set (res, gpointer, count, mono_type_get_object (domain, &klass->byval_arg));
2442 static MonoReflectionType*
2443 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
2446 int isbyref = 0, rank;
2447 char *str = mono_string_to_utf8 (smodifiers);
2450 MONO_ARCH_SAVE_REGS;
2452 klass = mono_class_from_mono_type (tb->type.type);
2454 /* logic taken from mono_reflection_parse_type(): keep in sync */
2458 if (isbyref) { /* only one level allowed by the spec */
2465 return mono_type_get_object (mono_object_domain (tb), &klass->this_arg);
2468 klass = mono_ptr_class_get (&klass->byval_arg);
2469 mono_class_init (klass);
2480 else if (*p != '*') { /* '*' means unknown lower bound */
2491 klass = mono_array_class_get (&klass->byval_arg, rank);
2492 mono_class_init (klass);
2499 return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
2503 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target,
2504 MonoReflectionMethod *info)
2506 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
2507 MonoObject *delegate;
2510 MONO_ARCH_SAVE_REGS;
2512 mono_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
2514 delegate = mono_object_new (mono_object_domain (type), delegate_class);
2516 func = mono_compile_method (info->method);
2518 mono_delegate_ctor (delegate, target, func);
2524 * Magic number to convert a time which is relative to
2525 * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
2527 #define EPOCH_ADJUST ((gint64)62135596800L)
2530 ves_icall_System_DateTime_GetNow (void)
2532 #ifdef PLATFORM_WIN32
2537 SystemTimeToFileTime (&st, &ft);
2538 return (gint64)504911232000000000L + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
2540 /* FIXME: put this in io-layer and call it GetLocalTime */
2544 MONO_ARCH_SAVE_REGS;
2546 if (gettimeofday (&tv, NULL) == 0) {
2547 res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
2550 /* fixme: raise exception */
2556 * This is heavily based on zdump.c from glibc 2.2.
2558 * * data[0]: start of daylight saving time (in DateTime ticks).
2559 * * data[1]: end of daylight saving time (in DateTime ticks).
2560 * * data[2]: utcoffset (in TimeSpan ticks).
2561 * * data[3]: additional offset when daylight saving (in TimeSpan ticks).
2562 * * name[0]: name of this timezone when not daylight saving.
2563 * * name[1]: name of this timezone when daylight saving.
2565 * FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
2566 * the class library allows years between 1 and 9999.
2568 * Returns true on success and zero on failure.
2571 ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
2573 #ifndef PLATFORM_WIN32
2574 MonoDomain *domain = mono_domain_get ();
2575 struct tm start, tt;
2579 int is_daylight = 0, day;
2581 MONO_ARCH_SAVE_REGS;
2583 memset (&start, 0, sizeof (start));
2586 start.tm_year = year-1900;
2588 t = mktime (&start);
2589 #if defined (HAVE_TIMEZONE)
2590 #define gmt_offset(x) (-1 * (((timezone / 60 / 60) - daylight) * 100))
2591 #elif defined (HAVE_TM_GMTOFF)
2592 #define gmt_offset(x) x.tm_gmtoff
2594 #error Neither HAVE_TIMEZONE nor HAVE_TM_GMTOFF defined. Rerun autoheader, autoconf, etc.
2597 gmtoff = gmt_offset (start);
2599 MONO_CHECK_ARG_NULL (data);
2600 MONO_CHECK_ARG_NULL (names);
2602 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
2603 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
2605 /* For each day of the year, calculate the tm_gmtoff. */
2606 for (day = 0; day < 365; day++) {
2609 tt = *localtime (&t);
2611 /* Daylight saving starts or ends here. */
2612 if (gmt_offset (tt) != gmtoff) {
2617 /* Try to find the exact hour when daylight saving starts/ends. */
2621 tt1 = *localtime (&t1);
2622 } while (gmt_offset (tt1) != gmtoff);
2624 /* Try to find the exact minute when daylight saving starts/ends. */
2627 tt1 = *localtime (&t1);
2628 } while (gmt_offset (tt1) == gmtoff);
2630 strftime (tzone, 10, "%Z", &tt);
2632 /* Write data, if we're already in daylight saving, we're done. */
2634 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
2635 mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
2638 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
2639 mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
2643 /* This is only set once when we enter daylight saving. */
2644 mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
2645 mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (tt) - gmtoff) * 10000000L);
2647 gmtoff = gmt_offset (tt);
2650 gmtoff = gmt_offset (tt);
2654 MonoDomain *domain = mono_domain_get ();
2655 TIME_ZONE_INFORMATION tz_info;
2659 GetTimeZoneInformation (&tz_info);
2661 MONO_CHECK_ARG_NULL (data);
2662 MONO_CHECK_ARG_NULL (names);
2664 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
2665 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
2667 for (i = 0; i < 32; ++i)
2668 if (!tz_info.DaylightName [i])
2670 mono_array_set ((*names), gpointer, 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
2671 for (i = 0; i < 32; ++i)
2672 if (!tz_info.StandardName [i])
2674 mono_array_set ((*names), gpointer, 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
2676 SystemTimeToFileTime (&tz_info.StandardDate, &ft);
2677 mono_array_set ((*data), gint64, 1, ((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime);
2678 SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
2679 mono_array_set ((*data), gint64, 0, ((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime);
2680 mono_array_set ((*data), gint64, 3, tz_info.Bias + tz_info.StandardBias);
2681 mono_array_set ((*data), gint64, 2, tz_info.Bias + tz_info.DaylightBias);
2688 ves_icall_System_Object_obj_address (MonoObject *this)
2690 MONO_ARCH_SAVE_REGS;
2698 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
2705 MONO_ARCH_SAVE_REGS;
2707 klass = array->obj.vtable->klass;
2708 etype = klass->element_class->byval_arg.type;
2709 if (etype < MONO_TYPE_BOOLEAN || etype > MONO_TYPE_R8)
2712 if (array->bounds == NULL)
2713 length = array->max_length;
2716 for (i = 0; i < klass->rank; ++ i)
2717 length += array->bounds [i].length;
2720 esize = mono_array_element_size (klass);
2721 return length * esize;
2725 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx)
2727 MONO_ARCH_SAVE_REGS;
2729 return mono_array_get (array, gint8, idx);
2733 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value)
2735 MONO_ARCH_SAVE_REGS;
2737 mono_array_set (array, gint8, idx, value);
2741 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count)
2743 char *src_buf, *dest_buf;
2745 MONO_ARCH_SAVE_REGS;
2747 src_buf = (gint8 *)src->vector + src_offset;
2748 dest_buf = (gint8 *)dest->vector + dest_offset;
2750 memcpy (dest_buf, src_buf, count);
2754 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this)
2756 MonoDomain *domain = mono_object_domain (this);
2758 MonoRealProxy *rp = ((MonoRealProxy *)this);
2762 MONO_ARCH_SAVE_REGS;
2764 res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
2766 ((MonoTransparentProxy *)res)->rp = rp;
2767 type = ((MonoReflectionType *)rp->class_to_proxy)->type;
2768 klass = mono_class_from_mono_type (type);
2770 ((MonoTransparentProxy *)res)->klass = klass;
2772 res->vtable = mono_class_proxy_vtable (domain, klass);
2777 /* System.Environment */
2780 ves_icall_System_Environment_get_MachineName (void)
2782 #if defined (PLATFORM_WIN32)
2787 len = MAX_COMPUTERNAME_LENGTH + 1;
2788 buf = g_new (gunichar2, len);
2791 if (GetComputerName (buf, (PDWORD) &len))
2792 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
2801 MONO_ARCH_SAVE_REGS;
2804 buf = g_new (gchar, len);
2807 if (gethostname (buf, len) == 0)
2808 result = mono_string_new (mono_domain_get (), buf);
2816 ves_icall_System_Environment_get_Platform (void)
2818 MONO_ARCH_SAVE_REGS;
2820 #if defined (PLATFORM_WIN32)
2830 ves_icall_System_Environment_get_NewLine (void)
2832 MONO_ARCH_SAVE_REGS;
2834 #if defined (PLATFORM_WIN32)
2835 return mono_string_new (mono_domain_get (), "\r\n");
2837 return mono_string_new (mono_domain_get (), "\n");
2842 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
2847 MONO_ARCH_SAVE_REGS;
2852 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
2853 value = g_getenv (utf8_name);
2859 return mono_string_new (mono_domain_get (), value);
2863 * There is no standard way to get at environ.
2865 extern char **environ;
2868 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
2876 MONO_ARCH_SAVE_REGS;
2879 for (e = environ; *e != 0; ++ e)
2882 domain = mono_domain_get ();
2883 names = mono_array_new (domain, mono_defaults.string_class, n);
2886 for (e = environ; *e != 0; ++ e) {
2887 parts = g_strsplit (*e, "=", 2);
2889 str = mono_string_new (domain, *parts);
2890 mono_array_set (names, MonoString *, n, str);
2902 * Returns the number of milliseconds elapsed since the system started.
2905 ves_icall_System_Environment_get_TickCount (void)
2907 #if defined (PLATFORM_WIN32)
2908 return GetTickCount();
2914 MONO_ARCH_SAVE_REGS;
2916 res = (gint32) gettimeofday (&tv, &tz);
2919 res = (gint32) ((tv.tv_sec & 0xFFFFF) * 1000 + (tv.tv_usec / 1000));
2926 ves_icall_System_Environment_Exit (int result)
2928 MONO_ARCH_SAVE_REGS;
2930 /* we may need to do some cleanup here... */
2935 ves_icall_System_Text_Encoding_InternalCodePage (void)
2939 MONO_ARCH_SAVE_REGS;
2941 g_get_charset (&cset);
2942 /* g_print ("charset: %s\n", cset); */
2943 /* handle some common aliases */
2946 if (strcmp (cset, "ANSI_X3.4-1968") == 0)
2950 return mono_string_new (mono_domain_get (), cset);
2954 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
2955 MonoReflectionMethod *method,
2956 MonoArray *out_args)
2958 MONO_ARCH_SAVE_REGS;
2960 mono_message_init (mono_object_domain (this), this, method, out_args);
2964 ves_icall_IsTransparentProxy (MonoObject *proxy)
2966 MONO_ARCH_SAVE_REGS;
2971 if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
2978 ves_icall_System_Runtime_Serialization_FormatterServices_GetUninitializedObject_Internal (MonoReflectionType *type)
2984 MONO_ARCH_SAVE_REGS;
2986 domain = mono_object_domain (type);
2987 klass = mono_class_from_mono_type (type->type);
2989 if (klass->rank >= 1) {
2990 g_assert (klass->rank == 1);
2991 obj = (MonoObject *) mono_array_new (domain, klass->element_class, 0);
2993 obj = mono_object_new (domain, klass);
3000 ves_icall_System_IO_get_temp_path (void)
3002 MONO_ARCH_SAVE_REGS;
3004 return mono_string_new (mono_domain_get (), g_get_tmp_dir ());
3008 ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
3010 MONO_ARCH_SAVE_REGS;
3012 return mono_compile_method (method);
3015 char * mono_cfg_dir = "";
3018 mono_install_get_config_dir()
3020 mono_cfg_dir = getenv ("MONO_CFG_DIR");
3023 mono_cfg_dir = MONO_CFG_DIR;
3028 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
3030 static MonoString *mcpath;
3033 MONO_ARCH_SAVE_REGS;
3038 path = g_build_path (G_DIR_SEPARATOR_S, mono_cfg_dir, "mono", "machine.config", NULL);
3040 #if defined (PLATFORM_WIN32)
3041 /* Avoid mixing '/' and '\\' */
3044 for (i = strlen (path) - 1; i >= 0; i--)
3045 if (path [i] == '/')
3049 mcpath = mono_string_new (mono_domain_get (), path);
3056 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
3058 #if defined (PLATFORM_WIN32)
3059 static void (*output_debug) (gchar *);
3060 static gboolean tried_loading = FALSE;
3063 MONO_ARCH_SAVE_REGS;
3065 if (!tried_loading && output_debug == NULL) {
3068 tried_loading = TRUE;
3069 k32 = g_module_open ("kernel32", G_MODULE_BIND_LAZY);
3071 gchar *error = g_strdup (g_module_error ());
3072 g_warning ("Failed to load kernel32.dll: %s\n", error);
3077 g_module_symbol (k32, "OutputDebugStringW", (gpointer *) &output_debug);
3078 if (!output_debug) {
3079 gchar *error = g_strdup (g_module_error ());
3080 g_warning ("Failed to load OutputDebugStringW: %s\n", error);
3086 if (output_debug == NULL)
3089 str = mono_string_to_utf8 (message);
3093 g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
3099 static gconstpointer icall_map [] = {
3103 "System.Array::GetValue", ves_icall_System_Array_GetValue,
3104 "System.Array::SetValue", ves_icall_System_Array_SetValue,
3105 "System.Array::GetValueImpl", ves_icall_System_Array_GetValueImpl,
3106 "System.Array::SetValueImpl", ves_icall_System_Array_SetValueImpl,
3107 "System.Array::GetRank", ves_icall_System_Array_GetRank,
3108 "System.Array::GetLength", ves_icall_System_Array_GetLength,
3109 "System.Array::GetLowerBound", ves_icall_System_Array_GetLowerBound,
3110 "System.Array::CreateInstanceImpl", ves_icall_System_Array_CreateInstanceImpl,
3111 "System.Array::FastCopy", ves_icall_System_Array_FastCopy,
3112 "System.Array::Clone", mono_array_clone,
3117 "System.Object::MemberwiseClone", ves_icall_System_Object_MemberwiseClone,
3118 "System.Object::GetType", ves_icall_System_Object_GetType,
3119 "System.Object::GetHashCode", ves_icall_System_Object_GetHashCode,
3120 "System.Object::obj_address", ves_icall_System_Object_obj_address,
3125 "System.ValueType::GetHashCode", ves_icall_System_ValueType_GetHashCode,
3126 "System.ValueType::Equals", ves_icall_System_ValueType_Equals,
3132 "System.String::.ctor(char*)", ves_icall_System_String_ctor_charp,
3133 "System.String::.ctor(char*,int,int)", ves_icall_System_String_ctor_charp_int_int,
3134 "System.String::.ctor(sbyte*)", ves_icall_System_String_ctor_sbytep,
3135 "System.String::.ctor(sbyte*,int,int)", ves_icall_System_String_ctor_sbytep_int_int,
3136 "System.String::.ctor(sbyte*,int,int,System.Text.Encoding)", ves_icall_System_String_ctor_encoding,
3137 "System.String::.ctor(char[])", ves_icall_System_String_ctor_chara,
3138 "System.String::.ctor(char[],int,int)", ves_icall_System_String_ctor_chara_int_int,
3139 "System.String::.ctor(char,int)", ves_icall_System_String_ctor_char_int,
3140 "System.String::InternalEquals", ves_icall_System_String_InternalEquals,
3141 "System.String::InternalJoin", ves_icall_System_String_InternalJoin,
3142 "System.String::InternalInsert", ves_icall_System_String_InternalInsert,
3143 "System.String::InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char,
3144 "System.String::InternalReplace(string,string)", ves_icall_System_String_InternalReplace_Str,
3145 "System.String::InternalRemove", ves_icall_System_String_InternalRemove,
3146 "System.String::InternalCopyTo", ves_icall_System_String_InternalCopyTo,
3147 "System.String::InternalSplit", ves_icall_System_String_InternalSplit,
3148 "System.String::InternalTrim", ves_icall_System_String_InternalTrim,
3149 "System.String::InternalIndexOf(char,int,int)", ves_icall_System_String_InternalIndexOf_Char,
3150 "System.String::InternalIndexOf(string,int,int)", ves_icall_System_String_InternalIndexOf_Str,
3151 "System.String::InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny,
3152 "System.String::InternalLastIndexOf(char,int,int)", ves_icall_System_String_InternalLastIndexOf_Char,
3153 "System.String::InternalLastIndexOf(string,int,int)", ves_icall_System_String_InternalLastIndexOf_Str,
3154 "System.String::InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny,
3155 "System.String::InternalPad", ves_icall_System_String_InternalPad,
3156 "System.String::InternalToLower", ves_icall_System_String_InternalToLower,
3157 "System.String::InternalToUpper", ves_icall_System_String_InternalToUpper,
3158 "System.String::InternalAllocateStr", ves_icall_System_String_InternalAllocateStr,
3159 "System.String::InternalStrcpy(string,int,string)", ves_icall_System_String_InternalStrcpy_Str,
3160 "System.String::InternalStrcpy(string,int,string,int,int)", ves_icall_System_String_InternalStrcpy_StrN,
3161 "System.String::InternalIntern", ves_icall_System_String_InternalIntern,
3162 "System.String::InternalIsInterned", ves_icall_System_String_InternalIsInterned,
3163 "System.String::InternalCompare(string,int,string,int,int,bool)", ves_icall_System_String_InternalCompareStr_N,
3164 "System.String::GetHashCode", ves_icall_System_String_GetHashCode,
3165 "System.String::get_Chars", ves_icall_System_String_get_Chars,
3170 "System.AppDomain::createDomain", ves_icall_System_AppDomain_createDomain,
3171 "System.AppDomain::getCurDomain", ves_icall_System_AppDomain_getCurDomain,
3172 "System.AppDomain::GetData", ves_icall_System_AppDomain_GetData,
3173 "System.AppDomain::SetData", ves_icall_System_AppDomain_SetData,
3174 "System.AppDomain::getSetup", ves_icall_System_AppDomain_getSetup,
3175 "System.AppDomain::getFriendlyName", ves_icall_System_AppDomain_getFriendlyName,
3176 "System.AppDomain::GetAssemblies", ves_icall_System_AppDomain_GetAssemblies,
3177 "System.AppDomain::LoadAssembly", ves_icall_System_AppDomain_LoadAssembly,
3178 "System.AppDomain::Unload", ves_icall_System_AppDomain_Unload,
3179 "System.AppDomain::ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly,
3182 * System.AppDomainSetup
3184 "System.AppDomainSetup::InitAppDomainSetup", ves_icall_System_AppDomainSetup_InitAppDomainSetup,
3189 "System.Double::ToStringImpl", mono_double_ToStringImpl,
3190 "System.Double::ParseImpl", mono_double_ParseImpl,
3195 "System.Single::ToStringImpl", mono_float_ToStringImpl,
3200 "System.Decimal::decimal2UInt64", mono_decimal2UInt64,
3201 "System.Decimal::decimal2Int64", mono_decimal2Int64,
3202 "System.Decimal::double2decimal", mono_double2decimal, /* FIXME: wrong signature. */
3203 "System.Decimal::decimalIncr", mono_decimalIncr,
3204 "System.Decimal::decimalSetExponent", mono_decimalSetExponent,
3205 "System.Decimal::decimal2double", mono_decimal2double,
3206 "System.Decimal::decimalFloorAndTrunc", mono_decimalFloorAndTrunc,
3207 "System.Decimal::decimalRound", mono_decimalRound,
3208 "System.Decimal::decimalMult", mono_decimalMult,
3209 "System.Decimal::decimalDiv", mono_decimalDiv,
3210 "System.Decimal::decimalIntDiv", mono_decimalIntDiv,
3211 "System.Decimal::decimalCompare", mono_decimalCompare,
3212 "System.Decimal::string2decimal", mono_string2decimal,
3213 "System.Decimal::decimal2string", mono_decimal2string,
3218 "System.Reflection.Emit.ModuleBuilder::create_modified_type", ves_icall_ModuleBuilder_create_modified_type,
3223 "System.Reflection.Emit.AssemblyBuilder::getDataChunk", ves_icall_AssemblyBuilder_getDataChunk,
3224 "System.Reflection.Emit.AssemblyBuilder::getUSIndex", mono_image_insert_string,
3225 "System.Reflection.Emit.AssemblyBuilder::getToken", ves_icall_AssemblyBuilder_getToken,
3226 "System.Reflection.Emit.AssemblyBuilder::basic_init", mono_image_basic_init,
3231 "System.Reflection.MonoMethodInfo::get_method_info", ves_icall_get_method_info,
3232 "System.Reflection.MonoMethodInfo::get_parameter_info", ves_icall_get_parameter_info,
3233 "System.Reflection.MonoFieldInfo::get_field_info", ves_icall_get_field_info,
3234 "System.Reflection.MonoPropertyInfo::get_property_info", ves_icall_get_property_info,
3235 "System.Reflection.MonoEventInfo::get_event_info", ves_icall_get_event_info,
3236 "System.Reflection.MonoMethod::InternalInvoke", ves_icall_InternalInvoke,
3237 "System.Reflection.MonoCMethod::InternalInvoke", ves_icall_InternalInvoke,
3238 "System.Reflection.MethodBase::GetCurrentMethod", ves_icall_GetCurrentMethod,
3239 "System.MonoCustomAttrs::GetCustomAttributes", mono_reflection_get_custom_attrs,
3240 "System.Reflection.Emit.CustomAttributeBuilder::GetBlob", mono_reflection_get_custom_attrs_blob,
3241 "System.Reflection.MonoField::GetValueInternal", ves_icall_MonoField_GetValueInternal,
3242 "System.Reflection.MonoField::SetValueInternal", ves_icall_FieldInfo_SetValueInternal,
3243 "System.Reflection.Emit.SignatureHelper::get_signature_local", mono_reflection_sighelper_get_signature_local,
3244 "System.Reflection.Emit.SignatureHelper::get_signature_field", mono_reflection_sighelper_get_signature_field,
3246 "System.RuntimeMethodHandle::GetFunctionPointer", ves_icall_RuntimeMethod_GetFunctionPointer,
3250 "System.MonoEnumInfo::get_enum_info", ves_icall_get_enum_info,
3251 "System.Enum::get_value", ves_icall_System_Enum_get_value,
3252 "System.Enum::ToObject", ves_icall_System_Enum_ToObject,
3257 "System.Reflection.Emit.TypeBuilder::setup_internal_class", mono_reflection_setup_internal_class,
3258 "System.Reflection.Emit.TypeBuilder::create_internal_class", mono_reflection_create_internal_class,
3259 "System.Reflection.Emit.TypeBuilder::create_runtime_class", mono_reflection_create_runtime_class,
3268 "System.Type::internal_from_name", ves_icall_type_from_name,
3269 "System.Type::internal_from_handle", ves_icall_type_from_handle,
3270 "System.MonoType::get_attributes", ves_icall_get_attributes,
3271 "System.Type::type_is_subtype_of", ves_icall_type_is_subtype_of,
3272 "System.Type::Equals", ves_icall_type_Equals,
3273 "System.Type::GetTypeCode", ves_icall_type_GetTypeCode,
3274 "System.Type::GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData,
3277 * System.Runtime.CompilerServices.RuntimeHelpers
3279 "System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray,
3280 "System.Runtime.CompilerServices.RuntimeHelpers::GetOffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData,
3281 "System.Runtime.CompilerServices.RuntimeHelpers::GetObjectValue", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue,
3282 "System.Runtime.CompilerServices.RuntimeHelpers::RunClassConstructor", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor,
3287 "System.Threading.Thread::Abort(object)", ves_icall_System_Threading_Thread_Abort,
3288 "System.Threading.Thread::ResetAbort", ves_icall_System_Threading_Thread_ResetAbort,
3289 "System.Threading.Thread::Thread_internal", ves_icall_System_Threading_Thread_Thread_internal,
3290 "System.Threading.Thread::Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal,
3291 "System.Threading.Thread::Start_internal", ves_icall_System_Threading_Thread_Start_internal,
3292 "System.Threading.Thread::Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal,
3293 "System.Threading.Thread::CurrentThread_internal", mono_thread_current,
3294 "System.Threading.Thread::Join_internal", ves_icall_System_Threading_Thread_Join_internal,
3295 "System.Threading.Thread::SlotHash_lookup", ves_icall_System_Threading_Thread_SlotHash_lookup,
3296 "System.Threading.Thread::SlotHash_store", ves_icall_System_Threading_Thread_SlotHash_store,
3297 "System.Threading.Thread::GetDomainID", ves_icall_System_Threading_Thread_GetDomainID,
3298 "System.Threading.Monitor::Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit,
3299 "System.Threading.Monitor::Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner,
3300 "System.Threading.Monitor::Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised,
3301 "System.Threading.Monitor::Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse,
3302 "System.Threading.Monitor::Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all,
3303 "System.Threading.Monitor::Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter,
3304 "System.Threading.Monitor::Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait,
3305 "System.Threading.Mutex::CreateMutex_internal", ves_icall_System_Threading_Mutex_CreateMutex_internal,
3306 "System.Threading.Mutex::ReleaseMutex_internal", ves_icall_System_Threading_Mutex_ReleaseMutex_internal,
3307 "System.Threading.NativeEventCalls::CreateEvent_internal", ves_icall_System_Threading_Events_CreateEvent_internal,
3308 "System.Threading.NativeEventCalls::SetEvent_internal", ves_icall_System_Threading_Events_SetEvent_internal,
3309 "System.Threading.NativeEventCalls::ResetEvent_internal", ves_icall_System_Threading_Events_ResetEvent_internal,
3312 * System.Threading.WaitHandle
3314 "System.Threading.WaitHandle::WaitAll_internal", ves_icall_System_Threading_WaitHandle_WaitAll_internal,
3315 "System.Threading.WaitHandle::WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny_internal,
3316 "System.Threading.WaitHandle::WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal,
3319 * System.Runtime.InteropServices.Marshal
3321 "System.Runtime.InteropServices.Marshal::ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr,
3322 "System.Runtime.InteropServices.Marshal::ReadByte", ves_icall_System_Runtime_InteropServices_Marshal_ReadByte,
3323 "System.Runtime.InteropServices.Marshal::ReadInt16", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt16,
3324 "System.Runtime.InteropServices.Marshal::ReadInt32", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt32,
3325 "System.Runtime.InteropServices.Marshal::ReadInt64", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64,
3326 "System.Runtime.InteropServices.Marshal::WriteIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_WriteIntPtr,
3327 "System.Runtime.InteropServices.Marshal::WriteByte", ves_icall_System_Runtime_InteropServices_Marshal_WriteByte,
3328 "System.Runtime.InteropServices.Marshal::WriteInt16", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt16,
3329 "System.Runtime.InteropServices.Marshal::WriteInt32", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt32,
3330 "System.Runtime.InteropServices.Marshal::WriteInt64", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt64,
3332 "System.Runtime.InteropServices.Marshal::PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi,
3333 "System.Runtime.InteropServices.Marshal::PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len,
3334 "System.Runtime.InteropServices.Marshal::PtrToStringAuto(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi,
3335 "System.Runtime.InteropServices.Marshal::PtrToStringAuto(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len,
3336 "System.Runtime.InteropServices.Marshal::PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni,
3337 "System.Runtime.InteropServices.Marshal::PtrToStringUni(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len,
3338 "System.Runtime.InteropServices.Marshal::PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR,
3340 "System.Runtime.InteropServices.Marshal::GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error,
3341 "System.Runtime.InteropServices.Marshal::AllocHGlobal", mono_marshal_alloc,
3342 "System.Runtime.InteropServices.Marshal::FreeHGlobal", mono_marshal_free,
3343 "System.Runtime.InteropServices.Marshal::ReAllocHGlobal", mono_marshal_realloc,
3344 "System.Runtime.InteropServices.Marshal::copy_to_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged,
3345 "System.Runtime.InteropServices.Marshal::copy_from_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged,
3346 "System.Runtime.InteropServices.Marshal::SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf,
3347 "System.Runtime.InteropServices.Marshal::StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr,
3348 "System.Runtime.InteropServices.Marshal::PtrToStructure(intptr,object)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure,
3349 "System.Runtime.InteropServices.Marshal::PtrToStructure(intptr,System.Type)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type,
3350 "System.Runtime.InteropServices.Marshal::OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf,
3351 "System.Runtime.InteropServices.Marshal::StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi,
3352 "System.Runtime.InteropServices.Marshal::StringToHGlobalAuto", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi,
3353 "System.Runtime.InteropServices.Marshal::StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni,
3354 "System.Runtime.InteropServices.Marshal::DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure,
3357 "System.Reflection.Assembly::LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom,
3358 "System.Reflection.Assembly::InternalGetType", ves_icall_System_Reflection_Assembly_InternalGetType,
3359 "System.Reflection.Assembly::GetTypes", ves_icall_System_Reflection_Assembly_GetTypes,
3360 "System.Reflection.Assembly::FillName", ves_icall_System_Reflection_Assembly_FillName,
3361 "System.Reflection.Assembly::get_code_base", ves_icall_System_Reflection_Assembly_get_code_base,
3362 "System.Reflection.Assembly::get_location", ves_icall_System_Reflection_Assembly_get_location,
3363 "System.Reflection.Assembly::GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly,
3364 "System.Reflection.Assembly::GetEntryAssembly", ves_icall_System_Reflection_Assembly_GetEntryAssembly,
3365 "System.Reflection.Assembly::GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly,
3366 "System.Reflection.Assembly::get_EntryPoint", ves_icall_System_Reflection_Assembly_get_EntryPoint,
3367 "System.Reflection.Assembly::GetManifestResourceNames", ves_icall_System_Reflection_Assembly_GetManifestResourceNames,
3368 "System.Reflection.Assembly::GetManifestResourceInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInternal,
3369 "System.Reflection.Assembly::GetFilesInternal", ves_icall_System_Reflection_Assembly_GetFilesInternal,
3370 "System.Reflection.Assembly::GetReferencedAssemblies", ves_icall_System_Reflection_Assembly_GetReferencedAssemblies,
3375 "System.MonoType::getFullName", ves_icall_System_MonoType_getFullName,
3376 "System.MonoType::type_from_obj", mono_type_type_from_obj,
3377 "System.MonoType::GetElementType", ves_icall_MonoType_GetElementType,
3378 "System.MonoType::get_type_info", ves_icall_get_type_info,
3379 "System.MonoType::get_BaseType", ves_icall_get_type_parent,
3380 "System.MonoType::get_Module", ves_icall_MonoType_get_Module,
3381 "System.MonoType::IsPointerImpl", ves_icall_type_ispointer,
3382 "System.MonoType::IsByRefImpl", ves_icall_type_isbyref,
3383 "System.MonoType::GetField", ves_icall_Type_GetField,
3384 "System.MonoType::GetFields", ves_icall_Type_GetFields,
3385 "System.MonoType::GetMethods", ves_icall_Type_GetMethods,
3386 "System.MonoType::GetConstructors", ves_icall_Type_GetConstructors,
3387 "System.MonoType::GetProperties", ves_icall_Type_GetProperties,
3388 "System.MonoType::GetEvents", ves_icall_Type_GetEvents,
3389 "System.MonoType::InternalGetEvent", ves_icall_MonoType_GetEvent,
3390 "System.MonoType::GetInterfaces", ves_icall_Type_GetInterfaces,
3391 "System.MonoType::GetNestedTypes", ves_icall_Type_GetNestedTypes,
3394 * System.Net.Sockets I/O Services
3396 "System.Net.Sockets.Socket::Socket_internal", ves_icall_System_Net_Sockets_Socket_Socket_internal,
3397 "System.Net.Sockets.Socket::Close_internal", ves_icall_System_Net_Sockets_Socket_Close_internal,
3398 "System.Net.Sockets.SocketException::WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal,
3399 "System.Net.Sockets.Socket::Available_internal", ves_icall_System_Net_Sockets_Socket_Available_internal,
3400 "System.Net.Sockets.Socket::Blocking_internal", ves_icall_System_Net_Sockets_Socket_Blocking_internal,
3401 "System.Net.Sockets.Socket::Accept_internal", ves_icall_System_Net_Sockets_Socket_Accept_internal,
3402 "System.Net.Sockets.Socket::Listen_internal", ves_icall_System_Net_Sockets_Socket_Listen_internal,
3403 "System.Net.Sockets.Socket::LocalEndPoint_internal", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal,
3404 "System.Net.Sockets.Socket::RemoteEndPoint_internal", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal,
3405 "System.Net.Sockets.Socket::Bind_internal", ves_icall_System_Net_Sockets_Socket_Bind_internal,
3406 "System.Net.Sockets.Socket::Connect_internal", ves_icall_System_Net_Sockets_Socket_Connect_internal,
3407 "System.Net.Sockets.Socket::Receive_internal", ves_icall_System_Net_Sockets_Socket_Receive_internal,
3408 "System.Net.Sockets.Socket::RecvFrom_internal", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal,
3409 "System.Net.Sockets.Socket::Send_internal", ves_icall_System_Net_Sockets_Socket_Send_internal,
3410 "System.Net.Sockets.Socket::SendTo_internal", ves_icall_System_Net_Sockets_Socket_SendTo_internal,
3411 "System.Net.Sockets.Socket::Select_internal", ves_icall_System_Net_Sockets_Socket_Select_internal,
3412 "System.Net.Sockets.Socket::Shutdown_internal", ves_icall_System_Net_Sockets_Socket_Shutdown_internal,
3413 "System.Net.Sockets.Socket::GetSocketOption_obj_internal", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal,
3414 "System.Net.Sockets.Socket::GetSocketOption_arr_internal", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal,
3415 "System.Net.Sockets.Socket::SetSocketOption_internal", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal,
3416 "System.Net.Dns::GetHostByName_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByName_internal,
3417 "System.Net.Dns::GetHostByAddr_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByAddr_internal,
3418 "System.Net.Dns::GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal,
3423 "System.Char::GetNumericValue", ves_icall_System_Char_GetNumericValue,
3424 "System.Char::GetUnicodeCategory", ves_icall_System_Char_GetUnicodeCategory,
3425 "System.Char::IsControl", ves_icall_System_Char_IsControl,
3426 "System.Char::IsDigit", ves_icall_System_Char_IsDigit,
3427 "System.Char::IsLetter", ves_icall_System_Char_IsLetter,
3428 "System.Char::IsLower", ves_icall_System_Char_IsLower,
3429 "System.Char::IsUpper", ves_icall_System_Char_IsUpper,
3430 "System.Char::IsNumber", ves_icall_System_Char_IsNumber,
3431 "System.Char::IsPunctuation", ves_icall_System_Char_IsPunctuation,
3432 "System.Char::IsSeparator", ves_icall_System_Char_IsSeparator,
3433 "System.Char::IsSurrogate", ves_icall_System_Char_IsSurrogate,
3434 "System.Char::IsSymbol", ves_icall_System_Char_IsSymbol,
3435 "System.Char::IsWhiteSpace", ves_icall_System_Char_IsWhiteSpace,
3436 "System.Char::ToLower", ves_icall_System_Char_ToLower,
3437 "System.Char::ToUpper", ves_icall_System_Char_ToUpper,
3440 * System.Text.Encoding
3442 "System.Text.Encoding::InternalCodePage", ves_icall_System_Text_Encoding_InternalCodePage,
3444 "System.DateTime::GetNow", ves_icall_System_DateTime_GetNow,
3445 "System.CurrentTimeZone::GetTimeZoneData", ves_icall_System_CurrentTimeZone_GetTimeZoneData,
3450 "System.GC::InternalCollect", ves_icall_System_GC_InternalCollect,
3451 "System.GC::GetTotalMemory", ves_icall_System_GC_GetTotalMemory,
3452 "System.GC::KeepAlive", ves_icall_System_GC_KeepAlive,
3453 "System.GC::ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize,
3454 "System.GC::SuppressFinalize", ves_icall_System_GC_SuppressFinalize,
3455 "System.GC::WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers,
3456 "System.Runtime.InteropServices.GCHandle::GetTarget", ves_icall_System_GCHandle_GetTarget,
3457 "System.Runtime.InteropServices.GCHandle::GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle,
3458 "System.Runtime.InteropServices.GCHandle::FreeHandle", ves_icall_System_GCHandle_FreeHandle,
3459 "System.Runtime.InteropServices.GCHandle::GetAddrOfPinnedObject", ves_icall_System_GCHandle_GetAddrOfPinnedObject,
3462 * System.Security.Cryptography calls
3465 "System.Security.Cryptography.RNGCryptoServiceProvider::GetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetBytes,
3466 "System.Security.Cryptography.RNGCryptoServiceProvider::GetNonZeroBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetNonZeroBytes,
3471 "System.Buffer::ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal,
3472 "System.Buffer::GetByteInternal", ves_icall_System_Buffer_GetByteInternal,
3473 "System.Buffer::SetByteInternal", ves_icall_System_Buffer_SetByteInternal,
3474 "System.Buffer::BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal,
3479 "System.IO.MonoIO::CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CreateDirectory,
3480 "System.IO.MonoIO::RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory,
3481 "System.IO.MonoIO::FindFirstFile(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindFirstFile,
3482 "System.IO.MonoIO::FindNextFile(intptr,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindNextFile,
3483 "System.IO.MonoIO::FindClose(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindClose,
3484 "System.IO.MonoIO::GetCurrentDirectory(System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetCurrentDirectory,
3485 "System.IO.MonoIO::SetCurrentDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetCurrentDirectory,
3486 "System.IO.MonoIO::MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile,
3487 "System.IO.MonoIO::CopyFile(string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CopyFile,
3488 "System.IO.MonoIO::DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile,
3489 "System.IO.MonoIO::GetFileAttributes(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileAttributes,
3490 "System.IO.MonoIO::SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes,
3491 "System.IO.MonoIO::GetFileType(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType,
3492 "System.IO.MonoIO::GetFileStat(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileStat,
3493 "System.IO.MonoIO::Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open,
3494 "System.IO.MonoIO::Close(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Close,
3495 "System.IO.MonoIO::Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read,
3496 "System.IO.MonoIO::Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write,
3497 "System.IO.MonoIO::Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek,
3498 "System.IO.MonoIO::GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength,
3499 "System.IO.MonoIO::SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength,
3500 "System.IO.MonoIO::SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime,
3501 "System.IO.MonoIO::Flush(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush,
3502 "System.IO.MonoIO::get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput,
3503 "System.IO.MonoIO::get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput,
3504 "System.IO.MonoIO::get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError,
3505 "System.IO.MonoIO::CreatePipe(intptr&,intptr&)", ves_icall_System_IO_MonoIO_CreatePipe,
3506 "System.IO.MonoIO::get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar,
3507 "System.IO.MonoIO::get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar,
3508 "System.IO.MonoIO::get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar,
3509 "System.IO.MonoIO::get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator,
3510 "System.IO.MonoIO::get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars,
3515 "System.Math::Sin", ves_icall_System_Math_Sin,
3516 "System.Math::Cos", ves_icall_System_Math_Cos,
3517 "System.Math::Tan", ves_icall_System_Math_Tan,
3518 "System.Math::Sinh", ves_icall_System_Math_Sinh,
3519 "System.Math::Cosh", ves_icall_System_Math_Cosh,
3520 "System.Math::Tanh", ves_icall_System_Math_Tanh,
3521 "System.Math::Acos", ves_icall_System_Math_Acos,
3522 "System.Math::Asin", ves_icall_System_Math_Asin,
3523 "System.Math::Atan", ves_icall_System_Math_Atan,
3524 "System.Math::Atan2", ves_icall_System_Math_Atan2,
3525 "System.Math::Exp", ves_icall_System_Math_Exp,
3526 "System.Math::Log", ves_icall_System_Math_Log,
3527 "System.Math::Log10", ves_icall_System_Math_Log10,
3528 "System.Math::PowImpl", ves_icall_System_Math_Pow,
3529 "System.Math::Sqrt", ves_icall_System_Math_Sqrt,
3532 * System.Environment
3534 "System.Environment::get_MachineName", ves_icall_System_Environment_get_MachineName,
3535 "System.Environment::get_NewLine", ves_icall_System_Environment_get_NewLine,
3536 "System.Environment::GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable,
3537 "System.Environment::GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames,
3538 "System.Environment::GetCommandLineArgs", mono_runtime_get_main_args,
3539 "System.Environment::get_TickCount", ves_icall_System_Environment_get_TickCount,
3540 "System.Environment::Exit", ves_icall_System_Environment_Exit,
3541 "System.Environment::get_Platform", ves_icall_System_Environment_get_Platform,
3544 * System.Runtime.Remoting
3546 "System.Runtime.Remoting.RemotingServices::InternalExecute",
3547 ves_icall_InternalExecute,
3548 "System.Runtime.Remoting.RemotingServices::IsTransparentProxy",
3549 ves_icall_IsTransparentProxy,
3552 * System.Runtime.Remoting.Messaging
3554 "System.Runtime.Remoting.Messaging.MonoMethodMessage::InitMessage",
3555 ves_icall_MonoMethodMessage_InitMessage,
3558 * System.Runtime.Remoting.Proxies
3560 "System.Runtime.Remoting.Proxies.RealProxy::GetTransparentProxy",
3561 ves_icall_Remoting_RealProxy_GetTransparentProxy,
3564 * System.Threading.Interlocked
3566 "System.Threading.Interlocked::Increment(int&)", ves_icall_System_Threading_Interlocked_Increment_Int,
3567 "System.Threading.Interlocked::Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long,
3568 "System.Threading.Interlocked::Decrement(int&)", ves_icall_System_Threading_Interlocked_Decrement_Int,
3569 "System.Threading.Interlocked::Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long,
3570 "System.Threading.Interlocked::CompareExchange(int&,int,int)", ves_icall_System_Threading_Interlocked_CompareExchange_Int,
3571 "System.Threading.Interlocked::CompareExchange(object&,object,object)", ves_icall_System_Threading_Interlocked_CompareExchange_Object,
3572 "System.Threading.Interlocked::CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single,
3573 "System.Threading.Interlocked::Exchange(int&,int)", ves_icall_System_Threading_Interlocked_Exchange_Int,
3574 "System.Threading.Interlocked::Exchange(object&,object)", ves_icall_System_Threading_Interlocked_Exchange_Object,
3575 "System.Threading.Interlocked::Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single,
3578 * System.Diagnostics.Process
3580 "System.Diagnostics.Process::GetProcess_internal(int)", ves_icall_System_Diagnostics_Process_GetProcess_internal,
3581 "System.Diagnostics.Process::GetProcesses_internal()", ves_icall_System_Diagnostics_Process_GetProcesses_internal,
3582 "System.Diagnostics.Process::GetPid_internal()", ves_icall_System_Diagnostics_Process_GetPid_internal,
3583 "System.Diagnostics.Process::Process_free_internal(intptr)", ves_icall_System_Diagnostics_Process_Process_free_internal,
3584 "System.Diagnostics.Process::GetModules_internal()", ves_icall_System_Diagnostics_Process_GetModules_internal,
3585 "System.Diagnostics.Process::Start_internal(string,string,intptr,intptr,intptr,ProcInfo&)", ves_icall_System_Diagnostics_Process_Start_internal,
3586 "System.Diagnostics.Process::WaitForExit_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForExit_internal,
3587 "System.Diagnostics.Process::ExitTime_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitTime_internal,
3588 "System.Diagnostics.Process::StartTime_internal(intptr)", ves_icall_System_Diagnostics_Process_StartTime_internal,
3589 "System.Diagnostics.Process::ExitCode_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitCode_internal,
3590 "System.Diagnostics.Process::ProcessName_internal(intptr)", ves_icall_System_Diagnostics_Process_ProcessName_internal,
3591 "System.Diagnostics.Process::GetWorkingSet_internal(intptr,int&,int&)", ves_icall_System_Diagnostics_Process_GetWorkingSet_internal,
3592 "System.Diagnostics.Process::SetWorkingSet_internal(intptr,int,int,bool)", ves_icall_System_Diagnostics_Process_SetWorkingSet_internal,
3593 "System.Diagnostics.FileVersionInfo::GetVersionInfo_internal(string)", ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal,
3598 "System.Delegate::CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal,
3601 * System.Runtime.Serialization
3603 "System.Runtime.Serialization.FormatterServices::GetUninitializedObjectInternal",
3604 ves_icall_System_Runtime_Serialization_FormatterServices_GetUninitializedObject_Internal,
3609 "System.IO.Path::get_temp_path", ves_icall_System_IO_get_temp_path,
3612 * Private icalls for the Mono Debugger
3614 "System.Reflection.Assembly::MonoDebugger_GetMethod",
3615 ves_icall_MonoDebugger_GetMethod,
3617 "System.Reflection.Assembly::MonoDebugger_GetLocalTypeFromSignature",
3618 ves_icall_MonoDebugger_GetLocalTypeFromSignature,
3620 "System.Reflection.Assembly::MonoDebugger_GetType",
3621 ves_icall_MonoDebugger_GetType,
3624 * System.Configuration
3626 "System.Configuration.DefaultConfig::get_machine_config_path",
3627 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path,
3630 * System.Diagnostics.DefaultTraceListener
3632 "System.Diagnostics.DefaultTraceListener::WriteWindowsDebugString",
3633 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString,
3635 * add other internal calls here
3641 mono_init_icall (void)
3646 while ((name = icall_map [i])) {
3647 mono_add_internal_call (name, icall_map [i+1]);