2004-12-12 Ben Maurer <bmaurer@ximian.com>
[mono-project.git] / mono / metadata / icall.c
blob20c6e5009157ad17aabd4f8c20f071246e2cf549
1 /*
2 * icall.c:
4 * Authors:
5 * Dietmar Maurer (dietmar@ximian.com)
6 * Paolo Molaro (lupus@ximian.com)
7 * Patrik Torstensson (patrik.torstensson@labs2.com)
9 * (C) 2001 Ximian, Inc.
12 #include <config.h>
13 #include <glib.h>
14 #include <stdarg.h>
15 #include <string.h>
16 #include <ctype.h>
17 #include <sys/time.h>
18 #include <unistd.h>
19 #if defined (PLATFORM_WIN32)
20 #include <stdlib.h>
21 #endif
23 #include <mono/metadata/object.h>
24 #include <mono/metadata/threads.h>
25 #include <mono/metadata/threads-types.h>
26 #include <mono/metadata/threadpool.h>
27 #include <mono/metadata/monitor.h>
28 #include <mono/metadata/reflection.h>
29 #include <mono/metadata/assembly.h>
30 #include <mono/metadata/tabledefs.h>
31 #include <mono/metadata/exception.h>
32 #include <mono/metadata/file-io.h>
33 #include <mono/metadata/socket-io.h>
34 #include <mono/metadata/mono-endian.h>
35 #include <mono/metadata/tokentype.h>
36 #include <mono/metadata/unicode.h>
37 #include <mono/metadata/domain-internals.h>
38 #include <mono/metadata/metadata-internals.h>
39 #include <mono/metadata/class-internals.h>
40 #include <mono/metadata/marshal.h>
41 #include <mono/metadata/gc-internal.h>
42 #include <mono/metadata/rand.h>
43 #include <mono/metadata/sysmath.h>
44 #include <mono/metadata/string-icalls.h>
45 #include <mono/metadata/mono-debug-debugger.h>
46 #include <mono/metadata/process.h>
47 #include <mono/metadata/environment.h>
48 #include <mono/metadata/profiler-private.h>
49 #include <mono/metadata/locales.h>
50 #include <mono/metadata/filewatcher.h>
51 #include <mono/metadata/char-conversions.h>
52 #include <mono/metadata/security.h>
53 #include <mono/metadata/mono-config.h>
54 #include <mono/metadata/cil-coff.h>
55 #include <mono/io-layer/io-layer.h>
56 #include <mono/utils/strtod.h>
57 #include <mono/utils/monobitset.h>
59 #if defined (PLATFORM_WIN32)
60 #include <windows.h>
61 #include <shlobj.h>
62 #endif
63 #include "decimal.h"
65 static MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
69 * We expect a pointer to a char, not a string
71 static double
72 mono_double_ParseImpl (char *ptr)
74 gchar *endptr = NULL;
75 gdouble result = 0.0;
77 MONO_ARCH_SAVE_REGS;
79 if (*ptr)
80 result = bsd_strtod (ptr, &endptr);
82 if (!*ptr || (endptr && *endptr))
83 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib,
84 "System",
85 "FormatException"));
87 return result;
90 static void
91 ves_icall_System_Double_AssertEndianity (double *value)
93 MONO_ARCH_SAVE_REGS;
95 MONO_DOUBLE_ASSERT_ENDIANITY (value);
98 static MonoObject *
99 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
101 MonoClass *ac;
102 MonoArray *ao;
103 gint32 esize;
104 gpointer *ea;
106 MONO_ARCH_SAVE_REGS;
108 ao = (MonoArray *)this;
109 ac = (MonoClass *)ao->obj.vtable->klass;
111 esize = mono_array_element_size (ac);
112 ea = (gpointer*)((char*)ao->vector + (pos * esize));
114 if (ac->element_class->valuetype)
115 return mono_value_box (this->vtable->domain, ac->element_class, ea);
116 else
117 return *ea;
120 static MonoObject *
121 ves_icall_System_Array_GetValue (MonoObject *this, MonoObject *idxs)
123 MonoClass *ac, *ic;
124 MonoArray *ao, *io;
125 gint32 i, pos, *ind;
127 MONO_ARCH_SAVE_REGS;
129 MONO_CHECK_ARG_NULL (idxs);
131 io = (MonoArray *)idxs;
132 ic = (MonoClass *)io->obj.vtable->klass;
134 ao = (MonoArray *)this;
135 ac = (MonoClass *)ao->obj.vtable->klass;
137 g_assert (ic->rank == 1);
138 if (io->bounds != NULL || io->max_length != ac->rank)
139 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
141 ind = (guint32 *)io->vector;
143 if (ao->bounds == NULL) {
144 if (*ind < 0 || *ind >= ao->max_length)
145 mono_raise_exception (mono_get_exception_index_out_of_range ());
147 return ves_icall_System_Array_GetValueImpl (this, *ind);
150 for (i = 0; i < ac->rank; i++)
151 if ((ind [i] < ao->bounds [i].lower_bound) ||
152 (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
153 mono_raise_exception (mono_get_exception_index_out_of_range ());
155 pos = ind [0] - ao->bounds [0].lower_bound;
156 for (i = 1; i < ac->rank; i++)
157 pos = pos*ao->bounds [i].length + ind [i] -
158 ao->bounds [i].lower_bound;
160 return ves_icall_System_Array_GetValueImpl (this, pos);
163 static void
164 ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
166 MonoClass *ac, *vc, *ec;
167 gint32 esize, vsize;
168 gpointer *ea, *va;
170 guint64 u64 = 0;
171 gint64 i64 = 0;
172 gdouble r64 = 0;
174 MONO_ARCH_SAVE_REGS;
176 if (value)
177 vc = value->vtable->klass;
178 else
179 vc = NULL;
181 ac = this->obj.vtable->klass;
182 ec = ac->element_class;
184 esize = mono_array_element_size (ac);
185 ea = (gpointer*)((char*)this->vector + (pos * esize));
186 va = (gpointer*)((char*)value + sizeof (MonoObject));
188 if (!value) {
189 memset (ea, 0, esize);
190 return;
193 #define NO_WIDENING_CONVERSION G_STMT_START{\
194 mono_raise_exception (mono_get_exception_argument ( \
195 "value", "not a widening conversion")); \
196 }G_STMT_END
198 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
199 if (esize < vsize + (extra)) \
200 mono_raise_exception (mono_get_exception_argument ( \
201 "value", "not a widening conversion")); \
202 }G_STMT_END
204 #define INVALID_CAST G_STMT_START{\
205 mono_raise_exception (mono_get_exception_invalid_cast ()); \
206 }G_STMT_END
208 /* Check element (destination) type. */
209 switch (ec->byval_arg.type) {
210 case MONO_TYPE_STRING:
211 switch (vc->byval_arg.type) {
212 case MONO_TYPE_STRING:
213 break;
214 default:
215 INVALID_CAST;
217 break;
218 case MONO_TYPE_BOOLEAN:
219 switch (vc->byval_arg.type) {
220 case MONO_TYPE_BOOLEAN:
221 break;
222 case MONO_TYPE_CHAR:
223 case MONO_TYPE_U1:
224 case MONO_TYPE_U2:
225 case MONO_TYPE_U4:
226 case MONO_TYPE_U8:
227 case MONO_TYPE_I1:
228 case MONO_TYPE_I2:
229 case MONO_TYPE_I4:
230 case MONO_TYPE_I8:
231 case MONO_TYPE_R4:
232 case MONO_TYPE_R8:
233 NO_WIDENING_CONVERSION;
234 default:
235 INVALID_CAST;
237 break;
240 if (!ec->valuetype) {
241 if (!mono_object_isinst (value, ec))
242 INVALID_CAST;
243 *ea = (gpointer)value;
244 return;
247 if (mono_object_isinst (value, ec)) {
248 memcpy (ea, (char *)value + sizeof (MonoObject), esize);
249 return;
252 if (!vc->valuetype)
253 INVALID_CAST;
255 vsize = mono_class_instance_size (vc) - sizeof (MonoObject);
257 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
258 switch (vc->byval_arg.type) { \
259 case MONO_TYPE_U1: \
260 case MONO_TYPE_U2: \
261 case MONO_TYPE_U4: \
262 case MONO_TYPE_U8: \
263 case MONO_TYPE_CHAR: \
264 CHECK_WIDENING_CONVERSION(0); \
265 *(etype *) ea = (etype) u64; \
266 return; \
267 /* You can't assign a signed value to an unsigned array. */ \
268 case MONO_TYPE_I1: \
269 case MONO_TYPE_I2: \
270 case MONO_TYPE_I4: \
271 case MONO_TYPE_I8: \
272 /* You can't assign a floating point number to an integer array. */ \
273 case MONO_TYPE_R4: \
274 case MONO_TYPE_R8: \
275 NO_WIDENING_CONVERSION; \
277 }G_STMT_END
279 #define ASSIGN_SIGNED(etype) G_STMT_START{\
280 switch (vc->byval_arg.type) { \
281 case MONO_TYPE_I1: \
282 case MONO_TYPE_I2: \
283 case MONO_TYPE_I4: \
284 case MONO_TYPE_I8: \
285 CHECK_WIDENING_CONVERSION(0); \
286 *(etype *) ea = (etype) i64; \
287 return; \
288 /* You can assign an unsigned value to a signed array if the array's */ \
289 /* element size is larger than the value size. */ \
290 case MONO_TYPE_U1: \
291 case MONO_TYPE_U2: \
292 case MONO_TYPE_U4: \
293 case MONO_TYPE_U8: \
294 case MONO_TYPE_CHAR: \
295 CHECK_WIDENING_CONVERSION(1); \
296 *(etype *) ea = (etype) u64; \
297 return; \
298 /* You can't assign a floating point number to an integer array. */ \
299 case MONO_TYPE_R4: \
300 case MONO_TYPE_R8: \
301 NO_WIDENING_CONVERSION; \
303 }G_STMT_END
305 #define ASSIGN_REAL(etype) G_STMT_START{\
306 switch (vc->byval_arg.type) { \
307 case MONO_TYPE_R4: \
308 case MONO_TYPE_R8: \
309 CHECK_WIDENING_CONVERSION(0); \
310 *(etype *) ea = (etype) r64; \
311 return; \
312 /* All integer values fit into a floating point array, so we don't */ \
313 /* need to CHECK_WIDENING_CONVERSION here. */ \
314 case MONO_TYPE_I1: \
315 case MONO_TYPE_I2: \
316 case MONO_TYPE_I4: \
317 case MONO_TYPE_I8: \
318 *(etype *) ea = (etype) i64; \
319 return; \
320 case MONO_TYPE_U1: \
321 case MONO_TYPE_U2: \
322 case MONO_TYPE_U4: \
323 case MONO_TYPE_U8: \
324 case MONO_TYPE_CHAR: \
325 *(etype *) ea = (etype) u64; \
326 return; \
328 }G_STMT_END
330 switch (vc->byval_arg.type) {
331 case MONO_TYPE_U1:
332 u64 = *(guint8 *) va;
333 break;
334 case MONO_TYPE_U2:
335 u64 = *(guint16 *) va;
336 break;
337 case MONO_TYPE_U4:
338 u64 = *(guint32 *) va;
339 break;
340 case MONO_TYPE_U8:
341 u64 = *(guint64 *) va;
342 break;
343 case MONO_TYPE_I1:
344 i64 = *(gint8 *) va;
345 break;
346 case MONO_TYPE_I2:
347 i64 = *(gint16 *) va;
348 break;
349 case MONO_TYPE_I4:
350 i64 = *(gint32 *) va;
351 break;
352 case MONO_TYPE_I8:
353 i64 = *(gint64 *) va;
354 break;
355 case MONO_TYPE_R4:
356 r64 = *(gfloat *) va;
357 break;
358 case MONO_TYPE_R8:
359 r64 = *(gdouble *) va;
360 break;
361 case MONO_TYPE_CHAR:
362 u64 = *(guint16 *) va;
363 break;
364 case MONO_TYPE_BOOLEAN:
365 /* Boolean is only compatible with itself. */
366 switch (ec->byval_arg.type) {
367 case MONO_TYPE_CHAR:
368 case MONO_TYPE_U1:
369 case MONO_TYPE_U2:
370 case MONO_TYPE_U4:
371 case MONO_TYPE_U8:
372 case MONO_TYPE_I1:
373 case MONO_TYPE_I2:
374 case MONO_TYPE_I4:
375 case MONO_TYPE_I8:
376 case MONO_TYPE_R4:
377 case MONO_TYPE_R8:
378 NO_WIDENING_CONVERSION;
379 default:
380 INVALID_CAST;
382 break;
385 /* If we can't do a direct copy, let's try a widening conversion. */
386 switch (ec->byval_arg.type) {
387 case MONO_TYPE_CHAR:
388 ASSIGN_UNSIGNED (guint16);
389 case MONO_TYPE_U1:
390 ASSIGN_UNSIGNED (guint8);
391 case MONO_TYPE_U2:
392 ASSIGN_UNSIGNED (guint16);
393 case MONO_TYPE_U4:
394 ASSIGN_UNSIGNED (guint32);
395 case MONO_TYPE_U8:
396 ASSIGN_UNSIGNED (guint64);
397 case MONO_TYPE_I1:
398 ASSIGN_SIGNED (gint8);
399 case MONO_TYPE_I2:
400 ASSIGN_SIGNED (gint16);
401 case MONO_TYPE_I4:
402 ASSIGN_SIGNED (gint32);
403 case MONO_TYPE_I8:
404 ASSIGN_SIGNED (gint64);
405 case MONO_TYPE_R4:
406 ASSIGN_REAL (gfloat);
407 case MONO_TYPE_R8:
408 ASSIGN_REAL (gdouble);
411 INVALID_CAST;
412 /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
413 return;
415 #undef INVALID_CAST
416 #undef NO_WIDENING_CONVERSION
417 #undef CHECK_WIDENING_CONVERSION
418 #undef ASSIGN_UNSIGNED
419 #undef ASSIGN_SIGNED
420 #undef ASSIGN_REAL
423 static void
424 ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
425 MonoArray *idxs)
427 MonoClass *ac, *ic;
428 gint32 i, pos, *ind;
430 MONO_ARCH_SAVE_REGS;
432 MONO_CHECK_ARG_NULL (idxs);
434 ic = idxs->obj.vtable->klass;
435 ac = this->obj.vtable->klass;
437 g_assert (ic->rank == 1);
438 if (idxs->bounds != NULL || idxs->max_length != ac->rank)
439 mono_raise_exception (mono_get_exception_argument (NULL, NULL));
441 ind = (guint32 *)idxs->vector;
443 if (this->bounds == NULL) {
444 if (*ind < 0 || *ind >= this->max_length)
445 mono_raise_exception (mono_get_exception_index_out_of_range ());
447 ves_icall_System_Array_SetValueImpl (this, value, *ind);
448 return;
451 for (i = 0; i < ac->rank; i++)
452 if ((ind [i] < this->bounds [i].lower_bound) ||
453 (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
454 mono_raise_exception (mono_get_exception_index_out_of_range ());
456 pos = ind [0] - this->bounds [0].lower_bound;
457 for (i = 1; i < ac->rank; i++)
458 pos = pos * this->bounds [i].length + ind [i] -
459 this->bounds [i].lower_bound;
461 ves_icall_System_Array_SetValueImpl (this, value, pos);
464 static MonoArray *
465 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType *type, MonoArray *lengths, MonoArray *bounds)
467 MonoClass *aklass;
468 MonoArray *array;
469 gint32 *sizes, i;
470 gboolean bounded = FALSE;
472 MONO_ARCH_SAVE_REGS;
474 MONO_CHECK_ARG_NULL (type);
475 MONO_CHECK_ARG_NULL (lengths);
477 MONO_CHECK_ARG (lengths, mono_array_length (lengths) > 0);
478 if (bounds)
479 MONO_CHECK_ARG (bounds, mono_array_length (lengths) == mono_array_length (bounds));
481 for (i = 0; i < mono_array_length (lengths); i++)
482 if (mono_array_get (lengths, gint32, i) < 0)
483 mono_raise_exception (mono_get_exception_argument_out_of_range (NULL));
485 if (bounds && (mono_array_length (bounds) == 1) && (mono_array_get (bounds, gint32, 0) != 0))
486 /* vectors are not the same as one dimensional arrays with no-zero bounds */
487 bounded = TRUE;
488 else
489 bounded = FALSE;
491 aklass = mono_bounded_array_class_get (mono_class_from_mono_type (type->type), mono_array_length (lengths), bounded);
493 sizes = alloca (aklass->rank * sizeof(guint32) * 2);
494 for (i = 0; i < aklass->rank; ++i) {
495 sizes [i] = mono_array_get (lengths, gint32, i);
496 if (bounds)
497 sizes [i + aklass->rank] = mono_array_get (bounds, gint32, i);
498 else
499 sizes [i + aklass->rank] = 0;
502 array = mono_array_new_full (mono_object_domain (type), aklass, sizes, sizes + aklass->rank);
504 return array;
507 static gint32
508 ves_icall_System_Array_GetRank (MonoObject *this)
510 MONO_ARCH_SAVE_REGS;
512 return this->vtable->klass->rank;
515 static gint32
516 ves_icall_System_Array_GetLength (MonoArray *this, gint32 dimension)
518 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
520 MONO_ARCH_SAVE_REGS;
522 if ((dimension < 0) || (dimension >= rank))
523 mono_raise_exception (mono_get_exception_index_out_of_range ());
525 if (this->bounds == NULL)
526 return this->max_length;
528 return this->bounds [dimension].length;
531 static gint32
532 ves_icall_System_Array_GetLowerBound (MonoArray *this, gint32 dimension)
534 gint32 rank = ((MonoObject *)this)->vtable->klass->rank;
536 MONO_ARCH_SAVE_REGS;
538 if ((dimension < 0) || (dimension >= rank))
539 mono_raise_exception (mono_get_exception_index_out_of_range ());
541 if (this->bounds == NULL)
542 return 0;
544 return this->bounds [dimension].lower_bound;
547 static void
548 ves_icall_System_Array_ClearInternal (MonoArray *arr, int idx, int length)
550 int sz = mono_array_element_size (mono_object_class (arr));
551 memset (mono_array_addr_with_size (arr, idx, sz), 0, length * sz);
554 static gboolean
555 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
557 int element_size;
558 void * dest_addr;
559 void * source_addr;
560 MonoClass *src_class;
561 MonoClass *dest_class;
562 int i;
564 MONO_ARCH_SAVE_REGS;
566 if (source->obj.vtable->klass->rank != dest->obj.vtable->klass->rank)
567 return FALSE;
569 if (source->bounds || dest->bounds)
570 return FALSE;
572 if ((dest_idx + length > mono_array_length (dest)) ||
573 (source_idx + length > mono_array_length (source)))
574 return FALSE;
576 element_size = mono_array_element_size (source->obj.vtable->klass);
577 dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
578 source_addr = mono_array_addr_with_size (source, element_size, source_idx);
580 src_class = source->obj.vtable->klass->element_class;
581 dest_class = dest->obj.vtable->klass->element_class;
584 * Handle common cases.
587 /* Case1: object[] -> valuetype[] (ArrayList::ToArray) */
588 if (src_class == mono_defaults.object_class && dest_class->valuetype) {
589 for (i = source_idx; i < source_idx + length; ++i) {
590 MonoObject *elem = mono_array_get (source, MonoObject*, i);
591 if (elem && !mono_object_isinst (elem, dest_class))
592 return FALSE;
595 element_size = mono_array_element_size (dest->obj.vtable->klass);
596 for (i = 0; i < length; ++i) {
597 MonoObject *elem = mono_array_get (source, MonoObject*, source_idx + i);
598 void *addr = mono_array_addr_with_size (dest, element_size, dest_idx + i);
599 if (!elem)
600 memset (addr, 0, element_size);
601 else
602 memcpy (addr, (char *)elem + sizeof (MonoObject), element_size);
604 return TRUE;
607 if (src_class != dest_class) {
608 if (dest_class->valuetype || dest_class->enumtype || src_class->valuetype || src_class->enumtype)
609 return FALSE;
611 if (mono_class_is_subclass_of (src_class, dest_class, FALSE))
613 /* Case2: object[] -> reftype[] (ArrayList::ToArray) */
614 else if (mono_class_is_subclass_of (dest_class, src_class, FALSE))
615 for (i = source_idx; i < source_idx + length; ++i) {
616 MonoObject *elem = mono_array_get (source, MonoObject*, i);
617 if (elem && !mono_object_isinst (elem, dest_class))
618 return FALSE;
620 else
621 return FALSE;
624 memmove (dest_addr, source_addr, element_size * length);
626 return TRUE;
629 static void
630 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArray *array, MonoClassField *field_handle)
632 MonoClass *klass = array->obj.vtable->klass;
633 guint32 size = mono_array_element_size (klass);
634 int i;
636 MONO_ARCH_SAVE_REGS;
638 if (array->bounds == NULL)
639 size *= array->max_length;
640 else
641 for (i = 0; i < klass->rank; ++i)
642 size *= array->bounds [i].length;
644 memcpy (mono_array_addr (array, char, 0), field_handle->data, size);
646 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
647 #define SWAP(n) {\
648 gint i; \
649 guint ## n tmp; \
650 guint ## n *data = (guint ## n *) mono_array_addr (array, char, 0); \
652 for (i = 0; i < size; i += n/8, data++) { \
653 tmp = read ## n (data); \
654 *data = tmp; \
658 /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
660 switch (klass->element_class->byval_arg.type) {
661 case MONO_TYPE_CHAR:
662 case MONO_TYPE_I2:
663 case MONO_TYPE_U2:
664 SWAP (16);
665 break;
666 case MONO_TYPE_I4:
667 case MONO_TYPE_U4:
668 SWAP (32);
669 break;
670 case MONO_TYPE_I8:
671 case MONO_TYPE_U8:
672 SWAP (64);
673 break;
676 #endif
679 static gint
680 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
682 MONO_ARCH_SAVE_REGS;
684 return offsetof (MonoString, chars);
687 static MonoObject *
688 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject *obj)
690 MONO_ARCH_SAVE_REGS;
692 if ((obj == NULL) || (! (obj->vtable->klass->valuetype)))
693 return obj;
694 else
695 return mono_object_clone (obj);
698 static void
699 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType *handle)
701 MonoClass *klass;
703 MONO_ARCH_SAVE_REGS;
705 MONO_CHECK_ARG_NULL (handle);
707 klass = mono_class_from_mono_type (handle);
708 MONO_CHECK_ARG (handle, klass);
710 /* This will call the type constructor */
711 if (! (klass->flags & TYPE_ATTRIBUTE_INTERFACE))
712 mono_runtime_class_init (mono_class_vtable (mono_domain_get (), klass));
715 static MonoObject *
716 ves_icall_System_Object_MemberwiseClone (MonoObject *this)
718 MONO_ARCH_SAVE_REGS;
720 return mono_object_clone (this);
723 #if HAVE_BOEHM_GC
724 #define MONO_OBJECT_ALIGNMENT_SHIFT 3
725 #else
726 #define MONO_OBJECT_ALIGNMENT_SHIFT 2
727 #endif
730 * Return hashcode based on object address. This function will need to be
731 * smarter in the presence of a moving garbage collector, which will cache
732 * the address hash before relocating the object.
734 * Wang's address-based hash function:
735 * http://www.concentric.net/~Ttwang/tech/addrhash.htm
737 static gint32
738 ves_icall_System_Object_GetHashCode (MonoObject *this)
740 register guint32 key;
742 MONO_ARCH_SAVE_REGS;
744 key = (GPOINTER_TO_UINT (this) >> MONO_OBJECT_ALIGNMENT_SHIFT) * 2654435761u;
746 return key & 0x7fffffff;
749 static gint32
750 ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fields)
752 int i;
753 MonoClass *klass;
754 MonoObject **values = NULL;
755 MonoObject *o;
756 int count = 0;
757 gint32 result = 0;
759 MONO_ARCH_SAVE_REGS;
761 klass = this->vtable->klass;
763 if (klass->field.count == 0)
764 return ves_icall_System_Object_GetHashCode (this);
767 * Compute the starting value of the hashcode for fields of primitive
768 * types, and return the remaining fields in an array to the managed side.
769 * This way, we can avoid costly reflection operations in managed code.
771 for (i = 0; i < klass->field.count; ++i) {
772 MonoClassField *field = &klass->fields [i];
773 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
774 continue;
775 if (mono_field_is_deleted (field))
776 continue;
777 /* FIXME: Add more types */
778 switch (field->type->type) {
779 case MONO_TYPE_I4:
780 result ^= *(gint32*)((guint8*)this + field->offset);
781 break;
782 case MONO_TYPE_STRING: {
783 MonoString *s;
784 s = *(MonoString**)((guint8*)this + field->offset);
785 if (s != NULL)
786 result ^= ves_icall_System_String_GetHashCode (s);
787 break;
789 default:
790 if (!values)
791 values = alloca (klass->field.count * sizeof (MonoObject*));
792 o = mono_field_get_value_object (mono_object_domain (this), field, this);
793 values [count++] = o;
797 if (values) {
798 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
799 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
801 else
802 *fields = NULL;
803 return result;
806 static MonoBoolean
807 ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that, MonoArray **fields)
809 int i;
810 MonoClass *klass;
811 MonoObject **values = NULL;
812 MonoObject *o;
813 int count = 0;
815 MONO_ARCH_SAVE_REGS;
817 MONO_CHECK_ARG_NULL (that);
819 if (this->vtable != that->vtable)
820 return FALSE;
822 klass = this->vtable->klass;
825 * Do the comparison for fields of primitive type and return a result if
826 * possible. Otherwise, return the remaining fields in an array to the
827 * managed side. This way, we can avoid costly reflection operations in
828 * managed code.
830 *fields = NULL;
831 for (i = 0; i < klass->field.count; ++i) {
832 MonoClassField *field = &klass->fields [i];
833 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
834 continue;
835 if (mono_field_is_deleted (field))
836 continue;
837 /* FIXME: Add more types */
838 switch (field->type->type) {
839 case MONO_TYPE_I4:
840 if (*(gint32*)((guint8*)this + field->offset) != *(gint32*)((guint8*)that + field->offset))
841 return FALSE;
842 break;
843 case MONO_TYPE_STRING: {
844 MonoString *s1, *s2;
845 guint32 s1len, s2len;
846 s1 = *(MonoString**)((guint8*)this + field->offset);
847 s2 = *(MonoString**)((guint8*)that + field->offset);
848 if (s1 == s2)
849 break;
850 if ((s1 == NULL) || (s2 == NULL))
851 return FALSE;
852 s1len = mono_string_length (s1);
853 s2len = mono_string_length (s2);
854 if (s1len != s2len)
855 return FALSE;
857 if (memcmp (mono_string_chars (s1), mono_string_chars (s2), s1len * sizeof (gunichar2)) != 0)
858 return FALSE;
859 break;
861 default:
862 if (!values)
863 values = alloca (klass->field.count * 2 * sizeof (MonoObject*));
864 o = mono_field_get_value_object (mono_object_domain (this), field, this);
865 values [count++] = o;
866 o = mono_field_get_value_object (mono_object_domain (this), field, that);
867 values [count++] = o;
871 if (values) {
872 *fields = mono_array_new (mono_domain_get (), mono_defaults.object_class, count);
873 memcpy (mono_array_addr (*fields, MonoObject*, 0), values, count * sizeof (MonoObject*));
875 return FALSE;
877 else
878 return TRUE;
881 static MonoReflectionType *
882 ves_icall_System_Object_GetType (MonoObject *obj)
884 MONO_ARCH_SAVE_REGS;
886 if (obj->vtable->klass != mono_defaults.transparent_proxy_class)
887 return mono_type_get_object (mono_object_domain (obj), &obj->vtable->klass->byval_arg);
888 else
889 return mono_type_get_object (mono_object_domain (obj), &((MonoTransparentProxy*)obj)->remote_class->proxy_class->byval_arg);
892 static void
893 mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
895 MONO_ARCH_SAVE_REGS;
897 mtype->type = &obj->vtable->klass->byval_arg;
898 g_assert (mtype->type->type);
901 static gint32
902 ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj)
904 MONO_ARCH_SAVE_REGS;
906 MONO_CHECK_ARG_NULL (obj);
908 return mono_image_create_token (mb->dynamic_image, obj, TRUE);
911 static gint32
912 ves_icall_ModuleBuilder_getMethodToken (MonoReflectionModuleBuilder *mb,
913 MonoReflectionMethod *method,
914 MonoArray *opt_param_types)
916 MONO_ARCH_SAVE_REGS;
918 MONO_CHECK_ARG_NULL (method);
920 return mono_image_create_method_token (
921 mb->dynamic_image, (MonoObject *) method, opt_param_types);
924 static void
925 ves_icall_ModuleBuilder_WriteToFile (MonoReflectionModuleBuilder *mb, HANDLE file)
927 MONO_ARCH_SAVE_REGS;
929 mono_image_create_pefile (mb, file);
932 static void
933 ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
935 MONO_ARCH_SAVE_REGS;
937 mono_image_build_metadata (mb);
940 static MonoReflectionType *
941 type_from_name (const char *str, MonoBoolean ignoreCase)
943 MonoType *type = NULL;
944 MonoAssembly *assembly;
945 MonoTypeNameParse info;
946 char *temp_str = g_strdup (str);
947 gboolean type_resolve = FALSE;
949 MONO_ARCH_SAVE_REGS;
951 /* mono_reflection_parse_type() mangles the string */
952 if (!mono_reflection_parse_type (temp_str, &info)) {
953 g_list_free (info.modifiers);
954 g_list_free (info.nested);
955 g_free (temp_str);
956 return NULL;
959 if (info.assembly.name) {
960 assembly = mono_assembly_load (&info.assembly, NULL, NULL);
961 } else {
962 MonoReflectionAssembly *refass;
964 refass = ves_icall_System_Reflection_Assembly_GetCallingAssembly ();
965 assembly = refass->assembly;
968 if (assembly)
969 type = mono_reflection_get_type (assembly->image, &info, ignoreCase, &type_resolve);
971 if (!info.assembly.name && !type) /* try mscorlib */
972 type = mono_reflection_get_type (NULL, &info, ignoreCase, &type_resolve);
974 g_list_free (info.modifiers);
975 g_list_free (info.nested);
976 g_free (temp_str);
978 if (!type)
979 return NULL;
981 return mono_type_get_object (mono_domain_get (), type);
984 #ifdef UNUSED
985 MonoReflectionType *
986 mono_type_get (const char *str)
988 char *copy = g_strdup (str);
989 MonoReflectionType *type = type_from_name (copy, FALSE);
991 g_free (copy);
992 return type;
994 #endif
996 static MonoReflectionType*
997 ves_icall_type_from_name (MonoString *name,
998 MonoBoolean throwOnError,
999 MonoBoolean ignoreCase)
1001 char *str = mono_string_to_utf8 (name);
1002 MonoReflectionType *type;
1004 type = type_from_name (str, ignoreCase);
1005 g_free (str);
1006 if (type == NULL){
1007 if (throwOnError)
1008 mono_raise_exception (mono_get_exception_type_load (name));
1011 return type;
1015 static MonoReflectionType*
1016 ves_icall_type_from_handle (MonoType *handle)
1018 MonoDomain *domain = mono_domain_get ();
1019 MonoClass *klass = mono_class_from_mono_type (handle);
1021 MONO_ARCH_SAVE_REGS;
1023 mono_class_init (klass);
1024 return mono_type_get_object (domain, handle);
1027 static guint32
1028 ves_icall_type_Equals (MonoReflectionType *type, MonoReflectionType *c)
1030 MONO_ARCH_SAVE_REGS;
1032 if (type->type && c->type)
1033 return mono_metadata_type_equal (type->type, c->type);
1034 g_print ("type equals\n");
1035 return 0;
1038 /* System.TypeCode */
1039 typedef enum {
1040 TYPECODE_EMPTY,
1041 TYPECODE_OBJECT,
1042 TYPECODE_DBNULL,
1043 TYPECODE_BOOLEAN,
1044 TYPECODE_CHAR,
1045 TYPECODE_SBYTE,
1046 TYPECODE_BYTE,
1047 TYPECODE_INT16,
1048 TYPECODE_UINT16,
1049 TYPECODE_INT32,
1050 TYPECODE_UINT32,
1051 TYPECODE_INT64,
1052 TYPECODE_UINT64,
1053 TYPECODE_SINGLE,
1054 TYPECODE_DOUBLE,
1055 TYPECODE_DECIMAL,
1056 TYPECODE_DATETIME,
1057 TYPECODE_STRING = 18
1058 } TypeCode;
1060 static guint32
1061 ves_icall_type_GetTypeCode (MonoReflectionType *type)
1063 int t = type->type->type;
1065 MONO_ARCH_SAVE_REGS;
1067 if (type->type->byref)
1068 return TYPECODE_OBJECT;
1070 handle_enum:
1071 switch (t) {
1072 case MONO_TYPE_VOID:
1073 return TYPECODE_OBJECT;
1074 case MONO_TYPE_BOOLEAN:
1075 return TYPECODE_BOOLEAN;
1076 case MONO_TYPE_U1:
1077 return TYPECODE_BYTE;
1078 case MONO_TYPE_I1:
1079 return TYPECODE_SBYTE;
1080 case MONO_TYPE_U2:
1081 return TYPECODE_UINT16;
1082 case MONO_TYPE_I2:
1083 return TYPECODE_INT16;
1084 case MONO_TYPE_CHAR:
1085 return TYPECODE_CHAR;
1086 case MONO_TYPE_PTR:
1087 case MONO_TYPE_U:
1088 case MONO_TYPE_I:
1089 return TYPECODE_OBJECT;
1090 case MONO_TYPE_U4:
1091 return TYPECODE_UINT32;
1092 case MONO_TYPE_I4:
1093 return TYPECODE_INT32;
1094 case MONO_TYPE_U8:
1095 return TYPECODE_UINT64;
1096 case MONO_TYPE_I8:
1097 return TYPECODE_INT64;
1098 case MONO_TYPE_R4:
1099 return TYPECODE_SINGLE;
1100 case MONO_TYPE_R8:
1101 return TYPECODE_DOUBLE;
1102 case MONO_TYPE_VALUETYPE:
1103 if (type->type->data.klass->enumtype) {
1104 t = type->type->data.klass->enum_basetype->type;
1105 goto handle_enum;
1106 } else {
1107 MonoClass *k = type->type->data.klass;
1108 if (strcmp (k->name_space, "System") == 0) {
1109 if (strcmp (k->name, "Decimal") == 0)
1110 return TYPECODE_DECIMAL;
1111 else if (strcmp (k->name, "DateTime") == 0)
1112 return TYPECODE_DATETIME;
1115 return TYPECODE_OBJECT;
1116 case MONO_TYPE_STRING:
1117 return TYPECODE_STRING;
1118 case MONO_TYPE_SZARRAY:
1119 case MONO_TYPE_ARRAY:
1120 case MONO_TYPE_OBJECT:
1121 case MONO_TYPE_VAR:
1122 case MONO_TYPE_MVAR:
1123 return TYPECODE_OBJECT;
1124 case MONO_TYPE_CLASS:
1126 MonoClass *k = type->type->data.klass;
1127 if (strcmp (k->name_space, "System") == 0) {
1128 if (strcmp (k->name, "DBNull") == 0)
1129 return TYPECODE_DBNULL;
1132 return TYPECODE_OBJECT;
1133 case MONO_TYPE_GENERICINST:
1134 return TYPECODE_OBJECT;
1135 default:
1136 g_error ("type 0x%02x not handled in GetTypeCode()", t);
1138 return 0;
1141 static guint32
1142 ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c, MonoBoolean check_interfaces)
1144 MonoDomain *domain;
1145 MonoClass *klass;
1146 MonoClass *klassc;
1148 MONO_ARCH_SAVE_REGS;
1150 g_assert (type != NULL);
1152 domain = ((MonoObject *)type)->vtable->domain;
1154 if (!c) /* FIXME: dont know what do do here */
1155 return 0;
1157 klass = mono_class_from_mono_type (type->type);
1158 klassc = mono_class_from_mono_type (c->type);
1160 if (type->type->byref)
1161 return klassc == mono_defaults.object_class;
1163 return mono_class_is_subclass_of (klass, klassc, check_interfaces);
1166 static guint32
1167 ves_icall_type_is_assignable_from (MonoReflectionType *type, MonoReflectionType *c)
1169 MonoDomain *domain;
1170 MonoClass *klass;
1171 MonoClass *klassc;
1173 MONO_ARCH_SAVE_REGS;
1175 g_assert (type != NULL);
1177 domain = ((MonoObject *)type)->vtable->domain;
1179 klass = mono_class_from_mono_type (type->type);
1180 klassc = mono_class_from_mono_type (c->type);
1182 if (type->type->byref && !c->type->byref)
1183 return FALSE;
1185 return mono_class_is_assignable_from (klass, klassc);
1188 static guint32
1189 ves_icall_type_IsInstanceOfType (MonoReflectionType *type, MonoObject *obj)
1191 MonoClass *klass = mono_class_from_mono_type (type->type);
1192 return mono_object_isinst (obj, klass) != NULL;
1195 static guint32
1196 ves_icall_get_attributes (MonoReflectionType *type)
1198 MonoClass *klass = mono_class_from_mono_type (type->type);
1200 MONO_ARCH_SAVE_REGS;
1202 return klass->flags;
1205 static MonoReflectionMarshal*
1206 ves_icall_System_Reflection_FieldInfo_GetUnmanagedMarshal (MonoReflectionField *field)
1208 MonoClass *klass = field->field->parent;
1209 MonoMarshalType *info;
1210 int i;
1212 if (klass->generic_container ||
1213 (klass->generic_class && klass->generic_class->inst->is_open))
1214 return NULL;
1216 info = mono_marshal_load_type_info (klass);
1218 for (i = 0; i < info->num_fields; ++i) {
1219 if (info->fields [i].field == field->field) {
1220 if (!info->fields [i].mspec)
1221 return NULL;
1222 else
1223 return mono_reflection_marshal_from_marshal_spec (field->object.vtable->domain, klass, info->fields [i].mspec);
1227 return NULL;
1230 static MonoReflectionField*
1231 ves_icall_System_Reflection_FieldInfo_internal_from_handle (MonoClassField *handle)
1233 MONO_ARCH_SAVE_REGS;
1235 g_assert (handle);
1237 return mono_field_get_object (mono_domain_get (), handle->parent, handle);
1240 static void
1241 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
1243 MonoDomain *domain = mono_domain_get ();
1245 MONO_ARCH_SAVE_REGS;
1247 info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
1248 info->ret = mono_type_get_object (domain, method->signature->ret);
1249 info->attrs = method->flags;
1250 info->implattrs = method->iflags;
1251 if (method->signature->call_convention == MONO_CALL_DEFAULT)
1252 info->callconv = 1;
1253 else {
1254 if (method->signature->call_convention == MONO_CALL_VARARG)
1255 info->callconv = 2;
1256 else
1257 info->callconv = 0;
1259 info->callconv |= (method->signature->hasthis << 5) | (method->signature->explicit_this << 6);
1262 static MonoArray*
1263 ves_icall_get_parameter_info (MonoMethod *method)
1265 MonoDomain *domain = mono_domain_get ();
1267 MONO_ARCH_SAVE_REGS;
1269 return mono_param_get_objects (domain, method);
1272 static gint32
1273 ves_icall_MonoField_GetFieldOffset (MonoReflectionField *field)
1275 return field->field->offset - sizeof (MonoObject);
1278 static MonoReflectionType*
1279 ves_icall_MonoField_GetParentType (MonoReflectionField *field, MonoBoolean declaring)
1281 MonoClass *parent;
1282 MONO_ARCH_SAVE_REGS;
1284 parent = declaring? field->field->parent: field->klass;
1286 return mono_type_get_object (mono_object_domain (field), &parent->byval_arg);
1289 static MonoObject *
1290 ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *obj)
1292 MonoObject *o;
1293 MonoClassField *cf = field->field;
1294 MonoClass *klass;
1295 MonoVTable *vtable;
1296 MonoDomain *domain = mono_object_domain (field);
1297 gchar *v;
1298 gboolean is_static = FALSE;
1299 gboolean is_ref = FALSE;
1301 MONO_ARCH_SAVE_REGS;
1303 mono_class_init (field->klass);
1305 switch (cf->type->type) {
1306 case MONO_TYPE_STRING:
1307 case MONO_TYPE_OBJECT:
1308 case MONO_TYPE_CLASS:
1309 case MONO_TYPE_ARRAY:
1310 case MONO_TYPE_SZARRAY:
1311 is_ref = TRUE;
1312 break;
1313 case MONO_TYPE_U1:
1314 case MONO_TYPE_I1:
1315 case MONO_TYPE_BOOLEAN:
1316 case MONO_TYPE_U2:
1317 case MONO_TYPE_I2:
1318 case MONO_TYPE_CHAR:
1319 case MONO_TYPE_U:
1320 case MONO_TYPE_I:
1321 case MONO_TYPE_U4:
1322 case MONO_TYPE_I4:
1323 case MONO_TYPE_R4:
1324 case MONO_TYPE_U8:
1325 case MONO_TYPE_I8:
1326 case MONO_TYPE_R8:
1327 case MONO_TYPE_VALUETYPE:
1328 is_ref = cf->type->byref;
1329 break;
1330 default:
1331 g_error ("type 0x%x not handled in "
1332 "ves_icall_Monofield_GetValue", cf->type->type);
1333 return NULL;
1336 vtable = NULL;
1337 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1338 is_static = TRUE;
1339 vtable = mono_class_vtable (domain, field->klass);
1340 if (!vtable->initialized && !(cf->type->attrs & FIELD_ATTRIBUTE_LITERAL))
1341 mono_runtime_class_init (vtable);
1344 if (is_ref) {
1345 if (is_static) {
1346 mono_field_static_get_value (vtable, cf, &o);
1347 } else {
1348 mono_field_get_value (obj, cf, &o);
1350 return o;
1353 /* boxed value type */
1354 klass = mono_class_from_mono_type (cf->type);
1355 o = mono_object_new (domain, klass);
1356 v = ((gchar *) o) + sizeof (MonoObject);
1357 if (is_static) {
1358 mono_field_static_get_value (vtable, cf, v);
1359 } else {
1360 mono_field_get_value (obj, cf, v);
1363 return o;
1366 static void
1367 ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
1369 MonoClassField *cf = field->field;
1370 gchar *v;
1372 MONO_ARCH_SAVE_REGS;
1374 v = (gchar *) value;
1375 if (!cf->type->byref) {
1376 switch (cf->type->type) {
1377 case MONO_TYPE_U1:
1378 case MONO_TYPE_I1:
1379 case MONO_TYPE_BOOLEAN:
1380 case MONO_TYPE_U2:
1381 case MONO_TYPE_I2:
1382 case MONO_TYPE_CHAR:
1383 case MONO_TYPE_U:
1384 case MONO_TYPE_I:
1385 case MONO_TYPE_U4:
1386 case MONO_TYPE_I4:
1387 case MONO_TYPE_R4:
1388 case MONO_TYPE_U8:
1389 case MONO_TYPE_I8:
1390 case MONO_TYPE_R8:
1391 case MONO_TYPE_VALUETYPE:
1392 v += sizeof (MonoObject);
1393 break;
1394 case MONO_TYPE_STRING:
1395 case MONO_TYPE_OBJECT:
1396 case MONO_TYPE_CLASS:
1397 case MONO_TYPE_ARRAY:
1398 case MONO_TYPE_SZARRAY:
1399 /* Do nothing */
1400 break;
1401 default:
1402 g_error ("type 0x%x not handled in "
1403 "ves_icall_FieldInfo_SetValueInternal", cf->type->type);
1404 return;
1408 if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
1409 MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), field->klass);
1410 if (!vtable->initialized)
1411 mono_runtime_class_init (vtable);
1412 mono_field_static_set_value (vtable, cf, v);
1413 } else {
1414 mono_field_set_value (obj, cf, v);
1418 static MonoReflectionField*
1419 ves_icall_MonoField_Mono_GetGenericFieldDefinition (MonoReflectionField *field)
1421 MONO_ARCH_SAVE_REGS;
1423 if (field->field->generic_info && field->field->generic_info->reflection_info)
1424 return field->field->generic_info->reflection_info;
1426 return field;
1429 /* From MonoProperty.cs */
1430 typedef enum {
1431 PInfo_Attributes = 1,
1432 PInfo_GetMethod = 1 << 1,
1433 PInfo_SetMethod = 1 << 2,
1434 PInfo_ReflectedType = 1 << 3,
1435 PInfo_DeclaringType = 1 << 4,
1436 PInfo_Name = 1 << 5
1437 } PInfo;
1439 static void
1440 ves_icall_get_property_info (MonoReflectionProperty *property, MonoPropertyInfo *info, PInfo req_info)
1442 MonoDomain *domain = mono_object_domain (property);
1444 MONO_ARCH_SAVE_REGS;
1446 if ((req_info & PInfo_ReflectedType) != 0)
1447 info->parent = mono_type_get_object (domain, &property->klass->byval_arg);
1448 else if ((req_info & PInfo_DeclaringType) != 0)
1449 info->parent = mono_type_get_object (domain, &property->property->parent->byval_arg);
1451 if ((req_info & PInfo_Name) != 0)
1452 info->name = mono_string_new (domain, property->property->name);
1454 if ((req_info & PInfo_Attributes) != 0)
1455 info->attrs = property->property->attrs;
1457 if ((req_info & PInfo_GetMethod) != 0)
1458 info->get = property->property->get ?
1459 mono_method_get_object (domain, property->property->get, NULL): NULL;
1461 if ((req_info & PInfo_SetMethod) != 0)
1462 info->set = property->property->set ?
1463 mono_method_get_object (domain, property->property->set, NULL): NULL;
1465 * There may be other methods defined for properties, though, it seems they are not exposed
1466 * in the reflection API
1470 static void
1471 ves_icall_get_event_info (MonoReflectionEvent *event, MonoEventInfo *info)
1473 MonoDomain *domain = mono_object_domain (event);
1475 MONO_ARCH_SAVE_REGS;
1477 info->declaring_type = mono_type_get_object (domain, &event->klass->byval_arg);
1478 info->reflected_type = mono_type_get_object (domain, &event->event->parent->byval_arg);
1480 info->name = mono_string_new (domain, event->event->name);
1481 info->attrs = event->event->attrs;
1482 info->add_method = event->event->add ? mono_method_get_object (domain, event->event->add, NULL): NULL;
1483 info->remove_method = event->event->remove ? mono_method_get_object (domain, event->event->remove, NULL): NULL;
1484 info->raise_method = event->event->raise ? mono_method_get_object (domain, event->event->raise, NULL): NULL;
1486 if (event->event->other) {
1487 int i, n = 0;
1488 while (event->event->other [n])
1489 n++;
1490 info->other_methods = mono_array_new (domain, mono_defaults.method_info_class, n);
1492 for (i = 0; i < n; i++)
1493 mono_array_set (info->other_methods, gpointer, i,
1494 mono_method_get_object (domain, event->event->other [i], NULL));
1498 static MonoArray*
1499 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
1501 MonoDomain *domain = mono_object_domain (type);
1502 MonoArray *intf;
1503 GPtrArray *ifaces = NULL;
1504 int i;
1505 MonoClass *class = mono_class_from_mono_type (type->type);
1506 MonoClass *parent;
1507 MonoBitSet *slots = mono_bitset_new (class->max_interface_id + 1, 0);
1509 MONO_ARCH_SAVE_REGS;
1511 if (class->rank) {
1512 /* GetInterfaces() returns an empty array in MS.NET (this may be a bug) */
1513 mono_bitset_free (slots);
1514 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1517 for (parent = class; parent; parent = parent->parent) {
1518 GPtrArray *tmp_ifaces = mono_class_get_implemented_interfaces (parent);
1519 if (tmp_ifaces) {
1520 for (i = 0; i < tmp_ifaces->len; ++i) {
1521 MonoClass *ic = g_ptr_array_index (tmp_ifaces, i);
1523 if (mono_bitset_test (slots, ic->interface_id))
1524 continue;
1526 mono_bitset_set (slots, ic->interface_id);
1527 if (ifaces == NULL)
1528 ifaces = g_ptr_array_new ();
1529 g_ptr_array_add (ifaces, ic);
1531 g_ptr_array_free (tmp_ifaces, TRUE);
1534 mono_bitset_free (slots);
1536 if (!ifaces)
1537 return mono_array_new (domain, mono_defaults.monotype_class, 0);
1539 intf = mono_array_new (domain, mono_defaults.monotype_class, ifaces->len);
1540 for (i = 0; i < ifaces->len; ++i) {
1541 MonoClass *ic = g_ptr_array_index (ifaces, i);
1543 mono_array_set (intf, gpointer, i,
1544 mono_type_get_object (domain, &ic->byval_arg));
1546 g_ptr_array_free (ifaces, TRUE);
1548 return intf;
1551 static void
1552 ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
1554 MonoClass *class = mono_class_from_mono_type (type->type);
1555 MonoClass *iclass = mono_class_from_mono_type (iface->type);
1556 MonoReflectionMethod *member;
1557 int i, len, ioffset;
1558 MonoDomain *domain;
1560 MONO_ARCH_SAVE_REGS;
1562 /* type doesn't implement iface: the exception is thrown in managed code */
1563 if ((iclass->interface_id > class->max_interface_id) || !class->interface_offsets [iclass->interface_id])
1564 return;
1566 len = iclass->method.count;
1567 ioffset = class->interface_offsets [iclass->interface_id];
1568 domain = mono_object_domain (type);
1569 *targets = mono_array_new (domain, mono_defaults.method_info_class, len);
1570 *methods = mono_array_new (domain, mono_defaults.method_info_class, len);
1571 for (i = 0; i < len; ++i) {
1572 member = mono_method_get_object (domain, iclass->methods [i], iclass);
1573 mono_array_set (*methods, gpointer, i, member);
1574 member = mono_method_get_object (domain, class->vtable [i + ioffset], class);
1575 mono_array_set (*targets, gpointer, i, member);
1579 static void
1580 ves_icall_Type_GetPacking (MonoReflectionType *type, guint32 *packing, guint32 *size)
1582 MonoClass *klass = mono_class_from_mono_type (type->type);
1584 g_assert (!klass->image->dynamic);
1586 mono_metadata_packing_from_typedef (klass->image, klass->type_token, packing, size);
1589 static MonoReflectionType*
1590 ves_icall_MonoType_GetElementType (MonoReflectionType *type)
1592 MonoClass *class = mono_class_from_mono_type (type->type);
1594 MONO_ARCH_SAVE_REGS;
1596 // GelElementType should only return a type for:
1597 // Array Pointer PassedByRef
1598 if (type->type->byref)
1599 return mono_type_get_object (mono_object_domain (type), &class->byval_arg);
1600 if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
1601 return mono_type_get_object (mono_object_domain (type), class->enum_basetype);
1602 else if (class->element_class && MONO_CLASS_IS_ARRAY (class))
1603 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1604 else if (class->element_class && type->type->type == MONO_TYPE_PTR)
1605 return mono_type_get_object (mono_object_domain (type), &class->element_class->byval_arg);
1606 else
1607 return NULL;
1610 static MonoReflectionType*
1611 ves_icall_get_type_parent (MonoReflectionType *type)
1613 MonoClass *class = mono_class_from_mono_type (type->type);
1615 MONO_ARCH_SAVE_REGS;
1617 return class->parent ? mono_type_get_object (mono_object_domain (type), &class->parent->byval_arg): NULL;
1620 static MonoBoolean
1621 ves_icall_type_ispointer (MonoReflectionType *type)
1623 MONO_ARCH_SAVE_REGS;
1625 return type->type->type == MONO_TYPE_PTR;
1628 static MonoBoolean
1629 ves_icall_type_isprimitive (MonoReflectionType *type)
1631 MONO_ARCH_SAVE_REGS;
1633 return (!type->type->byref && (((type->type->type >= MONO_TYPE_BOOLEAN) && (type->type->type <= MONO_TYPE_R8)) || (type->type->type == MONO_TYPE_I) || (type->type->type == MONO_TYPE_U)));
1636 static MonoBoolean
1637 ves_icall_type_isbyref (MonoReflectionType *type)
1639 MONO_ARCH_SAVE_REGS;
1641 return type->type->byref;
1644 static MonoReflectionModule*
1645 ves_icall_MonoType_get_Module (MonoReflectionType *type)
1647 MonoClass *class = mono_class_from_mono_type (type->type);
1649 MONO_ARCH_SAVE_REGS;
1651 return mono_module_get_object (mono_object_domain (type), class->image);
1654 static MonoReflectionAssembly*
1655 ves_icall_MonoType_get_Assembly (MonoReflectionType *type)
1657 MonoDomain *domain = mono_domain_get ();
1658 MonoClass *class = mono_class_from_mono_type (type->type);
1660 MONO_ARCH_SAVE_REGS;
1662 return mono_assembly_get_object (domain, class->image->assembly);
1665 static MonoReflectionType*
1666 ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
1668 MonoDomain *domain = mono_domain_get ();
1669 MonoClass *class = mono_class_from_mono_type (type->type);
1671 MONO_ARCH_SAVE_REGS;
1673 return class->nested_in ? mono_type_get_object (domain, &class->nested_in->byval_arg) : NULL;
1676 static MonoReflectionType*
1677 ves_icall_MonoType_get_UnderlyingSystemType (MonoReflectionType *type)
1679 MonoDomain *domain = mono_domain_get ();
1680 MonoClass *class = mono_class_from_mono_type (type->type);
1682 MONO_ARCH_SAVE_REGS;
1684 if (class->enumtype && class->enum_basetype) /* types that are modified typebuilders may not have enum_basetype set */
1685 return mono_type_get_object (domain, class->enum_basetype);
1686 else if (class->element_class)
1687 return mono_type_get_object (domain, &class->element_class->byval_arg);
1688 else
1689 return NULL;
1692 static MonoString*
1693 ves_icall_MonoType_get_Name (MonoReflectionType *type)
1695 MonoDomain *domain = mono_domain_get ();
1696 MonoClass *class = mono_class_from_mono_type (type->type);
1698 MONO_ARCH_SAVE_REGS;
1700 return mono_string_new (domain, class->name);
1703 static MonoString*
1704 ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
1706 MonoDomain *domain = mono_domain_get ();
1707 MonoClass *class = mono_class_from_mono_type (type->type);
1709 MONO_ARCH_SAVE_REGS;
1711 while (class->nested_in)
1712 class = class->nested_in;
1714 if (class->name_space [0] == '\0')
1715 return NULL;
1716 else
1717 return mono_string_new (domain, class->name_space);
1720 static gint32
1721 ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
1723 MonoClass *class = mono_class_from_mono_type (type->type);
1725 MONO_ARCH_SAVE_REGS;
1727 return class->rank;
1730 static MonoArray*
1731 ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type)
1733 MonoArray *res;
1734 MonoClass *klass, *pklass;
1735 int i;
1736 MONO_ARCH_SAVE_REGS;
1738 klass = mono_class_from_mono_type (type->type);
1740 if (klass->generic_container) {
1741 MonoGenericContainer *container = klass->generic_container;
1742 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, container->type_argc);
1743 for (i = 0; i < container->type_argc; ++i) {
1744 pklass = mono_class_from_generic_parameter (&container->type_params [i], klass->image, FALSE);
1745 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), &pklass->byval_arg));
1747 } else if (klass->generic_class) {
1748 MonoGenericInst *inst = klass->generic_class->inst;
1749 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, inst->type_argc);
1750 for (i = 0; i < inst->type_argc; ++i) {
1751 mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), inst->type_argv [i]));
1753 } else {
1754 res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, 0);
1756 return res;
1759 static gboolean
1760 ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
1762 MonoClass *klass;
1763 MONO_ARCH_SAVE_REGS;
1765 klass = mono_class_from_mono_type (type->type);
1767 return klass->generic_container != NULL;
1770 static MonoReflectionType*
1771 ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
1773 MonoClass *klass;
1774 MONO_ARCH_SAVE_REGS;
1776 klass = mono_class_from_mono_type (type->type);
1777 if (klass->generic_container) {
1778 return type; /* check this one */
1780 if (klass->generic_class) {
1781 MonoType *generic_type = klass->generic_class->generic_type;
1782 MonoClass *generic_class = mono_class_from_mono_type (generic_type);
1784 if (generic_class->wastypebuilder && generic_class->reflection_info)
1785 return generic_class->reflection_info;
1786 else
1787 return mono_type_get_object (mono_object_domain (type), generic_type);
1789 return NULL;
1792 static MonoReflectionType*
1793 ves_icall_Type_BindGenericParameters (MonoReflectionType *type, MonoArray *type_array)
1795 MonoType *geninst, **types;
1796 int i, count;
1798 MONO_ARCH_SAVE_REGS;
1800 count = mono_array_length (type_array);
1801 types = g_new0 (MonoType *, count);
1803 for (i = 0; i < count; i++) {
1804 MonoReflectionType *t = mono_array_get (type_array, gpointer, i);
1805 types [i] = t->type;
1808 geninst = mono_reflection_bind_generic_parameters (type, count, types);
1810 return mono_type_get_object (mono_object_domain (type), geninst);
1813 static gboolean
1814 ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
1816 MonoClass *klass;
1817 MONO_ARCH_SAVE_REGS;
1819 klass = mono_class_from_mono_type (type->type);
1820 return klass->generic_class != NULL;
1823 static gint32
1824 ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
1826 MONO_ARCH_SAVE_REGS;
1828 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1829 return type->type->data.generic_param->num;
1830 return -1;
1833 static GenericParameterAttributes
1834 ves_icall_Type_GetGenericParameterAttributes (MonoReflectionType *type)
1836 MONO_ARCH_SAVE_REGS;
1837 return type->type->data.generic_param->flags;
1840 static MonoArray *
1841 ves_icall_Type_GetGenericParameterConstraints (MonoReflectionType *type)
1843 MonoGenericParam *param;
1844 MonoDomain *domain;
1845 MonoClass **ptr;
1846 MonoArray *res;
1847 int i, count;
1849 MONO_ARCH_SAVE_REGS;
1851 domain = mono_object_domain (type);
1852 param = type->type->data.generic_param;
1853 for (count = 0, ptr = param->constraints; ptr && *ptr; ptr++, count++)
1856 res = mono_array_new (domain, mono_defaults.monotype_class, count);
1857 for (i = 0; i < count; i++)
1858 mono_array_set (res, gpointer, i,
1859 mono_type_get_object (domain, &param->constraints [i]->byval_arg));
1862 return res;
1865 static MonoBoolean
1866 ves_icall_MonoType_get_HasGenericArguments (MonoReflectionType *type)
1868 MonoClass *klass;
1869 MONO_ARCH_SAVE_REGS;
1871 klass = mono_class_from_mono_type (type->type);
1872 if (klass->generic_container || klass->generic_class)
1873 return TRUE;
1874 return FALSE;
1877 static MonoBoolean
1878 ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
1880 MONO_ARCH_SAVE_REGS;
1882 if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
1883 return TRUE;
1884 return FALSE;
1887 static MonoBoolean
1888 ves_icall_TypeBuilder_get_IsGenericParameter (MonoReflectionTypeBuilder *tb)
1890 MONO_ARCH_SAVE_REGS;
1892 if (tb->type.type->type == MONO_TYPE_VAR || tb->type.type->type == MONO_TYPE_MVAR)
1893 return TRUE;
1894 return FALSE;
1897 static void
1898 ves_icall_EnumBuilder_setup_enum_type (MonoReflectionType *enumtype,
1899 MonoReflectionType *t)
1901 enumtype->type = t->type;
1904 static MonoReflectionType*
1905 ves_icall_MonoGenericClass_GetParentType (MonoReflectionGenericClass *type)
1907 MonoGenericClass *gclass;
1908 MonoClass *klass;
1910 MONO_ARCH_SAVE_REGS;
1912 gclass = type->type.type->data.generic_class;
1913 if (!gclass || !gclass->parent || (gclass->parent->type != MONO_TYPE_GENERICINST))
1914 return NULL;
1916 klass = mono_class_from_mono_type (gclass->parent);
1917 if (!klass->generic_class && !klass->generic_container)
1918 return NULL;
1920 return mono_type_get_object (mono_object_domain (type), gclass->parent);
1923 static MonoArray*
1924 ves_icall_MonoGenericClass_GetInterfaces (MonoReflectionGenericClass *type)
1926 static MonoClass *System_Reflection_MonoGenericClass;
1927 MonoGenericClass *gclass;
1928 MonoDomain *domain;
1929 MonoClass *klass;
1930 MonoArray *res;
1931 int i;
1933 MONO_ARCH_SAVE_REGS;
1935 if (!System_Reflection_MonoGenericClass) {
1936 System_Reflection_MonoGenericClass = mono_class_from_name (
1937 mono_defaults.corlib, "System.Reflection", "MonoGenericClass");
1938 g_assert (System_Reflection_MonoGenericClass);
1941 domain = mono_object_domain (type);
1943 gclass = type->type.type->data.generic_class;
1944 if (!gclass || !gclass->ifaces)
1945 return mono_array_new (domain, System_Reflection_MonoGenericClass, 0);
1947 klass = mono_class_from_mono_type (gclass->generic_type);
1949 res = mono_array_new (domain, System_Reflection_MonoGenericClass, gclass->count_ifaces);
1951 for (i = 0; i < gclass->count_ifaces; i++) {
1952 MonoReflectionType *iface = mono_type_get_object (domain, gclass->ifaces [i]);
1954 mono_array_set (res, gpointer, i, iface);
1957 return res;
1960 static MonoArray*
1961 ves_icall_MonoGenericClass_GetMethods (MonoReflectionGenericClass *type,
1962 MonoReflectionType *reflected_type)
1964 MonoGenericClass *gclass;
1965 MonoDynamicGenericClass *dgclass;
1966 MonoDomain *domain;
1967 MonoClass *refclass;
1968 MonoArray *res;
1969 int i;
1971 MONO_ARCH_SAVE_REGS;
1973 gclass = type->type.type->data.generic_class;
1974 g_assert ((dgclass = gclass->dynamic_info) != NULL);
1976 refclass = mono_class_from_mono_type (reflected_type->type);
1978 domain = mono_object_domain (type);
1979 res = mono_array_new (domain, mono_defaults.method_info_class, dgclass->count_methods);
1981 for (i = 0; i < dgclass->count_methods; i++)
1982 mono_array_set (res, gpointer, i,
1983 mono_method_get_object (domain, dgclass->methods [i], refclass));
1985 return res;
1988 static MonoArray*
1989 ves_icall_MonoGenericClass_GetConstructors (MonoReflectionGenericClass *type,
1990 MonoReflectionType *reflected_type)
1992 static MonoClass *System_Reflection_ConstructorInfo;
1993 MonoGenericClass *gclass;
1994 MonoDynamicGenericClass *dgclass;
1995 MonoDomain *domain;
1996 MonoClass *refclass;
1997 MonoArray *res;
1998 int i;
2000 MONO_ARCH_SAVE_REGS;
2002 if (!System_Reflection_ConstructorInfo)
2003 System_Reflection_ConstructorInfo = mono_class_from_name (
2004 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
2006 gclass = type->type.type->data.generic_class;
2007 g_assert ((dgclass = gclass->dynamic_info) != NULL);
2009 refclass = mono_class_from_mono_type (reflected_type->type);
2011 domain = mono_object_domain (type);
2012 res = mono_array_new (domain, System_Reflection_ConstructorInfo, dgclass->count_ctors);
2014 for (i = 0; i < dgclass->count_ctors; i++)
2015 mono_array_set (res, gpointer, i,
2016 mono_method_get_object (domain, dgclass->ctors [i], refclass));
2018 return res;
2021 static MonoArray*
2022 ves_icall_MonoGenericClass_GetFields (MonoReflectionGenericClass *type,
2023 MonoReflectionType *reflected_type)
2025 MonoGenericClass *gclass;
2026 MonoDynamicGenericClass *dgclass;
2027 MonoDomain *domain;
2028 MonoClass *refclass;
2029 MonoArray *res;
2030 int i;
2032 MONO_ARCH_SAVE_REGS;
2034 gclass = type->type.type->data.generic_class;
2035 g_assert ((dgclass = gclass->dynamic_info) != NULL);
2037 refclass = mono_class_from_mono_type (reflected_type->type);
2039 domain = mono_object_domain (type);
2040 res = mono_array_new (domain, mono_defaults.field_info_class, dgclass->count_fields);
2042 for (i = 0; i < dgclass->count_fields; i++)
2043 mono_array_set (res, gpointer, i,
2044 mono_field_get_object (domain, refclass, &dgclass->fields [i]));
2046 return res;
2049 static MonoArray*
2050 ves_icall_MonoGenericClass_GetProperties (MonoReflectionGenericClass *type,
2051 MonoReflectionType *reflected_type)
2053 static MonoClass *System_Reflection_PropertyInfo;
2054 MonoGenericClass *gclass;
2055 MonoDynamicGenericClass *dgclass;
2056 MonoDomain *domain;
2057 MonoClass *refclass;
2058 MonoArray *res;
2059 int i;
2061 MONO_ARCH_SAVE_REGS;
2063 if (!System_Reflection_PropertyInfo)
2064 System_Reflection_PropertyInfo = mono_class_from_name (
2065 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
2067 gclass = type->type.type->data.generic_class;
2068 g_assert ((dgclass = gclass->dynamic_info) != NULL);
2070 refclass = mono_class_from_mono_type (reflected_type->type);
2072 domain = mono_object_domain (type);
2073 res = mono_array_new (domain, System_Reflection_PropertyInfo, dgclass->count_properties);
2075 for (i = 0; i < dgclass->count_properties; i++)
2076 mono_array_set (res, gpointer, i,
2077 mono_property_get_object (domain, refclass, &dgclass->properties [i]));
2079 return res;
2082 static MonoArray*
2083 ves_icall_MonoGenericClass_GetEvents (MonoReflectionGenericClass *type,
2084 MonoReflectionType *reflected_type)
2086 static MonoClass *System_Reflection_EventInfo;
2087 MonoGenericClass *gclass;
2088 MonoDynamicGenericClass *dgclass;
2089 MonoDomain *domain;
2090 MonoClass *refclass;
2091 MonoArray *res;
2092 int i;
2094 MONO_ARCH_SAVE_REGS;
2096 if (!System_Reflection_EventInfo)
2097 System_Reflection_EventInfo = mono_class_from_name (
2098 mono_defaults.corlib, "System.Reflection", "EventInfo");
2100 gclass = type->type.type->data.generic_class;
2101 g_assert ((dgclass = gclass->dynamic_info) != NULL);
2103 refclass = mono_class_from_mono_type (reflected_type->type);
2105 domain = mono_object_domain (type);
2106 res = mono_array_new (domain, System_Reflection_EventInfo, dgclass->count_events);
2108 for (i = 0; i < dgclass->count_events; i++)
2109 mono_array_set (res, gpointer, i,
2110 mono_event_get_object (domain, refclass, &dgclass->events [i]));
2112 return res;
2115 static MonoReflectionMethod *
2116 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *type)
2118 MonoMethod *method;
2119 MonoClass *klass;
2121 MONO_ARCH_SAVE_REGS;
2123 method = type->type->data.generic_param->method;
2124 if (!method)
2125 return NULL;
2127 klass = mono_class_from_mono_type (type->type);
2128 return mono_method_get_object (mono_object_domain (type), method, klass);
2131 static MonoReflectionDllImportAttribute*
2132 ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
2134 static MonoClass *DllImportAttributeClass = NULL;
2135 MonoDomain *domain = mono_domain_get ();
2136 MonoReflectionDllImportAttribute *attr;
2137 MonoImage *image = method->klass->image;
2138 MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)method;
2139 MonoTableInfo *tables = image->tables;
2140 MonoTableInfo *im = &tables [MONO_TABLE_IMPLMAP];
2141 MonoTableInfo *mr = &tables [MONO_TABLE_MODULEREF];
2142 guint32 im_cols [MONO_IMPLMAP_SIZE];
2143 guint32 scope_token;
2144 const char *import = NULL;
2145 const char *scope = NULL;
2146 guint32 flags;
2148 if (!method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
2149 return NULL;
2151 if (!DllImportAttributeClass) {
2152 DllImportAttributeClass =
2153 mono_class_from_name (mono_defaults.corlib,
2154 "System.Runtime.InteropServices", "DllImportAttribute");
2155 g_assert (DllImportAttributeClass);
2158 if (method->klass->image->dynamic) {
2159 MonoReflectionMethodAux *method_aux =
2160 mono_g_hash_table_lookup (
2161 ((MonoDynamicImage*)method->klass->image)->method_aux_hash, method);
2162 if (method_aux) {
2163 import = method_aux->dllentry;
2164 scope = method_aux->dll;
2167 else {
2168 if (piinfo->implmap_idx) {
2169 mono_metadata_decode_row (im, piinfo->implmap_idx - 1, im_cols, MONO_IMPLMAP_SIZE);
2171 piinfo->piflags = im_cols [MONO_IMPLMAP_FLAGS];
2172 import = mono_metadata_string_heap (image, im_cols [MONO_IMPLMAP_NAME]);
2173 scope_token = mono_metadata_decode_row_col (mr, im_cols [MONO_IMPLMAP_SCOPE] - 1, MONO_MODULEREF_NAME);
2174 scope = mono_metadata_string_heap (image, scope_token);
2177 flags = piinfo->piflags;
2179 attr = (MonoReflectionDllImportAttribute*)mono_object_new (domain, DllImportAttributeClass);
2181 attr->dll = mono_string_new (domain, scope);
2182 attr->entry_point = mono_string_new (domain, import);
2183 attr->call_conv = (flags & 0x700) >> 8;
2184 attr->charset = ((flags & 0x6) >> 1) + 1;
2185 if (attr->charset == 1)
2186 attr->charset = 2;
2187 attr->exact_spelling = (flags & 0x1) != 0;
2188 attr->set_last_error = (flags & 0x4) != 0;
2189 attr->best_fit_mapping = (flags & 0x10) != 0;
2190 attr->throw_on_unmappable = (flags & 0x1000) != 0;
2191 attr->preserve_sig = FALSE;
2193 return attr;
2196 static MonoReflectionMethod *
2197 ves_icall_MonoMethod_GetGenericMethodDefinition (MonoReflectionMethod *method)
2199 MonoMethodInflated *imethod;
2201 MONO_ARCH_SAVE_REGS;
2203 if (!method->method->signature->is_inflated) {
2204 if (method->method->signature->generic_param_count)
2205 return method;
2207 return NULL;
2210 imethod = (MonoMethodInflated *) method->method;
2211 if (imethod->context->gmethod && imethod->context->gmethod->reflection_info)
2212 return imethod->context->gmethod->reflection_info;
2213 else
2214 return mono_method_get_object (
2215 mono_object_domain (method), imethod->declaring, NULL);
2218 static gboolean
2219 ves_icall_MonoMethod_get_HasGenericParameters (MonoReflectionMethod *method)
2221 MONO_ARCH_SAVE_REGS;
2223 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2224 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2225 return FALSE;
2227 return method->method->signature->generic_param_count != 0;
2230 static gboolean
2231 ves_icall_MonoMethod_get_Mono_IsInflatedMethod (MonoReflectionMethod *method)
2233 MONO_ARCH_SAVE_REGS;
2235 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2236 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2237 return FALSE;
2239 return method->method->signature->is_inflated;
2242 static gboolean
2243 ves_icall_MonoMethod_get_IsGenericMethodDefinition (MonoReflectionMethod *method)
2245 MONO_ARCH_SAVE_REGS;
2247 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2248 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2249 return FALSE;
2251 return method->method->signature->generic_param_count != 0;
2254 static MonoArray*
2255 ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethod *method)
2257 MonoArray *res;
2258 MonoDomain *domain;
2259 MonoMethodNormal *mn;
2260 int count, i;
2261 MONO_ARCH_SAVE_REGS;
2263 domain = mono_object_domain (method);
2265 if ((method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
2266 (method->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
2267 return mono_array_new (domain, mono_defaults.monotype_class, 0);
2269 if (method->method->signature->is_inflated) {
2270 MonoMethodInflated *imethod = (MonoMethodInflated *) method->method;
2271 MonoGenericMethod *gmethod = imethod->context->gmethod;
2273 if (gmethod) {
2274 count = gmethod->inst->type_argc;
2275 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2277 for (i = 0; i < count; i++) {
2278 MonoType *t = gmethod->inst->type_argv [i];
2279 mono_array_set (
2280 res, gpointer, i, mono_type_get_object (domain, t));
2283 return res;
2287 mn = (MonoMethodNormal *) method->method;
2288 count = method->method->signature->generic_param_count;
2289 res = mono_array_new (domain, mono_defaults.monotype_class, count);
2291 for (i = 0; i < count; i++) {
2292 MonoGenericParam *param = &mn->generic_container->type_params [i];
2293 MonoClass *pklass = mono_class_from_generic_parameter (
2294 param, method->method->klass->image, TRUE);
2295 mono_array_set (res, gpointer, i,
2296 mono_type_get_object (domain, &pklass->byval_arg));
2299 return res;
2302 static MonoObject *
2303 ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
2306 * Invoke from reflection is supposed to always be a virtual call (the API
2307 * is stupid), mono_runtime_invoke_*() calls the provided method, allowing
2308 * greater flexibility.
2310 MonoMethod *m = method->method;
2311 int pcount;
2312 void *obj = this;
2314 MONO_ARCH_SAVE_REGS;
2316 if (this) {
2317 if (!mono_object_isinst (this, m->klass))
2318 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2319 m = mono_object_get_virtual_method (this, m);
2320 /* must pass the pointer to the value for valuetype methods */
2321 if (m->klass->valuetype)
2322 obj = mono_object_unbox (this);
2323 } else if (!(m->flags & METHOD_ATTRIBUTE_STATIC) && strcmp (m->name, ".ctor") && !m->wrapper_type)
2324 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
2326 pcount = params? mono_array_length (params): 0;
2327 if (pcount != m->signature->param_count)
2328 mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetParameterCountException"));
2330 if ((m->klass->flags & TYPE_ATTRIBUTE_ABSTRACT) && !strcmp (m->name, ".ctor"))
2331 mono_raise_exception (mono_exception_from_name_msg (mono_defaults.corlib, "System", "MethodAccessException", "Cannot invoke constructor of an abstract class."));
2333 if (m->klass->rank && !strcmp (m->name, ".ctor")) {
2334 int i;
2335 guint32 *lengths;
2336 guint32 *lower_bounds;
2337 pcount = mono_array_length (params);
2338 lengths = alloca (sizeof (guint32) * pcount);
2339 for (i = 0; i < pcount; ++i)
2340 lengths [i] = *(gint32*) ((char*)mono_array_get (params, gpointer, i) + sizeof (MonoObject));
2342 if (m->klass->rank == pcount) {
2343 /* Only lengths provided. */
2344 lower_bounds = NULL;
2345 } else {
2346 g_assert (pcount == (m->klass->rank * 2));
2347 /* lower bounds are first. */
2348 lower_bounds = lengths;
2349 lengths += m->klass->rank;
2352 return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
2354 return mono_runtime_invoke_array (m, obj, params, NULL);
2357 static MonoObject *
2358 ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs)
2360 MonoDomain *domain = mono_object_domain (method);
2361 MonoMethod *m = method->method;
2362 MonoMethodSignature *sig = m->signature;
2363 MonoArray *out_args;
2364 MonoObject *result;
2365 int i, j, outarg_count = 0;
2367 MONO_ARCH_SAVE_REGS;
2369 if (m->klass == mono_defaults.object_class) {
2371 if (!strcmp (m->name, "FieldGetter")) {
2372 MonoClass *k = this->vtable->klass;
2373 MonoString *name;
2374 char *str;
2376 /* If this is a proxy, then it must be a CBO */
2377 if (k == mono_defaults.transparent_proxy_class) {
2378 MonoTransparentProxy *tp = (MonoTransparentProxy*) this;
2379 this = tp->rp->unwrapped_server;
2380 g_assert (this);
2381 k = this->vtable->klass;
2384 name = mono_array_get (params, MonoString *, 1);
2385 str = mono_string_to_utf8 (name);
2387 do {
2388 for (i = 0; i < k->field.count; i++) {
2389 if (!strcmp (k->fields [i].name, str)) {
2390 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
2391 if (field_klass->valuetype)
2392 result = mono_value_box (domain, field_klass,
2393 (char *)this + k->fields [i].offset);
2394 else
2395 result = *((gpointer *)((char *)this + k->fields [i].offset));
2397 g_assert (result);
2398 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
2399 *outArgs = out_args;
2400 mono_array_set (out_args, gpointer, 0, result);
2401 g_free (str);
2402 return NULL;
2405 k = k->parent;
2407 while (k != NULL);
2409 g_free (str);
2410 g_assert_not_reached ();
2412 } else if (!strcmp (m->name, "FieldSetter")) {
2413 MonoClass *k = this->vtable->klass;
2414 MonoString *name;
2415 int size, align;
2416 char *str;
2418 /* If this is a proxy, then it must be a CBO */
2419 if (k == mono_defaults.transparent_proxy_class) {
2420 MonoTransparentProxy *tp = (MonoTransparentProxy*) this;
2421 this = tp->rp->unwrapped_server;
2422 g_assert (this);
2423 k = this->vtable->klass;
2426 name = mono_array_get (params, MonoString *, 1);
2427 str = mono_string_to_utf8 (name);
2429 do {
2430 for (i = 0; i < k->field.count; i++) {
2431 if (!strcmp (k->fields [i].name, str)) {
2432 MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
2433 MonoObject *val = mono_array_get (params, gpointer, 2);
2435 if (field_klass->valuetype) {
2436 size = mono_type_size (k->fields [i].type, &align);
2437 memcpy ((char *)this + k->fields [i].offset,
2438 ((char *)val) + sizeof (MonoObject), size);
2439 } else
2440 *(MonoObject**)((char *)this + k->fields [i].offset) = val;
2442 out_args = mono_array_new (domain, mono_defaults.object_class, 0);
2443 *outArgs = out_args;
2445 g_free (str);
2446 return NULL;
2449 k = k->parent;
2451 while (k != NULL);
2453 g_free (str);
2454 g_assert_not_reached ();
2459 for (i = 0; i < mono_array_length (params); i++) {
2460 if (sig->params [i]->byref)
2461 outarg_count++;
2464 out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
2466 /* handle constructors only for objects already allocated */
2467 if (!strcmp (method->method->name, ".ctor"))
2468 g_assert (this);
2470 /* This can be called only on MBR objects, so no need to unbox for valuetypes. */
2471 g_assert (!method->method->klass->valuetype);
2472 result = mono_runtime_invoke_array (method->method, this, params, NULL);
2474 for (i = 0, j = 0; i < mono_array_length (params); i++) {
2475 if (sig->params [i]->byref) {
2476 gpointer arg;
2477 arg = mono_array_get (params, gpointer, i);
2478 mono_array_set (out_args, gpointer, j, arg);
2479 j++;
2483 *outArgs = out_args;
2485 return result;
2488 static MonoObject *
2489 ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
2491 MonoDomain *domain;
2492 MonoClass *enumc, *objc;
2493 gint32 s1, s2;
2494 MonoObject *res;
2496 MONO_ARCH_SAVE_REGS;
2498 MONO_CHECK_ARG_NULL (type);
2499 MONO_CHECK_ARG_NULL (obj);
2501 domain = mono_object_domain (type);
2502 enumc = mono_class_from_mono_type (type->type);
2503 objc = obj->vtable->klass;
2505 MONO_CHECK_ARG (obj, enumc->enumtype == TRUE);
2506 MONO_CHECK_ARG (obj, (objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 &&
2507 objc->byval_arg.type <= MONO_TYPE_U8));
2509 s1 = mono_class_value_size (enumc, NULL);
2510 s2 = mono_class_value_size (objc, NULL);
2512 res = mono_object_new (domain, enumc);
2514 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2515 memcpy ((char *)res + sizeof (MonoObject), (char *)obj + sizeof (MonoObject), MIN (s1, s2));
2516 #else
2517 memcpy ((char *)res + sizeof (MonoObject) + (s1 > s2 ? s1 - s2 : 0),
2518 (char *)obj + sizeof (MonoObject) + (s2 > s1 ? s2 - s1 : 0),
2519 MIN (s1, s2));
2520 #endif
2521 return res;
2524 static MonoObject *
2525 ves_icall_System_Enum_get_value (MonoObject *this)
2527 MonoObject *res;
2528 MonoClass *enumc;
2529 gpointer dst;
2530 gpointer src;
2531 int size;
2533 MONO_ARCH_SAVE_REGS;
2535 if (!this)
2536 return NULL;
2538 g_assert (this->vtable->klass->enumtype);
2540 enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
2541 res = mono_object_new (mono_object_domain (this), enumc);
2542 dst = (char *)res + sizeof (MonoObject);
2543 src = (char *)this + sizeof (MonoObject);
2544 size = mono_class_value_size (enumc, NULL);
2546 memcpy (dst, src, size);
2548 return res;
2551 static void
2552 ves_icall_get_enum_info (MonoReflectionType *type, MonoEnumInfo *info)
2554 MonoDomain *domain = mono_object_domain (type);
2555 MonoClass *enumc = mono_class_from_mono_type (type->type);
2556 guint i, j, nvalues, crow;
2557 MonoClassField *field;
2559 MONO_ARCH_SAVE_REGS;
2561 info->utype = mono_type_get_object (domain, enumc->enum_basetype);
2562 nvalues = enumc->field.count ? enumc->field.count - 1 : 0;
2563 info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
2564 info->values = mono_array_new (domain, enumc, nvalues);
2566 crow = -1;
2567 for (i = 0, j = 0; i < enumc->field.count; ++i) {
2568 const char *p;
2569 int len;
2571 field = &enumc->fields [i];
2572 if (strcmp ("value__", field->name) == 0)
2573 continue;
2574 if (mono_field_is_deleted (field))
2575 continue;
2576 mono_array_set (info->names, gpointer, j, mono_string_new (domain, field->name));
2578 if (!field->data) {
2579 crow = mono_metadata_get_constant_index (enumc->image, MONO_TOKEN_FIELD_DEF | (i+enumc->field.first+1), crow + 1);
2580 field->def_type = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_TYPE);
2581 crow = mono_metadata_decode_row_col (&enumc->image->tables [MONO_TABLE_CONSTANT], crow-1, MONO_CONSTANT_VALUE);
2582 field->data = (gpointer)mono_metadata_blob_heap (enumc->image, crow);
2585 p = field->data;
2586 len = mono_metadata_decode_blob_size (p, &p);
2587 switch (enumc->enum_basetype->type) {
2588 case MONO_TYPE_U1:
2589 case MONO_TYPE_I1:
2590 mono_array_set (info->values, gchar, j, *p);
2591 break;
2592 case MONO_TYPE_CHAR:
2593 case MONO_TYPE_U2:
2594 case MONO_TYPE_I2:
2595 mono_array_set (info->values, gint16, j, read16 (p));
2596 break;
2597 case MONO_TYPE_U4:
2598 case MONO_TYPE_I4:
2599 mono_array_set (info->values, gint32, j, read32 (p));
2600 break;
2601 case MONO_TYPE_U8:
2602 case MONO_TYPE_I8:
2603 mono_array_set (info->values, gint64, j, read64 (p));
2604 break;
2605 default:
2606 g_error ("Implement type 0x%02x in get_enum_info", enumc->enum_basetype->type);
2608 ++j;
2612 enum {
2613 BFLAGS_IgnoreCase = 1,
2614 BFLAGS_DeclaredOnly = 2,
2615 BFLAGS_Instance = 4,
2616 BFLAGS_Static = 8,
2617 BFLAGS_Public = 0x10,
2618 BFLAGS_NonPublic = 0x20,
2619 BFLAGS_FlattenHierarchy = 0x40,
2620 BFLAGS_InvokeMethod = 0x100,
2621 BFLAGS_CreateInstance = 0x200,
2622 BFLAGS_GetField = 0x400,
2623 BFLAGS_SetField = 0x800,
2624 BFLAGS_GetProperty = 0x1000,
2625 BFLAGS_SetProperty = 0x2000,
2626 BFLAGS_ExactBinding = 0x10000,
2627 BFLAGS_SuppressChangeType = 0x20000,
2628 BFLAGS_OptionalParamBinding = 0x40000
2631 static MonoReflectionField *
2632 ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bflags)
2634 MonoDomain *domain;
2635 MonoClass *startklass, *klass;
2636 int i, match;
2637 MonoClassField *field;
2638 char *utf8_name;
2639 int (*compare_func) (const char *s1, const char *s2) = NULL;
2640 domain = ((MonoObject *)type)->vtable->domain;
2641 klass = startklass = mono_class_from_mono_type (type->type);
2643 MONO_ARCH_SAVE_REGS;
2645 if (!name)
2646 mono_raise_exception (mono_get_exception_argument_null ("name"));
2648 compare_func = (bflags & BFLAGS_IgnoreCase) ? g_strcasecmp : strcmp;
2650 handle_parent:
2651 for (i = 0; i < klass->field.count; ++i) {
2652 match = 0;
2653 field = &klass->fields [i];
2654 if (mono_field_is_deleted (field))
2655 continue;
2656 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2657 if (bflags & BFLAGS_Public)
2658 match++;
2659 } else {
2660 if (bflags & BFLAGS_NonPublic)
2661 match++;
2663 if (!match)
2664 continue;
2665 match = 0;
2666 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2667 if (bflags & BFLAGS_Static)
2668 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2669 match++;
2670 } else {
2671 if (bflags & BFLAGS_Instance)
2672 match++;
2675 if (!match)
2676 continue;
2678 utf8_name = mono_string_to_utf8 (name);
2680 if (compare_func (field->name, utf8_name)) {
2681 g_free (utf8_name);
2682 continue;
2684 g_free (utf8_name);
2686 return mono_field_get_object (domain, startklass, field);
2688 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2689 goto handle_parent;
2691 return NULL;
2694 static MonoArray*
2695 ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2697 MonoDomain *domain;
2698 GSList *l = NULL, *tmp;
2699 MonoClass *startklass, *klass, *refklass;
2700 MonoArray *res;
2701 MonoObject *member;
2702 int i, len, match;
2703 MonoClassField *field;
2705 MONO_ARCH_SAVE_REGS;
2707 domain = ((MonoObject *)type)->vtable->domain;
2708 klass = startklass = mono_class_from_mono_type (type->type);
2709 refklass = mono_class_from_mono_type (reftype->type);
2711 handle_parent:
2712 for (i = 0; i < klass->field.count; ++i) {
2713 match = 0;
2714 field = &klass->fields [i];
2715 if (mono_field_is_deleted (field))
2716 continue;
2717 if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
2718 if (bflags & BFLAGS_Public)
2719 match++;
2720 } else {
2721 if (bflags & BFLAGS_NonPublic)
2722 match++;
2724 if (!match)
2725 continue;
2726 match = 0;
2727 if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
2728 if (bflags & BFLAGS_Static)
2729 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2730 match++;
2731 } else {
2732 if (bflags & BFLAGS_Instance)
2733 match++;
2736 if (!match)
2737 continue;
2738 member = (MonoObject*)mono_field_get_object (domain, refklass, field);
2739 l = g_slist_prepend (l, member);
2741 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2742 goto handle_parent;
2743 len = g_slist_length (l);
2744 res = mono_array_new (domain, mono_defaults.field_info_class, len);
2745 i = 0;
2746 tmp = l = g_slist_reverse (l);
2747 for (; tmp; tmp = tmp->next, ++i)
2748 mono_array_set (res, gpointer, i, tmp->data);
2749 g_slist_free (l);
2750 return res;
2753 static MonoArray*
2754 ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
2756 MonoDomain *domain;
2757 GSList *l = NULL, *tmp;
2758 MonoClass *startklass, *klass, *refklass;
2759 MonoArray *res;
2760 MonoMethod *method;
2761 MonoObject *member;
2762 int i, len, match;
2763 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2764 gchar *mname = NULL;
2765 int (*compare_func) (const char *s1, const char *s2) = NULL;
2767 MONO_ARCH_SAVE_REGS;
2769 domain = ((MonoObject *)type)->vtable->domain;
2770 klass = startklass = mono_class_from_mono_type (type->type);
2771 refklass = mono_class_from_mono_type (reftype->type);
2772 len = 0;
2773 if (name != NULL) {
2774 mname = mono_string_to_utf8 (name);
2775 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2778 handle_parent:
2779 for (i = 0; i < klass->method.count; ++i) {
2780 match = 0;
2781 method = klass->methods [i];
2782 if (strcmp (method->name, ".ctor") == 0 || strcmp (method->name, ".cctor") == 0)
2783 continue;
2784 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2785 if (bflags & BFLAGS_Public)
2786 match++;
2787 } else {
2788 if (bflags & BFLAGS_NonPublic)
2789 match++;
2791 if (!match)
2792 continue;
2793 match = 0;
2794 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2795 if (bflags & BFLAGS_Static)
2796 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2797 match++;
2798 } else {
2799 if (bflags & BFLAGS_Instance)
2800 match++;
2803 if (!match)
2804 continue;
2806 if (name != NULL) {
2807 if (compare_func (mname, method->name))
2808 continue;
2811 match = 0;
2812 if (method->slot != -1) {
2813 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (method->slot)))
2814 continue;
2815 g_hash_table_insert (method_slots, GUINT_TO_POINTER (method->slot), method);
2818 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
2820 l = g_slist_prepend (l, member);
2821 len++;
2823 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
2824 goto handle_parent;
2826 g_free (mname);
2827 res = mono_array_new (domain, mono_defaults.method_info_class, len);
2828 i = 0;
2830 tmp = l = g_slist_reverse (l);
2832 for (; tmp; tmp = tmp->next, ++i)
2833 mono_array_set (res, gpointer, i, tmp->data);
2834 g_slist_free (l);
2835 g_hash_table_destroy (method_slots);
2836 return res;
2839 static MonoArray*
2840 ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
2842 MonoDomain *domain;
2843 GSList *l = NULL, *tmp;
2844 static MonoClass *System_Reflection_ConstructorInfo;
2845 MonoClass *startklass, *klass, *refklass;
2846 MonoArray *res;
2847 MonoMethod *method;
2848 MonoObject *member;
2849 int i, len, match;
2851 MONO_ARCH_SAVE_REGS;
2853 domain = ((MonoObject *)type)->vtable->domain;
2854 klass = startklass = mono_class_from_mono_type (type->type);
2855 refklass = mono_class_from_mono_type (reftype->type);
2857 for (i = 0; i < klass->method.count; ++i) {
2858 match = 0;
2859 method = klass->methods [i];
2860 if (strcmp (method->name, ".ctor") && strcmp (method->name, ".cctor"))
2861 continue;
2862 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
2863 if (bflags & BFLAGS_Public)
2864 match++;
2865 } else {
2866 if (bflags & BFLAGS_NonPublic)
2867 match++;
2869 if (!match)
2870 continue;
2871 match = 0;
2872 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
2873 if (bflags & BFLAGS_Static)
2874 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2875 match++;
2876 } else {
2877 if (bflags & BFLAGS_Instance)
2878 match++;
2881 if (!match)
2882 continue;
2883 member = (MonoObject*)mono_method_get_object (domain, method, refklass);
2885 l = g_slist_prepend (l, member);
2887 len = g_slist_length (l);
2888 if (!System_Reflection_ConstructorInfo)
2889 System_Reflection_ConstructorInfo = mono_class_from_name (
2890 mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
2891 res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
2892 i = 0;
2893 tmp = l = g_slist_reverse (l);
2894 for (; tmp; tmp = tmp->next, ++i)
2895 mono_array_set (res, gpointer, i, tmp->data);
2896 g_slist_free (l);
2897 return res;
2900 static MonoArray*
2901 ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
2903 MonoDomain *domain;
2904 GSList *l = NULL, *tmp;
2905 static MonoClass *System_Reflection_PropertyInfo;
2906 MonoClass *startklass, *klass;
2907 MonoArray *res;
2908 MonoMethod *method;
2909 MonoProperty *prop;
2910 int i, match;
2911 int len = 0;
2912 guint32 flags;
2913 GHashTable *method_slots = g_hash_table_new (NULL, NULL);
2914 gchar *propname = NULL;
2915 int (*compare_func) (const char *s1, const char *s2) = NULL;
2917 MONO_ARCH_SAVE_REGS;
2919 domain = ((MonoObject *)type)->vtable->domain;
2920 klass = startklass = mono_class_from_mono_type (type->type);
2921 if (name != NULL) {
2922 propname = mono_string_to_utf8 (name);
2923 compare_func = (ignore_case) ? g_strcasecmp : strcmp;
2926 handle_parent:
2927 for (i = 0; i < klass->property.count; ++i) {
2928 prop = &klass->properties [i];
2929 match = 0;
2930 method = prop->get;
2931 if (!method)
2932 method = prop->set;
2933 if (method)
2934 flags = method->flags;
2935 else
2936 flags = 0;
2937 if ((prop->get && ((prop->get->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC)) ||
2938 (prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC))) {
2939 if (bflags & BFLAGS_Public)
2940 match++;
2941 } else {
2942 if (bflags & BFLAGS_NonPublic)
2943 match++;
2945 if (!match)
2946 continue;
2947 match = 0;
2948 if (flags & METHOD_ATTRIBUTE_STATIC) {
2949 if (bflags & BFLAGS_Static)
2950 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
2951 match++;
2952 } else {
2953 if (bflags & BFLAGS_Instance)
2954 match++;
2957 if (!match)
2958 continue;
2959 match = 0;
2961 if (name != NULL) {
2962 if (compare_func (propname, prop->name))
2963 continue;
2966 if (prop->get && prop->get->slot != -1) {
2967 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (prop->get->slot)))
2968 continue;
2969 g_hash_table_insert (method_slots, GUINT_TO_POINTER (prop->get->slot), prop);
2971 if (prop->set && prop->set->slot != -1) {
2972 if (g_hash_table_lookup (method_slots, GUINT_TO_POINTER (prop->set->slot)))
2973 continue;
2974 g_hash_table_insert (method_slots, GUINT_TO_POINTER (prop->set->slot), prop);
2977 l = g_slist_prepend (l, mono_property_get_object (domain, startklass, prop));
2978 len++;
2980 if ((!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
2981 goto handle_parent;
2983 g_free (propname);
2984 if (!System_Reflection_PropertyInfo)
2985 System_Reflection_PropertyInfo = mono_class_from_name (
2986 mono_defaults.corlib, "System.Reflection", "PropertyInfo");
2987 res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
2988 i = 0;
2990 tmp = l = g_slist_reverse (l);
2992 for (; tmp; tmp = tmp->next, ++i)
2993 mono_array_set (res, gpointer, i, tmp->data);
2994 g_slist_free (l);
2995 g_hash_table_destroy (method_slots);
2996 return res;
2999 static MonoReflectionEvent *
3000 ves_icall_MonoType_GetEvent (MonoReflectionType *type, MonoString *name, guint32 bflags)
3002 MonoDomain *domain;
3003 MonoClass *klass, *startklass;
3004 gint i;
3005 MonoEvent *event;
3006 MonoMethod *method;
3007 gchar *event_name;
3009 MONO_ARCH_SAVE_REGS;
3011 event_name = mono_string_to_utf8 (name);
3012 klass = startklass = mono_class_from_mono_type (type->type);
3013 domain = mono_object_domain (type);
3015 handle_parent:
3016 for (i = 0; i < klass->event.count; i++) {
3017 event = &klass->events [i];
3018 if (strcmp (event->name, event_name))
3019 continue;
3021 method = event->add;
3022 if (!method)
3023 method = event->remove;
3024 if (!method)
3025 method = event->raise;
3026 if (method) {
3027 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
3028 if (!(bflags & BFLAGS_Public))
3029 continue;
3030 } else {
3031 if (!(bflags & BFLAGS_NonPublic))
3032 continue;
3035 else
3036 if (!(bflags & BFLAGS_NonPublic))
3037 continue;
3039 g_free (event_name);
3040 return mono_event_get_object (domain, startklass, event);
3043 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3044 goto handle_parent;
3046 g_free (event_name);
3047 return NULL;
3050 static MonoArray*
3051 ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
3053 MonoDomain *domain;
3054 GSList *l = NULL, *tmp;
3055 static MonoClass *System_Reflection_EventInfo;
3056 MonoClass *startklass, *klass;
3057 MonoArray *res;
3058 MonoMethod *method;
3059 MonoEvent *event;
3060 int i, len, match;
3062 MONO_ARCH_SAVE_REGS;
3064 domain = ((MonoObject *)type)->vtable->domain;
3065 klass = startklass = mono_class_from_mono_type (type->type);
3067 handle_parent:
3068 for (i = 0; i < klass->event.count; ++i) {
3069 event = &klass->events [i];
3070 match = 0;
3071 method = event->add;
3072 if (!method)
3073 method = event->remove;
3074 if (!method)
3075 method = event->raise;
3076 if (method) {
3077 if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC) {
3078 if (bflags & BFLAGS_Public)
3079 match++;
3080 } else {
3081 if (bflags & BFLAGS_NonPublic)
3082 match++;
3085 else
3086 if (bflags & BFLAGS_NonPublic)
3087 match ++;
3088 if (!match)
3089 continue;
3090 match = 0;
3091 if (method) {
3092 if (method->flags & METHOD_ATTRIBUTE_STATIC) {
3093 if (bflags & BFLAGS_Static)
3094 if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
3095 match++;
3096 } else {
3097 if (bflags & BFLAGS_Instance)
3098 match++;
3101 else
3102 if (bflags & BFLAGS_Instance)
3103 match ++;
3104 if (!match)
3105 continue;
3106 match = 0;
3107 l = g_slist_prepend (l, mono_event_get_object (domain, klass, event));
3109 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3110 goto handle_parent;
3111 len = g_slist_length (l);
3112 if (!System_Reflection_EventInfo)
3113 System_Reflection_EventInfo = mono_class_from_name (
3114 mono_defaults.corlib, "System.Reflection", "EventInfo");
3115 res = mono_array_new (domain, System_Reflection_EventInfo, len);
3116 i = 0;
3118 tmp = l = g_slist_reverse (l);
3120 for (; tmp; tmp = tmp->next, ++i)
3121 mono_array_set (res, gpointer, i, tmp->data);
3122 g_slist_free (l);
3123 return res;
3126 static MonoReflectionType *
3127 ves_icall_Type_GetNestedType (MonoReflectionType *type, MonoString *name, guint32 bflags)
3129 MonoDomain *domain;
3130 MonoClass *startklass, *klass;
3131 MonoClass *nested;
3132 GList *tmpn;
3133 char *str;
3135 MONO_ARCH_SAVE_REGS;
3137 domain = ((MonoObject *)type)->vtable->domain;
3138 klass = startklass = mono_class_from_mono_type (type->type);
3139 str = mono_string_to_utf8 (name);
3141 handle_parent:
3142 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
3143 int match = 0;
3144 nested = tmpn->data;
3145 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
3146 if (bflags & BFLAGS_Public)
3147 match++;
3148 } else {
3149 if (bflags & BFLAGS_NonPublic)
3150 match++;
3152 if (!match)
3153 continue;
3154 if (strcmp (nested->name, str) == 0){
3155 g_free (str);
3156 return mono_type_get_object (domain, &nested->byval_arg);
3159 if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
3160 goto handle_parent;
3161 g_free (str);
3162 return NULL;
3165 static MonoArray*
3166 ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
3168 MonoDomain *domain;
3169 GSList *l = NULL, *tmp;
3170 GList *tmpn;
3171 MonoClass *startklass, *klass;
3172 MonoArray *res;
3173 MonoObject *member;
3174 int i, len, match;
3175 MonoClass *nested;
3177 MONO_ARCH_SAVE_REGS;
3179 domain = ((MonoObject *)type)->vtable->domain;
3180 klass = startklass = mono_class_from_mono_type (type->type);
3182 for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
3183 match = 0;
3184 nested = tmpn->data;
3185 if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
3186 if (bflags & BFLAGS_Public)
3187 match++;
3188 } else {
3189 if (bflags & BFLAGS_NonPublic)
3190 match++;
3192 if (!match)
3193 continue;
3194 member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
3195 l = g_slist_prepend (l, member);
3197 len = g_slist_length (l);
3198 res = mono_array_new (domain, mono_defaults.monotype_class, len);
3199 i = 0;
3200 tmp = l = g_slist_reverse (l);
3201 for (; tmp; tmp = tmp->next, ++i)
3202 mono_array_set (res, gpointer, i, tmp->data);
3203 g_slist_free (l);
3204 return res;
3207 static MonoReflectionType*
3208 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *assembly, MonoReflectionModule *module, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
3210 gchar *str;
3211 MonoType *type = NULL;
3212 MonoTypeNameParse info;
3213 gboolean type_resolve = FALSE;
3215 MONO_ARCH_SAVE_REGS;
3217 str = mono_string_to_utf8 (name);
3218 /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
3219 if (!mono_reflection_parse_type (str, &info)) {
3220 g_free (str);
3221 g_list_free (info.modifiers);
3222 g_list_free (info.nested);
3223 if (throwOnError) /* uhm: this is a parse error, though... */
3224 mono_raise_exception (mono_get_exception_type_load (name));
3225 /*g_print ("failed parse\n");*/
3226 return NULL;
3229 if (module != NULL) {
3230 if (module->image)
3231 type = mono_reflection_get_type (module->image, &info, ignoreCase, &type_resolve);
3232 else
3233 type = NULL;
3235 else
3236 if (assembly->assembly->dynamic) {
3237 /* Enumerate all modules */
3238 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
3239 int i;
3241 type = NULL;
3242 if (abuilder->modules) {
3243 for (i = 0; i < mono_array_length (abuilder->modules); ++i) {
3244 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
3245 type = mono_reflection_get_type (&mb->dynamic_image->image, &info, ignoreCase, &type_resolve);
3246 if (type)
3247 break;
3251 if (!type && abuilder->loaded_modules) {
3252 for (i = 0; i < mono_array_length (abuilder->loaded_modules); ++i) {
3253 MonoReflectionModule *mod = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
3254 type = mono_reflection_get_type (mod->image, &info, ignoreCase, &type_resolve);
3255 if (type)
3256 break;
3260 else
3261 type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase, &type_resolve);
3262 g_free (str);
3263 g_list_free (info.modifiers);
3264 g_list_free (info.nested);
3265 if (!type) {
3266 if (throwOnError)
3267 mono_raise_exception (mono_get_exception_type_load (name));
3268 /* g_print ("failed find\n"); */
3269 return NULL;
3271 /* g_print ("got it\n"); */
3272 return mono_type_get_object (mono_object_domain (assembly), type);
3276 static MonoString *
3277 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *assembly)
3279 MonoDomain *domain = mono_object_domain (assembly);
3280 MonoAssembly *mass = assembly->assembly;
3281 MonoString *res;
3282 gchar *uri;
3283 gchar *absolute;
3285 MONO_ARCH_SAVE_REGS;
3287 absolute = g_build_filename (mass->basedir, mass->image->module_name, NULL);
3288 uri = g_filename_to_uri (absolute, NULL, NULL);
3289 res = mono_string_new (domain, uri);
3290 g_free (uri);
3291 g_free (absolute);
3292 return res;
3295 static MonoBoolean
3296 ves_icall_System_Reflection_Assembly_get_global_assembly_cache (MonoReflectionAssembly *assembly)
3298 MonoAssembly *mass = assembly->assembly;
3300 MONO_ARCH_SAVE_REGS;
3302 return mass->in_gac;
3305 static MonoReflectionAssembly*
3306 ves_icall_System_Reflection_Assembly_load_with_partial_name (MonoString *mname, MonoObject *evidence)
3308 gchar *name;
3309 MonoAssembly *res;
3310 MonoImageOpenStatus status;
3312 MONO_ARCH_SAVE_REGS;
3314 name = mono_string_to_utf8 (mname);
3315 res = mono_assembly_load_with_partial_name (name, &status);
3317 g_free (name);
3319 if (res == NULL)
3320 return NULL;
3321 return mono_assembly_get_object (mono_domain_get (), res);
3324 static MonoString *
3325 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssembly *assembly)
3327 MonoDomain *domain = mono_object_domain (assembly);
3328 MonoString *res;
3330 MONO_ARCH_SAVE_REGS;
3332 res = mono_string_new (domain, mono_image_get_filename (assembly->assembly->image));
3334 return res;
3337 static MonoString *
3338 ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflectionAssembly *assembly)
3340 MonoDomain *domain = mono_object_domain (assembly);
3342 MONO_ARCH_SAVE_REGS;
3344 return mono_string_new (domain, assembly->assembly->image->version);
3347 static MonoReflectionMethod*
3348 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly)
3350 guint32 token = mono_image_get_entry_point (assembly->assembly->image);
3352 MONO_ARCH_SAVE_REGS;
3354 if (!token)
3355 return NULL;
3356 return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL), NULL);
3359 static MonoReflectionModule*
3360 ves_icall_System_Reflection_Assembly_get_ManifestModule (MonoReflectionAssembly *assembly)
3362 return mono_module_get_object (mono_object_domain (assembly), assembly->assembly->image);
3365 static MonoArray*
3366 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly)
3368 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3369 MonoArray *result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
3370 int i;
3371 const char *val;
3373 MONO_ARCH_SAVE_REGS;
3375 for (i = 0; i < table->rows; ++i) {
3376 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_MANIFEST_NAME));
3377 mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), val));
3379 return result;
3382 static MonoArray*
3383 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly)
3385 static MonoClass *System_Reflection_AssemblyName;
3386 MonoArray *result;
3387 MonoDomain *domain = mono_object_domain (assembly);
3388 int i, count = 0;
3389 static MonoMethod *create_culture = NULL;
3390 MonoTableInfo *t;
3392 MONO_ARCH_SAVE_REGS;
3394 if (!System_Reflection_AssemblyName)
3395 System_Reflection_AssemblyName = mono_class_from_name (
3396 mono_defaults.corlib, "System.Reflection", "AssemblyName");
3398 t = &assembly->assembly->image->tables [MONO_TABLE_ASSEMBLYREF];
3399 count = t->rows;
3401 result = mono_array_new (domain, System_Reflection_AssemblyName, count);
3403 if (count > 0) {
3404 MonoMethodDesc *desc = mono_method_desc_new (
3405 "System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3406 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3407 g_assert (create_culture);
3408 mono_method_desc_free (desc);
3411 for (i = 0; i < count; i++) {
3412 MonoAssembly *assem;
3413 MonoReflectionAssemblyName *aname;
3414 char *codebase, *absolute;
3416 /* FIXME: There is no need to load the assemblies themselves */
3417 mono_assembly_load_reference (assembly->assembly->image, i);
3419 assem = assembly->assembly->image->references [i];
3420 if (assem == (gpointer)-1) {
3421 char *msg = g_strdup_printf ("Assembly %d referenced from assembly %s not found ", i, assembly->assembly->image->name);
3422 MonoException *ex = mono_get_exception_file_not_found2 (msg, NULL);
3423 g_free (msg);
3424 mono_raise_exception (ex);
3427 aname = (MonoReflectionAssemblyName *) mono_object_new (
3428 domain, System_Reflection_AssemblyName);
3430 aname->name = mono_string_new (domain, assem->aname.name);
3432 aname->major = assem->aname.major;
3433 aname->minor = assem->aname.minor;
3434 aname->build = assem->aname.build;
3435 aname->revision = assem->aname.revision;
3436 aname->revision = assem->aname.revision;
3437 aname->hashalg = assem->aname.hash_alg;
3438 aname->flags = assem->aname.flags;
3440 if (create_culture) {
3441 gpointer args [1];
3442 args [0] = mono_string_new (domain, assem->aname.culture);
3443 aname->cultureInfo = mono_runtime_invoke (create_culture, NULL, args, NULL);
3446 if (assem->aname.public_key) {
3447 guint32 pkey_len;
3448 const char *pkey_ptr = assem->aname.public_key;
3449 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3451 aname->publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
3452 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3455 /* public key token isn't copied - the class library will
3456 automatically generate it from the public key if required */
3458 absolute = g_build_filename (assem->basedir, assem->image->module_name, NULL);
3459 codebase = g_filename_to_uri (absolute, NULL, NULL);
3460 aname->codebase = mono_string_new (domain, codebase);
3461 g_free (codebase);
3462 g_free (absolute);
3463 mono_array_set (result, gpointer, i, aname);
3465 return result;
3468 typedef struct {
3469 MonoArray *res;
3470 int idx;
3471 } NameSpaceInfo;
3473 static void
3474 foreach_namespace (const char* key, gconstpointer val, NameSpaceInfo *info)
3476 MonoString *name = mono_string_new (mono_object_domain (info->res), key);
3478 mono_array_set (info->res, gpointer, info->idx, name);
3479 info->idx++;
3482 static MonoArray*
3483 ves_icall_System_Reflection_Assembly_GetNamespaces (MonoReflectionAssembly *assembly)
3485 MonoImage *img = assembly->assembly->image;
3486 MonoArray *res;
3487 NameSpaceInfo info;
3489 MONO_ARCH_SAVE_REGS;
3491 res = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, g_hash_table_size (img->name_cache));
3492 info.res = res;
3493 info.idx = 0;
3494 g_hash_table_foreach (img->name_cache, (GHFunc)foreach_namespace, &info);
3496 return res;
3499 /* move this in some file in mono/util/ */
3500 static char *
3501 g_concat_dir_and_file (const char *dir, const char *file)
3503 g_return_val_if_fail (dir != NULL, NULL);
3504 g_return_val_if_fail (file != NULL, NULL);
3507 * If the directory name doesn't have a / on the end, we need
3508 * to add one so we get a proper path to the file
3510 if (dir [strlen(dir) - 1] != G_DIR_SEPARATOR)
3511 return g_strconcat (dir, G_DIR_SEPARATOR_S, file, NULL);
3512 else
3513 return g_strconcat (dir, file, NULL);
3516 static void *
3517 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name, gint32 *size, MonoReflectionModule **ref_module)
3519 char *n = mono_string_to_utf8 (name);
3520 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3521 guint32 i;
3522 guint32 cols [MONO_MANIFEST_SIZE];
3523 guint32 impl, file_idx;
3524 const char *val;
3525 MonoImage *module;
3527 MONO_ARCH_SAVE_REGS;
3529 for (i = 0; i < table->rows; ++i) {
3530 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3531 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3532 if (strcmp (val, n) == 0)
3533 break;
3535 g_free (n);
3536 if (i == table->rows)
3537 return NULL;
3538 /* FIXME */
3539 impl = cols [MONO_MANIFEST_IMPLEMENTATION];
3540 if (impl) {
3542 * this code should only be called after obtaining the
3543 * ResourceInfo and handling the other cases.
3545 g_assert ((impl & MONO_IMPLEMENTATION_MASK) == MONO_IMPLEMENTATION_FILE);
3546 file_idx = impl >> MONO_IMPLEMENTATION_BITS;
3548 module = mono_image_load_file_for_image (assembly->assembly->image, file_idx);
3549 if (!module)
3550 return NULL;
3552 else
3553 module = assembly->assembly->image;
3555 *ref_module = mono_module_get_object (mono_domain_get (), module);
3557 return (void*)mono_image_get_resource (module, cols [MONO_MANIFEST_OFFSET], size);
3560 static gboolean
3561 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoManifestResourceInfo *info)
3563 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
3564 int i;
3565 guint32 cols [MONO_MANIFEST_SIZE];
3566 guint32 file_cols [MONO_FILE_SIZE];
3567 const char *val;
3568 char *n;
3570 MONO_ARCH_SAVE_REGS;
3572 n = mono_string_to_utf8 (name);
3573 for (i = 0; i < table->rows; ++i) {
3574 mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
3575 val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
3576 if (strcmp (val, n) == 0)
3577 break;
3579 g_free (n);
3580 if (i == table->rows)
3581 return FALSE;
3583 if (!cols [MONO_MANIFEST_IMPLEMENTATION]) {
3584 info->location = RESOURCE_LOCATION_EMBEDDED | RESOURCE_LOCATION_IN_MANIFEST;
3586 else {
3587 switch (cols [MONO_MANIFEST_IMPLEMENTATION] & MONO_IMPLEMENTATION_MASK) {
3588 case MONO_IMPLEMENTATION_FILE:
3589 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> MONO_IMPLEMENTATION_BITS;
3590 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3591 mono_metadata_decode_row (table, i - 1, file_cols, MONO_FILE_SIZE);
3592 val = mono_metadata_string_heap (assembly->assembly->image, file_cols [MONO_FILE_NAME]);
3593 info->filename = mono_string_new (mono_object_domain (assembly), val);
3594 if (file_cols [MONO_FILE_FLAGS] && FILE_CONTAINS_NO_METADATA)
3595 info->location = 0;
3596 else
3597 info->location = RESOURCE_LOCATION_EMBEDDED;
3598 break;
3600 case MONO_IMPLEMENTATION_ASSEMBLYREF:
3601 i = cols [MONO_MANIFEST_IMPLEMENTATION] >> MONO_IMPLEMENTATION_BITS;
3602 mono_assembly_load_reference (assembly->assembly->image, i - 1);
3603 if (assembly->assembly->image->references [i - 1] == (gpointer)-1) {
3604 char *msg = g_strdup_printf ("Assembly %d referenced from assembly %s not found ", i - 1, assembly->assembly->image->name);
3605 MonoException *ex = mono_get_exception_file_not_found2 (msg, NULL);
3606 g_free (msg);
3607 mono_raise_exception (ex);
3609 info->assembly = mono_assembly_get_object (mono_domain_get (), assembly->assembly->image->references [i - 1]);
3611 /* Obtain info recursively */
3612 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (info->assembly, name, info);
3613 info->location |= RESOURCE_LOCATION_ANOTHER_ASSEMBLY;
3614 break;
3616 case MONO_IMPLEMENTATION_EXP_TYPE:
3617 g_assert_not_reached ();
3618 break;
3622 return TRUE;
3625 static MonoObject*
3626 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name, MonoBoolean resource_modules)
3628 MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3629 MonoArray *result = NULL;
3630 int i, count;
3631 const char *val;
3632 char *n;
3634 MONO_ARCH_SAVE_REGS;
3636 /* check hash if needed */
3637 if (name) {
3638 n = mono_string_to_utf8 (name);
3639 for (i = 0; i < table->rows; ++i) {
3640 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3641 if (strcmp (val, n) == 0) {
3642 MonoString *fn;
3643 g_free (n);
3644 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3645 fn = mono_string_new (mono_object_domain (assembly), n);
3646 g_free (n);
3647 return (MonoObject*)fn;
3650 g_free (n);
3651 return NULL;
3654 count = 0;
3655 for (i = 0; i < table->rows; ++i) {
3656 if (resource_modules || !(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA))
3657 count ++;
3660 result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, count);
3662 count = 0;
3663 for (i = 0; i < table->rows; ++i) {
3664 if (resource_modules || !(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
3665 val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_FILE_NAME));
3666 n = g_concat_dir_and_file (assembly->assembly->basedir, val);
3667 mono_array_set (result, gpointer, count, mono_string_new (mono_object_domain (assembly), n));
3668 g_free (n);
3669 count ++;
3672 return (MonoObject*)result;
3675 static MonoArray*
3676 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly *assembly)
3678 MonoDomain *domain = mono_domain_get();
3679 MonoArray *res;
3680 MonoClass *klass;
3681 int i, j, file_count = 0;
3682 MonoImage **modules;
3683 guint32 module_count, real_module_count;
3684 MonoTableInfo *table;
3686 g_assert (assembly->assembly->image != NULL);
3688 if (assembly->assembly->dynamic) {
3689 MonoReflectionAssemblyBuilder *assemblyb = (MonoReflectionAssemblyBuilder*)assembly;
3691 if (assemblyb->modules)
3692 module_count = mono_array_length (assemblyb->modules);
3693 else
3694 module_count = 0;
3695 real_module_count = module_count;
3697 modules = g_new0 (MonoImage*, module_count);
3698 for (i = 0; i < mono_array_length (assemblyb->modules); ++i) {
3699 modules [i] =
3700 mono_array_get (assemblyb->modules, MonoReflectionModuleBuilder*, i)->module.image;
3703 else {
3704 table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
3705 file_count = table->rows;
3707 modules = assembly->assembly->image->modules;
3708 module_count = assembly->assembly->image->module_count;
3710 real_module_count = 0;
3711 for (i = 0; i < module_count; ++i)
3712 if (modules [i])
3713 real_module_count ++;
3716 klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "Module");
3717 res = mono_array_new (domain, klass, 1 + real_module_count + file_count);
3719 mono_array_set (res, gpointer, 0, mono_module_get_object (domain, assembly->assembly->image));
3720 j = 1;
3721 for (i = 0; i < module_count; ++i)
3722 if (modules [i]) {
3723 mono_array_set (res, gpointer, j, mono_module_get_object (domain, modules[i]));
3724 ++j;
3727 for (i = 0; i < file_count; ++i, ++j)
3728 mono_array_set (res, gpointer, j, mono_module_file_get_object (domain, assembly->assembly->image, i));
3730 if (assembly->assembly->dynamic)
3731 g_free (modules);
3733 return res;
3736 static MonoReflectionMethod*
3737 ves_icall_GetCurrentMethod (void)
3739 MonoMethod *m = mono_method_get_last_managed ();
3741 MONO_ARCH_SAVE_REGS;
3743 return mono_method_get_object (mono_domain_get (), m, NULL);
3746 static MonoReflectionMethod*
3747 ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternal (MonoMethod *method)
3749 return mono_method_get_object (mono_domain_get (), method, NULL);
3752 static MonoReflectionMethodBody*
3753 ves_icall_System_Reflection_MethodBase_GetMethodBodyInternal (MonoMethod *method)
3755 return mono_method_body_get_object (mono_domain_get (), method);
3758 static MonoReflectionAssembly*
3759 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
3761 MonoMethod *m = mono_method_get_last_managed ();
3763 MONO_ARCH_SAVE_REGS;
3765 return mono_assembly_get_object (mono_domain_get (), m->klass->image->assembly);
3769 static gboolean
3770 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
3772 MonoMethod **dest = data;
3774 /* skip unmanaged frames */
3775 if (!managed)
3776 return FALSE;
3778 if (m == *dest) {
3779 *dest = NULL;
3780 return FALSE;
3782 if (!(*dest)) {
3783 *dest = m;
3784 return TRUE;
3786 return FALSE;
3789 static MonoReflectionAssembly*
3790 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
3792 MonoDomain* domain = mono_domain_get ();
3794 MONO_ARCH_SAVE_REGS;
3796 if (!domain->entry_assembly)
3797 return NULL;
3799 return mono_assembly_get_object (domain, domain->entry_assembly);
3803 static MonoReflectionAssembly*
3804 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
3806 MonoMethod *m = mono_method_get_last_managed ();
3807 MonoMethod *dest = m;
3809 MONO_ARCH_SAVE_REGS;
3811 mono_stack_walk_no_il (get_caller, &dest);
3812 if (!dest)
3813 dest = m;
3814 return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
3817 static MonoString *
3818 ves_icall_System_MonoType_getFullName (MonoReflectionType *object, gboolean full_name)
3820 MonoDomain *domain = mono_object_domain (object);
3821 MonoString *res;
3822 gchar *name;
3824 MONO_ARCH_SAVE_REGS;
3826 if (full_name)
3827 name = mono_type_get_full_name (object->type);
3828 else
3829 name = mono_type_get_name (object->type);
3830 res = mono_string_new (domain, name);
3831 g_free (name);
3833 return res;
3836 static void
3837 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute)
3839 static MonoMethod *create_culture = NULL;
3840 gpointer args [1];
3841 guint32 pkey_len;
3842 const char *pkey_ptr;
3843 gchar *codebase;
3845 MONO_ARCH_SAVE_REGS;
3847 aname->name = mono_string_new (domain, name->name);
3848 aname->major = name->major;
3849 aname->minor = name->minor;
3850 aname->build = name->build;
3851 aname->revision = name->revision;
3852 aname->hashalg = name->hash_alg;
3854 codebase = g_filename_to_uri (absolute, NULL, NULL);
3855 if (codebase) {
3856 aname->codebase = mono_string_new (domain, codebase);
3857 g_free (codebase);
3860 if (!create_culture) {
3861 MonoMethodDesc *desc = mono_method_desc_new ("System.Globalization.CultureInfo:CreateSpecificCulture(string)", TRUE);
3862 create_culture = mono_method_desc_search_in_image (desc, mono_defaults.corlib);
3863 g_assert (create_culture);
3864 mono_method_desc_free (desc);
3867 args [0] = mono_string_new (domain, name->culture);
3868 aname->cultureInfo =
3869 mono_runtime_invoke (create_culture, NULL, args, NULL);
3871 if (name->public_key) {
3872 pkey_ptr = name->public_key;
3873 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, &pkey_ptr);
3875 aname->publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
3876 memcpy (mono_array_addr (aname->publicKey, guint8, 0), pkey_ptr, pkey_len);
3879 /* MonoAssemblyName keeps the public key token as an hexadecimal string */
3880 if (name->public_key_token [0]) {
3881 int i, j;
3882 char *p;
3884 aname->keyToken = mono_array_new (domain, mono_defaults.byte_class, 8);
3885 p = mono_array_addr (aname->keyToken, char, 0);
3887 for (i = 0, j = 0; i < 8; i++) {
3888 *p = g_ascii_xdigit_value (name->public_key_token [j++]) << 4;
3889 *p |= g_ascii_xdigit_value (name->public_key_token [j++]);
3890 p++;
3895 static void
3896 ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
3898 gchar *absolute;
3900 MONO_ARCH_SAVE_REGS;
3902 absolute = g_build_filename (assembly->assembly->basedir, assembly->assembly->image->module_name, NULL);
3904 fill_reflection_assembly_name (mono_object_domain (assembly), aname,
3905 &assembly->assembly->aname, absolute);
3907 g_free (absolute);
3910 static void
3911 ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname, MonoReflectionAssemblyName *aname)
3913 char *filename;
3914 MonoImageOpenStatus status = MONO_IMAGE_OK;
3915 gboolean res;
3916 MonoImage *image;
3917 MonoAssemblyName name;
3919 MONO_ARCH_SAVE_REGS;
3921 filename = mono_string_to_utf8 (fname);
3923 image = mono_image_open (filename, &status);
3925 if (!image){
3926 MonoException *exc;
3928 g_free (filename);
3929 exc = mono_get_exception_file_not_found (fname);
3930 mono_raise_exception (exc);
3933 res = mono_assembly_fill_assembly_name (image, &name);
3934 if (!res) {
3935 mono_image_close (image);
3936 g_free (filename);
3937 mono_raise_exception (mono_get_exception_argument ("assemblyFile", "The file does not contain a manifest"));
3940 fill_reflection_assembly_name (mono_domain_get (), aname, &name, filename);
3942 g_free (filename);
3943 mono_image_close (image);
3946 static MonoArray*
3947 mono_module_get_types (MonoDomain *domain, MonoImage *image,
3948 MonoBoolean exportedOnly)
3950 MonoArray *res;
3951 MonoClass *klass;
3952 MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF];
3953 int i, count;
3954 guint32 attrs, visibility;
3956 /* we start the count from 1 because we skip the special type <Module> */
3957 if (exportedOnly) {
3958 count = 0;
3959 for (i = 1; i < tdef->rows; ++i) {
3960 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3961 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3962 if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
3963 count++;
3965 } else {
3966 count = tdef->rows - 1;
3968 res = mono_array_new (domain, mono_defaults.monotype_class, count);
3969 count = 0;
3970 for (i = 1; i < tdef->rows; ++i) {
3971 attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
3972 visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
3973 if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
3974 klass = mono_class_get (image, (i + 1) | MONO_TOKEN_TYPE_DEF);
3975 mono_array_set (res, gpointer, count, mono_type_get_object (domain, &klass->byval_arg));
3976 count++;
3980 return res;
3983 static MonoArray*
3984 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
3986 MonoArray *res = NULL;
3987 MonoImage *image = NULL;
3988 MonoTableInfo *table = NULL;
3989 MonoDomain *domain;
3990 int i;
3992 MONO_ARCH_SAVE_REGS;
3994 domain = mono_object_domain (assembly);
3996 if (assembly->assembly->dynamic) {
3997 MonoReflectionAssemblyBuilder *abuilder = (MonoReflectionAssemblyBuilder*)assembly;
3998 if (abuilder->modules) {
3999 for (i = 0; i < mono_array_length(abuilder->modules); i++) {
4000 MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
4001 if (res == NULL)
4002 res = mb->types;
4003 else {
4004 MonoArray *append = mb->types;
4005 if (mono_array_length (append) > 0) {
4006 guint32 len1, len2;
4007 MonoArray *new;
4008 len1 = mono_array_length (res);
4009 len2 = mono_array_length (append);
4010 new = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
4011 memcpy (mono_array_addr (new, MonoReflectionType*, 0),
4012 mono_array_addr (res, MonoReflectionType*, 0),
4013 len1 * sizeof (MonoReflectionType*));
4014 memcpy (mono_array_addr (new, MonoReflectionType*, len1),
4015 mono_array_addr (append, MonoReflectionType*, 0),
4016 len2 * sizeof (MonoReflectionType*));
4017 res = new;
4023 * Replace TypeBuilders with the created types to be compatible
4024 * with MS.NET.
4026 if (res) {
4027 for (i = 0; i < mono_array_length (res); ++i) {
4028 MonoReflectionTypeBuilder *tb = mono_array_get (res, MonoReflectionTypeBuilder*, i);
4029 if (tb->created)
4030 mono_array_set (res, MonoReflectionType*, i, tb->created);
4035 if (abuilder->loaded_modules)
4036 for (i = 0; i < mono_array_length(abuilder->loaded_modules); i++) {
4037 MonoReflectionModule *rm = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
4038 if (res == NULL)
4039 res = mono_module_get_types (domain, rm->image, exportedOnly);
4040 else {
4041 MonoArray *append = mono_module_get_types (domain, rm->image, exportedOnly);
4042 if (mono_array_length (append) > 0) {
4043 guint32 len1, len2;
4044 MonoArray *new;
4045 len1 = mono_array_length (res);
4046 len2 = mono_array_length (append);
4047 new = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
4048 memcpy (mono_array_addr (new, MonoReflectionType*, 0),
4049 mono_array_addr (res, MonoReflectionType*, 0),
4050 len1 * sizeof (MonoReflectionType*));
4051 memcpy (mono_array_addr (new, MonoReflectionType*, len1),
4052 mono_array_addr (append, MonoReflectionType*, 0),
4053 len2 * sizeof (MonoReflectionType*));
4054 res = new;
4058 return res;
4060 image = assembly->assembly->image;
4061 table = &image->tables [MONO_TABLE_FILE];
4062 res = mono_module_get_types (domain, image, exportedOnly);
4064 /* Append data from all modules in the assembly */
4065 for (i = 0; i < table->rows; ++i) {
4066 if (!(mono_metadata_decode_row_col (table, i, MONO_FILE_FLAGS) & FILE_CONTAINS_NO_METADATA)) {
4067 MonoImage *loaded_image = mono_assembly_load_module (image->assembly, i + 1);
4068 if (loaded_image) {
4069 MonoArray *res2 = mono_module_get_types (domain, loaded_image, exportedOnly);
4070 /* Append the new types to the end of the array */
4071 if (mono_array_length (res2) > 0) {
4072 guint32 len1, len2;
4073 MonoArray *res3;
4075 len1 = mono_array_length (res);
4076 len2 = mono_array_length (res2);
4077 res3 = mono_array_new (domain, mono_defaults.monotype_class, len1 + len2);
4078 memcpy (mono_array_addr (res3, MonoReflectionType*, 0),
4079 mono_array_addr (res, MonoReflectionType*, 0),
4080 len1 * sizeof (MonoReflectionType*));
4081 memcpy (mono_array_addr (res3, MonoReflectionType*, len1),
4082 mono_array_addr (res2, MonoReflectionType*, 0),
4083 len2 * sizeof (MonoReflectionType*));
4084 res = res3;
4089 return res;
4092 static MonoReflectionType*
4093 ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModule *module)
4095 MonoDomain *domain = mono_object_domain (module);
4096 MonoClass *klass;
4098 MONO_ARCH_SAVE_REGS;
4100 g_assert (module->image);
4102 if (module->image->dynamic && ((MonoDynamicImage*)(module->image))->initial_image)
4103 /* These images do not have a global type */
4104 return NULL;
4106 klass = mono_class_get (module->image, 1 | MONO_TOKEN_TYPE_DEF);
4107 return mono_type_get_object (domain, &klass->byval_arg);
4110 static void
4111 ves_icall_System_Reflection_Module_Close (MonoReflectionModule *module)
4113 if (module->image)
4114 mono_image_close (module->image);
4117 static MonoString*
4118 ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module)
4120 MonoDomain *domain = mono_object_domain (module);
4122 MONO_ARCH_SAVE_REGS;
4124 g_assert (module->image);
4125 return mono_string_new (domain, module->image->guid);
4128 static void
4129 ves_icall_System_Reflection_Module_GetPEKind (MonoImage *image, gint32 *pe_kind, gint32 *machine)
4131 if (image->dynamic) {
4132 MonoDynamicImage *dyn = (MonoDynamicImage*)image;
4133 *pe_kind = dyn->pe_kind;
4134 *machine = dyn->machine;
4136 else {
4137 *pe_kind = ((MonoCLIImageInfo*)(image->image_info))->cli_cli_header.ch_flags & 0x3;
4138 *machine = ((MonoCLIImageInfo*)(image->image_info))->cli_header.coff.coff_machine;
4142 static MonoArray*
4143 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *module)
4145 MONO_ARCH_SAVE_REGS;
4147 if (!module->image)
4148 return mono_array_new (mono_object_domain (module), mono_defaults.monotype_class, 0);
4149 else
4150 return mono_module_get_types (mono_object_domain (module), module->image, FALSE);
4153 static gboolean
4154 mono_metadata_memberref_is_method (MonoImage *image, guint32 token)
4156 guint32 cols [MONO_MEMBERREF_SIZE];
4157 const char *sig;
4158 mono_metadata_decode_row (&image->tables [MONO_TABLE_MEMBERREF], mono_metadata_token_index (token) - 1, cols, MONO_MEMBERREF_SIZE);
4159 sig = mono_metadata_blob_heap (image, cols [MONO_MEMBERREF_SIGNATURE]);
4160 mono_metadata_decode_blob_size (sig, &sig);
4161 return (*sig != 0x6);
4164 static MonoType*
4165 ves_icall_System_Reflection_Module_ResolveTypeToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4167 MonoClass *klass;
4168 int table = mono_metadata_token_table (token);
4169 int index = mono_metadata_token_index (token);
4171 *error = ResolveTokenError_Other;
4173 /* Validate token */
4174 if ((table != MONO_TABLE_TYPEDEF) && (table != MONO_TABLE_TYPEREF) &&
4175 (table != MONO_TABLE_TYPESPEC)) {
4176 *error = ResolveTokenError_BadTable;
4177 return NULL;
4180 if (image->dynamic)
4181 return mono_lookup_dynamic_token (image, token);
4183 if ((index <= 0) || (index > image->tables [table].rows)) {
4184 *error = ResolveTokenError_OutOfRange;
4185 return NULL;
4188 klass = mono_class_get (image, token);
4189 if (klass)
4190 return &klass->byval_arg;
4191 else
4192 return NULL;
4195 static MonoMethod*
4196 ves_icall_System_Reflection_Module_ResolveMethodToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4198 int table = mono_metadata_token_table (token);
4199 int index = mono_metadata_token_index (token);
4201 *error = ResolveTokenError_Other;
4203 /* Validate token */
4204 if ((table != MONO_TABLE_METHOD) && (table != MONO_TABLE_METHODSPEC) &&
4205 (table != MONO_TABLE_MEMBERREF)) {
4206 *error = ResolveTokenError_BadTable;
4207 return NULL;
4210 if (image->dynamic)
4211 /* FIXME: validate memberref token type */
4212 return mono_lookup_dynamic_token (image, token);
4214 if ((index <= 0) || (index > image->tables [table].rows)) {
4215 *error = ResolveTokenError_OutOfRange;
4216 return NULL;
4218 if ((table == MONO_TABLE_MEMBERREF) && (!mono_metadata_memberref_is_method (image, token))) {
4219 *error = ResolveTokenError_BadTable;
4220 return NULL;
4223 return mono_get_method (image, token, NULL);
4226 static MonoString*
4227 ves_icall_System_Reflection_Module_ResolveStringToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4229 int index = mono_metadata_token_index (token);
4231 *error = ResolveTokenError_Other;
4233 /* Validate token */
4234 if (mono_metadata_token_code (token) != MONO_TOKEN_STRING) {
4235 *error = ResolveTokenError_BadTable;
4236 return NULL;
4239 if (image->dynamic)
4240 return mono_lookup_dynamic_token (image, token);
4242 if ((index <= 0) || (index >= image->heap_us.size)) {
4243 *error = ResolveTokenError_OutOfRange;
4244 return NULL;
4247 /* FIXME: What to do if the index points into the middle of a string ? */
4249 return mono_ldstr (mono_domain_get (), image, index);
4252 static MonoClassField*
4253 ves_icall_System_Reflection_Module_ResolveFieldToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4255 MonoClass *klass;
4256 int table = mono_metadata_token_table (token);
4257 int index = mono_metadata_token_index (token);
4259 *error = ResolveTokenError_Other;
4261 /* Validate token */
4262 if ((table != MONO_TABLE_FIELD) && (table != MONO_TABLE_MEMBERREF)) {
4263 *error = ResolveTokenError_BadTable;
4264 return NULL;
4267 if (image->dynamic)
4268 /* FIXME: validate memberref token type */
4269 return mono_lookup_dynamic_token (image, token);
4271 if ((index <= 0) || (index > image->tables [table].rows)) {
4272 *error = ResolveTokenError_OutOfRange;
4273 return NULL;
4275 if ((table == MONO_TABLE_MEMBERREF) && (mono_metadata_memberref_is_method (image, token))) {
4276 *error = ResolveTokenError_BadTable;
4277 return NULL;
4280 return mono_field_from_token (image, token, &klass, NULL);
4284 static MonoObject*
4285 ves_icall_System_Reflection_Module_ResolveMemberToken (MonoImage *image, guint32 token, MonoResolveTokenError *error)
4287 int table = mono_metadata_token_table (token);
4289 *error = ResolveTokenError_Other;
4291 switch (table) {
4292 case MONO_TABLE_TYPEDEF:
4293 case MONO_TABLE_TYPEREF:
4294 case MONO_TABLE_TYPESPEC: {
4295 MonoType *t = ves_icall_System_Reflection_Module_ResolveTypeToken (image, token, error);
4296 if (t)
4297 return (MonoObject*)mono_type_get_object (mono_domain_get (), t);
4298 else
4299 return NULL;
4301 case MONO_TABLE_METHOD:
4302 case MONO_TABLE_METHODSPEC: {
4303 MonoMethod *m = ves_icall_System_Reflection_Module_ResolveMethodToken (image, token, error);
4304 if (m)
4305 return (MonoObject*)mono_method_get_object (mono_domain_get (), m, m->klass);
4306 else
4307 return NULL;
4309 case MONO_TABLE_FIELD: {
4310 MonoClassField *f = ves_icall_System_Reflection_Module_ResolveFieldToken (image, token, error);
4311 if (f)
4312 return (MonoObject*)mono_field_get_object (mono_domain_get (), f->parent, f);
4313 else
4314 return NULL;
4316 case MONO_TABLE_MEMBERREF:
4317 if (mono_metadata_memberref_is_method (image, token)) {
4318 MonoMethod *m = ves_icall_System_Reflection_Module_ResolveMethodToken (image, token, error);
4319 if (m)
4320 return (MonoObject*)mono_method_get_object (mono_domain_get (), m, m->klass);
4321 else
4322 return NULL;
4324 else {
4325 MonoClassField *f = ves_icall_System_Reflection_Module_ResolveFieldToken (image, token, error);
4326 if (f)
4327 return (MonoObject*)mono_field_get_object (mono_domain_get (), f->parent, f);
4328 else
4329 return NULL;
4331 break;
4333 default:
4334 *error = ResolveTokenError_BadTable;
4337 return NULL;
4340 static MonoReflectionType*
4341 ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
4343 MonoClass *klass;
4344 int isbyref = 0, rank;
4345 char *str = mono_string_to_utf8 (smodifiers);
4346 char *p;
4348 MONO_ARCH_SAVE_REGS;
4350 klass = mono_class_from_mono_type (tb->type.type);
4351 p = str;
4352 /* logic taken from mono_reflection_parse_type(): keep in sync */
4353 while (*p) {
4354 switch (*p) {
4355 case '&':
4356 if (isbyref) { /* only one level allowed by the spec */
4357 g_free (str);
4358 return NULL;
4360 isbyref = 1;
4361 p++;
4362 g_free (str);
4363 return mono_type_get_object (mono_object_domain (tb), &klass->this_arg);
4364 break;
4365 case '*':
4366 klass = mono_ptr_class_get (&klass->byval_arg);
4367 mono_class_init (klass);
4368 p++;
4369 break;
4370 case '[':
4371 rank = 1;
4372 p++;
4373 while (*p) {
4374 if (*p == ']')
4375 break;
4376 if (*p == ',')
4377 rank++;
4378 else if (*p != '*') { /* '*' means unknown lower bound */
4379 g_free (str);
4380 return NULL;
4382 ++p;
4384 if (*p != ']') {
4385 g_free (str);
4386 return NULL;
4388 p++;
4389 klass = mono_array_class_get (klass, rank);
4390 mono_class_init (klass);
4391 break;
4392 default:
4393 break;
4396 g_free (str);
4397 return mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
4400 static MonoBoolean
4401 ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
4403 MonoType *type;
4404 MonoBoolean res;
4406 MONO_ARCH_SAVE_REGS;
4408 type = t->type;
4409 res = !type->byref && (type->type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY);
4411 return res;
4414 static MonoReflectionType *
4415 ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
4417 MonoClass *klass, *aklass;
4419 MONO_ARCH_SAVE_REGS;
4421 klass = mono_class_from_mono_type (type->type);
4422 aklass = mono_array_class_get (klass, rank);
4424 return mono_type_get_object (mono_object_domain (type), &aklass->byval_arg);
4427 static MonoReflectionType *
4428 ves_icall_Type_make_byref_type (MonoReflectionType *type)
4430 MonoClass *klass;
4432 MONO_ARCH_SAVE_REGS;
4434 klass = mono_class_from_mono_type (type->type);
4436 return mono_type_get_object (mono_object_domain (type), &klass->this_arg);
4439 static MonoReflectionType *
4440 ves_icall_Type_MakePointerType (MonoReflectionType *type)
4442 MonoClass *pklass;
4444 MONO_ARCH_SAVE_REGS;
4446 pklass = mono_ptr_class_get (type->type);
4448 return mono_type_get_object (mono_object_domain (type), &pklass->byval_arg);
4451 static MonoObject *
4452 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target,
4453 MonoReflectionMethod *info)
4455 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
4456 MonoObject *delegate;
4457 gpointer func;
4459 MONO_ARCH_SAVE_REGS;
4461 mono_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
4463 delegate = mono_object_new (mono_object_domain (type), delegate_class);
4465 func = mono_compile_method (info->method);
4467 mono_delegate_ctor (delegate, target, func);
4469 return delegate;
4472 static void
4473 ves_icall_System_Delegate_FreeTrampoline (MonoDelegate *this)
4475 mono_delegate_free_ftnptr (this);
4479 * Magic number to convert a time which is relative to
4480 * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
4482 #define EPOCH_ADJUST ((guint64)62135596800LL)
4485 * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
4487 #define FILETIME_ADJUST ((guint64)504911232000000000LL)
4490 * This returns Now in UTC
4492 static gint64
4493 ves_icall_System_DateTime_GetNow (void)
4495 #ifdef PLATFORM_WIN32
4496 SYSTEMTIME st;
4497 FILETIME ft;
4499 GetSystemTime (&st);
4500 SystemTimeToFileTime (&st, &ft);
4501 return (gint64) FILETIME_ADJUST + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
4502 #else
4503 /* FIXME: put this in io-layer and call it GetLocalTime */
4504 struct timeval tv;
4505 gint64 res;
4507 MONO_ARCH_SAVE_REGS;
4509 if (gettimeofday (&tv, NULL) == 0) {
4510 res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 + tv.tv_usec)*10;
4511 return res;
4513 /* fixme: raise exception */
4514 return 0;
4515 #endif
4518 #ifdef PLATFORM_WIN32
4519 /* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
4520 static void
4521 convert_to_absolute_date(SYSTEMTIME *date)
4523 #define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
4524 static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4525 static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4526 /* from the calendar FAQ */
4527 int a = (14 - date->wMonth) / 12;
4528 int y = date->wYear - a;
4529 int m = date->wMonth + 12 * a - 2;
4530 int d = (1 + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
4532 /* d is now the day of the week for the first of the month (0 == Sunday) */
4534 int day_of_week = date->wDayOfWeek;
4536 /* set day_in_month to the first day in the month which falls on day_of_week */
4537 int day_in_month = 1 + (day_of_week - d);
4538 if (day_in_month <= 0)
4539 day_in_month += 7;
4541 /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
4542 date->wDay = day_in_month + (date->wDay - 1) * 7;
4543 if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
4544 date->wDay -= 7;
4546 #endif
4548 #ifndef PLATFORM_WIN32
4550 * Return's the offset from GMT of a local time.
4552 * tm is a local time
4553 * t is the same local time as seconds.
4555 static int
4556 gmt_offset(struct tm *tm, time_t t)
4558 #if defined (HAVE_TM_GMTOFF)
4559 return tm->tm_gmtoff;
4560 #else
4561 struct tm g;
4562 time_t t2;
4563 g = *gmtime(&t);
4564 g.tm_isdst = tm->tm_isdst;
4565 t2 = mktime(&g);
4566 return (int)difftime(t, t2);
4567 #endif
4569 #endif
4571 * This is heavily based on zdump.c from glibc 2.2.
4573 * * data[0]: start of daylight saving time (in DateTime ticks).
4574 * * data[1]: end of daylight saving time (in DateTime ticks).
4575 * * data[2]: utcoffset (in TimeSpan ticks).
4576 * * data[3]: additional offset when daylight saving (in TimeSpan ticks).
4577 * * name[0]: name of this timezone when not daylight saving.
4578 * * name[1]: name of this timezone when daylight saving.
4580 * FIXME: This only works with "standard" Unix dates (years between 1900 and 2100) while
4581 * the class library allows years between 1 and 9999.
4583 * Returns true on success and zero on failure.
4585 static guint32
4586 ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
4588 #ifndef PLATFORM_WIN32
4589 MonoDomain *domain = mono_domain_get ();
4590 struct tm start, tt;
4591 time_t t;
4593 long int gmtoff;
4594 int is_daylight = 0, day;
4595 char tzone [64];
4597 MONO_ARCH_SAVE_REGS;
4599 MONO_CHECK_ARG_NULL (data);
4600 MONO_CHECK_ARG_NULL (names);
4602 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
4603 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
4606 * no info is better than crashing: we'll need our own tz data to make
4607 * this work properly, anyway. The range is reduced to 1970 .. 2037 because
4608 * that is what mktime is guaranteed to support (we get into an infinite loop
4609 * otherwise).
4611 if ((year < 1970) || (year > 2037)) {
4612 t = time (NULL);
4613 tt = *localtime (&t);
4614 strftime (tzone, sizeof (tzone), "%Z", &tt);
4615 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4616 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4617 return 1;
4620 memset (&start, 0, sizeof (start));
4622 start.tm_mday = 1;
4623 start.tm_year = year-1900;
4625 t = mktime (&start);
4626 gmtoff = gmt_offset (&start, t);
4628 /* For each day of the year, calculate the tm_gmtoff. */
4629 for (day = 0; day < 365; day++) {
4631 t += 3600*24;
4632 tt = *localtime (&t);
4634 /* Daylight saving starts or ends here. */
4635 if (gmt_offset (&tt, t) != gmtoff) {
4636 struct tm tt1;
4637 time_t t1;
4639 /* Try to find the exact hour when daylight saving starts/ends. */
4640 t1 = t;
4641 do {
4642 t1 -= 3600;
4643 tt1 = *localtime (&t1);
4644 } while (gmt_offset (&tt1, t1) != gmtoff);
4646 /* Try to find the exact minute when daylight saving starts/ends. */
4647 do {
4648 t1 += 60;
4649 tt1 = *localtime (&t1);
4650 } while (gmt_offset (&tt1, t1) == gmtoff);
4651 t1+=gmtoff;
4652 strftime (tzone, sizeof (tzone), "%Z", &tt);
4654 /* Write data, if we're already in daylight saving, we're done. */
4655 if (is_daylight) {
4656 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4657 mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
4658 return 1;
4659 } else {
4660 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4661 mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
4662 is_daylight = 1;
4665 /* This is only set once when we enter daylight saving. */
4666 mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
4667 mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (&tt, t) - gmtoff) * 10000000L);
4669 gmtoff = gmt_offset (&tt, t);
4673 if (!is_daylight) {
4674 strftime (tzone, sizeof (tzone), "%Z", &tt);
4675 mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
4676 mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
4677 mono_array_set ((*data), gint64, 0, 0);
4678 mono_array_set ((*data), gint64, 1, 0);
4679 mono_array_set ((*data), gint64, 2, (gint64) gmtoff * 10000000L);
4680 mono_array_set ((*data), gint64, 3, 0);
4683 return 1;
4684 #else
4685 MonoDomain *domain = mono_domain_get ();
4686 TIME_ZONE_INFORMATION tz_info;
4687 FILETIME ft;
4688 int i;
4689 int err, tz_id;
4691 tz_id = GetTimeZoneInformation (&tz_info);
4692 if (tz_id == TIME_ZONE_ID_INVALID)
4693 return 0;
4695 MONO_CHECK_ARG_NULL (data);
4696 MONO_CHECK_ARG_NULL (names);
4698 (*data) = mono_array_new (domain, mono_defaults.int64_class, 4);
4699 (*names) = mono_array_new (domain, mono_defaults.string_class, 2);
4701 for (i = 0; i < 32; ++i)
4702 if (!tz_info.DaylightName [i])
4703 break;
4704 mono_array_set ((*names), gpointer, 1, mono_string_new_utf16 (domain, tz_info.DaylightName, i));
4705 for (i = 0; i < 32; ++i)
4706 if (!tz_info.StandardName [i])
4707 break;
4708 mono_array_set ((*names), gpointer, 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
4710 if ((year <= 1601) || (year > 30827)) {
4712 * According to MSDN, the MS time functions can't handle dates outside
4713 * this interval.
4715 return 1;
4718 /* even if the timezone has no daylight savings it may have Bias (e.g. GMT+13 it seems) */
4719 if (tz_id != TIME_ZONE_ID_UNKNOWN) {
4720 tz_info.StandardDate.wYear = year;
4721 convert_to_absolute_date(&tz_info.StandardDate);
4722 err = SystemTimeToFileTime (&tz_info.StandardDate, &ft);
4723 g_assert(err);
4724 mono_array_set ((*data), gint64, 1, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
4725 tz_info.DaylightDate.wYear = year;
4726 convert_to_absolute_date(&tz_info.DaylightDate);
4727 err = SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
4728 g_assert(err);
4729 mono_array_set ((*data), gint64, 0, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
4731 mono_array_set ((*data), gint64, 2, (tz_info.Bias + tz_info.StandardBias) * -600000000LL);
4732 mono_array_set ((*data), gint64, 3, (tz_info.DaylightBias - tz_info.StandardBias) * -600000000LL);
4734 return 1;
4735 #endif
4738 static gpointer
4739 ves_icall_System_Object_obj_address (MonoObject *this)
4741 MONO_ARCH_SAVE_REGS;
4743 return this;
4746 /* System.Buffer */
4748 static inline gint32
4749 mono_array_get_byte_length (MonoArray *array)
4751 MonoClass *klass;
4752 int length;
4753 int i;
4755 klass = array->obj.vtable->klass;
4757 if (array->bounds == NULL)
4758 length = array->max_length;
4759 else {
4760 length = 1;
4761 for (i = 0; i < klass->rank; ++ i)
4762 length *= array->bounds [i].length;
4765 switch (klass->element_class->byval_arg.type) {
4766 case MONO_TYPE_I1:
4767 case MONO_TYPE_U1:
4768 case MONO_TYPE_BOOLEAN:
4769 return length;
4770 case MONO_TYPE_I2:
4771 case MONO_TYPE_U2:
4772 case MONO_TYPE_CHAR:
4773 return length << 1;
4774 case MONO_TYPE_I4:
4775 case MONO_TYPE_U4:
4776 case MONO_TYPE_R4:
4777 return length << 2;
4778 case MONO_TYPE_I:
4779 case MONO_TYPE_U:
4780 return length * sizeof (gpointer);
4781 case MONO_TYPE_I8:
4782 case MONO_TYPE_U8:
4783 case MONO_TYPE_R8:
4784 return length << 3;
4785 default:
4786 return -1;
4790 static gint32
4791 ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
4793 MONO_ARCH_SAVE_REGS;
4795 return mono_array_get_byte_length (array);
4798 static gint8
4799 ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx)
4801 MONO_ARCH_SAVE_REGS;
4803 return mono_array_get (array, gint8, idx);
4806 static void
4807 ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value)
4809 MONO_ARCH_SAVE_REGS;
4811 mono_array_set (array, gint8, idx, value);
4814 static MonoBoolean
4815 ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count)
4817 char *src_buf, *dest_buf;
4819 MONO_ARCH_SAVE_REGS;
4821 /* watch out for integer overflow */
4822 if ((src_offset > mono_array_get_byte_length (src) - count) || (dest_offset > mono_array_get_byte_length (dest) - count))
4823 return FALSE;
4825 src_buf = (gint8 *)src->vector + src_offset;
4826 dest_buf = (gint8 *)dest->vector + dest_offset;
4828 if (src != dest)
4829 memcpy (dest_buf, src_buf, count);
4830 else
4831 memmove (dest_buf, src_buf, count); /* Source and dest are the same array */
4833 return TRUE;
4836 static MonoObject *
4837 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this, MonoString *class_name)
4839 MonoDomain *domain = mono_object_domain (this);
4840 MonoObject *res;
4841 MonoRealProxy *rp = ((MonoRealProxy *)this);
4842 MonoTransparentProxy *tp;
4843 MonoType *type;
4844 MonoClass *klass;
4846 MONO_ARCH_SAVE_REGS;
4848 res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
4849 tp = (MonoTransparentProxy*) res;
4851 tp->rp = rp;
4852 type = ((MonoReflectionType *)rp->class_to_proxy)->type;
4853 klass = mono_class_from_mono_type (type);
4855 tp->custom_type_info = (mono_object_isinst (this, mono_defaults.iremotingtypeinfo_class) != NULL);
4856 tp->remote_class = mono_remote_class (domain, class_name, klass);
4858 res->vtable = mono_remote_class_vtable (domain, tp->remote_class, rp);
4859 return res;
4862 static MonoReflectionType *
4863 ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy *tp)
4865 return mono_type_get_object (mono_object_domain (tp), &tp->remote_class->proxy_class->byval_arg);
4868 /* System.Environment */
4870 static MonoString *
4871 ves_icall_System_Environment_get_MachineName (void)
4873 #if defined (PLATFORM_WIN32)
4874 gunichar2 *buf;
4875 guint32 len;
4876 MonoString *result;
4878 len = MAX_COMPUTERNAME_LENGTH + 1;
4879 buf = g_new (gunichar2, len);
4881 result = NULL;
4882 if (GetComputerName (buf, (PDWORD) &len))
4883 result = mono_string_new_utf16 (mono_domain_get (), buf, len);
4885 g_free (buf);
4886 return result;
4887 #else
4888 gchar *buf;
4889 int len;
4890 MonoString *result;
4892 MONO_ARCH_SAVE_REGS;
4894 len = 256;
4895 buf = g_new (gchar, len);
4897 result = NULL;
4898 if (gethostname (buf, len) == 0)
4899 result = mono_string_new (mono_domain_get (), buf);
4901 g_free (buf);
4902 return result;
4903 #endif
4906 static int
4907 ves_icall_System_Environment_get_Platform (void)
4909 MONO_ARCH_SAVE_REGS;
4911 #if defined (PLATFORM_WIN32)
4912 /* Win32NT */
4913 return 2;
4914 #else
4915 /* Unix */
4916 return 128;
4917 #endif
4920 static MonoString *
4921 ves_icall_System_Environment_get_NewLine (void)
4923 MONO_ARCH_SAVE_REGS;
4925 #if defined (PLATFORM_WIN32)
4926 return mono_string_new (mono_domain_get (), "\r\n");
4927 #else
4928 return mono_string_new (mono_domain_get (), "\n");
4929 #endif
4932 static MonoString *
4933 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
4935 const gchar *value;
4936 gchar *utf8_name;
4938 MONO_ARCH_SAVE_REGS;
4940 if (name == NULL)
4941 return NULL;
4943 utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
4944 value = g_getenv (utf8_name);
4945 g_free (utf8_name);
4947 if (value == 0)
4948 return NULL;
4950 return mono_string_new (mono_domain_get (), value);
4954 * There is no standard way to get at environ.
4956 #ifndef _MSC_VER
4957 extern
4958 #endif
4959 char **environ;
4961 static MonoArray *
4962 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
4964 MonoArray *names;
4965 MonoDomain *domain;
4966 MonoString *str;
4967 gchar **e, **parts;
4968 int n;
4970 MONO_ARCH_SAVE_REGS;
4972 n = 0;
4973 for (e = environ; *e != 0; ++ e)
4974 ++ n;
4976 domain = mono_domain_get ();
4977 names = mono_array_new (domain, mono_defaults.string_class, n);
4979 n = 0;
4980 for (e = environ; *e != 0; ++ e) {
4981 parts = g_strsplit (*e, "=", 2);
4982 if (*parts != 0) {
4983 str = mono_string_new (domain, *parts);
4984 mono_array_set (names, MonoString *, n, str);
4987 g_strfreev (parts);
4989 ++ n;
4992 return names;
4996 * Returns: the number of milliseconds elapsed since the system started.
4998 static gint32
4999 ves_icall_System_Environment_get_TickCount (void)
5001 return GetTickCount ();
5005 static void
5006 ves_icall_System_Environment_Exit (int result)
5008 MONO_ARCH_SAVE_REGS;
5010 mono_runtime_quit ();
5012 /* we may need to do some cleanup here... */
5013 exit (result);
5016 static MonoString*
5017 ves_icall_System_Environment_GetGacPath (void)
5019 return mono_string_new (mono_domain_get (), mono_assembly_getrootdir ());
5022 static MonoString*
5023 ves_icall_System_Environment_GetWindowsFolderPath (int folder)
5025 #if defined (PLATFORM_WIN32)
5026 #ifndef CSIDL_FLAG_CREATE
5027 #define CSIDL_FLAG_CREATE 0x8000
5028 #endif
5030 WCHAR path [MAX_PATH];
5031 /* Create directory if no existing */
5032 if (SUCCEEDED (SHGetFolderPathW (NULL, folder | CSIDL_FLAG_CREATE, NULL, 0, path))) {
5033 int len = 0;
5034 while (path [len])
5035 ++ len;
5036 return mono_string_new_utf16 (mono_domain_get (), path, len);
5038 #else
5039 g_warning ("ves_icall_System_Environment_GetWindowsFolderPath should only be called on Windows!");
5040 #endif
5041 return mono_string_new (mono_domain_get (), "");
5044 static MonoArray *
5045 ves_icall_System_Environment_GetLogicalDrives (void)
5047 gunichar2 buf [128], *ptr, *dname;
5048 gchar *u8;
5049 gint initial_size = 127, size = 128;
5050 gint ndrives;
5051 MonoArray *result;
5052 MonoString *drivestr;
5053 MonoDomain *domain = mono_domain_get ();
5055 MONO_ARCH_SAVE_REGS;
5057 buf [0] = '\0';
5058 ptr = buf;
5060 while (size > initial_size) {
5061 size = GetLogicalDriveStrings (initial_size, ptr);
5062 if (size > initial_size) {
5063 if (ptr != buf)
5064 g_free (ptr);
5065 ptr = g_malloc0 ((size + 1) * sizeof (gunichar2));
5066 initial_size = size;
5067 size++;
5071 /* Count strings */
5072 dname = ptr;
5073 ndrives = 0;
5074 do {
5075 while (*dname++);
5076 ndrives++;
5077 } while (*dname);
5079 dname = ptr;
5080 result = mono_array_new (domain, mono_defaults.string_class, ndrives);
5081 ndrives = 0;
5082 do {
5083 u8 = g_utf16_to_utf8 (dname, -1, NULL, NULL, NULL);
5084 drivestr = mono_string_new (domain, u8);
5085 g_free (u8);
5086 mono_array_set (result, gpointer, ndrives++, drivestr);
5087 while (*dname++);
5088 } while (*dname);
5090 if (ptr != buf)
5091 g_free (ptr);
5093 return result;
5096 static MonoString *
5097 ves_icall_System_Environment_InternalGetHome (void)
5099 MONO_ARCH_SAVE_REGS;
5101 return mono_string_new (mono_domain_get (), g_get_home_dir ());
5104 static const char *encodings [] = {
5105 (char *) 1,
5106 "ascii", "us_ascii", "us", "ansi_x3.4_1968",
5107 "ansi_x3.4_1986", "cp367", "csascii", "ibm367",
5108 "iso_ir_6", "iso646_us", "iso_646.irv:1991",
5109 (char *) 2,
5110 "utf_7", "csunicode11utf7", "unicode_1_1_utf_7",
5111 "unicode_2_0_utf_7", "x_unicode_1_1_utf_7",
5112 "x_unicode_2_0_utf_7",
5113 (char *) 3,
5114 "utf_8", "unicode_1_1_utf_8", "unicode_2_0_utf_8",
5115 "x_unicode_1_1_utf_8", "x_unicode_2_0_utf_8",
5116 (char *) 4,
5117 "utf_16", "UTF_16LE", "ucs_2", "unicode",
5118 "iso_10646_ucs2",
5119 (char *) 5,
5120 "unicodefffe", "utf_16be",
5121 (char *) 6,
5122 "iso_8859_1",
5123 (char *) 0
5127 * Returns the internal codepage, if the value of "int_code_page" is
5128 * 1 at entry, and we can not compute a suitable code page number,
5129 * returns the code page as a string
5131 static MonoString*
5132 ves_icall_System_Text_Encoding_InternalCodePage (gint32 *int_code_page)
5134 const char *cset;
5135 const char *p;
5136 char *c;
5137 char *codepage = NULL;
5138 int code;
5139 int want_name = *int_code_page;
5140 int i;
5142 *int_code_page = -1;
5143 MONO_ARCH_SAVE_REGS;
5145 g_get_charset (&cset);
5146 c = codepage = strdup (cset);
5147 for (c = codepage; *c; c++){
5148 if (isascii (*c) && isalpha (*c))
5149 *c = tolower (*c);
5150 if (*c == '-')
5151 *c = '_';
5153 /* g_print ("charset: %s\n", cset); */
5155 /* handle some common aliases */
5156 p = encodings [0];
5157 code = 0;
5158 for (i = 0; p != 0; ){
5159 if ((gssize) p < 7){
5160 code = (gssize) p;
5161 p = encodings [++i];
5162 continue;
5164 if (strcmp (p, codepage) == 0){
5165 *int_code_page = code;
5166 break;
5168 p = encodings [++i];
5171 if (strstr (codepage, "utf_8") != NULL)
5172 *int_code_page |= 0x10000000;
5173 free (codepage);
5175 if (want_name && *int_code_page == -1)
5176 return mono_string_new (mono_domain_get (), cset);
5177 else
5178 return NULL;
5181 static MonoBoolean
5182 ves_icall_System_Environment_get_HasShutdownStarted (void)
5184 if (mono_runtime_is_shutting_down ())
5185 return TRUE;
5187 if (mono_domain_is_unloading (mono_domain_get ()))
5188 return TRUE;
5190 return FALSE;
5193 static void
5194 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
5195 MonoReflectionMethod *method,
5196 MonoArray *out_args)
5198 MONO_ARCH_SAVE_REGS;
5200 mono_message_init (mono_object_domain (this), this, method, out_args);
5203 static MonoBoolean
5204 ves_icall_IsTransparentProxy (MonoObject *proxy)
5206 MONO_ARCH_SAVE_REGS;
5208 if (!proxy)
5209 return 0;
5211 if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
5212 return 1;
5214 return 0;
5217 static void
5218 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
5220 MonoClass *klass;
5221 MonoVTable* vtable;
5223 MONO_ARCH_SAVE_REGS;
5225 klass = mono_class_from_mono_type (type->type);
5226 vtable = mono_class_vtable (mono_domain_get (), klass);
5228 if (enable) vtable->remote = 1;
5229 else vtable->remote = 0;
5232 static MonoObject *
5233 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType *type)
5235 MonoClass *klass;
5236 MonoDomain *domain;
5238 MONO_ARCH_SAVE_REGS;
5240 domain = mono_object_domain (type);
5241 klass = mono_class_from_mono_type (type->type);
5243 if (klass->rank >= 1) {
5244 g_assert (klass->rank == 1);
5245 return (MonoObject *) mono_array_new (domain, klass->element_class, 0);
5246 } else {
5247 /* Bypass remoting object creation check */
5248 return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
5252 static MonoString *
5253 ves_icall_System_IO_get_temp_path (void)
5255 MONO_ARCH_SAVE_REGS;
5257 return mono_string_new (mono_domain_get (), g_get_tmp_dir ());
5260 static gpointer
5261 ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
5263 MONO_ARCH_SAVE_REGS;
5265 return mono_compile_method (method);
5268 static MonoString *
5269 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
5271 MonoString *mcpath;
5272 gchar *path;
5274 MONO_ARCH_SAVE_REGS;
5276 path = g_build_path (G_DIR_SEPARATOR_S, mono_get_config_dir (), "mono", mono_get_framework_version (), "machine.config", NULL);
5278 #if defined (PLATFORM_WIN32)
5279 /* Avoid mixing '/' and '\\' */
5281 gint i;
5282 for (i = strlen (path) - 1; i >= 0; i--)
5283 if (path [i] == '/')
5284 path [i] = '\\';
5286 #endif
5287 mcpath = mono_string_new (mono_domain_get (), path);
5288 g_free (path);
5290 return mcpath;
5293 static MonoString *
5294 ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
5296 MonoString *ipath;
5297 gchar *path;
5299 MONO_ARCH_SAVE_REGS;
5301 path = g_path_get_dirname (mono_get_config_dir ());
5303 #if defined (PLATFORM_WIN32)
5304 /* Avoid mixing '/' and '\\' */
5306 gint i;
5307 for (i = strlen (path) - 1; i >= 0; i--)
5308 if (path [i] == '/')
5309 path [i] = '\\';
5311 #endif
5312 ipath = mono_string_new (mono_domain_get (), path);
5313 g_free (path);
5315 return ipath;
5318 static void
5319 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
5321 #if defined (PLATFORM_WIN32)
5322 static void (*output_debug) (gchar *);
5323 static gboolean tried_loading = FALSE;
5325 MONO_ARCH_SAVE_REGS;
5327 if (!tried_loading && output_debug == NULL) {
5328 GModule *k32;
5330 tried_loading = TRUE;
5331 k32 = g_module_open ("kernel32", G_MODULE_BIND_LAZY);
5332 if (!k32) {
5333 gchar *error = g_strdup (g_module_error ());
5334 g_warning ("Failed to load kernel32.dll: %s\n", error);
5335 g_free (error);
5336 return;
5339 g_module_symbol (k32, "OutputDebugStringW", (gpointer *) &output_debug);
5340 if (!output_debug) {
5341 gchar *error = g_strdup (g_module_error ());
5342 g_warning ("Failed to load OutputDebugStringW: %s\n", error);
5343 g_free (error);
5344 return;
5348 if (output_debug == NULL)
5349 return;
5351 output_debug (mono_string_chars (message));
5352 #else
5353 g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
5354 #endif
5357 /* Only used for value types */
5358 static MonoObject *
5359 ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
5361 MonoClass *klass;
5362 MonoDomain *domain;
5364 MONO_ARCH_SAVE_REGS;
5366 domain = mono_object_domain (type);
5367 klass = mono_class_from_mono_type (type->type);
5369 return mono_object_new (domain, klass);
5372 static MonoReflectionMethod *
5373 ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
5375 MonoClass *klass;
5376 MonoMethod *method = m->method;
5377 MonoMethod *result = NULL;
5379 MONO_ARCH_SAVE_REGS;
5381 if (!(method->flags & METHOD_ATTRIBUTE_VIRTUAL) ||
5382 MONO_CLASS_IS_INTERFACE (method->klass) ||
5383 method->flags & METHOD_ATTRIBUTE_NEW_SLOT)
5384 return m;
5386 if (method->klass == NULL || (klass = method->klass->parent) == NULL)
5387 return m;
5389 if (klass->generic_class)
5390 klass = mono_class_from_mono_type (klass->generic_class->generic_type);
5392 while (result == NULL && klass != NULL && (klass->vtable_size > method->slot))
5394 result = klass->vtable [method->slot];
5395 if (result == NULL) {
5396 /* It is an abstract method */
5397 int i;
5398 for (i=0; i<klass->method.count; i++) {
5399 if (klass->methods [i]->slot == method->slot) {
5400 result = klass->methods [i];
5401 break;
5405 klass = klass->parent;
5408 if (result == NULL)
5409 return m;
5411 return mono_method_get_object (mono_domain_get (), result, NULL);
5414 static void
5415 mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
5417 MONO_ARCH_SAVE_REGS;
5419 iter->sig = *(MonoMethodSignature**)argsp;
5421 g_assert (iter->sig->sentinelpos <= iter->sig->param_count);
5422 g_assert (iter->sig->call_convention == MONO_CALL_VARARG);
5424 iter->next_arg = 0;
5425 /* FIXME: it's not documented what start is exactly... */
5426 if (start) {
5427 iter->args = start;
5428 } else {
5429 int i, align, arg_size;
5430 iter->args = argsp + sizeof (gpointer);
5431 #ifndef MONO_ARCH_REGPARMS
5432 for (i = 0; i < iter->sig->sentinelpos; ++i) {
5433 arg_size = mono_type_stack_size (iter->sig->params [i], &align);
5434 iter->args = (char*)iter->args + arg_size;
5436 #endif
5438 iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
5440 /* g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos); */
5443 static MonoTypedRef
5444 mono_ArgIterator_IntGetNextArg (MonoArgIterator *iter)
5446 gint i, align, arg_size;
5447 MonoTypedRef res;
5448 MONO_ARCH_SAVE_REGS;
5450 i = iter->sig->sentinelpos + iter->next_arg;
5452 g_assert (i < iter->sig->param_count);
5454 res.type = iter->sig->params [i];
5455 res.klass = mono_class_from_mono_type (res.type);
5456 /* FIXME: endianess issue... */
5457 res.value = iter->args;
5458 arg_size = mono_type_stack_size (res.type, &align);
5459 iter->args = (char*)iter->args + arg_size;
5460 iter->next_arg++;
5462 /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
5464 return res;
5467 static MonoTypedRef
5468 mono_ArgIterator_IntGetNextArgT (MonoArgIterator *iter, MonoType *type)
5470 gint i, align, arg_size;
5471 MonoTypedRef res;
5472 MONO_ARCH_SAVE_REGS;
5474 i = iter->sig->sentinelpos + iter->next_arg;
5476 g_assert (i < iter->sig->param_count);
5478 while (i < iter->sig->param_count) {
5479 if (!mono_metadata_type_equal (type, iter->sig->params [i]))
5480 continue;
5481 res.type = iter->sig->params [i];
5482 res.klass = mono_class_from_mono_type (res.type);
5483 /* FIXME: endianess issue... */
5484 res.value = iter->args;
5485 arg_size = mono_type_stack_size (res.type, &align);
5486 iter->args = (char*)iter->args + arg_size;
5487 iter->next_arg++;
5488 /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
5489 return res;
5491 /* g_print ("arg type 0x%02x not found\n", res.type->type); */
5493 res.type = NULL;
5494 res.value = NULL;
5495 res.klass = NULL;
5496 return res;
5499 static MonoType*
5500 mono_ArgIterator_IntGetNextArgType (MonoArgIterator *iter)
5502 gint i;
5503 MONO_ARCH_SAVE_REGS;
5505 i = iter->sig->sentinelpos + iter->next_arg;
5507 g_assert (i < iter->sig->param_count);
5509 return iter->sig->params [i];
5512 static MonoObject*
5513 mono_TypedReference_ToObject (MonoTypedRef tref)
5515 MONO_ARCH_SAVE_REGS;
5517 if (MONO_TYPE_IS_REFERENCE (tref.type)) {
5518 MonoObject** objp = tref.value;
5519 return *objp;
5522 return mono_value_box (mono_domain_get (), tref.klass, tref.value);
5525 static MonoObject*
5526 mono_TypedReference_ToObjectInternal (MonoType *type, gpointer value, MonoClass *klass)
5528 MONO_ARCH_SAVE_REGS;
5530 if (MONO_TYPE_IS_REFERENCE (type)) {
5531 MonoObject** objp = value;
5532 return *objp;
5535 return mono_value_box (mono_domain_get (), klass, value);
5538 static void
5539 prelink_method (MonoMethod *method)
5541 const char *exc_class, *exc_arg;
5542 if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
5543 return;
5544 mono_lookup_pinvoke_call (method, &exc_class, &exc_arg);
5545 if (exc_class) {
5546 mono_raise_exception(
5547 mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg ) );
5549 /* create the wrapper, too? */
5552 static void
5553 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod *method)
5555 MONO_ARCH_SAVE_REGS;
5556 prelink_method (method->method);
5559 static void
5560 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType *type)
5562 MonoClass *klass = mono_class_from_mono_type (type->type);
5563 int i;
5564 MONO_ARCH_SAVE_REGS;
5566 mono_class_init (klass);
5567 for (i = 0; i < klass->method.count; ++i)
5568 prelink_method (klass->methods [i]);
5571 /* These parameters are "readonly" in corlib/System/Char.cs */
5572 static void
5573 ves_icall_System_Char_GetDataTablePointers (guint8 const **category_data,
5574 guint8 const **numeric_data,
5575 gdouble const **numeric_data_values,
5576 guint16 const **to_lower_data_low,
5577 guint16 const **to_lower_data_high,
5578 guint16 const **to_upper_data_low,
5579 guint16 const **to_upper_data_high)
5581 *category_data = CategoryData;
5582 *numeric_data = NumericData;
5583 *numeric_data_values = NumericDataValues;
5584 *to_lower_data_low = ToLowerDataLow;
5585 *to_lower_data_high = ToLowerDataHigh;
5586 *to_upper_data_low = ToUpperDataLow;
5587 *to_upper_data_high = ToUpperDataHigh;
5590 static MonoString *
5591 ves_icall_MonoDebugger_check_runtime_version (MonoString *fname)
5593 gchar *filename, *error = NULL;
5595 MONO_ARCH_SAVE_REGS;
5597 filename = mono_string_to_utf8 (fname);
5598 error = mono_debugger_check_runtime_version (filename);
5599 g_free (filename);
5601 if (error)
5602 return mono_string_new (mono_domain_get (), error);
5603 else
5604 return NULL;
5607 /* icall map */
5608 typedef struct {
5609 const char *method;
5610 gconstpointer func;
5611 } IcallEntry;
5613 typedef struct {
5614 const char *klass;
5615 const IcallEntry *icalls;
5616 const int size;
5617 } IcallMap;
5619 static const IcallEntry activator_icalls [] = {
5620 {"CreateInstanceInternal", ves_icall_System_Activator_CreateInstanceInternal}
5622 static const IcallEntry appdomain_icalls [] = {
5623 {"ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly},
5624 {"GetAssemblies", ves_icall_System_AppDomain_GetAssemblies},
5625 {"GetData", ves_icall_System_AppDomain_GetData},
5626 {"InternalGetContext", ves_icall_System_AppDomain_InternalGetContext},
5627 {"InternalGetDefaultContext", ves_icall_System_AppDomain_InternalGetDefaultContext},
5628 {"InternalGetProcessGuid", ves_icall_System_AppDomain_InternalGetProcessGuid},
5629 {"InternalIsFinalizingForUnload", ves_icall_System_AppDomain_InternalIsFinalizingForUnload},
5630 {"InternalPopDomainRef", ves_icall_System_AppDomain_InternalPopDomainRef},
5631 {"InternalPushDomainRef", ves_icall_System_AppDomain_InternalPushDomainRef},
5632 {"InternalPushDomainRefByID", ves_icall_System_AppDomain_InternalPushDomainRefByID},
5633 {"InternalSetContext", ves_icall_System_AppDomain_InternalSetContext},
5634 {"InternalSetDomain", ves_icall_System_AppDomain_InternalSetDomain},
5635 {"InternalSetDomainByID", ves_icall_System_AppDomain_InternalSetDomainByID},
5636 {"InternalUnload", ves_icall_System_AppDomain_InternalUnload},
5637 {"LoadAssembly", ves_icall_System_AppDomain_LoadAssembly},
5638 {"LoadAssemblyRaw", ves_icall_System_AppDomain_LoadAssemblyRaw},
5639 {"SetData", ves_icall_System_AppDomain_SetData},
5640 {"createDomain", ves_icall_System_AppDomain_createDomain},
5641 {"getCurDomain", ves_icall_System_AppDomain_getCurDomain},
5642 {"getDomainByID", ves_icall_System_AppDomain_getDomainByID},
5643 {"getFriendlyName", ves_icall_System_AppDomain_getFriendlyName},
5644 {"getSetup", ves_icall_System_AppDomain_getSetup}
5647 static const IcallEntry argiterator_icalls [] = {
5648 {"IntGetNextArg()", mono_ArgIterator_IntGetNextArg},
5649 {"IntGetNextArg(intptr)", mono_ArgIterator_IntGetNextArgT},
5650 {"IntGetNextArgType", mono_ArgIterator_IntGetNextArgType},
5651 {"Setup", mono_ArgIterator_Setup}
5654 static const IcallEntry array_icalls [] = {
5655 {"ClearInternal", ves_icall_System_Array_ClearInternal},
5656 {"Clone", mono_array_clone},
5657 {"CreateInstanceImpl", ves_icall_System_Array_CreateInstanceImpl},
5658 {"FastCopy", ves_icall_System_Array_FastCopy},
5659 {"GetLength", ves_icall_System_Array_GetLength},
5660 {"GetLowerBound", ves_icall_System_Array_GetLowerBound},
5661 {"GetRank", ves_icall_System_Array_GetRank},
5662 {"GetValue", ves_icall_System_Array_GetValue},
5663 {"GetValueImpl", ves_icall_System_Array_GetValueImpl},
5664 {"SetValue", ves_icall_System_Array_SetValue},
5665 {"SetValueImpl", ves_icall_System_Array_SetValueImpl}
5668 static const IcallEntry buffer_icalls [] = {
5669 {"BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal},
5670 {"ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal},
5671 {"GetByteInternal", ves_icall_System_Buffer_GetByteInternal},
5672 {"SetByteInternal", ves_icall_System_Buffer_SetByteInternal}
5675 static const IcallEntry char_icalls [] = {
5676 {"GetDataTablePointers", ves_icall_System_Char_GetDataTablePointers},
5677 {"InternalToLower(char,System.Globalization.CultureInfo)", ves_icall_System_Char_InternalToLower_Comp},
5678 {"InternalToUpper(char,System.Globalization.CultureInfo)", ves_icall_System_Char_InternalToUpper_Comp}
5681 static const IcallEntry defaultconf_icalls [] = {
5682 {"get_machine_config_path", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path}
5685 static const IcallEntry timezone_icalls [] = {
5686 {"GetTimeZoneData", ves_icall_System_CurrentTimeZone_GetTimeZoneData}
5689 static const IcallEntry datetime_icalls [] = {
5690 {"GetNow", ves_icall_System_DateTime_GetNow}
5693 #ifndef DISABLE_DECIMAL
5694 static const IcallEntry decimal_icalls [] = {
5695 {"decimal2Int64", mono_decimal2Int64},
5696 {"decimal2UInt64", mono_decimal2UInt64},
5697 {"decimal2double", mono_decimal2double},
5698 {"decimal2string", mono_decimal2string},
5699 {"decimalCompare", mono_decimalCompare},
5700 {"decimalDiv", mono_decimalDiv},
5701 {"decimalFloorAndTrunc", mono_decimalFloorAndTrunc},
5702 {"decimalIncr", mono_decimalIncr},
5703 {"decimalIntDiv", mono_decimalIntDiv},
5704 {"decimalMult", mono_decimalMult},
5705 {"decimalRound", mono_decimalRound},
5706 {"decimalSetExponent", mono_decimalSetExponent},
5707 {"double2decimal", mono_double2decimal}, /* FIXME: wrong signature. */
5708 {"string2decimal", mono_string2decimal}
5710 #endif
5712 static const IcallEntry delegate_icalls [] = {
5713 {"CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal},
5714 {"FreeTrampoline", ves_icall_System_Delegate_FreeTrampoline}
5717 static const IcallEntry tracelist_icalls [] = {
5718 {"WriteWindowsDebugString", ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString}
5721 static const IcallEntry fileversion_icalls [] = {
5722 {"GetVersionInfo_internal(string)", ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal}
5725 static const IcallEntry process_icalls [] = {
5726 {"ExitCode_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitCode_internal},
5727 {"ExitTime_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitTime_internal},
5728 {"GetModules_internal()", ves_icall_System_Diagnostics_Process_GetModules_internal},
5729 {"GetPid_internal()", ves_icall_System_Diagnostics_Process_GetPid_internal},
5730 {"GetProcess_internal(int)", ves_icall_System_Diagnostics_Process_GetProcess_internal},
5731 {"GetProcesses_internal()", ves_icall_System_Diagnostics_Process_GetProcesses_internal},
5732 {"GetWorkingSet_internal(intptr,int&,int&)", ves_icall_System_Diagnostics_Process_GetWorkingSet_internal},
5733 {"Kill_internal", ves_icall_System_Diagnostics_Process_Kill_internal},
5734 {"ProcessName_internal(intptr)", ves_icall_System_Diagnostics_Process_ProcessName_internal},
5735 {"Process_free_internal(intptr)", ves_icall_System_Diagnostics_Process_Process_free_internal},
5736 {"SetWorkingSet_internal(intptr,int,int,bool)", ves_icall_System_Diagnostics_Process_SetWorkingSet_internal},
5737 {"StartTime_internal(intptr)", ves_icall_System_Diagnostics_Process_StartTime_internal},
5738 {"Start_internal(string,string,string,intptr,intptr,intptr,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_Start_internal},
5739 {"WaitForExit_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForExit_internal}
5742 static const IcallEntry double_icalls [] = {
5743 {"AssertEndianity", ves_icall_System_Double_AssertEndianity},
5744 {"ParseImpl", mono_double_ParseImpl}
5747 static const IcallEntry enum_icalls [] = {
5748 {"ToObject", ves_icall_System_Enum_ToObject},
5749 {"get_value", ves_icall_System_Enum_get_value}
5752 static const IcallEntry environment_icalls [] = {
5753 {"Exit", ves_icall_System_Environment_Exit},
5754 {"GetCommandLineArgs", mono_runtime_get_main_args},
5755 {"GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable},
5756 {"GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames},
5757 {"GetLogicalDrivesInternal", ves_icall_System_Environment_GetLogicalDrives },
5758 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
5759 {"GetOSVersionString", ves_icall_System_Environment_GetOSVersionString},
5760 {"GetWindowsFolderPath", ves_icall_System_Environment_GetWindowsFolderPath},
5761 {"get_ExitCode", mono_environment_exitcode_get},
5762 {"get_HasShutdownStarted", ves_icall_System_Environment_get_HasShutdownStarted},
5763 {"get_MachineName", ves_icall_System_Environment_get_MachineName},
5764 {"get_NewLine", ves_icall_System_Environment_get_NewLine},
5765 {"get_Platform", ves_icall_System_Environment_get_Platform},
5766 {"get_TickCount", ves_icall_System_Environment_get_TickCount},
5767 {"get_UserName", ves_icall_System_Environment_get_UserName},
5768 {"internalGetGacPath", ves_icall_System_Environment_GetGacPath},
5769 {"internalGetHome", ves_icall_System_Environment_InternalGetHome},
5770 {"set_ExitCode", mono_environment_exitcode_set}
5773 static const IcallEntry cultureinfo_icalls [] = {
5774 {"construct_compareinfo(object,string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
5775 {"construct_datetime_format", ves_icall_System_Globalization_CultureInfo_construct_datetime_format},
5776 {"construct_internal_locale(string)", ves_icall_System_Globalization_CultureInfo_construct_internal_locale},
5777 {"construct_internal_locale_from_current_locale", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_current_locale},
5778 {"construct_internal_locale_from_lcid", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_lcid},
5779 {"construct_internal_locale_from_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name},
5780 {"construct_internal_locale_from_specific_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_specific_name},
5781 {"construct_number_format", ves_icall_System_Globalization_CultureInfo_construct_number_format},
5782 {"internal_get_cultures", ves_icall_System_Globalization_CultureInfo_internal_get_cultures},
5783 {"internal_is_lcid_neutral", ves_icall_System_Globalization_CultureInfo_internal_is_lcid_neutral}
5786 static const IcallEntry compareinfo_icalls [] = {
5787 {"assign_sortkey(object,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_assign_sortkey},
5788 {"construct_compareinfo(string)", ves_icall_System_Globalization_CompareInfo_construct_compareinfo},
5789 {"free_internal_collator()", ves_icall_System_Globalization_CompareInfo_free_internal_collator},
5790 {"internal_compare(string,int,int,string,int,int,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_internal_compare},
5791 {"internal_index(string,int,int,char,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index_char},
5792 {"internal_index(string,int,int,string,System.Globalization.CompareOptions,bool)", ves_icall_System_Globalization_CompareInfo_internal_index}
5795 static const IcallEntry gc_icalls [] = {
5796 {"GetTotalMemory", ves_icall_System_GC_GetTotalMemory},
5797 {"InternalCollect", ves_icall_System_GC_InternalCollect},
5798 {"KeepAlive", ves_icall_System_GC_KeepAlive},
5799 {"ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize},
5800 {"SuppressFinalize", ves_icall_System_GC_SuppressFinalize},
5801 {"WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers}
5804 static const IcallEntry famwatcher_icalls [] = {
5805 {"InternalFAMNextEvent", ves_icall_System_IO_FAMW_InternalFAMNextEvent}
5808 static const IcallEntry filewatcher_icalls [] = {
5809 {"InternalCloseDirectory", ves_icall_System_IO_FSW_CloseDirectory},
5810 {"InternalOpenDirectory", ves_icall_System_IO_FSW_OpenDirectory},
5811 {"InternalReadDirectoryChanges", ves_icall_System_IO_FSW_ReadDirectoryChanges},
5812 {"InternalSupportsFSW", ves_icall_System_IO_FSW_SupportsFSW}
5815 static const IcallEntry path_icalls [] = {
5816 {"get_temp_path", ves_icall_System_IO_get_temp_path}
5819 static const IcallEntry monoio_icalls [] = {
5820 {"BeginRead", ves_icall_System_IO_MonoIO_BeginRead },
5821 {"BeginWrite", ves_icall_System_IO_MonoIO_BeginWrite },
5822 {"Close(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Close},
5823 {"CopyFile(string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CopyFile},
5824 {"CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CreateDirectory},
5825 {"CreatePipe(intptr&,intptr&)", ves_icall_System_IO_MonoIO_CreatePipe},
5826 {"DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile},
5827 {"FindClose(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindClose},
5828 {"FindFirstFile(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindFirstFile},
5829 {"FindNextFile(intptr,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_FindNextFile},
5830 {"Flush(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush},
5831 {"GetCurrentDirectory(System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetCurrentDirectory},
5832 {"GetFileAttributes(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileAttributes},
5833 {"GetFileStat(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileStat},
5834 {"GetFileType(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType},
5835 {"GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength},
5836 {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
5837 {"GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath},
5838 {"Lock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Lock},
5839 {"MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile},
5840 {"Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open},
5841 {"Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read},
5842 {"RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory},
5843 {"Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek},
5844 {"SetCurrentDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetCurrentDirectory},
5845 {"SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes},
5846 {"SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime},
5847 {"SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength},
5848 {"Unlock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Unlock},
5849 {"Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write},
5850 {"get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar},
5851 {"get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError},
5852 {"get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput},
5853 {"get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput},
5854 {"get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar},
5855 {"get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars},
5856 {"get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator},
5857 {"get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar}
5860 static const IcallEntry math_icalls [] = {
5861 {"Acos", ves_icall_System_Math_Acos},
5862 {"Asin", ves_icall_System_Math_Asin},
5863 {"Atan", ves_icall_System_Math_Atan},
5864 {"Atan2", ves_icall_System_Math_Atan2},
5865 {"Cos", ves_icall_System_Math_Cos},
5866 {"Cosh", ves_icall_System_Math_Cosh},
5867 {"Exp", ves_icall_System_Math_Exp},
5868 {"Floor", ves_icall_System_Math_Floor},
5869 {"Log", ves_icall_System_Math_Log},
5870 {"Log10", ves_icall_System_Math_Log10},
5871 {"Pow", ves_icall_System_Math_Pow},
5872 {"Round", ves_icall_System_Math_Round},
5873 {"Round2", ves_icall_System_Math_Round2},
5874 {"Sin", ves_icall_System_Math_Sin},
5875 {"Sinh", ves_icall_System_Math_Sinh},
5876 {"Sqrt", ves_icall_System_Math_Sqrt},
5877 {"Tan", ves_icall_System_Math_Tan},
5878 {"Tanh", ves_icall_System_Math_Tanh}
5881 static const IcallEntry customattrs_icalls [] = {
5882 {"GetCustomAttributesInternal", mono_reflection_get_custom_attrs}
5885 static const IcallEntry enuminfo_icalls [] = {
5886 {"get_enum_info", ves_icall_get_enum_info}
5889 static const IcallEntry fieldinfo_icalls [] = {
5890 {"GetUnmanagedMarshal", ves_icall_System_Reflection_FieldInfo_GetUnmanagedMarshal},
5891 {"internal_from_handle", ves_icall_System_Reflection_FieldInfo_internal_from_handle}
5894 static const IcallEntry memberinfo_icalls [] = {
5895 {"get_MetadataToken", mono_reflection_get_token}
5898 static const IcallEntry monotype_icalls [] = {
5899 {"GetArrayRank", ves_icall_MonoType_GetArrayRank},
5900 {"GetConstructors", ves_icall_Type_GetConstructors_internal},
5901 {"GetConstructors_internal", ves_icall_Type_GetConstructors_internal},
5902 {"GetElementType", ves_icall_MonoType_GetElementType},
5903 {"GetEvents_internal", ves_icall_Type_GetEvents_internal},
5904 {"GetField", ves_icall_Type_GetField},
5905 {"GetFields_internal", ves_icall_Type_GetFields_internal},
5906 {"GetGenericArguments", ves_icall_MonoType_GetGenericArguments},
5907 {"GetInterfaces", ves_icall_Type_GetInterfaces},
5908 {"GetMethodsByName", ves_icall_Type_GetMethodsByName},
5909 {"GetNestedType", ves_icall_Type_GetNestedType},
5910 {"GetNestedTypes", ves_icall_Type_GetNestedTypes},
5911 {"GetPropertiesByName", ves_icall_Type_GetPropertiesByName},
5912 {"InternalGetEvent", ves_icall_MonoType_GetEvent},
5913 {"IsByRefImpl", ves_icall_type_isbyref},
5914 {"IsPointerImpl", ves_icall_type_ispointer},
5915 {"IsPrimitiveImpl", ves_icall_type_isprimitive},
5916 {"getFullName", ves_icall_System_MonoType_getFullName},
5917 {"get_Assembly", ves_icall_MonoType_get_Assembly},
5918 {"get_BaseType", ves_icall_get_type_parent},
5919 {"get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod},
5920 {"get_DeclaringType", ves_icall_MonoType_get_DeclaringType},
5921 {"get_HasGenericArguments", ves_icall_MonoType_get_HasGenericArguments},
5922 {"get_IsGenericParameter", ves_icall_MonoType_get_IsGenericParameter},
5923 {"get_Module", ves_icall_MonoType_get_Module},
5924 {"get_Name", ves_icall_MonoType_get_Name},
5925 {"get_Namespace", ves_icall_MonoType_get_Namespace},
5926 {"get_UnderlyingSystemType", ves_icall_MonoType_get_UnderlyingSystemType},
5927 {"get_attributes", ves_icall_get_attributes},
5928 {"type_from_obj", mono_type_type_from_obj}
5931 static const IcallEntry assembly_icalls [] = {
5932 {"FillName", ves_icall_System_Reflection_Assembly_FillName},
5933 {"GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly},
5934 {"GetEntryAssembly", ves_icall_System_Reflection_Assembly_GetEntryAssembly},
5935 {"GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly},
5936 {"GetFilesInternal", ves_icall_System_Reflection_Assembly_GetFilesInternal},
5937 {"GetManifestResourceInfoInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal},
5938 {"GetManifestResourceInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInternal},
5939 {"GetManifestResourceNames", ves_icall_System_Reflection_Assembly_GetManifestResourceNames},
5940 {"GetModulesInternal", ves_icall_System_Reflection_Assembly_GetModulesInternal},
5941 {"GetNamespaces", ves_icall_System_Reflection_Assembly_GetNamespaces},
5942 {"GetReferencedAssemblies", ves_icall_System_Reflection_Assembly_GetReferencedAssemblies},
5943 {"GetTypes", ves_icall_System_Reflection_Assembly_GetTypes},
5944 {"InternalGetAssemblyName", ves_icall_System_Reflection_Assembly_InternalGetAssemblyName},
5945 {"InternalGetType", ves_icall_System_Reflection_Assembly_InternalGetType},
5946 {"InternalImageRuntimeVersion", ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion},
5947 {"LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom},
5949 * Private icalls for the Mono Debugger
5951 {"MonoDebugger_CheckRuntimeVersion", ves_icall_MonoDebugger_check_runtime_version},
5952 {"MonoDebugger_GetLocalTypeFromSignature", ves_icall_MonoDebugger_GetLocalTypeFromSignature},
5953 {"MonoDebugger_GetMethod", ves_icall_MonoDebugger_GetMethod},
5954 {"MonoDebugger_GetMethodToken", ves_icall_MonoDebugger_GetMethodToken},
5955 {"MonoDebugger_GetType", ves_icall_MonoDebugger_GetType},
5957 /* normal icalls again */
5958 {"get_EntryPoint", ves_icall_System_Reflection_Assembly_get_EntryPoint},
5959 {"get_ManifestModule", ves_icall_System_Reflection_Assembly_get_ManifestModule},
5960 {"get_MetadataToken", mono_reflection_get_token},
5961 {"get_code_base", ves_icall_System_Reflection_Assembly_get_code_base},
5962 {"get_global_assembly_cache", ves_icall_System_Reflection_Assembly_get_global_assembly_cache},
5963 {"get_location", ves_icall_System_Reflection_Assembly_get_location},
5964 {"load_with_partial_name", ves_icall_System_Reflection_Assembly_load_with_partial_name}
5967 static const IcallEntry methodbase_icalls [] = {
5968 {"GetCurrentMethod", ves_icall_GetCurrentMethod},
5969 {"GetMethodBodyInternal", ves_icall_System_Reflection_MethodBase_GetMethodBodyInternal},
5970 {"GetMethodFromHandleInternal", ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternal}
5973 static const IcallEntry module_icalls [] = {
5974 {"Close", ves_icall_System_Reflection_Module_Close},
5975 {"GetGlobalType", ves_icall_System_Reflection_Module_GetGlobalType},
5976 {"GetGuidInternal", ves_icall_System_Reflection_Module_GetGuidInternal},
5977 {"GetPEKind", ves_icall_System_Reflection_Module_GetPEKind},
5978 {"InternalGetTypes", ves_icall_System_Reflection_Module_InternalGetTypes},
5979 {"ResolveFieldToken", ves_icall_System_Reflection_Module_ResolveFieldToken},
5980 {"ResolveMemberToken", ves_icall_System_Reflection_Module_ResolveMemberToken},
5981 {"ResolveMethodToken", ves_icall_System_Reflection_Module_ResolveMethodToken},
5982 {"ResolveStringToken", ves_icall_System_Reflection_Module_ResolveStringToken},
5983 {"ResolveTypeToken", ves_icall_System_Reflection_Module_ResolveTypeToken},
5984 {"get_MetadataToken", mono_reflection_get_token}
5987 static const IcallEntry monocmethod_icalls [] = {
5988 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
5989 {"InternalInvoke", ves_icall_InternalInvoke},
5990 {"get_Mono_IsInflatedMethod", ves_icall_MonoMethod_get_Mono_IsInflatedMethod}
5993 static const IcallEntry monoeventinfo_icalls [] = {
5994 {"get_event_info", ves_icall_get_event_info}
5997 static const IcallEntry monofield_icalls [] = {
5998 {"GetFieldOffset", ves_icall_MonoField_GetFieldOffset},
5999 {"GetParentType", ves_icall_MonoField_GetParentType},
6000 {"GetValueInternal", ves_icall_MonoField_GetValueInternal},
6001 {"Mono_GetGenericFieldDefinition", ves_icall_MonoField_Mono_GetGenericFieldDefinition},
6002 {"SetValueInternal", ves_icall_FieldInfo_SetValueInternal}
6005 static const IcallEntry monogenericclass_icalls [] = {
6006 {"GetConstructors_internal", ves_icall_MonoGenericClass_GetConstructors},
6007 {"GetEvents_internal", ves_icall_MonoGenericClass_GetEvents},
6008 {"GetFields_internal", ves_icall_MonoGenericClass_GetFields},
6009 {"GetInterfaces_internal", ves_icall_MonoGenericClass_GetInterfaces},
6010 {"GetMethods_internal", ves_icall_MonoGenericClass_GetMethods},
6011 {"GetParentType", ves_icall_MonoGenericClass_GetParentType},
6012 {"GetProperties_internal", ves_icall_MonoGenericClass_GetProperties},
6013 {"initialize", mono_reflection_generic_class_initialize}
6016 static const IcallEntry generictypeparambuilder_icalls [] = {
6017 {"initialize", mono_reflection_initialize_generic_parameter}
6020 static const IcallEntry monomethod_icalls [] = {
6021 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters},
6022 {"GetDllImportAttribute", ves_icall_MonoMethod_GetDllImportAttribute},
6023 {"GetGenericArguments", ves_icall_MonoMethod_GetGenericArguments},
6024 {"GetGenericMethodDefinition_impl", ves_icall_MonoMethod_GetGenericMethodDefinition},
6025 {"InternalInvoke", ves_icall_InternalInvoke},
6026 {"get_HasGenericParameters", ves_icall_MonoMethod_get_HasGenericParameters},
6027 {"get_IsGenericMethodDefinition", ves_icall_MonoMethod_get_IsGenericMethodDefinition},
6028 {"get_Mono_IsInflatedMethod", ves_icall_MonoMethod_get_Mono_IsInflatedMethod},
6029 {"get_base_definition", ves_icall_MonoMethod_get_base_definition}
6032 static const IcallEntry monomethodinfo_icalls [] = {
6033 {"get_method_info", ves_icall_get_method_info},
6034 {"get_parameter_info", ves_icall_get_parameter_info}
6037 static const IcallEntry monopropertyinfo_icalls [] = {
6038 {"get_property_info", ves_icall_get_property_info}
6041 static const IcallEntry parameterinfo_icalls [] = {
6042 {"get_MetadataToken", mono_reflection_get_token}
6045 static const IcallEntry dns_icalls [] = {
6046 {"GetHostByAddr_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByAddr_internal},
6047 {"GetHostByName_internal(string,string&,string[]&,string[]&)", ves_icall_System_Net_Dns_GetHostByName_internal},
6048 {"GetHostName_internal(string&)", ves_icall_System_Net_Dns_GetHostName_internal}
6051 static const IcallEntry socket_icalls [] = {
6052 {"Accept_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Accept_internal},
6053 {"AsyncReceiveInternal", ves_icall_System_Net_Sockets_Socket_AsyncReceive},
6054 {"AsyncSendInternal", ves_icall_System_Net_Sockets_Socket_AsyncSend},
6055 {"Available_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Available_internal},
6056 {"Bind_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Bind_internal},
6057 {"Blocking_internal(intptr,bool,int&)", ves_icall_System_Net_Sockets_Socket_Blocking_internal},
6058 {"Close_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_Close_internal},
6059 {"Connect_internal(intptr,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_Connect_internal},
6060 {"GetSocketOption_arr_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,byte[]&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal},
6061 {"GetSocketOption_obj_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal},
6062 {"GetSupportsAsync", ves_icall_System_IO_MonoIO_GetSupportsAsync},
6063 {"Listen_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_Listen_internal},
6064 {"LocalEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal},
6065 {"Poll_internal", ves_icall_System_Net_Sockets_Socket_Poll_internal},
6066 {"Receive_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Receive_internal},
6067 {"RecvFrom_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal},
6068 {"RemoteEndPoint_internal(intptr,int&)", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal},
6069 {"Select_internal(System.Net.Sockets.Socket[]&,System.Net.Sockets.Socket[]&,System.Net.Sockets.Socket[]&,int,int&)", ves_icall_System_Net_Sockets_Socket_Select_internal},
6070 {"SendTo_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_SendTo_internal},
6071 {"Send_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Send_internal},
6072 {"SetSocketOption_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object,byte[],int,int&)", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal},
6073 {"Shutdown_internal(intptr,System.Net.Sockets.SocketShutdown,int&)", ves_icall_System_Net_Sockets_Socket_Shutdown_internal},
6074 {"Socket_internal(System.Net.Sockets.AddressFamily,System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,int&)", ves_icall_System_Net_Sockets_Socket_Socket_internal},
6075 {"WSAIoctl(intptr,int,byte[],byte[],int&)", ves_icall_System_Net_Sockets_Socket_WSAIoctl}
6078 static const IcallEntry socketex_icalls [] = {
6079 {"WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketException_WSAGetLastError_internal}
6082 static const IcallEntry object_icalls [] = {
6083 {"GetType", ves_icall_System_Object_GetType},
6084 {"InternalGetHashCode", ves_icall_System_Object_GetHashCode},
6085 {"MemberwiseClone", ves_icall_System_Object_MemberwiseClone},
6086 {"obj_address", ves_icall_System_Object_obj_address}
6089 static const IcallEntry assemblybuilder_icalls[] = {
6090 {"InternalAddModule", mono_image_load_module},
6091 {"basic_init", mono_image_basic_init}
6094 static const IcallEntry customattrbuilder_icalls [] = {
6095 {"GetBlob", mono_reflection_get_custom_attrs_blob}
6098 static const IcallEntry dynamicmethod_icalls [] = {
6099 {"create_dynamic_method", mono_reflection_create_dynamic_method}
6102 static const IcallEntry methodbuilder_icalls [] = {
6103 {"BindGenericParameters", mono_reflection_bind_generic_method_parameters}
6106 static const IcallEntry modulebuilder_icalls [] = {
6107 {"WriteToFile", ves_icall_ModuleBuilder_WriteToFile},
6108 {"basic_init", mono_image_module_basic_init},
6109 {"build_metadata", ves_icall_ModuleBuilder_build_metadata},
6110 {"create_modified_type", ves_icall_ModuleBuilder_create_modified_type},
6111 {"getMethodToken", ves_icall_ModuleBuilder_getMethodToken},
6112 {"getToken", ves_icall_ModuleBuilder_getToken},
6113 {"getUSIndex", mono_image_insert_string}
6116 static const IcallEntry signaturehelper_icalls [] = {
6117 {"get_signature_field", mono_reflection_sighelper_get_signature_field},
6118 {"get_signature_local", mono_reflection_sighelper_get_signature_local}
6121 static const IcallEntry typebuilder_icalls [] = {
6122 {"create_generic_class", mono_reflection_create_generic_class},
6123 {"create_internal_class", mono_reflection_create_internal_class},
6124 {"create_runtime_class", mono_reflection_create_runtime_class},
6125 {"get_IsGenericParameter", ves_icall_TypeBuilder_get_IsGenericParameter},
6126 {"get_event_info", mono_reflection_event_builder_get_event_info},
6127 {"setup_generic_class", mono_reflection_setup_generic_class},
6128 {"setup_internal_class", mono_reflection_setup_internal_class}
6131 static const IcallEntry enumbuilder_icalls [] = {
6132 {"setup_enum_type", ves_icall_EnumBuilder_setup_enum_type}
6135 static const IcallEntry runtimehelpers_icalls [] = {
6136 {"GetObjectValue", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue},
6137 /* REMOVEME: no longer needed, just so we dont break things when not needed */
6138 {"GetOffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData},
6139 {"InitializeArray", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray},
6140 {"RunClassConstructor", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor},
6141 {"get_OffsetToStringData", ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData}
6144 static const IcallEntry gchandle_icalls [] = {
6145 {"FreeHandle", ves_icall_System_GCHandle_FreeHandle},
6146 {"GetAddrOfPinnedObject", ves_icall_System_GCHandle_GetAddrOfPinnedObject},
6147 {"GetTarget", ves_icall_System_GCHandle_GetTarget},
6148 {"GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle}
6151 static const IcallEntry marshal_icalls [] = {
6152 {"AllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem},
6153 {"AllocHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_AllocHGlobal},
6154 {"DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure},
6155 {"FreeCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem},
6156 {"FreeHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_FreeHGlobal},
6157 {"GetDelegateForFunctionPointerInternal", ves_icall_System_Runtime_InteropServices_Marshal_GetDelegateForFunctionPointerInternal},
6158 {"GetFunctionPointerForDelegateInternal", mono_delegate_to_ftnptr},
6159 {"GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error},
6160 {"OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf},
6161 {"Prelink", ves_icall_System_Runtime_InteropServices_Marshal_Prelink},
6162 {"PrelinkAll", ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll},
6163 {"PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
6164 {"PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
6165 {"PtrToStringAuto(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi},
6166 {"PtrToStringAuto(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len},
6167 {"PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR},
6168 {"PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni},
6169 {"PtrToStringUni(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len},
6170 {"PtrToStructure(intptr,System.Type)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type},
6171 {"PtrToStructure(intptr,object)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure},
6172 {"ReAllocHGlobal", mono_marshal_realloc},
6173 {"ReadByte", ves_icall_System_Runtime_InteropServices_Marshal_ReadByte},
6174 {"ReadInt16", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt16},
6175 {"ReadInt32", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt32},
6176 {"ReadInt64", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64},
6177 {"ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr},
6178 {"SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf},
6179 {"StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
6180 {"StringToHGlobalAuto", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
6181 {"StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni},
6182 {"StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr},
6183 {"UnsafeAddrOfPinnedArrayElement", ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement},
6184 {"WriteByte", ves_icall_System_Runtime_InteropServices_Marshal_WriteByte},
6185 {"WriteInt16", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt16},
6186 {"WriteInt32", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt32},
6187 {"WriteInt64", ves_icall_System_Runtime_InteropServices_Marshal_WriteInt64},
6188 {"WriteIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_WriteIntPtr},
6189 {"copy_from_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged},
6190 {"copy_to_unmanaged", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged}
6193 static const IcallEntry activationservices_icalls [] = {
6194 {"AllocateUninitializedClassInstance", ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance},
6195 {"EnableProxyActivation", ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation}
6198 static const IcallEntry monomethodmessage_icalls [] = {
6199 {"InitMessage", ves_icall_MonoMethodMessage_InitMessage}
6202 static const IcallEntry realproxy_icalls [] = {
6203 {"InternalGetProxyType", ves_icall_Remoting_RealProxy_InternalGetProxyType},
6204 {"InternalGetTransparentProxy", ves_icall_Remoting_RealProxy_GetTransparentProxy}
6207 static const IcallEntry remotingservices_icalls [] = {
6208 {"InternalExecute", ves_icall_InternalExecute},
6209 {"IsTransparentProxy", ves_icall_IsTransparentProxy}
6212 static const IcallEntry rng_icalls [] = {
6213 {"RngClose", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose},
6214 {"RngGetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes},
6215 {"RngInitialize", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize}
6218 static const IcallEntry methodhandle_icalls [] = {
6219 {"GetFunctionPointer", ves_icall_RuntimeMethod_GetFunctionPointer}
6222 static const IcallEntry string_icalls [] = {
6223 {".ctor(char*)", ves_icall_System_String_ctor_charp},
6224 {".ctor(char*,int,int)", ves_icall_System_String_ctor_charp_int_int},
6225 {".ctor(char,int)", ves_icall_System_String_ctor_char_int},
6226 {".ctor(char[])", ves_icall_System_String_ctor_chara},
6227 {".ctor(char[],int,int)", ves_icall_System_String_ctor_chara_int_int},
6228 {".ctor(sbyte*)", ves_icall_System_String_ctor_sbytep},
6229 {".ctor(sbyte*,int,int)", ves_icall_System_String_ctor_sbytep_int_int},
6230 {".ctor(sbyte*,int,int,System.Text.Encoding)", ves_icall_System_String_ctor_encoding},
6231 {"GetHashCode", ves_icall_System_String_GetHashCode},
6232 {"InternalAllocateStr", ves_icall_System_String_InternalAllocateStr},
6233 {"InternalCharCopy", ves_icall_System_String_InternalCharCopy},
6234 {"InternalCopyTo", ves_icall_System_String_InternalCopyTo},
6235 {"InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny},
6236 {"InternalInsert", ves_icall_System_String_InternalInsert},
6237 {"InternalIntern", ves_icall_System_String_InternalIntern},
6238 {"InternalIsInterned", ves_icall_System_String_InternalIsInterned},
6239 {"InternalJoin", ves_icall_System_String_InternalJoin},
6240 {"InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny},
6241 {"InternalPad", ves_icall_System_String_InternalPad},
6242 {"InternalRemove", ves_icall_System_String_InternalRemove},
6243 {"InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char},
6244 {"InternalReplace(string,string,System.Globalization.CompareInfo)", ves_icall_System_String_InternalReplace_Str_Comp},
6245 {"InternalSplit", ves_icall_System_String_InternalSplit},
6246 {"InternalStrcpy(string,int,char[])", ves_icall_System_String_InternalStrcpy_Chars},
6247 {"InternalStrcpy(string,int,char[],int,int)", ves_icall_System_String_InternalStrcpy_CharsN},
6248 {"InternalStrcpy(string,int,string)", ves_icall_System_String_InternalStrcpy_Str},
6249 {"InternalStrcpy(string,int,string,int,int)", ves_icall_System_String_InternalStrcpy_StrN},
6250 {"InternalToLower(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToLower_Comp},
6251 {"InternalToUpper(System.Globalization.CultureInfo)", ves_icall_System_String_InternalToUpper_Comp},
6252 {"InternalTrim", ves_icall_System_String_InternalTrim},
6253 {"get_Chars", ves_icall_System_String_get_Chars}
6256 static const IcallEntry encoding_icalls [] = {
6257 {"InternalCodePage", ves_icall_System_Text_Encoding_InternalCodePage}
6260 static const IcallEntry monitor_icalls [] = {
6261 {"Monitor_exit", ves_icall_System_Threading_Monitor_Monitor_exit},
6262 {"Monitor_pulse", ves_icall_System_Threading_Monitor_Monitor_pulse},
6263 {"Monitor_pulse_all", ves_icall_System_Threading_Monitor_Monitor_pulse_all},
6264 {"Monitor_test_owner", ves_icall_System_Threading_Monitor_Monitor_test_owner},
6265 {"Monitor_test_synchronised", ves_icall_System_Threading_Monitor_Monitor_test_synchronised},
6266 {"Monitor_try_enter", ves_icall_System_Threading_Monitor_Monitor_try_enter},
6267 {"Monitor_wait", ves_icall_System_Threading_Monitor_Monitor_wait}
6270 static const IcallEntry interlocked_icalls [] = {
6271 {"CompareExchange(int&,int,int)", ves_icall_System_Threading_Interlocked_CompareExchange_Int},
6272 {"CompareExchange(object&,object,object)", ves_icall_System_Threading_Interlocked_CompareExchange_Object},
6273 {"CompareExchange(single&,single,single)", ves_icall_System_Threading_Interlocked_CompareExchange_Single},
6274 {"Decrement(int&)", ves_icall_System_Threading_Interlocked_Decrement_Int},
6275 {"Decrement(long&)", ves_icall_System_Threading_Interlocked_Decrement_Long},
6276 {"Exchange(int&,int)", ves_icall_System_Threading_Interlocked_Exchange_Int},
6277 {"Exchange(object&,object)", ves_icall_System_Threading_Interlocked_Exchange_Object},
6278 {"Exchange(single&,single)", ves_icall_System_Threading_Interlocked_Exchange_Single},
6279 {"Increment(int&)", ves_icall_System_Threading_Interlocked_Increment_Int},
6280 {"Increment(long&)", ves_icall_System_Threading_Interlocked_Increment_Long}
6283 static const IcallEntry mutex_icalls [] = {
6284 {"CreateMutex_internal(bool,string,bool&)", ves_icall_System_Threading_Mutex_CreateMutex_internal},
6285 {"ReleaseMutex_internal(intptr)", ves_icall_System_Threading_Mutex_ReleaseMutex_internal}
6288 static const IcallEntry nativeevents_icalls [] = {
6289 {"CloseEvent_internal", ves_icall_System_Threading_Events_CloseEvent_internal},
6290 {"CreateEvent_internal", ves_icall_System_Threading_Events_CreateEvent_internal},
6291 {"ResetEvent_internal", ves_icall_System_Threading_Events_ResetEvent_internal},
6292 {"SetEvent_internal", ves_icall_System_Threading_Events_SetEvent_internal}
6295 static const IcallEntry thread_icalls [] = {
6296 {"Abort_internal(object)", ves_icall_System_Threading_Thread_Abort},
6297 {"CurrentThread_internal", mono_thread_current},
6298 {"GetCachedCurrentCulture", ves_icall_System_Threading_Thread_GetCachedCurrentCulture},
6299 {"GetDomainID", ves_icall_System_Threading_Thread_GetDomainID},
6300 {"GetName_internal", ves_icall_System_Threading_Thread_GetName_internal},
6301 {"GetSerializedCurrentCulture", ves_icall_System_Threading_Thread_GetSerializedCurrentCulture},
6302 {"Join_internal", ves_icall_System_Threading_Thread_Join_internal},
6303 {"ResetAbort_internal()", ves_icall_System_Threading_Thread_ResetAbort},
6304 {"Resume_internal()", ves_icall_System_Threading_Thread_Resume},
6305 {"SetCachedCurrentCulture", ves_icall_System_Threading_Thread_SetCachedCurrentCulture},
6306 {"SetName_internal", ves_icall_System_Threading_Thread_SetName_internal},
6307 {"SetSerializedCurrentCulture", ves_icall_System_Threading_Thread_SetSerializedCurrentCulture},
6308 {"Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal},
6309 {"SlotHash_lookup", ves_icall_System_Threading_Thread_SlotHash_lookup},
6310 {"SlotHash_store", ves_icall_System_Threading_Thread_SlotHash_store},
6311 {"Start_internal", ves_icall_System_Threading_Thread_Start_internal},
6312 {"Suspend_internal", ves_icall_System_Threading_Thread_Suspend},
6313 {"Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal},
6314 {"Thread_internal", ves_icall_System_Threading_Thread_Thread_internal},
6315 {"VolatileRead(byte&)", ves_icall_System_Threading_Thread_VolatileRead1},
6316 {"VolatileRead(double&)", ves_icall_System_Threading_Thread_VolatileRead8},
6317 {"VolatileRead(int&)", ves_icall_System_Threading_Thread_VolatileRead4},
6318 {"VolatileRead(int16&)", ves_icall_System_Threading_Thread_VolatileRead2},
6319 {"VolatileRead(intptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
6320 {"VolatileRead(long&)", ves_icall_System_Threading_Thread_VolatileRead8},
6321 {"VolatileRead(object&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
6322 {"VolatileRead(sbyte&)", ves_icall_System_Threading_Thread_VolatileRead1},
6323 {"VolatileRead(single&)", ves_icall_System_Threading_Thread_VolatileRead4},
6324 {"VolatileRead(uint&)", ves_icall_System_Threading_Thread_VolatileRead2},
6325 {"VolatileRead(uint16&)", ves_icall_System_Threading_Thread_VolatileRead2},
6326 {"VolatileRead(uintptr&)", ves_icall_System_Threading_Thread_VolatileReadIntPtr},
6327 {"VolatileRead(ulong&)", ves_icall_System_Threading_Thread_VolatileRead8},
6328 {"VolatileWrite(byte&,byte)", ves_icall_System_Threading_Thread_VolatileWrite1},
6329 {"VolatileWrite(double&,double)", ves_icall_System_Threading_Thread_VolatileWrite8},
6330 {"VolatileWrite(int&,int)", ves_icall_System_Threading_Thread_VolatileWrite4},
6331 {"VolatileWrite(int16&,int16)", ves_icall_System_Threading_Thread_VolatileWrite2},
6332 {"VolatileWrite(intptr&,intptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
6333 {"VolatileWrite(long&,long)", ves_icall_System_Threading_Thread_VolatileWrite8},
6334 {"VolatileWrite(object&,object)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
6335 {"VolatileWrite(sbyte&,sbyte)", ves_icall_System_Threading_Thread_VolatileWrite1},
6336 {"VolatileWrite(single&,single)", ves_icall_System_Threading_Thread_VolatileWrite4},
6337 {"VolatileWrite(uint&,uint)", ves_icall_System_Threading_Thread_VolatileWrite2},
6338 {"VolatileWrite(uint16&,uint16)", ves_icall_System_Threading_Thread_VolatileWrite2},
6339 {"VolatileWrite(uintptr&,uintptr)", ves_icall_System_Threading_Thread_VolatileWriteIntPtr},
6340 {"VolatileWrite(ulong&,ulong)", ves_icall_System_Threading_Thread_VolatileWrite8},
6341 {"current_lcid()", ves_icall_System_Threading_Thread_current_lcid}
6344 static const IcallEntry threadpool_icalls [] = {
6345 {"BindHandleInternal", ves_icall_System_Threading_ThreadPool_BindHandle},
6346 {"GetAvailableThreads", ves_icall_System_Threading_ThreadPool_GetAvailableThreads},
6347 {"GetMaxThreads", ves_icall_System_Threading_ThreadPool_GetMaxThreads},
6348 {"GetMinThreads", ves_icall_System_Threading_ThreadPool_GetMinThreads},
6349 {"SetMinThreads", ves_icall_System_Threading_ThreadPool_SetMinThreads}
6352 static const IcallEntry waithandle_icalls [] = {
6353 {"WaitAll_internal", ves_icall_System_Threading_WaitHandle_WaitAll_internal},
6354 {"WaitAny_internal", ves_icall_System_Threading_WaitHandle_WaitAny_internal},
6355 {"WaitOne_internal", ves_icall_System_Threading_WaitHandle_WaitOne_internal}
6358 static const IcallEntry type_icalls [] = {
6359 {"BindGenericParameters", ves_icall_Type_BindGenericParameters},
6360 {"Equals", ves_icall_type_Equals},
6361 {"GetGenericParameterAttributes", ves_icall_Type_GetGenericParameterAttributes},
6362 {"GetGenericParameterConstraints_impl", ves_icall_Type_GetGenericParameterConstraints},
6363 {"GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition},
6364 {"GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl},
6365 {"GetInterfaceMapData", ves_icall_Type_GetInterfaceMapData},
6366 {"GetPacking", ves_icall_Type_GetPacking},
6367 {"GetTypeCode", ves_icall_type_GetTypeCode},
6368 {"IsArrayImpl", ves_icall_Type_IsArrayImpl},
6369 {"IsInstanceOfType", ves_icall_type_IsInstanceOfType},
6370 {"MakePointerType", ves_icall_Type_MakePointerType},
6371 {"get_IsGenericInstance", ves_icall_Type_get_IsGenericInstance},
6372 {"get_IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition},
6373 {"internal_from_handle", ves_icall_type_from_handle},
6374 {"internal_from_name", ves_icall_type_from_name},
6375 {"make_array_type", ves_icall_Type_make_array_type},
6376 {"make_byref_type", ves_icall_Type_make_byref_type},
6377 {"type_is_assignable_from", ves_icall_type_is_assignable_from},
6378 {"type_is_subtype_of", ves_icall_type_is_subtype_of}
6381 static const IcallEntry typedref_icalls [] = {
6382 {"ToObject", mono_TypedReference_ToObject},
6383 {"ToObjectInternal", mono_TypedReference_ToObjectInternal}
6386 static const IcallEntry valuetype_icalls [] = {
6387 {"InternalEquals", ves_icall_System_ValueType_Equals},
6388 {"InternalGetHashCode", ves_icall_System_ValueType_InternalGetHashCode}
6391 static const IcallEntry web_icalls [] = {
6392 {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
6393 {"GetMachineInstallDirectory", ves_icall_System_Web_Util_ICalls_get_machine_install_dir}
6396 static const IcallEntry identity_icalls [] = {
6397 {"GetCurrentToken", ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken},
6398 {"GetTokenName", ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName},
6399 {"GetUserToken", ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken},
6400 {"_GetRoles", ves_icall_System_Security_Principal_WindowsIdentity_GetRoles}
6403 static const IcallEntry impersonation_icalls [] = {
6404 {"CloseToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_CloseToken},
6405 {"DuplicateToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_DuplicateToken},
6406 {"RevertToSelf", ves_icall_System_Security_Principal_WindowsImpersonationContext_RevertToSelf},
6407 {"SetCurrentToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_SetCurrentToken}
6410 static const IcallEntry principal_icalls [] = {
6411 {"IsMemberOfGroupId", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupId},
6412 {"IsMemberOfGroupName", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupName}
6415 static const IcallEntry keypair_icalls [] = {
6416 {"_CanSecure", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_CanSecure},
6417 {"_IsMachineProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsMachineProtected},
6418 {"_IsUserProtected", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_IsUserProtected},
6419 {"_ProtectMachine", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectMachine},
6420 {"_ProtectUser", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectUser}
6423 static const IcallEntry evidence_icalls [] = {
6424 {"IsAuthenticodePresent", ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent}
6427 /* proto
6428 static const IcallEntry array_icalls [] = {
6433 /* keep the entries all sorted */
6434 static const IcallMap icall_entries [] = {
6435 {"Mono.Security.Cryptography.KeyPairPersistence", keypair_icalls, G_N_ELEMENTS (keypair_icalls)},
6436 {"System.Activator", activator_icalls, G_N_ELEMENTS (activator_icalls)},
6437 {"System.AppDomain", appdomain_icalls, G_N_ELEMENTS (appdomain_icalls)},
6438 {"System.ArgIterator", argiterator_icalls, G_N_ELEMENTS (argiterator_icalls)},
6439 {"System.Array", array_icalls, G_N_ELEMENTS (array_icalls)},
6440 {"System.Buffer", buffer_icalls, G_N_ELEMENTS (buffer_icalls)},
6441 {"System.Char", char_icalls, G_N_ELEMENTS (char_icalls)},
6442 {"System.Configuration.DefaultConfig", defaultconf_icalls, G_N_ELEMENTS (defaultconf_icalls)},
6443 {"System.CurrentTimeZone", timezone_icalls, G_N_ELEMENTS (timezone_icalls)},
6444 {"System.DateTime", datetime_icalls, G_N_ELEMENTS (datetime_icalls)},
6445 #ifndef DISABLE_DECIMAL
6446 {"System.Decimal", decimal_icalls, G_N_ELEMENTS (decimal_icalls)},
6447 #endif
6448 {"System.Delegate", delegate_icalls, G_N_ELEMENTS (delegate_icalls)},
6449 {"System.Diagnostics.DefaultTraceListener", tracelist_icalls, G_N_ELEMENTS (tracelist_icalls)},
6450 {"System.Diagnostics.FileVersionInfo", fileversion_icalls, G_N_ELEMENTS (fileversion_icalls)},
6451 {"System.Diagnostics.Process", process_icalls, G_N_ELEMENTS (process_icalls)},
6452 {"System.Double", double_icalls, G_N_ELEMENTS (double_icalls)},
6453 {"System.Enum", enum_icalls, G_N_ELEMENTS (enum_icalls)},
6454 {"System.Environment", environment_icalls, G_N_ELEMENTS (environment_icalls)},
6455 {"System.GC", gc_icalls, G_N_ELEMENTS (gc_icalls)},
6456 {"System.Globalization.CompareInfo", compareinfo_icalls, G_N_ELEMENTS (compareinfo_icalls)},
6457 {"System.Globalization.CultureInfo", cultureinfo_icalls, G_N_ELEMENTS (cultureinfo_icalls)},
6458 {"System.IO.FAMWatcher", famwatcher_icalls, G_N_ELEMENTS (famwatcher_icalls)},
6459 {"System.IO.FileSystemWatcher", filewatcher_icalls, G_N_ELEMENTS (filewatcher_icalls)},
6460 {"System.IO.MonoIO", monoio_icalls, G_N_ELEMENTS (monoio_icalls)},
6461 {"System.IO.Path", path_icalls, G_N_ELEMENTS (path_icalls)},
6462 {"System.Math", math_icalls, G_N_ELEMENTS (math_icalls)},
6463 {"System.MonoCustomAttrs", customattrs_icalls, G_N_ELEMENTS (customattrs_icalls)},
6464 {"System.MonoEnumInfo", enuminfo_icalls, G_N_ELEMENTS (enuminfo_icalls)},
6465 {"System.MonoType", monotype_icalls, G_N_ELEMENTS (monotype_icalls)},
6466 {"System.Net.Dns", dns_icalls, G_N_ELEMENTS (dns_icalls)},
6467 {"System.Net.Sockets.Socket", socket_icalls, G_N_ELEMENTS (socket_icalls)},
6468 {"System.Net.Sockets.SocketException", socketex_icalls, G_N_ELEMENTS (socketex_icalls)},
6469 {"System.Object", object_icalls, G_N_ELEMENTS (object_icalls)},
6470 {"System.Reflection.Assembly", assembly_icalls, G_N_ELEMENTS (assembly_icalls)},
6471 {"System.Reflection.Emit.AssemblyBuilder", assemblybuilder_icalls, G_N_ELEMENTS (assemblybuilder_icalls)},
6472 {"System.Reflection.Emit.CustomAttributeBuilder", customattrbuilder_icalls, G_N_ELEMENTS (customattrbuilder_icalls)},
6473 {"System.Reflection.Emit.DynamicMethod", dynamicmethod_icalls, G_N_ELEMENTS (dynamicmethod_icalls)},
6474 {"System.Reflection.Emit.EnumBuilder", enumbuilder_icalls, G_N_ELEMENTS (enumbuilder_icalls)},
6475 {"System.Reflection.Emit.GenericTypeParameterBuilder", generictypeparambuilder_icalls, G_N_ELEMENTS (generictypeparambuilder_icalls)},
6476 {"System.Reflection.Emit.MethodBuilder", methodbuilder_icalls, G_N_ELEMENTS (methodbuilder_icalls)},
6477 {"System.Reflection.Emit.ModuleBuilder", modulebuilder_icalls, G_N_ELEMENTS (modulebuilder_icalls)},
6478 {"System.Reflection.Emit.SignatureHelper", signaturehelper_icalls, G_N_ELEMENTS (signaturehelper_icalls)},
6479 {"System.Reflection.Emit.TypeBuilder", typebuilder_icalls, G_N_ELEMENTS (typebuilder_icalls)},
6480 {"System.Reflection.FieldInfo", fieldinfo_icalls, G_N_ELEMENTS (fieldinfo_icalls)},
6481 {"System.Reflection.MemberInfo", memberinfo_icalls, G_N_ELEMENTS (memberinfo_icalls)},
6482 {"System.Reflection.MethodBase", methodbase_icalls, G_N_ELEMENTS (methodbase_icalls)},
6483 {"System.Reflection.Module", module_icalls, G_N_ELEMENTS (module_icalls)},
6484 {"System.Reflection.MonoCMethod", monocmethod_icalls, G_N_ELEMENTS (monocmethod_icalls)},
6485 {"System.Reflection.MonoEventInfo", monoeventinfo_icalls, G_N_ELEMENTS (monoeventinfo_icalls)},
6486 {"System.Reflection.MonoField", monofield_icalls, G_N_ELEMENTS (monofield_icalls)},
6487 {"System.Reflection.MonoGenericClass", monogenericclass_icalls, G_N_ELEMENTS (monogenericclass_icalls)},
6488 {"System.Reflection.MonoMethod", monomethod_icalls, G_N_ELEMENTS (monomethod_icalls)},
6489 {"System.Reflection.MonoMethodInfo", monomethodinfo_icalls, G_N_ELEMENTS (monomethodinfo_icalls)},
6490 {"System.Reflection.MonoPropertyInfo", monopropertyinfo_icalls, G_N_ELEMENTS (monopropertyinfo_icalls)},
6491 {"System.Reflection.ParameterInfo", parameterinfo_icalls, G_N_ELEMENTS (parameterinfo_icalls)},
6492 {"System.Runtime.CompilerServices.RuntimeHelpers", runtimehelpers_icalls, G_N_ELEMENTS (runtimehelpers_icalls)},
6493 {"System.Runtime.InteropServices.GCHandle", gchandle_icalls, G_N_ELEMENTS (gchandle_icalls)},
6494 {"System.Runtime.InteropServices.Marshal", marshal_icalls, G_N_ELEMENTS (marshal_icalls)},
6495 {"System.Runtime.Remoting.Activation.ActivationServices", activationservices_icalls, G_N_ELEMENTS (activationservices_icalls)},
6496 {"System.Runtime.Remoting.Messaging.MonoMethodMessage", monomethodmessage_icalls, G_N_ELEMENTS (monomethodmessage_icalls)},
6497 {"System.Runtime.Remoting.Proxies.RealProxy", realproxy_icalls, G_N_ELEMENTS (realproxy_icalls)},
6498 {"System.Runtime.Remoting.RemotingServices", remotingservices_icalls, G_N_ELEMENTS (remotingservices_icalls)},
6499 {"System.RuntimeMethodHandle", methodhandle_icalls, G_N_ELEMENTS (methodhandle_icalls)},
6500 {"System.Security.Cryptography.RNGCryptoServiceProvider", rng_icalls, G_N_ELEMENTS (rng_icalls)},
6501 {"System.Security.Policy.Evidence", evidence_icalls, G_N_ELEMENTS (evidence_icalls)},
6502 {"System.Security.Principal.WindowsIdentity", identity_icalls, G_N_ELEMENTS (identity_icalls)},
6503 {"System.Security.Principal.WindowsImpersonationContext", impersonation_icalls, G_N_ELEMENTS (impersonation_icalls)},
6504 {"System.Security.Principal.WindowsPrincipal", principal_icalls, G_N_ELEMENTS (principal_icalls)},
6505 {"System.String", string_icalls, G_N_ELEMENTS (string_icalls)},
6506 {"System.Text.Encoding", encoding_icalls, G_N_ELEMENTS (encoding_icalls)},
6507 {"System.Threading.Interlocked", interlocked_icalls, G_N_ELEMENTS (interlocked_icalls)},
6508 {"System.Threading.Monitor", monitor_icalls, G_N_ELEMENTS (monitor_icalls)},
6509 {"System.Threading.Mutex", mutex_icalls, G_N_ELEMENTS (mutex_icalls)},
6510 {"System.Threading.NativeEventCalls", nativeevents_icalls, G_N_ELEMENTS (nativeevents_icalls)},
6511 {"System.Threading.Thread", thread_icalls, G_N_ELEMENTS (thread_icalls)},
6512 {"System.Threading.ThreadPool", threadpool_icalls, G_N_ELEMENTS (threadpool_icalls)},
6513 {"System.Threading.WaitHandle", waithandle_icalls, G_N_ELEMENTS (waithandle_icalls)},
6514 {"System.Type", type_icalls, G_N_ELEMENTS (type_icalls)},
6515 {"System.TypedReference", typedref_icalls, G_N_ELEMENTS (typedref_icalls)},
6516 {"System.ValueType", valuetype_icalls, G_N_ELEMENTS (valuetype_icalls)},
6517 {"System.Web.Util.ICalls", web_icalls, G_N_ELEMENTS (web_icalls)}
6520 static GHashTable *icall_hash = NULL;
6521 static GHashTable *jit_icall_hash_name = NULL;
6522 static GHashTable *jit_icall_hash_addr = NULL;
6524 void
6525 mono_init_icall (void)
6527 int i = 0;
6529 /* check that tables are sorted: disable in release */
6530 if (TRUE) {
6531 int j;
6532 const IcallMap *imap;
6533 const IcallEntry *ientry;
6534 const char *prev_class = NULL;
6535 const char *prev_method;
6537 for (i = 0; i < G_N_ELEMENTS (icall_entries); ++i) {
6538 imap = &icall_entries [i];
6539 prev_method = NULL;
6540 if (prev_class && strcmp (prev_class, imap->klass) >= 0)
6541 g_print ("class %s should come before class %s\n", imap->klass, prev_class);
6542 prev_class = imap->klass;
6543 for (j = 0; j < imap->size; ++j) {
6544 ientry = &imap->icalls [j];
6545 if (prev_method && strcmp (prev_method, ientry->method) >= 0)
6546 g_print ("method %s should come before method %s\n", ientry->method, prev_method);
6547 prev_method = ientry->method;
6552 icall_hash = g_hash_table_new (g_str_hash , g_str_equal);
6555 void
6556 mono_add_internal_call (const char *name, gconstpointer method)
6558 mono_loader_lock ();
6560 g_hash_table_insert (icall_hash, g_strdup (name), (gpointer) method);
6562 mono_loader_unlock ();
6565 static int
6566 compare_class_imap (const void *key, const void *elem)
6568 const IcallMap* imap = (const IcallMap*)elem;
6569 return strcmp (key, imap->klass);
6572 static const IcallMap*
6573 find_class_icalls (const char *name)
6575 return (const IcallMap*) bsearch (name, icall_entries, G_N_ELEMENTS (icall_entries), sizeof (IcallMap), compare_class_imap);
6578 static int
6579 compare_method_imap (const void *key, const void *elem)
6581 const IcallEntry* ientry = (const IcallEntry*)elem;
6582 return strcmp (key, ientry->method);
6585 static void*
6586 find_method_icall (const IcallMap *imap, const char *name)
6588 const IcallEntry *ientry = (const IcallEntry*) bsearch (name, imap->icalls, imap->size, sizeof (IcallEntry), compare_method_imap);
6589 if (ientry)
6590 return (void*)ientry->func;
6591 return NULL;
6595 * we should probably export this as an helper (handle nested types).
6596 * Returns the number of chars written in buf.
6598 static int
6599 concat_class_name (char *buf, int bufsize, MonoClass *klass)
6601 int nspacelen, cnamelen;
6602 nspacelen = strlen (klass->name_space);
6603 cnamelen = strlen (klass->name);
6604 if (nspacelen + cnamelen + 2 > bufsize)
6605 return 0;
6606 if (nspacelen) {
6607 memcpy (buf, klass->name_space, nspacelen);
6608 buf [nspacelen ++] = '.';
6610 memcpy (buf + nspacelen, klass->name, cnamelen);
6611 buf [nspacelen + cnamelen] = 0;
6612 return nspacelen + cnamelen;
6615 gpointer
6616 mono_lookup_internal_call (MonoMethod *method)
6618 char *sigstart;
6619 char *tmpsig;
6620 char mname [2048];
6621 int typelen = 0, mlen, siglen;
6622 gpointer res;
6623 const IcallMap *imap;
6625 g_assert (method != NULL);
6627 typelen = concat_class_name (mname, sizeof (mname), method->klass);
6628 if (!typelen)
6629 return NULL;
6631 imap = find_class_icalls (mname);
6633 mname [typelen] = ':';
6634 mname [typelen + 1] = ':';
6636 mlen = strlen (method->name);
6637 memcpy (mname + typelen + 2, method->name, mlen);
6638 sigstart = mname + typelen + 2 + mlen;
6639 *sigstart = 0;
6641 tmpsig = mono_signature_get_desc (method->signature, TRUE);
6642 siglen = strlen (tmpsig);
6643 if (typelen + mlen + siglen + 6 > sizeof (mname))
6644 return NULL;
6645 sigstart [0] = '(';
6646 memcpy (sigstart + 1, tmpsig, siglen);
6647 sigstart [siglen + 1] = ')';
6648 sigstart [siglen + 2] = 0;
6649 g_free (tmpsig);
6651 mono_loader_lock ();
6653 res = g_hash_table_lookup (icall_hash, mname);
6654 if (res) {
6655 mono_loader_unlock ();
6656 return res;
6658 /* try without signature */
6659 *sigstart = 0;
6660 res = g_hash_table_lookup (icall_hash, mname);
6661 if (res) {
6662 mono_loader_unlock ();
6663 return res;
6666 /* it wasn't found in the static call tables */
6667 if (!imap) {
6668 mono_loader_unlock ();
6669 return NULL;
6671 res = find_method_icall (imap, sigstart - mlen);
6672 if (res) {
6673 mono_loader_unlock ();
6674 return res;
6676 /* try _with_ signature */
6677 *sigstart = '(';
6678 res = find_method_icall (imap, sigstart - mlen);
6679 if (res) {
6680 mono_loader_unlock ();
6681 return res;
6684 g_warning ("cant resolve internal call to \"%s\" (tested without signature also)", mname);
6685 g_print ("\nYour mono runtime and class libraries are out of sync.\n");
6686 g_print ("The out of sync library is: %s\n", method->klass->image->name);
6687 g_print ("\nWhen you update one from cvs you need to update, compile and install\nthe other too.\n");
6688 g_print ("Do not report this as a bug unless you're sure you have updated correctly:\nyou probably have a broken mono install.\n");
6689 g_print ("If you see other errors or faults after this message they are probably related\n");
6690 g_print ("and you need to fix your mono install first.\n");
6692 mono_loader_unlock ();
6694 return NULL;
6697 static MonoType*
6698 type_from_typename (char *typename)
6700 MonoClass *klass = NULL; /* assignment to shut GCC warning up */
6702 if (!strcmp (typename, "int"))
6703 klass = mono_defaults.int_class;
6704 else if (!strcmp (typename, "ptr"))
6705 klass = mono_defaults.int_class;
6706 else if (!strcmp (typename, "void"))
6707 klass = mono_defaults.void_class;
6708 else if (!strcmp (typename, "int32"))
6709 klass = mono_defaults.int32_class;
6710 else if (!strcmp (typename, "uint32"))
6711 klass = mono_defaults.uint32_class;
6712 else if (!strcmp (typename, "long"))
6713 klass = mono_defaults.int64_class;
6714 else if (!strcmp (typename, "ulong"))
6715 klass = mono_defaults.uint64_class;
6716 else if (!strcmp (typename, "float"))
6717 klass = mono_defaults.single_class;
6718 else if (!strcmp (typename, "double"))
6719 klass = mono_defaults.double_class;
6720 else if (!strcmp (typename, "object"))
6721 klass = mono_defaults.object_class;
6722 else if (!strcmp (typename, "obj"))
6723 klass = mono_defaults.object_class;
6724 else {
6725 g_error (typename);
6726 g_assert_not_reached ();
6728 return &klass->byval_arg;
6731 MonoMethodSignature*
6732 mono_create_icall_signature (const char *sigstr)
6734 gchar **parts;
6735 int i, len;
6736 gchar **tmp;
6737 MonoMethodSignature *res;
6739 mono_loader_lock ();
6740 res = g_hash_table_lookup (mono_defaults.corlib->helper_signatures, sigstr);
6741 if (res) {
6742 mono_loader_unlock ();
6743 return res;
6746 parts = g_strsplit (sigstr, " ", 256);
6748 tmp = parts;
6749 len = 0;
6750 while (*tmp) {
6751 len ++;
6752 tmp ++;
6755 res = mono_metadata_signature_alloc (mono_defaults.corlib, len - 1);
6756 res->pinvoke = 1;
6758 #ifdef PLATFORM_WIN32
6760 * Under windows, the default pinvoke calling convention is STDCALL but
6761 * we need CDECL.
6763 res->call_convention = MONO_CALL_C;
6764 #endif
6766 res->ret = type_from_typename (parts [0]);
6767 for (i = 1; i < len; ++i) {
6768 res->params [i - 1] = type_from_typename (parts [i]);
6771 g_strfreev (parts);
6773 g_hash_table_insert (mono_defaults.corlib->helper_signatures, (gpointer)sigstr, res);
6775 mono_loader_unlock ();
6777 return res;
6780 MonoJitICallInfo *
6781 mono_find_jit_icall_by_name (const char *name)
6783 MonoJitICallInfo *info;
6784 g_assert (jit_icall_hash_name);
6786 mono_loader_lock ();
6787 info = g_hash_table_lookup (jit_icall_hash_name, name);
6788 mono_loader_unlock ();
6789 return info;
6792 MonoJitICallInfo *
6793 mono_find_jit_icall_by_addr (gconstpointer addr)
6795 MonoJitICallInfo *info;
6796 g_assert (jit_icall_hash_addr);
6798 mono_loader_lock ();
6799 info = g_hash_table_lookup (jit_icall_hash_addr, (gpointer)addr);
6800 mono_loader_unlock ();
6802 return info;
6805 void
6806 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper)
6808 mono_loader_lock ();
6809 g_hash_table_insert (jit_icall_hash_addr, (gpointer)info->wrapper, info);
6810 mono_loader_unlock ();
6813 MonoJitICallInfo *
6814 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save)
6816 MonoJitICallInfo *info;
6818 g_assert (func);
6819 g_assert (name);
6821 mono_loader_lock ();
6823 if (!jit_icall_hash_name) {
6824 jit_icall_hash_name = g_hash_table_new (g_str_hash, g_str_equal);
6825 jit_icall_hash_addr = g_hash_table_new (NULL, NULL);
6828 if (g_hash_table_lookup (jit_icall_hash_name, name)) {
6829 g_warning ("jit icall already defined \"%s\"\n", name);
6830 g_assert_not_reached ();
6833 info = g_new (MonoJitICallInfo, 1);
6835 info->name = name;
6836 info->func = func;
6837 info->sig = sig;
6839 if (is_save) {
6840 info->wrapper = func;
6841 } else {
6842 info->wrapper = NULL;
6845 g_hash_table_insert (jit_icall_hash_name, (gpointer)info->name, info);
6846 g_hash_table_insert (jit_icall_hash_addr, (gpointer)func, info);
6848 mono_loader_unlock ();
6849 return info;