5 * Dietmar Maurer (dietmar@ximian.com)
6 * Paolo Molaro (lupus@ximian.com)
7 * Patrik Torstensson (patrik.torstensson@labs2.com)
8 * Marek Safar (marek.safar@gmail.com)
9 * Aleksey Kliger (aleksey@xamarin.com)
11 * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
12 * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
13 * Copyright 2011-2015 Xamarin Inc (http://www.xamarin.com).
14 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
25 #ifdef HAVE_SYS_TIME_H
31 #if defined (HAVE_WCHAR_H)
34 #include "mono/metadata/icall-internals.h"
35 #include "mono/utils/mono-membar.h"
36 #include <mono/metadata/object.h>
37 #include <mono/metadata/threads.h>
38 #include <mono/metadata/threads-types.h>
39 #include <mono/metadata/threadpool.h>
40 #include <mono/metadata/threadpool-io.h>
41 #include <mono/metadata/monitor.h>
42 #include <mono/metadata/reflection.h>
43 #include <mono/metadata/image-internals.h>
44 #include <mono/metadata/assembly.h>
45 #include <mono/metadata/assembly-internals.h>
46 #include <mono/metadata/tabledefs.h>
47 #include <mono/metadata/exception.h>
48 #include <mono/metadata/exception-internals.h>
49 #include <mono/metadata/w32file.h>
50 #include <mono/metadata/console-io.h>
51 #include <mono/metadata/mono-route.h>
52 #include <mono/metadata/w32socket.h>
53 #include <mono/metadata/mono-endian.h>
54 #include <mono/metadata/tokentype.h>
55 #include <mono/metadata/metadata-internals.h>
56 #include <mono/metadata/class-internals.h>
57 #include <mono/metadata/reflection-internals.h>
58 #include <mono/metadata/marshal.h>
59 #include <mono/metadata/gc-internals.h>
60 #include <mono/metadata/mono-gc.h>
61 #include <mono/metadata/rand.h>
62 #include <mono/metadata/sysmath.h>
63 #include <mono/metadata/appdomain-icalls.h>
64 #include <mono/metadata/string-icalls.h>
65 #include <mono/metadata/debug-helpers.h>
66 #include <mono/metadata/w32process.h>
67 #include <mono/metadata/environment.h>
68 #include <mono/metadata/profiler-private.h>
69 #include <mono/metadata/locales.h>
70 #include <mono/metadata/filewatcher.h>
71 #include <mono/metadata/security.h>
72 #include <mono/metadata/mono-config.h>
73 #include <mono/metadata/cil-coff.h>
74 #include <mono/metadata/number-formatter.h>
75 #include <mono/metadata/security-manager.h>
76 #include <mono/metadata/security-core-clr.h>
77 #include <mono/metadata/mono-perfcounters.h>
78 #include <mono/metadata/mono-debug.h>
79 #include <mono/metadata/mono-ptr-array.h>
80 #include <mono/metadata/verify-internals.h>
81 #include <mono/metadata/runtime.h>
82 #include <mono/metadata/file-mmap.h>
83 #include <mono/metadata/seq-points-data.h>
84 #include <mono/metadata/handle.h>
85 #include <mono/metadata/w32mutex.h>
86 #include <mono/metadata/w32semaphore.h>
87 #include <mono/metadata/w32event.h>
88 #include <mono/utils/monobitset.h>
89 #include <mono/utils/mono-time.h>
90 #include <mono/utils/mono-proclib.h>
91 #include <mono/utils/mono-string.h>
92 #include <mono/utils/mono-error-internals.h>
93 #include <mono/utils/mono-mmap.h>
94 #include <mono/utils/mono-io-portability.h>
95 #include <mono/utils/mono-digest.h>
96 #include <mono/utils/bsearch.h>
97 #include <mono/utils/mono-os-mutex.h>
98 #include <mono/utils/mono-threads.h>
99 #include <mono/metadata/w32error.h>
100 #include <mono/utils/w32api.h>
102 #include "decimal-ms.h"
103 #include "number-ms.h"
105 #if !defined(HOST_WIN32) && defined(HAVE_SYS_UTSNAME_H)
106 #include <sys/utsname.h>
109 extern MonoStringHandle
ves_icall_System_Environment_GetOSVersionString (MonoError
*error
);
111 ICALL_EXPORT MonoReflectionAssemblyHandle
ves_icall_System_Reflection_Assembly_GetCallingAssembly (MonoError
*error
);
113 /* Lazy class loading functions */
114 static GENERATE_GET_CLASS_WITH_CACHE (system_version
, "System", "Version")
115 static GENERATE_GET_CLASS_WITH_CACHE (assembly_name
, "System.Reflection", "AssemblyName")
116 static GENERATE_GET_CLASS_WITH_CACHE (constructor_info
, "System.Reflection", "ConstructorInfo")
117 static GENERATE_GET_CLASS_WITH_CACHE (property_info
, "System.Reflection", "PropertyInfo")
118 static GENERATE_GET_CLASS_WITH_CACHE (event_info
, "System.Reflection", "EventInfo")
119 static GENERATE_GET_CLASS_WITH_CACHE (module
, "System.Reflection", "Module")
121 static MonoArrayHandle
122 type_array_from_modifiers (MonoImage
*image
, MonoType
*type
, int optional
, MonoError
*error
);
124 static inline MonoBoolean
125 is_generic_parameter (MonoType
*type
)
127 return !type
->byref
&& (type
->type
== MONO_TYPE_VAR
|| type
->type
== MONO_TYPE_MVAR
);
131 mono_class_init_checked (MonoClass
*klass
, MonoError
*error
)
135 if (!mono_class_init (klass
))
136 mono_error_set_for_class_failure (error
, klass
);
141 mono_icall_make_platform_path (gchar
*path
)
146 static inline const gchar
*
147 mono_icall_get_file_path_prefix (const gchar
*path
)
151 #endif /* HOST_WIN32 */
153 ICALL_EXPORT MonoObject
*
154 ves_icall_System_Array_GetValueImpl (MonoArray
*arr
, guint32 pos
)
160 MonoObject
*result
= NULL
;
162 ac
= (MonoClass
*)arr
->obj
.vtable
->klass
;
164 esize
= mono_array_element_size (ac
);
165 ea
= (gpointer
*)((char*)arr
->vector
+ (pos
* esize
));
167 if (ac
->element_class
->valuetype
) {
168 result
= mono_value_box_checked (arr
->obj
.vtable
->domain
, ac
->element_class
, ea
, &error
);
169 mono_error_set_pending_exception (&error
);
171 result
= (MonoObject
*)*ea
;
175 ICALL_EXPORT MonoObject
*
176 ves_icall_System_Array_GetValue (MonoArray
*arr
, MonoArray
*idxs
)
182 MONO_CHECK_ARG_NULL (idxs
, NULL
);
185 ic
= (MonoClass
*)io
->obj
.vtable
->klass
;
187 ac
= (MonoClass
*)arr
->obj
.vtable
->klass
;
189 g_assert (ic
->rank
== 1);
190 if (io
->bounds
!= NULL
|| io
->max_length
!= ac
->rank
) {
191 mono_set_pending_exception (mono_get_exception_argument (NULL
, NULL
));
195 ind
= (gint32
*)io
->vector
;
197 if (arr
->bounds
== NULL
) {
198 if (*ind
< 0 || *ind
>= arr
->max_length
) {
199 mono_set_pending_exception (mono_get_exception_index_out_of_range ());
203 return ves_icall_System_Array_GetValueImpl (arr
, *ind
);
206 for (i
= 0; i
< ac
->rank
; i
++) {
207 if ((ind
[i
] < arr
->bounds
[i
].lower_bound
) ||
208 (ind
[i
] >= (mono_array_lower_bound_t
)arr
->bounds
[i
].length
+ arr
->bounds
[i
].lower_bound
)) {
209 mono_set_pending_exception (mono_get_exception_index_out_of_range ());
214 pos
= ind
[0] - arr
->bounds
[0].lower_bound
;
215 for (i
= 1; i
< ac
->rank
; i
++)
216 pos
= pos
* arr
->bounds
[i
].length
+ ind
[i
] -
217 arr
->bounds
[i
].lower_bound
;
219 return ves_icall_System_Array_GetValueImpl (arr
, pos
);
223 ves_icall_System_Array_SetValueImpl (MonoArray
*arr
, MonoObject
*value
, guint32 pos
)
226 MonoClass
*ac
, *vc
, *ec
;
238 vc
= value
->vtable
->klass
;
242 ac
= arr
->obj
.vtable
->klass
;
243 ec
= ac
->element_class
;
245 esize
= mono_array_element_size (ac
);
246 ea
= (gpointer
*)((char*)arr
->vector
+ (pos
* esize
));
247 va
= (gpointer
*)((char*)value
+ sizeof (MonoObject
));
249 if (mono_class_is_nullable (ec
)) {
250 mono_nullable_init ((guint8
*)ea
, value
, ec
);
255 mono_gc_bzero_atomic (ea
, esize
);
259 #define NO_WIDENING_CONVERSION G_STMT_START{\
260 mono_set_pending_exception (mono_get_exception_argument ( \
261 "value", "not a widening conversion")); \
265 #define CHECK_WIDENING_CONVERSION(extra) G_STMT_START{\
266 if (esize < vsize + (extra)) { \
267 mono_set_pending_exception (mono_get_exception_argument ( \
268 "value", "not a widening conversion")); \
273 #define INVALID_CAST G_STMT_START{ \
274 mono_get_runtime_callbacks ()->set_cast_details (vc, ec); \
275 mono_set_pending_exception (mono_get_exception_invalid_cast ()); \
279 /* Check element (destination) type. */
280 switch (ec
->byval_arg
.type
) {
281 case MONO_TYPE_STRING
:
282 switch (vc
->byval_arg
.type
) {
283 case MONO_TYPE_STRING
:
289 case MONO_TYPE_BOOLEAN
:
290 switch (vc
->byval_arg
.type
) {
291 case MONO_TYPE_BOOLEAN
:
304 NO_WIDENING_CONVERSION
;
313 if (!ec
->valuetype
) {
314 gboolean castOk
= (NULL
!= mono_object_isinst_checked (value
, ec
, &error
));
315 if (mono_error_set_pending_exception (&error
))
319 mono_gc_wbarrier_set_arrayref (arr
, ea
, (MonoObject
*)value
);
323 if (mono_object_isinst_checked (value
, ec
, &error
)) {
324 if (ec
->has_references
)
325 mono_value_copy (ea
, (char*)value
+ sizeof (MonoObject
), ec
);
327 mono_gc_memmove_atomic (ea
, (char *)value
+ sizeof (MonoObject
), esize
);
330 if (mono_error_set_pending_exception (&error
))
336 vsize
= mono_class_instance_size (vc
) - sizeof (MonoObject
);
338 et
= ec
->byval_arg
.type
;
339 if (et
== MONO_TYPE_VALUETYPE
&& ec
->byval_arg
.data
.klass
->enumtype
)
340 et
= mono_class_enum_basetype (ec
->byval_arg
.data
.klass
)->type
;
342 vt
= vc
->byval_arg
.type
;
343 if (vt
== MONO_TYPE_VALUETYPE
&& vc
->byval_arg
.data
.klass
->enumtype
)
344 vt
= mono_class_enum_basetype (vc
->byval_arg
.data
.klass
)->type
;
346 #define ASSIGN_UNSIGNED(etype) G_STMT_START{\
352 case MONO_TYPE_CHAR: \
353 CHECK_WIDENING_CONVERSION(0); \
354 *(etype *) ea = (etype) u64; \
356 /* You can't assign a signed value to an unsigned array. */ \
361 /* You can't assign a floating point number to an integer array. */ \
364 NO_WIDENING_CONVERSION; \
368 #define ASSIGN_SIGNED(etype) G_STMT_START{\
374 CHECK_WIDENING_CONVERSION(0); \
375 *(etype *) ea = (etype) i64; \
377 /* You can assign an unsigned value to a signed array if the array's */ \
378 /* element size is larger than the value size. */ \
383 case MONO_TYPE_CHAR: \
384 CHECK_WIDENING_CONVERSION(1); \
385 *(etype *) ea = (etype) u64; \
387 /* You can't assign a floating point number to an integer array. */ \
390 NO_WIDENING_CONVERSION; \
394 #define ASSIGN_REAL(etype) G_STMT_START{\
398 CHECK_WIDENING_CONVERSION(0); \
399 *(etype *) ea = (etype) r64; \
401 /* All integer values fit into a floating point array, so we don't */ \
402 /* need to CHECK_WIDENING_CONVERSION here. */ \
407 *(etype *) ea = (etype) i64; \
413 case MONO_TYPE_CHAR: \
414 *(etype *) ea = (etype) u64; \
421 u64
= *(guint8
*) va
;
424 u64
= *(guint16
*) va
;
427 u64
= *(guint32
*) va
;
430 u64
= *(guint64
*) va
;
436 i64
= *(gint16
*) va
;
439 i64
= *(gint32
*) va
;
442 i64
= *(gint64
*) va
;
445 r64
= *(gfloat
*) va
;
448 r64
= *(gdouble
*) va
;
451 u64
= *(guint16
*) va
;
453 case MONO_TYPE_BOOLEAN
:
454 /* Boolean is only compatible with itself. */
467 NO_WIDENING_CONVERSION
;
474 /* If we can't do a direct copy, let's try a widening conversion. */
477 ASSIGN_UNSIGNED (guint16
);
479 ASSIGN_UNSIGNED (guint8
);
481 ASSIGN_UNSIGNED (guint16
);
483 ASSIGN_UNSIGNED (guint32
);
485 ASSIGN_UNSIGNED (guint64
);
487 ASSIGN_SIGNED (gint8
);
489 ASSIGN_SIGNED (gint16
);
491 ASSIGN_SIGNED (gint32
);
493 ASSIGN_SIGNED (gint64
);
495 ASSIGN_REAL (gfloat
);
497 ASSIGN_REAL (gdouble
);
501 /* Not reached, INVALID_CAST does not return. Just to avoid a compiler warning ... */
505 #undef NO_WIDENING_CONVERSION
506 #undef CHECK_WIDENING_CONVERSION
507 #undef ASSIGN_UNSIGNED
513 ves_icall_System_Array_SetValue (MonoArray
*arr
, MonoObject
*value
,
519 MONO_CHECK_ARG_NULL (idxs
,);
521 ic
= idxs
->obj
.vtable
->klass
;
522 ac
= arr
->obj
.vtable
->klass
;
524 g_assert (ic
->rank
== 1);
525 if (idxs
->bounds
!= NULL
|| idxs
->max_length
!= ac
->rank
) {
526 mono_set_pending_exception (mono_get_exception_argument (NULL
, NULL
));
530 ind
= (gint32
*)idxs
->vector
;
532 if (arr
->bounds
== NULL
) {
533 if (*ind
< 0 || *ind
>= arr
->max_length
) {
534 mono_set_pending_exception (mono_get_exception_index_out_of_range ());
538 ves_icall_System_Array_SetValueImpl (arr
, value
, *ind
);
542 for (i
= 0; i
< ac
->rank
; i
++)
543 if ((ind
[i
] < arr
->bounds
[i
].lower_bound
) ||
544 (ind
[i
] >= (mono_array_lower_bound_t
)arr
->bounds
[i
].length
+ arr
->bounds
[i
].lower_bound
)) {
545 mono_set_pending_exception (mono_get_exception_index_out_of_range ());
549 pos
= ind
[0] - arr
->bounds
[0].lower_bound
;
550 for (i
= 1; i
< ac
->rank
; i
++)
551 pos
= pos
* arr
->bounds
[i
].length
+ ind
[i
] -
552 arr
->bounds
[i
].lower_bound
;
554 ves_icall_System_Array_SetValueImpl (arr
, value
, pos
);
557 ICALL_EXPORT MonoArray
*
558 ves_icall_System_Array_CreateInstanceImpl (MonoReflectionType
*type
, MonoArray
*lengths
, MonoArray
*bounds
)
561 MonoClass
*aklass
, *klass
;
564 gboolean bounded
= FALSE
;
566 MONO_CHECK_ARG_NULL (type
, NULL
);
567 MONO_CHECK_ARG_NULL (lengths
, NULL
);
569 MONO_CHECK_ARG (lengths
, mono_array_length (lengths
) > 0, NULL
);
571 MONO_CHECK_ARG (bounds
, mono_array_length (lengths
) == mono_array_length (bounds
), NULL
);
573 for (i
= 0; i
< mono_array_length (lengths
); i
++) {
574 if (mono_array_get (lengths
, gint32
, i
) < 0) {
575 mono_set_pending_exception (mono_get_exception_argument_out_of_range (NULL
));
580 klass
= mono_class_from_mono_type (type
->type
);
581 mono_class_init_checked (klass
, &error
);
582 if (mono_error_set_pending_exception (&error
))
585 if (klass
->element_class
->byval_arg
.type
== MONO_TYPE_VOID
) {
586 mono_set_pending_exception (mono_get_exception_not_supported ("Arrays of System.Void are not supported."));
590 if (bounds
&& (mono_array_length (bounds
) == 1) && (mono_array_get (bounds
, gint32
, 0) != 0))
591 /* vectors are not the same as one dimensional arrays with no-zero bounds */
596 aklass
= mono_bounded_array_class_get (klass
, mono_array_length (lengths
), bounded
);
598 sizes
= (uintptr_t *)alloca (aklass
->rank
* sizeof(intptr_t) * 2);
599 for (i
= 0; i
< aklass
->rank
; ++i
) {
600 sizes
[i
] = mono_array_get (lengths
, guint32
, i
);
602 sizes
[i
+ aklass
->rank
] = mono_array_get (bounds
, gint32
, i
);
604 sizes
[i
+ aklass
->rank
] = 0;
607 array
= mono_array_new_full_checked (mono_object_domain (type
), aklass
, sizes
, (intptr_t*)sizes
+ aklass
->rank
, &error
);
608 mono_error_set_pending_exception (&error
);
613 ICALL_EXPORT MonoArray
*
614 ves_icall_System_Array_CreateInstanceImpl64 (MonoReflectionType
*type
, MonoArray
*lengths
, MonoArray
*bounds
)
617 MonoClass
*aklass
, *klass
;
620 gboolean bounded
= FALSE
;
622 MONO_CHECK_ARG_NULL (type
, NULL
);
623 MONO_CHECK_ARG_NULL (lengths
, NULL
);
625 MONO_CHECK_ARG (lengths
, mono_array_length (lengths
) > 0, NULL
);
627 MONO_CHECK_ARG (bounds
, mono_array_length (lengths
) == mono_array_length (bounds
), NULL
);
629 for (i
= 0; i
< mono_array_length (lengths
); i
++) {
630 if ((mono_array_get (lengths
, gint64
, i
) < 0) ||
631 (mono_array_get (lengths
, gint64
, i
) > MONO_ARRAY_MAX_INDEX
)) {
632 mono_set_pending_exception (mono_get_exception_argument_out_of_range (NULL
));
637 klass
= mono_class_from_mono_type (type
->type
);
638 mono_class_init_checked (klass
, &error
);
639 if (mono_error_set_pending_exception (&error
))
642 if (bounds
&& (mono_array_length (bounds
) == 1) && (mono_array_get (bounds
, gint64
, 0) != 0))
643 /* vectors are not the same as one dimensional arrays with no-zero bounds */
648 aklass
= mono_bounded_array_class_get (klass
, mono_array_length (lengths
), bounded
);
650 sizes
= (uintptr_t *)alloca (aklass
->rank
* sizeof(intptr_t) * 2);
651 for (i
= 0; i
< aklass
->rank
; ++i
) {
652 sizes
[i
] = mono_array_get (lengths
, guint64
, i
);
654 sizes
[i
+ aklass
->rank
] = (mono_array_size_t
) mono_array_get (bounds
, guint64
, i
);
656 sizes
[i
+ aklass
->rank
] = 0;
659 array
= mono_array_new_full_checked (mono_object_domain (type
), aklass
, sizes
, (intptr_t*)sizes
+ aklass
->rank
, &error
);
660 mono_error_set_pending_exception (&error
);
666 ves_icall_System_Array_GetRank (MonoObject
*arr
)
668 return arr
->vtable
->klass
->rank
;
672 ves_icall_System_Array_GetLength (MonoArray
*arr
, gint32 dimension
)
674 gint32 rank
= arr
->obj
.vtable
->klass
->rank
;
677 if ((dimension
< 0) || (dimension
>= rank
)) {
678 mono_set_pending_exception (mono_get_exception_index_out_of_range ());
682 if (arr
->bounds
== NULL
)
683 length
= arr
->max_length
;
685 length
= arr
->bounds
[dimension
].length
;
687 #ifdef MONO_BIG_ARRAYS
688 if (length
> G_MAXINT32
) {
689 mono_set_pending_exception (mono_get_exception_overflow ());
697 ves_icall_System_Array_GetLongLength (MonoArray
*arr
, gint32 dimension
)
699 gint32 rank
= arr
->obj
.vtable
->klass
->rank
;
701 if ((dimension
< 0) || (dimension
>= rank
)) {
702 mono_set_pending_exception (mono_get_exception_index_out_of_range ());
706 if (arr
->bounds
== NULL
)
707 return arr
->max_length
;
709 return arr
->bounds
[dimension
].length
;
713 ves_icall_System_Array_GetLowerBound (MonoArray
*arr
, gint32 dimension
)
715 gint32 rank
= arr
->obj
.vtable
->klass
->rank
;
717 if ((dimension
< 0) || (dimension
>= rank
)) {
718 mono_set_pending_exception (mono_get_exception_index_out_of_range ());
722 if (arr
->bounds
== NULL
)
725 return arr
->bounds
[dimension
].lower_bound
;
729 ves_icall_System_Array_ClearInternal (MonoArray
*arr
, int idx
, int length
)
731 int sz
= mono_array_element_size (mono_object_class (arr
));
732 mono_gc_bzero_atomic (mono_array_addr_with_size_fast (arr
, sz
, idx
), length
* sz
);
736 ICALL_EXPORT gboolean
737 ves_icall_System_Array_FastCopy (MonoArray
*source
, int source_idx
, MonoArray
* dest
, int dest_idx
, int length
)
742 MonoVTable
*src_vtable
;
743 MonoVTable
*dest_vtable
;
744 MonoClass
*src_class
;
745 MonoClass
*dest_class
;
747 src_vtable
= source
->obj
.vtable
;
748 dest_vtable
= dest
->obj
.vtable
;
750 if (src_vtable
->rank
!= dest_vtable
->rank
)
753 if (source
->bounds
|| dest
->bounds
)
756 /* there's no integer overflow since mono_array_length returns an unsigned integer */
757 if ((dest_idx
+ length
> mono_array_length_fast (dest
)) ||
758 (source_idx
+ length
> mono_array_length_fast (source
)))
761 src_class
= src_vtable
->klass
->element_class
;
762 dest_class
= dest_vtable
->klass
->element_class
;
765 * Handle common cases.
768 /* Case1: object[] -> valuetype[] (ArrayList::ToArray)
769 We fallback to managed here since we need to typecheck each boxed valuetype before storing them in the dest array.
771 if (src_class
== mono_defaults
.object_class
&& dest_class
->valuetype
)
774 /* Check if we're copying a char[] <==> (u)short[] */
775 if (src_class
!= dest_class
) {
776 if (dest_class
->valuetype
|| dest_class
->enumtype
|| src_class
->valuetype
|| src_class
->enumtype
)
779 /* It's only safe to copy between arrays if we can ensure the source will always have a subtype of the destination. We bail otherwise. */
780 if (!mono_class_is_subclass_of (src_class
, dest_class
, FALSE
))
784 if (dest_class
->valuetype
) {
785 element_size
= mono_array_element_size (source
->obj
.vtable
->klass
);
786 source_addr
= mono_array_addr_with_size_fast (source
, element_size
, source_idx
);
787 if (dest_class
->has_references
) {
788 mono_value_copy_array (dest
, dest_idx
, source_addr
, length
);
790 dest_addr
= mono_array_addr_with_size_fast (dest
, element_size
, dest_idx
);
791 mono_gc_memmove_atomic (dest_addr
, source_addr
, element_size
* length
);
794 mono_array_memcpy_refs_fast (dest
, dest_idx
, source
, source_idx
, length
);
801 ves_icall_System_Array_GetGenericValueImpl (MonoArray
*arr
, guint32 pos
, gpointer value
)
807 ac
= (MonoClass
*)arr
->obj
.vtable
->klass
;
809 esize
= mono_array_element_size (ac
);
810 ea
= (gpointer
*)((char*)arr
->vector
+ (pos
* esize
));
812 mono_gc_memmove_atomic (value
, ea
, esize
);
816 ves_icall_System_Array_SetGenericValueImpl (MonoArray
*arr
, guint32 pos
, gpointer value
)
822 ac
= (MonoClass
*)arr
->obj
.vtable
->klass
;
823 ec
= ac
->element_class
;
825 esize
= mono_array_element_size (ac
);
826 ea
= (gpointer
*)((char*)arr
->vector
+ (pos
* esize
));
828 if (MONO_TYPE_IS_REFERENCE (&ec
->byval_arg
)) {
829 g_assert (esize
== sizeof (gpointer
));
830 mono_gc_wbarrier_generic_store (ea
, *(MonoObject
**)value
);
832 g_assert (ec
->inited
);
833 g_assert (esize
== mono_class_value_size (ec
, NULL
));
834 if (ec
->has_references
)
835 mono_gc_wbarrier_value_copy (ea
, value
, 1, ec
);
837 mono_gc_memmove_atomic (ea
, value
, esize
);
842 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray (MonoArrayHandle array
, MonoClassField
*field_handle
, MonoError
*error
)
846 MonoClass
*klass
= mono_handle_class (array
);
847 guint32 size
= mono_array_element_size (klass
);
848 MonoType
*type
= mono_type_get_underlying_type (&klass
->element_class
->byval_arg
);
850 const char *field_data
;
852 if (MONO_TYPE_IS_REFERENCE (type
) || type
->type
== MONO_TYPE_VALUETYPE
) {
853 mono_error_set_argument (error
, "array", "Cannot initialize array of non-primitive type");
857 if (!(field_handle
->type
->attrs
& FIELD_ATTRIBUTE_HAS_FIELD_RVA
)) {
858 mono_error_set_argument (error
, "field_handle", "Field '%s' doesn't have an RVA", mono_field_get_name (field_handle
));
862 size
*= MONO_HANDLE_GETVAL(array
, max_length
);
863 field_data
= mono_field_get_data (field_handle
);
865 if (size
> mono_type_size (field_handle
->type
, &align
)) {
866 mono_error_set_argument (error
, "field_handle", "Field not large enough to fill array");
870 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
872 guint ## n *data = (guint ## n *) mono_array_addr (MONO_HANDLE_RAW(array), char, 0); \
873 guint ## n *src = (guint ## n *) field_data; \
875 nEnt = (size / sizeof(guint ## n)); \
877 for (i = 0; i < nEnt; i++) { \
878 data[i] = read ## n (&src[i]); \
882 /* printf ("Initialize array with elements of %s type\n", klass->element_class->name); */
884 switch (type
->type
) {
901 memcpy (mono_array_addr (MONO_HANDLE_RAW(array
), char, 0), field_data
, size
);
905 memcpy (mono_array_addr (MONO_HANDLE_RAW(array
), char, 0), field_data
, size
);
910 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetOffsetToStringData (void)
912 return offsetof (MonoString
, chars
);
915 ICALL_EXPORT MonoObject
*
916 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_GetObjectValue (MonoObject
*obj
)
918 if ((obj
== NULL
) || (! (obj
->vtable
->klass
->valuetype
)))
922 MonoObject
*ret
= mono_object_clone_checked (obj
, &error
);
923 mono_error_set_pending_exception (&error
);
930 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor (MonoType
*handle
)
936 MONO_CHECK_ARG_NULL (handle
,);
938 klass
= mono_class_from_mono_type (handle
);
939 MONO_CHECK_ARG (handle
, klass
,);
941 if (mono_class_is_gtd (klass
))
944 vtable
= mono_class_vtable_full (mono_domain_get (), klass
, &error
);
945 if (!is_ok (&error
)) {
946 mono_error_set_pending_exception (&error
);
950 /* This will call the type constructor */
951 if (!mono_runtime_class_init_full (vtable
, &error
))
952 mono_error_set_pending_exception (&error
);
956 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunModuleConstructor (MonoImage
*image
)
960 mono_image_check_for_module_cctor (image
);
961 if (image
->has_module_cctor
) {
962 MonoClass
*module_klass
= mono_class_get_checked (image
, MONO_TOKEN_TYPE_DEF
| 1, &error
);
963 if (!mono_error_ok (&error
)) {
964 mono_error_set_pending_exception (&error
);
967 /*It's fine to raise the exception here*/
968 MonoVTable
* vtable
= mono_class_vtable_full (mono_domain_get (), module_klass
, &error
);
969 if (!is_ok (&error
)) {
970 mono_error_set_pending_exception (&error
);
973 if (!mono_runtime_class_init_full (vtable
, &error
))
974 mono_error_set_pending_exception (&error
);
978 ICALL_EXPORT MonoBoolean
979 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_SufficientExecutionStack (void)
981 #if defined(TARGET_WIN32) || defined(HOST_WIN32)
982 // It does not work on win32
983 #elif defined(TARGET_ANDROID)
990 MonoInternalThread
*thread
;
992 mono_thread_info_get_stack_bounds (&stack_addr
, &stack_size
);
993 /* if we have no info we are optimistic and assume there is enough room */
997 thread
= mono_thread_internal_current ();
998 // .net seems to check that at least 50% of stack is available
999 min_size
= thread
->stack_size
/ 2;
1001 // TODO: It's not always set
1005 current
= (guint8
*)&stack_addr
;
1006 if (current
> stack_addr
) {
1007 if ((current
- stack_addr
) < min_size
)
1010 if (current
- (stack_addr
- stack_size
) < min_size
)
1017 ICALL_EXPORT MonoObject
*
1018 ves_icall_System_Object_MemberwiseClone (MonoObject
*this_obj
)
1021 MonoObject
*ret
= mono_object_clone_checked (this_obj
, &error
);
1022 mono_error_set_pending_exception (&error
);
1028 ves_icall_System_ValueType_InternalGetHashCode (MonoObject
*this_obj
, MonoArray
**fields
)
1032 MonoObject
**values
= NULL
;
1035 gint32 result
= (int)(gsize
)mono_defaults
.int32_class
;
1036 MonoClassField
* field
;
1039 klass
= mono_object_class (this_obj
);
1041 if (mono_class_num_fields (klass
) == 0)
1045 * Compute the starting value of the hashcode for fields of primitive
1046 * types, and return the remaining fields in an array to the managed side.
1047 * This way, we can avoid costly reflection operations in managed code.
1050 while ((field
= mono_class_get_fields (klass
, &iter
))) {
1051 if (field
->type
->attrs
& FIELD_ATTRIBUTE_STATIC
)
1053 if (mono_field_is_deleted (field
))
1055 /* FIXME: Add more types */
1056 switch (field
->type
->type
) {
1058 result
^= *(gint32
*)((guint8
*)this_obj
+ field
->offset
);
1060 case MONO_TYPE_STRING
: {
1062 s
= *(MonoString
**)((guint8
*)this_obj
+ field
->offset
);
1064 result
^= mono_string_hash (s
);
1069 values
= g_newa (MonoObject
*, mono_class_num_fields (klass
));
1070 o
= mono_field_get_value_object_checked (mono_object_domain (this_obj
), field
, this_obj
, &error
);
1071 if (!is_ok (&error
)) {
1072 mono_error_set_pending_exception (&error
);
1075 values
[count
++] = o
;
1081 MonoArray
*fields_arr
= mono_array_new_checked (mono_domain_get (), mono_defaults
.object_class
, count
, &error
);
1082 if (mono_error_set_pending_exception (&error
))
1084 mono_gc_wbarrier_generic_store (fields
, (MonoObject
*) fields_arr
);
1085 for (i
= 0; i
< count
; ++i
)
1086 mono_array_setref (*fields
, i
, values
[i
]);
1093 ICALL_EXPORT MonoBoolean
1094 ves_icall_System_ValueType_Equals (MonoObject
*this_obj
, MonoObject
*that
, MonoArray
**fields
)
1098 MonoObject
**values
= NULL
;
1100 MonoClassField
* field
;
1104 MONO_CHECK_ARG_NULL (that
, FALSE
);
1106 if (this_obj
->vtable
!= that
->vtable
)
1109 klass
= mono_object_class (this_obj
);
1111 if (klass
->enumtype
&& mono_class_enum_basetype (klass
) && mono_class_enum_basetype (klass
)->type
== MONO_TYPE_I4
)
1112 return (*(gint32
*)((guint8
*)this_obj
+ sizeof (MonoObject
)) == *(gint32
*)((guint8
*)that
+ sizeof (MonoObject
)));
1115 * Do the comparison for fields of primitive type and return a result if
1116 * possible. Otherwise, return the remaining fields in an array to the
1117 * managed side. This way, we can avoid costly reflection operations in
1122 while ((field
= mono_class_get_fields (klass
, &iter
))) {
1123 if (field
->type
->attrs
& FIELD_ATTRIBUTE_STATIC
)
1125 if (mono_field_is_deleted (field
))
1127 /* FIXME: Add more types */
1128 switch (field
->type
->type
) {
1131 case MONO_TYPE_BOOLEAN
:
1132 if (*((guint8
*)this_obj
+ field
->offset
) != *((guint8
*)that
+ field
->offset
))
1137 case MONO_TYPE_CHAR
:
1138 if (*(gint16
*)((guint8
*)this_obj
+ field
->offset
) != *(gint16
*)((guint8
*)that
+ field
->offset
))
1143 if (*(gint32
*)((guint8
*)this_obj
+ field
->offset
) != *(gint32
*)((guint8
*)that
+ field
->offset
))
1148 if (*(gint64
*)((guint8
*)this_obj
+ field
->offset
) != *(gint64
*)((guint8
*)that
+ field
->offset
))
1152 if (*(float*)((guint8
*)this_obj
+ field
->offset
) != *(float*)((guint8
*)that
+ field
->offset
))
1156 if (*(double*)((guint8
*)this_obj
+ field
->offset
) != *(double*)((guint8
*)that
+ field
->offset
))
1161 case MONO_TYPE_STRING
: {
1162 MonoString
*s1
, *s2
;
1163 guint32 s1len
, s2len
;
1164 s1
= *(MonoString
**)((guint8
*)this_obj
+ field
->offset
);
1165 s2
= *(MonoString
**)((guint8
*)that
+ field
->offset
);
1168 if ((s1
== NULL
) || (s2
== NULL
))
1170 s1len
= mono_string_length (s1
);
1171 s2len
= mono_string_length (s2
);
1175 if (memcmp (mono_string_chars (s1
), mono_string_chars (s2
), s1len
* sizeof (gunichar2
)) != 0)
1181 values
= g_newa (MonoObject
*, mono_class_num_fields (klass
) * 2);
1182 o
= mono_field_get_value_object_checked (mono_object_domain (this_obj
), field
, this_obj
, &error
);
1183 if (!is_ok (&error
)) {
1184 mono_error_set_pending_exception (&error
);
1187 values
[count
++] = o
;
1188 o
= mono_field_get_value_object_checked (mono_object_domain (this_obj
), field
, that
, &error
);
1189 if (!is_ok (&error
)) {
1190 mono_error_set_pending_exception (&error
);
1193 values
[count
++] = o
;
1196 if (klass
->enumtype
)
1197 /* enums only have one non-static field */
1203 MonoArray
*fields_arr
= mono_array_new_checked (mono_domain_get (), mono_defaults
.object_class
, count
, &error
);
1204 if (mono_error_set_pending_exception (&error
))
1206 mono_gc_wbarrier_generic_store (fields
, (MonoObject
*) fields_arr
);
1207 for (i
= 0; i
< count
; ++i
)
1208 mono_array_setref_fast (*fields
, i
, values
[i
]);
1215 ICALL_EXPORT MonoReflectionTypeHandle
1216 ves_icall_System_Object_GetType (MonoObjectHandle obj
, MonoError
*error
)
1219 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (obj
);
1220 MonoClass
*klass
= mono_handle_class (obj
);
1221 #ifndef DISABLE_REMOTING
1222 if (mono_class_is_transparent_proxy (klass
)) {
1223 MonoTransparentProxyHandle proxy_obj
= MONO_HANDLE_CAST (MonoTransparentProxy
, obj
);
1224 MonoRemoteClass
*remote_class
= MONO_HANDLE_GETVAL (proxy_obj
, remote_class
);
1225 MonoType
*proxy_type
= &remote_class
->proxy_class
->byval_arg
;
1226 return mono_type_get_object_handle (domain
, proxy_type
, error
);
1229 return mono_type_get_object_handle (domain
, &klass
->byval_arg
, error
);
1233 get_executing (MonoMethod
*m
, gint32 no
, gint32 ilo
, gboolean managed
, gpointer data
)
1235 MonoMethod
**dest
= (MonoMethod
**)data
;
1237 /* skip unmanaged frames */
1242 if (!strcmp (m
->klass
->name_space
, "System.Reflection"))
1251 get_caller_no_reflection (MonoMethod
*m
, gint32 no
, gint32 ilo
, gboolean managed
, gpointer data
)
1253 MonoMethod
**dest
= (MonoMethod
**)data
;
1255 /* skip unmanaged frames */
1259 if (m
->wrapper_type
!= MONO_WRAPPER_NONE
)
1267 if (m
->klass
->image
== mono_defaults
.corlib
&& !strcmp (m
->klass
->name_space
, "System.Reflection"))
1278 get_caller_no_system_or_reflection (MonoMethod
*m
, gint32 no
, gint32 ilo
, gboolean managed
, gpointer data
)
1280 MonoMethod
**dest
= (MonoMethod
**)data
;
1282 /* skip unmanaged frames */
1286 if (m
->wrapper_type
!= MONO_WRAPPER_NONE
)
1294 if (m
->klass
->image
== mono_defaults
.corlib
&& ((!strcmp (m
->klass
->name_space
, "System.Reflection"))
1295 || (!strcmp (m
->klass
->name_space
, "System"))))
1305 static MonoReflectionTypeHandle
1306 type_from_parsed_name (MonoTypeNameParse
*info
, MonoBoolean ignoreCase
, MonoAssembly
**caller_assembly
, MonoError
*error
)
1308 MonoMethod
*m
, *dest
;
1310 MonoType
*type
= NULL
;
1311 MonoAssembly
*assembly
= NULL
;
1312 gboolean type_resolve
= FALSE
;
1313 MonoImage
*rootimage
= NULL
;
1318 * We must compute the calling assembly as type loading must happen under a metadata context.
1319 * For example. The main assembly is a.exe and Type.GetType is called from dir/b.dll. Without
1320 * the metadata context (basedir currently) set to dir/b.dll we won't be able to load a dir/c.dll.
1322 m
= mono_method_get_last_managed ();
1324 if (m
&& m
->klass
->image
!= mono_defaults
.corlib
) {
1325 /* Happens with inlining */
1327 /* Ugly hack: type_from_parsed_name is called from
1328 * System.Type.internal_from_name, which is called most
1329 * directly from System.Type.GetType(string,bool,bool) but
1330 * also indirectly from places such as
1331 * System.Type.GetType(string,func,func) (via
1332 * System.TypeNameParser.GetType and System.TypeSpec.Resolve)
1333 * so we need to skip over all of those to find the true caller.
1335 * It would be nice if we had stack marks.
1337 mono_stack_walk_no_il (get_caller_no_system_or_reflection
, &dest
);
1343 * FIXME: mono_method_get_last_managed() sometimes returns NULL, thus
1344 * causing ves_icall_System_Reflection_Assembly_GetCallingAssembly()
1345 * to crash. This only seems to happen in some strange remoting
1346 * scenarios and I was unable to figure out what's happening there.
1347 * Dec 10, 2005 - Martin.
1351 assembly
= dest
->klass
->image
->assembly
;
1352 type_resolve
= TRUE
;
1353 rootimage
= assembly
->image
;
1355 g_warning (G_STRLOC
);
1357 *caller_assembly
= assembly
;
1359 if (info
->assembly
.name
)
1360 assembly
= mono_assembly_load (&info
->assembly
, assembly
? assembly
->basedir
: NULL
, NULL
);
1363 /* When loading from the current assembly, AppDomain.TypeResolve will not be called yet */
1364 type
= mono_reflection_get_type_checked (rootimage
, assembly
->image
, info
, ignoreCase
, &type_resolve
, error
);
1370 // Say we're looking for System.Generic.Dict<int, Local>
1371 // we FAIL the get type above, because S.G.Dict isn't in assembly->image. So we drop down here.
1372 // but then we FAIL AGAIN because now we pass null as the image and the rootimage and everything
1373 // is messed up when we go to construct the Local as the type arg...
1375 // By contrast, if we started with Mine<System.Generic.Dict<int, Local>> we'd go in with assembly->image
1376 // as the root and then even the detour into generics would still not screw us when we went to load Local.
1377 if (!info
->assembly
.name
&& !type
) {
1379 type
= mono_reflection_get_type_checked (rootimage
, NULL
, info
, ignoreCase
, &type_resolve
, error
);
1383 if (assembly
&& !type
&& type_resolve
) {
1384 type_resolve
= FALSE
; /* This will invoke TypeResolve if not done in the first 'if' */
1385 type
= mono_reflection_get_type_checked (rootimage
, assembly
->image
, info
, ignoreCase
, &type_resolve
, error
);
1393 return mono_type_get_object_handle (mono_domain_get (), type
, error
);
1395 return MONO_HANDLE_NEW (MonoReflectionType
, NULL
);
1398 ICALL_EXPORT MonoReflectionTypeHandle
1399 ves_icall_System_Type_internal_from_name (MonoStringHandle name
,
1400 MonoBoolean throwOnError
,
1401 MonoBoolean ignoreCase
,
1405 MonoTypeNameParse info
;
1407 MonoAssembly
*caller_assembly
;
1408 MonoReflectionTypeHandle type
= MONO_HANDLE_NEW (MonoReflectionType
, NULL
);
1410 char *str
= mono_string_handle_to_utf8 (name
, error
);
1414 parsedOk
= mono_reflection_parse_type (str
, &info
);
1416 /* mono_reflection_parse_type() mangles the string */
1418 mono_reflection_free_type_info (&info
);
1420 mono_error_set_argument (error
, "typeName", "failed parse: %s", str
);
1424 MONO_HANDLE_ASSIGN (type
, type_from_parsed_name (&info
, ignoreCase
, &caller_assembly
, error
));
1426 if (!is_ok (error
)) {
1427 mono_reflection_free_type_info (&info
);
1431 if (MONO_HANDLE_IS_NULL (type
)) {
1433 char *tname
= info
.name_space
? g_strdup_printf ("%s.%s", info
.name_space
, info
.name
) : g_strdup (info
.name
);
1435 if (info
.assembly
.name
)
1436 aname
= mono_stringify_assembly_name (&info
.assembly
);
1437 else if (caller_assembly
)
1438 aname
= mono_stringify_assembly_name (mono_assembly_get_name (caller_assembly
));
1440 aname
= g_strdup ("");
1441 mono_error_set_type_load_name (error
, tname
, aname
, "");
1443 mono_reflection_free_type_info (&info
);
1449 if (!is_ok (error
)) {
1451 mono_error_cleanup (error
);
1452 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
1459 ICALL_EXPORT MonoReflectionTypeHandle
1460 ves_icall_System_Type_internal_from_handle (MonoType
*handle
, MonoError
*error
)
1463 MonoDomain
*domain
= mono_domain_get ();
1465 return mono_type_get_object_handle (domain
, handle
, error
);
1468 ICALL_EXPORT MonoType
*
1469 ves_icall_Mono_RuntimeClassHandle_GetTypeFromClass (MonoClass
*klass
)
1471 return mono_class_get_type (klass
);
1475 ves_icall_Mono_RuntimeGPtrArrayHandle_GPtrArrayFree (GPtrArray
*ptr_array
)
1477 g_ptr_array_free (ptr_array
, TRUE
);
1481 ves_icall_Mono_SafeStringMarshal_GFree (void *c_str
)
1487 ves_icall_Mono_SafeStringMarshal_StringToUtf8 (MonoString
*s
)
1490 char *res
= mono_string_to_utf8_checked (s
, &error
);
1491 mono_error_set_pending_exception (&error
);
1495 /* System.TypeCode */
1514 TYPECODE_STRING
= 18
1517 ICALL_EXPORT guint32
1518 ves_icall_type_GetTypeCodeInternal (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
1521 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
1525 return TYPECODE_OBJECT
;
1529 case MONO_TYPE_VOID
:
1530 return TYPECODE_OBJECT
;
1531 case MONO_TYPE_BOOLEAN
:
1532 return TYPECODE_BOOLEAN
;
1534 return TYPECODE_BYTE
;
1536 return TYPECODE_SBYTE
;
1538 return TYPECODE_UINT16
;
1540 return TYPECODE_INT16
;
1541 case MONO_TYPE_CHAR
:
1542 return TYPECODE_CHAR
;
1546 return TYPECODE_OBJECT
;
1548 return TYPECODE_UINT32
;
1550 return TYPECODE_INT32
;
1552 return TYPECODE_UINT64
;
1554 return TYPECODE_INT64
;
1556 return TYPECODE_SINGLE
;
1558 return TYPECODE_DOUBLE
;
1559 case MONO_TYPE_VALUETYPE
: {
1560 MonoClass
*klass
= type
->data
.klass
;
1562 if (klass
->enumtype
) {
1563 t
= mono_class_enum_basetype (klass
)->type
;
1565 } else if (mono_is_corlib_image (klass
->image
)) {
1566 if (strcmp (klass
->name_space
, "System") == 0) {
1567 if (strcmp (klass
->name
, "Decimal") == 0)
1568 return TYPECODE_DECIMAL
;
1569 else if (strcmp (klass
->name
, "DateTime") == 0)
1570 return TYPECODE_DATETIME
;
1573 return TYPECODE_OBJECT
;
1575 case MONO_TYPE_STRING
:
1576 return TYPECODE_STRING
;
1577 case MONO_TYPE_SZARRAY
:
1578 case MONO_TYPE_ARRAY
:
1579 case MONO_TYPE_OBJECT
:
1581 case MONO_TYPE_MVAR
:
1582 case MONO_TYPE_TYPEDBYREF
:
1583 return TYPECODE_OBJECT
;
1584 case MONO_TYPE_CLASS
:
1586 MonoClass
*klass
= type
->data
.klass
;
1587 if (klass
->image
== mono_defaults
.corlib
&& strcmp (klass
->name_space
, "System") == 0) {
1588 if (strcmp (klass
->name
, "DBNull") == 0)
1589 return TYPECODE_DBNULL
;
1592 return TYPECODE_OBJECT
;
1593 case MONO_TYPE_GENERICINST
:
1594 return TYPECODE_OBJECT
;
1596 g_error ("type 0x%02x not handled in GetTypeCode()", t
);
1602 mono_type_get_underlying_type_ignore_byref (MonoType
*type
)
1604 if (type
->type
== MONO_TYPE_VALUETYPE
&& type
->data
.klass
->enumtype
)
1605 return mono_class_enum_basetype (type
->data
.klass
);
1606 if (type
->type
== MONO_TYPE_GENERICINST
&& type
->data
.generic_class
->container_class
->enumtype
)
1607 return mono_class_enum_basetype (type
->data
.generic_class
->container_class
);
1611 ICALL_EXPORT guint32
1612 ves_icall_RuntimeTypeHandle_type_is_assignable_from (MonoReflectionTypeHandle ref_type
, MonoReflectionTypeHandle ref_c
, MonoError
*error
)
1616 g_assert (!MONO_HANDLE_IS_NULL (ref_type
));
1618 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
1619 MonoClass
*klass
= mono_class_from_mono_type (type
);
1620 MonoType
*ctype
= MONO_HANDLE_GETVAL (ref_c
, type
);
1621 MonoClass
*klassc
= mono_class_from_mono_type (ctype
);
1623 if (type
->byref
^ ctype
->byref
)
1627 MonoType
*t
= mono_type_get_underlying_type_ignore_byref (type
);
1628 MonoType
*ot
= mono_type_get_underlying_type_ignore_byref (ctype
);
1630 klass
= mono_class_from_mono_type (t
);
1631 klassc
= mono_class_from_mono_type (ot
);
1633 if (mono_type_is_primitive (t
)) {
1634 return mono_type_is_primitive (ot
) && klass
->instance_size
== klassc
->instance_size
;
1635 } else if (t
->type
== MONO_TYPE_VAR
|| t
->type
== MONO_TYPE_MVAR
) {
1636 return t
->type
== ot
->type
&& t
->data
.generic_param
->num
== ot
->data
.generic_param
->num
;
1637 } else if (t
->type
== MONO_TYPE_PTR
|| t
->type
== MONO_TYPE_FNPTR
) {
1638 return t
->type
== ot
->type
;
1640 if (ot
->type
== MONO_TYPE_VAR
|| ot
->type
== MONO_TYPE_MVAR
)
1643 if (klass
->valuetype
)
1644 return klass
== klassc
;
1645 return klass
->valuetype
== klassc
->valuetype
;
1648 return mono_class_is_assignable_from (klass
, klassc
);
1651 ICALL_EXPORT guint32
1652 ves_icall_RuntimeTypeHandle_IsInstanceOfType (MonoReflectionTypeHandle ref_type
, MonoObjectHandle obj
, MonoError
*error
)
1655 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
1656 MonoClass
*klass
= mono_class_from_mono_type (type
);
1657 mono_class_init_checked (klass
, error
);
1658 return_val_if_nok (error
, FALSE
);
1659 MonoObjectHandle inst
= mono_object_handle_isinst (obj
, klass
, error
);
1660 return_val_if_nok (error
, FALSE
);
1661 return !MONO_HANDLE_IS_NULL (inst
);
1664 ICALL_EXPORT guint32
1665 ves_icall_RuntimeTypeHandle_GetAttributes (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
1668 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
1669 MonoClass
*klass
= mono_class_from_mono_type (type
);
1670 return mono_class_get_flags (klass
);
1673 ICALL_EXPORT MonoReflectionMarshalAsAttributeHandle
1674 ves_icall_System_Reflection_FieldInfo_get_marshal_info (MonoReflectionFieldHandle field_h
, MonoError
*error
)
1677 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (field_h
);
1678 MonoClassField
*field
= MONO_HANDLE_GETVAL (field_h
, field
);
1679 MonoClass
*klass
= field
->parent
;
1681 MonoGenericClass
*gklass
= mono_class_try_get_generic_class (klass
);
1682 if (mono_class_is_gtd (klass
) ||
1683 (gklass
&& gklass
->context
.class_inst
->is_open
))
1684 return MONO_HANDLE_CAST (MonoReflectionMarshalAsAttribute
, NULL_HANDLE
);
1686 MonoType
*ftype
= mono_field_get_type (field
);
1687 if (ftype
&& !(ftype
->attrs
& FIELD_ATTRIBUTE_HAS_FIELD_MARSHAL
))
1688 return MONO_HANDLE_CAST (MonoReflectionMarshalAsAttribute
, NULL_HANDLE
);
1690 MonoMarshalType
*info
= mono_marshal_load_type_info (klass
);
1692 for (int i
= 0; i
< info
->num_fields
; ++i
) {
1693 if (info
->fields
[i
].field
== field
) {
1694 if (!info
->fields
[i
].mspec
)
1695 return MONO_HANDLE_CAST (MonoReflectionMarshalAsAttribute
, NULL_HANDLE
);
1697 return mono_reflection_marshal_as_attribute_from_marshal_spec (domain
, klass
, info
->fields
[i
].mspec
, error
);
1702 return MONO_HANDLE_CAST (MonoReflectionMarshalAsAttribute
, NULL_HANDLE
);
1705 ICALL_EXPORT MonoReflectionFieldHandle
1706 ves_icall_System_Reflection_FieldInfo_internal_from_handle_type (MonoClassField
*handle
, MonoType
*type
, MonoError
*error
)
1715 klass
= handle
->parent
;
1717 klass
= mono_class_from_mono_type (type
);
1719 gboolean found
= klass
== handle
->parent
|| mono_class_has_parent (klass
, handle
->parent
);
1722 /* The managed code will throw the exception */
1723 return MONO_HANDLE_CAST (MonoReflectionField
, NULL_HANDLE
);
1726 return mono_field_get_object_handle (mono_domain_get (), klass
, handle
, error
);
1729 ICALL_EXPORT MonoReflectionEventHandle
1730 ves_icall_System_Reflection_EventInfo_internal_from_handle_type (MonoEvent
*handle
, MonoType
*type
, MonoError
*error
)
1739 klass
= handle
->parent
;
1741 klass
= mono_class_from_mono_type (type
);
1743 gboolean found
= klass
== handle
->parent
|| mono_class_has_parent (klass
, handle
->parent
);
1745 /* Managed code will throw an exception */
1746 return MONO_HANDLE_CAST (MonoReflectionEvent
, NULL_HANDLE
);
1749 return mono_event_get_object_handle (mono_domain_get (), klass
, handle
, error
);
1753 ICALL_EXPORT MonoReflectionPropertyHandle
1754 ves_icall_System_Reflection_PropertyInfo_internal_from_handle_type (MonoProperty
*handle
, MonoType
*type
, MonoError
*error
)
1762 klass
= handle
->parent
;
1764 klass
= mono_class_from_mono_type (type
);
1766 gboolean found
= klass
== handle
->parent
|| mono_class_has_parent (klass
, handle
->parent
);
1768 /* Managed code will throw an exception */
1769 return MONO_HANDLE_CAST (MonoReflectionProperty
, NULL_HANDLE
);
1772 return mono_property_get_object_handle (mono_domain_get (), klass
, handle
, error
);
1775 ICALL_EXPORT MonoArrayHandle
1776 ves_icall_System_Reflection_FieldInfo_GetTypeModifiers (MonoReflectionFieldHandle field_h
, MonoBoolean optional
, MonoError
*error
)
1779 MonoClassField
*field
= MONO_HANDLE_GETVAL (field_h
, field
);
1781 MonoType
*type
= mono_field_get_type_checked (field
, error
);
1783 return MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
);
1785 return type_array_from_modifiers (field
->parent
->image
, type
, optional
, error
);
1789 vell_icall_get_method_attributes (MonoMethod
*method
)
1791 return method
->flags
;
1795 ves_icall_get_method_info (MonoMethod
*method
, MonoMethodInfo
*info
, MonoError
*error
)
1797 MonoDomain
*domain
= mono_domain_get ();
1799 MonoMethodSignature
* sig
= mono_method_signature_checked (method
, error
);
1800 return_if_nok (error
);
1802 MonoReflectionTypeHandle rt
= mono_type_get_object_handle (domain
, &method
->klass
->byval_arg
, error
);
1803 return_if_nok (error
);
1805 MONO_STRUCT_SETREF (info
, parent
, MONO_HANDLE_RAW (rt
));
1807 MONO_HANDLE_ASSIGN (rt
, mono_type_get_object_handle (domain
, sig
->ret
, error
));
1808 return_if_nok (error
);
1810 MONO_STRUCT_SETREF (info
, ret
, MONO_HANDLE_RAW (rt
));
1812 info
->attrs
= method
->flags
;
1813 info
->implattrs
= method
->iflags
;
1815 if (sig
->call_convention
== MONO_CALL_DEFAULT
)
1816 callconv
= sig
->sentinelpos
>= 0 ? 2 : 1;
1818 if (sig
->call_convention
== MONO_CALL_VARARG
|| sig
->sentinelpos
>= 0)
1823 callconv
|= (sig
->hasthis
<< 5) | (sig
->explicit_this
<< 6);
1824 info
->callconv
= callconv
;
1827 ICALL_EXPORT MonoArrayHandle
1828 ves_icall_System_Reflection_MonoMethodInfo_get_parameter_info (MonoMethod
*method
, MonoReflectionMethodHandle member
, MonoError
*error
)
1831 MonoDomain
*domain
= mono_domain_get ();
1833 MonoReflectionTypeHandle reftype
= MONO_HANDLE_NEW (MonoReflectionType
, NULL
);
1834 MONO_HANDLE_GET (reftype
, member
, reftype
);
1835 MonoClass
*klass
= NULL
;
1836 if (!MONO_HANDLE_IS_NULL (reftype
))
1837 klass
= mono_class_from_mono_type (MONO_HANDLE_GETVAL (reftype
, type
));
1838 return mono_param_get_objects_internal (domain
, method
, klass
, error
);
1841 ICALL_EXPORT MonoReflectionMarshalAsAttributeHandle
1842 ves_icall_System_MonoMethodInfo_get_retval_marshal (MonoMethod
*method
, MonoError
*error
)
1845 MonoDomain
*domain
= mono_domain_get ();
1846 MonoReflectionMarshalAsAttributeHandle res
= MONO_HANDLE_NEW (MonoReflectionMarshalAsAttribute
, NULL
);
1848 MonoMarshalSpec
**mspecs
= g_new (MonoMarshalSpec
*, mono_method_signature (method
)->param_count
+ 1);
1849 mono_method_get_marshal_info (method
, mspecs
);
1852 MONO_HANDLE_ASSIGN (res
, mono_reflection_marshal_as_attribute_from_marshal_spec (domain
, method
->klass
, mspecs
[0], error
));
1858 for (int i
= mono_method_signature (method
)->param_count
; i
>= 0; i
--)
1860 mono_metadata_free_marshal_spec (mspecs
[i
]);
1867 ves_icall_MonoField_GetFieldOffset (MonoReflectionField
*field
)
1869 MonoClass
*parent
= field
->field
->parent
;
1870 mono_class_setup_fields (parent
);
1872 return field
->field
->offset
- sizeof (MonoObject
);
1875 ICALL_EXPORT MonoReflectionTypeHandle
1876 ves_icall_MonoField_GetParentType (MonoReflectionFieldHandle field
, MonoBoolean declaring
, MonoError
*error
)
1879 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (field
);
1883 MonoClassField
*f
= MONO_HANDLE_GETVAL (field
, field
);
1886 parent
= MONO_HANDLE_GETVAL (field
, klass
);
1889 return mono_type_get_object_handle (domain
, &parent
->byval_arg
, error
);
1892 ICALL_EXPORT MonoObject
*
1893 ves_icall_MonoField_GetValueInternal (MonoReflectionField
*field
, MonoObject
*obj
)
1896 MonoClass
*fklass
= field
->klass
;
1897 MonoClassField
*cf
= field
->field
;
1898 MonoDomain
*domain
= mono_object_domain (field
);
1900 if (fklass
->image
->assembly
->ref_only
) {
1901 mono_set_pending_exception (mono_get_exception_invalid_operation (
1902 "It is illegal to get the value on a field on a type loaded using the ReflectionOnly methods."));
1906 if (mono_security_core_clr_enabled () &&
1907 !mono_security_core_clr_ensure_reflection_access_field (cf
, &error
)) {
1908 mono_error_set_pending_exception (&error
);
1912 MonoObject
* result
= mono_field_get_value_object_checked (domain
, cf
, obj
, &error
);
1913 mono_error_set_pending_exception (&error
);
1918 ves_icall_MonoField_SetValueInternal (MonoReflectionField
*field
, MonoObject
*obj
, MonoObject
*value
)
1921 MonoClassField
*cf
= field
->field
;
1925 if (field
->klass
->image
->assembly
->ref_only
) {
1926 mono_set_pending_exception (mono_get_exception_invalid_operation (
1927 "It is illegal to set the value on a field on a type loaded using the ReflectionOnly methods."));
1931 if (mono_security_core_clr_enabled () &&
1932 !mono_security_core_clr_ensure_reflection_access_field (cf
, &error
)) {
1933 mono_error_set_pending_exception (&error
);
1937 type
= mono_field_get_type_checked (cf
, &error
);
1938 if (!mono_error_ok (&error
)) {
1939 mono_error_set_pending_exception (&error
);
1943 v
= (gchar
*) value
;
1945 switch (type
->type
) {
1948 case MONO_TYPE_BOOLEAN
:
1951 case MONO_TYPE_CHAR
:
1960 case MONO_TYPE_VALUETYPE
:
1963 v
+= sizeof (MonoObject
);
1965 case MONO_TYPE_STRING
:
1966 case MONO_TYPE_OBJECT
:
1967 case MONO_TYPE_CLASS
:
1968 case MONO_TYPE_ARRAY
:
1969 case MONO_TYPE_SZARRAY
:
1972 case MONO_TYPE_GENERICINST
: {
1973 MonoGenericClass
*gclass
= type
->data
.generic_class
;
1974 g_assert (!gclass
->context
.class_inst
->is_open
);
1976 if (mono_class_is_nullable (mono_class_from_mono_type (type
))) {
1977 MonoClass
*nklass
= mono_class_from_mono_type (type
);
1978 MonoObject
*nullable
;
1981 * Convert the boxed vtype into a Nullable structure.
1982 * This is complicated by the fact that Nullables have
1983 * a variable structure.
1985 nullable
= mono_object_new_checked (mono_domain_get (), nklass
, &error
);
1986 if (!mono_error_ok (&error
)) {
1987 mono_error_set_pending_exception (&error
);
1991 mono_nullable_init ((guint8
*)mono_object_unbox (nullable
), value
, nklass
);
1993 v
= (gchar
*)mono_object_unbox (nullable
);
1996 if (gclass
->container_class
->valuetype
&& (v
!= NULL
))
1997 v
+= sizeof (MonoObject
);
2001 g_error ("type 0x%x not handled in "
2002 "ves_icall_FieldInfo_SetValueInternal", type
->type
);
2007 if (type
->attrs
& FIELD_ATTRIBUTE_STATIC
) {
2008 MonoVTable
*vtable
= mono_class_vtable_full (mono_object_domain (field
), cf
->parent
, &error
);
2009 if (!is_ok (&error
)) {
2010 mono_error_set_pending_exception (&error
);
2013 if (!vtable
->initialized
) {
2014 if (!mono_runtime_class_init_full (vtable
, &error
)) {
2015 mono_error_set_pending_exception (&error
);
2019 mono_field_static_set_value (vtable
, cf
, v
);
2021 mono_field_set_value (obj
, cf
, v
);
2026 ves_icall_System_RuntimeFieldHandle_SetValueDirect (MonoReflectionField
*field
, MonoReflectionType
*field_type
, MonoTypedRef
*obj
, MonoObject
*value
, MonoReflectionType
*context_type
)
2035 if (!MONO_TYPE_ISSTRUCT (&f
->parent
->byval_arg
)) {
2036 mono_set_pending_exception (mono_get_exception_not_implemented (NULL
));
2040 if (MONO_TYPE_IS_REFERENCE (f
->type
))
2041 mono_copy_value (f
->type
, (guint8
*)obj
->value
+ f
->offset
- sizeof (MonoObject
), value
, FALSE
);
2043 mono_copy_value (f
->type
, (guint8
*)obj
->value
+ f
->offset
- sizeof (MonoObject
), mono_object_unbox (value
), FALSE
);
2046 ICALL_EXPORT MonoObject
*
2047 ves_icall_MonoField_GetRawConstantValue (MonoReflectionField
*rfield
)
2049 MonoObject
*o
= NULL
;
2050 MonoClassField
*field
= rfield
->field
;
2052 MonoDomain
*domain
= mono_object_domain (rfield
);
2054 MonoTypeEnum def_type
;
2055 const char *def_value
;
2059 mono_class_init (field
->parent
);
2061 t
= mono_field_get_type_checked (field
, &error
);
2062 if (!mono_error_ok (&error
)) {
2063 mono_error_set_pending_exception (&error
);
2067 if (!(t
->attrs
& FIELD_ATTRIBUTE_HAS_DEFAULT
)) {
2068 mono_set_pending_exception (mono_get_exception_invalid_operation (NULL
));
2072 if (image_is_dynamic (field
->parent
->image
)) {
2073 MonoClass
*klass
= field
->parent
;
2074 int fidx
= field
- klass
->fields
;
2075 MonoFieldDefaultValue
*def_values
= mono_class_get_field_def_values (klass
);
2077 g_assert (def_values
);
2078 def_type
= def_values
[fidx
].def_type
;
2079 def_value
= def_values
[fidx
].data
;
2081 if (def_type
== MONO_TYPE_END
) {
2082 mono_set_pending_exception (mono_get_exception_invalid_operation (NULL
));
2086 def_value
= mono_class_get_field_default_value (field
, &def_type
);
2087 /* FIXME, maybe we should try to raise TLE if field->parent is broken */
2089 mono_set_pending_exception (mono_get_exception_invalid_operation (NULL
));
2094 /*FIXME unify this with reflection.c:mono_get_object_from_blob*/
2098 case MONO_TYPE_BOOLEAN
:
2101 case MONO_TYPE_CHAR
:
2109 case MONO_TYPE_R8
: {
2112 /* boxed value type */
2113 t
= g_new0 (MonoType
, 1);
2115 klass
= mono_class_from_mono_type (t
);
2117 o
= mono_object_new_checked (domain
, klass
, &error
);
2118 if (!mono_error_ok (&error
)) {
2119 mono_error_set_pending_exception (&error
);
2122 v
= ((gchar
*) o
) + sizeof (MonoObject
);
2123 mono_get_constant_value_from_blob (domain
, def_type
, def_value
, v
, &error
);
2124 if (mono_error_set_pending_exception (&error
))
2128 case MONO_TYPE_STRING
:
2129 case MONO_TYPE_CLASS
:
2130 mono_get_constant_value_from_blob (domain
, def_type
, def_value
, &o
, &error
);
2131 if (mono_error_set_pending_exception (&error
))
2135 g_assert_not_reached ();
2141 ICALL_EXPORT MonoReflectionTypeHandle
2142 ves_icall_MonoField_ResolveType (MonoReflectionFieldHandle ref_field
, MonoError
*error
)
2145 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_field
);
2146 MonoClassField
*field
= MONO_HANDLE_GETVAL (ref_field
, field
);
2147 MonoType
*type
= mono_field_get_type_checked (field
, error
);
2148 if (!is_ok (error
)) {
2149 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
2151 return mono_type_get_object_handle (domain
, type
, error
);
2154 /* From MonoProperty.cs */
2156 PInfo_Attributes
= 1,
2157 PInfo_GetMethod
= 1 << 1,
2158 PInfo_SetMethod
= 1 << 2,
2159 PInfo_ReflectedType
= 1 << 3,
2160 PInfo_DeclaringType
= 1 << 4,
2165 ves_icall_MonoPropertyInfo_get_property_info (MonoReflectionPropertyHandle property
, MonoPropertyInfo
*info
, PInfo req_info
, MonoError
*error
)
2168 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (property
);
2169 const MonoProperty
*pproperty
= MONO_HANDLE_GETVAL (property
, property
);
2171 if ((req_info
& PInfo_ReflectedType
) != 0) {
2172 MonoClass
*klass
= MONO_HANDLE_GETVAL (property
, klass
);
2173 MonoReflectionTypeHandle rt
= mono_type_get_object_handle (domain
, &klass
->byval_arg
, error
);
2174 return_if_nok (error
);
2176 MONO_STRUCT_SETREF (info
, parent
, MONO_HANDLE_RAW (rt
));
2178 if ((req_info
& PInfo_DeclaringType
) != 0) {
2179 MonoReflectionTypeHandle rt
= mono_type_get_object_handle (domain
, &pproperty
->parent
->byval_arg
, error
);
2180 return_if_nok (error
);
2182 MONO_STRUCT_SETREF (info
, declaring_type
, MONO_HANDLE_RAW (rt
));
2185 if ((req_info
& PInfo_Name
) != 0) {
2186 MonoStringHandle name
= mono_string_new_handle (domain
, pproperty
->name
, error
);
2187 return_if_nok (error
);
2189 MONO_STRUCT_SETREF (info
, name
, MONO_HANDLE_RAW (name
));
2192 if ((req_info
& PInfo_Attributes
) != 0)
2193 info
->attrs
= pproperty
->attrs
;
2195 if ((req_info
& PInfo_GetMethod
) != 0) {
2196 MonoClass
*property_klass
= MONO_HANDLE_GETVAL (property
, klass
);
2197 MonoReflectionMethodHandle rm
;
2198 if (pproperty
->get
&&
2199 (((pproperty
->get
->flags
& METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK
) != METHOD_ATTRIBUTE_PRIVATE
) ||
2200 pproperty
->get
->klass
== property_klass
)) {
2201 rm
= mono_method_get_object_handle (domain
, pproperty
->get
, property_klass
, error
);
2202 return_if_nok (error
);
2204 rm
= MONO_HANDLE_NEW (MonoReflectionMethod
, NULL
);
2207 MONO_STRUCT_SETREF (info
, get
, MONO_HANDLE_RAW (rm
));
2209 if ((req_info
& PInfo_SetMethod
) != 0) {
2210 MonoClass
*property_klass
= MONO_HANDLE_GETVAL (property
, klass
);
2211 MonoReflectionMethodHandle rm
;
2212 if (pproperty
->set
&&
2213 (((pproperty
->set
->flags
& METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK
) != METHOD_ATTRIBUTE_PRIVATE
) ||
2214 pproperty
->set
->klass
== property_klass
)) {
2215 rm
= mono_method_get_object_handle (domain
, pproperty
->set
, property_klass
, error
);
2216 return_if_nok (error
);
2218 rm
= MONO_HANDLE_NEW (MonoReflectionMethod
, NULL
);
2221 MONO_STRUCT_SETREF (info
, set
, MONO_HANDLE_RAW (rm
));
2224 * There may be other methods defined for properties, though, it seems they are not exposed
2225 * in the reflection API
2230 add_event_other_methods_to_array (MonoDomain
*domain
, MonoMethod
*m
, MonoArrayHandle dest
, int i
, MonoError
*error
)
2232 HANDLE_FUNCTION_ENTER ();
2234 MonoReflectionMethodHandle rm
= mono_method_get_object_handle (domain
, m
, NULL
, error
);
2237 MONO_HANDLE_ARRAY_SETREF (dest
, i
, rm
);
2239 HANDLE_FUNCTION_RETURN_VAL (is_ok (error
));
2243 ves_icall_MonoEventInfo_get_event_info (MonoReflectionMonoEventHandle ref_event
, MonoEventInfo
*info
, MonoError
*error
)
2246 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_event
);
2248 MonoClass
*klass
= MONO_HANDLE_GETVAL (ref_event
, klass
);
2249 MonoEvent
*event
= MONO_HANDLE_GETVAL (ref_event
, event
);
2251 MonoReflectionTypeHandle rt
= mono_type_get_object_handle (domain
, &klass
->byval_arg
, error
);
2252 return_if_nok (error
);
2253 MONO_STRUCT_SETREF (info
, reflected_type
, MONO_HANDLE_RAW (rt
));
2255 rt
= mono_type_get_object_handle (domain
, &event
->parent
->byval_arg
, error
);
2256 return_if_nok (error
);
2257 MONO_STRUCT_SETREF (info
, declaring_type
, MONO_HANDLE_RAW (rt
));
2259 MonoStringHandle ev_name
= mono_string_new_handle (domain
, event
->name
, error
);
2260 return_if_nok (error
);
2261 MONO_STRUCT_SETREF (info
, name
, MONO_HANDLE_RAW (ev_name
));
2263 info
->attrs
= event
->attrs
;
2265 MonoReflectionMethodHandle rm
;
2267 rm
= mono_method_get_object_handle (domain
, event
->add
, NULL
, error
);
2268 return_if_nok (error
);
2270 rm
= MONO_HANDLE_NEW (MonoReflectionMethod
, NULL
);
2273 MONO_STRUCT_SETREF (info
, add_method
, MONO_HANDLE_RAW (rm
));
2275 if (event
->remove
) {
2276 rm
= mono_method_get_object_handle (domain
, event
->remove
, NULL
, error
);
2277 return_if_nok (error
);
2279 rm
= MONO_HANDLE_NEW (MonoReflectionMethod
, NULL
);
2282 MONO_STRUCT_SETREF (info
, remove_method
, MONO_HANDLE_RAW (rm
));
2285 rm
= mono_method_get_object_handle (domain
, event
->raise
, NULL
, error
);
2286 return_if_nok (error
);
2288 rm
= MONO_HANDLE_NEW (MonoReflectionMethod
, NULL
);
2291 MONO_STRUCT_SETREF (info
, raise_method
, MONO_HANDLE_RAW (rm
));
2293 #ifndef MONO_SMALL_CONFIG
2296 while (event
->other
[n
])
2298 MonoArrayHandle info_arr
= mono_array_new_handle (domain
, mono_defaults
.method_info_class
, n
, error
);
2299 return_if_nok (error
);
2301 MONO_STRUCT_SETREF (info
, other_methods
, MONO_HANDLE_RAW (info_arr
));
2303 for (i
= 0; i
< n
; i
++)
2304 if (!add_event_other_methods_to_array (domain
, event
->other
[i
], info_arr
, i
, error
))
2311 collect_interfaces (MonoClass
*klass
, GHashTable
*ifaces
, MonoError
*error
)
2316 mono_class_setup_interfaces (klass
, error
);
2317 if (!mono_error_ok (error
))
2320 for (i
= 0; i
< klass
->interface_count
; i
++) {
2321 ic
= klass
->interfaces
[i
];
2322 g_hash_table_insert (ifaces
, ic
, ic
);
2324 collect_interfaces (ic
, ifaces
, error
);
2325 if (!mono_error_ok (error
))
2331 MonoArrayHandle iface_array
;
2332 MonoGenericContext
*context
;
2336 } FillIfaceArrayData
;
2339 fill_iface_array (gpointer key
, gpointer value
, gpointer user_data
)
2341 HANDLE_FUNCTION_ENTER ();
2342 FillIfaceArrayData
*data
= (FillIfaceArrayData
*)user_data
;
2343 MonoClass
*ic
= (MonoClass
*)key
;
2344 MonoType
*ret
= &ic
->byval_arg
, *inflated
= NULL
;
2345 MonoError
*error
= data
->error
;
2350 if (data
->context
&& mono_class_is_ginst (ic
) && mono_class_get_generic_class (ic
)->context
.class_inst
->is_open
) {
2351 inflated
= ret
= mono_class_inflate_generic_type_checked (ret
, data
->context
, error
);
2356 MonoReflectionTypeHandle rt
= mono_type_get_object_handle (data
->domain
, ret
, error
);
2360 MONO_HANDLE_ARRAY_SETREF (data
->iface_array
, data
->next_idx
, rt
);
2364 mono_metadata_free_type (inflated
);
2366 HANDLE_FUNCTION_RETURN ();
2370 get_interfaces_hash (gconstpointer v1
)
2372 MonoClass
*k
= (MonoClass
*)v1
;
2374 return k
->type_token
;
2377 ICALL_EXPORT MonoArrayHandle
2378 ves_icall_RuntimeType_GetInterfaces (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2381 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2382 MonoClass
*klass
= mono_class_from_mono_type (type
);
2384 GHashTable
*iface_hash
= g_hash_table_new (get_interfaces_hash
, NULL
);
2386 MonoGenericContext
*context
= NULL
;
2387 if (mono_class_is_ginst (klass
) && mono_class_get_generic_class (klass
)->context
.class_inst
->is_open
) {
2388 context
= mono_class_get_context (klass
);
2389 klass
= mono_class_get_generic_class (klass
)->container_class
;
2392 for (MonoClass
*parent
= klass
; parent
; parent
= parent
->parent
) {
2393 mono_class_setup_interfaces (parent
, error
);
2396 collect_interfaces (parent
, iface_hash
, error
);
2401 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_type
);
2403 int len
= g_hash_table_size (iface_hash
);
2405 g_hash_table_destroy (iface_hash
);
2406 if (!domain
->empty_types
) {
2407 domain
->empty_types
= mono_array_new_cached (domain
, mono_defaults
.runtimetype_class
, 0, error
);
2411 return MONO_HANDLE_NEW (MonoArray
, domain
->empty_types
);
2414 FillIfaceArrayData data
;
2415 data
.iface_array
= MONO_HANDLE_NEW (MonoArray
, mono_array_new_cached (domain
, mono_defaults
.runtimetype_class
, len
, error
));
2418 data
.context
= context
;
2420 data
.domain
= domain
;
2423 g_hash_table_foreach (iface_hash
, fill_iface_array
, &data
);
2428 g_hash_table_destroy (iface_hash
);
2429 return data
.iface_array
;
2432 g_hash_table_destroy (iface_hash
);
2433 return MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
);
2437 set_interface_map_data_method_object (MonoDomain
*domain
, MonoMethod
*method
, MonoClass
*iclass
, int ioffset
, MonoClass
*klass
, MonoArrayHandle targets
, MonoArrayHandle methods
, int i
, MonoError
*error
)
2439 HANDLE_FUNCTION_ENTER ();
2441 MonoReflectionMethodHandle member
= mono_method_get_object_handle (domain
, method
, iclass
, error
);
2445 MONO_HANDLE_ARRAY_SETREF (methods
, i
, member
);
2447 MONO_HANDLE_ASSIGN (member
, mono_method_get_object_handle (domain
, klass
->vtable
[i
+ ioffset
], klass
, error
));
2451 MONO_HANDLE_ARRAY_SETREF (targets
, i
, member
);
2454 HANDLE_FUNCTION_RETURN_VAL (is_ok (error
));
2458 ves_icall_RuntimeType_GetInterfaceMapData (MonoReflectionTypeHandle ref_type
, MonoReflectionTypeHandle ref_iface
, MonoArrayHandleOut targets
, MonoArrayHandleOut methods
, MonoError
*error
)
2461 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2462 MonoClass
*klass
= mono_class_from_mono_type (type
);
2463 MonoType
*iface
= MONO_HANDLE_GETVAL (ref_iface
, type
);
2464 MonoClass
*iclass
= mono_class_from_mono_type (iface
);
2466 mono_class_init_checked (klass
, error
);
2467 return_if_nok (error
);
2468 mono_class_init_checked (iclass
, error
);
2469 return_if_nok (error
);
2471 mono_class_setup_vtable (klass
);
2473 gboolean variance_used
;
2474 int ioffset
= mono_class_interface_offset_with_variance (klass
, iclass
, &variance_used
);
2478 int len
= mono_class_num_methods (iclass
);
2479 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_type
);
2480 MonoArrayHandle targets_arr
= mono_array_new_handle (domain
, mono_defaults
.method_info_class
, len
, error
);
2481 return_if_nok (error
);
2482 MONO_HANDLE_ASSIGN (targets
, targets_arr
);
2484 MonoArrayHandle methods_arr
= mono_array_new_handle (domain
, mono_defaults
.method_info_class
, len
, error
);
2485 return_if_nok (error
);
2486 MONO_HANDLE_ASSIGN (methods
, methods_arr
);
2490 gpointer iter
= NULL
;
2491 while ((method
= mono_class_get_methods (iclass
, &iter
))) {
2492 if (!set_interface_map_data_method_object (domain
, method
, iclass
, ioffset
, klass
, targets
, methods
, i
, error
))
2499 ves_icall_RuntimeType_GetPacking (MonoReflectionTypeHandle ref_type
, guint32
*packing
, guint32
*size
, MonoError
*error
)
2502 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2503 MonoClass
*klass
= mono_class_from_mono_type (type
);
2505 mono_class_init_checked (klass
, error
);
2509 if (image_is_dynamic (klass
->image
)) {
2510 MonoReflectionTypeBuilderHandle tb
= MONO_HANDLE_CAST (MonoReflectionTypeBuilder
, ref_type
);
2511 *packing
= MONO_HANDLE_GETVAL (tb
, packing_size
);
2512 *size
= MONO_HANDLE_GETVAL (tb
, class_size
);
2514 mono_metadata_packing_from_typedef (klass
->image
, klass
->type_token
, packing
, size
);
2518 ICALL_EXPORT MonoReflectionTypeHandle
2519 ves_icall_RuntimeTypeHandle_GetElementType (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2523 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_type
);
2524 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2526 if (!type
->byref
&& type
->type
== MONO_TYPE_SZARRAY
) {
2527 return mono_type_get_object_handle (domain
, &type
->data
.klass
->byval_arg
, error
);
2530 MonoClass
*klass
= mono_class_from_mono_type (type
);
2531 mono_class_init_checked (klass
, error
);
2533 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
2535 // GetElementType should only return a type for:
2536 // Array Pointer PassedByRef
2538 return mono_type_get_object_handle (domain
, &klass
->byval_arg
, error
);
2539 else if (klass
->element_class
&& MONO_CLASS_IS_ARRAY (klass
))
2540 return mono_type_get_object_handle (domain
, &klass
->element_class
->byval_arg
, error
);
2541 else if (klass
->element_class
&& type
->type
== MONO_TYPE_PTR
)
2542 return mono_type_get_object_handle (domain
, &klass
->element_class
->byval_arg
, error
);
2544 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
2547 ICALL_EXPORT MonoReflectionTypeHandle
2548 ves_icall_RuntimeTypeHandle_GetBaseType (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2552 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_type
);
2553 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2556 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
2558 MonoClass
*klass
= mono_class_from_mono_type (type
);
2560 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
2562 return mono_type_get_object_handle (domain
, &klass
->parent
->byval_arg
, error
);
2565 ICALL_EXPORT MonoBoolean
2566 ves_icall_RuntimeTypeHandle_IsPointer (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2569 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2570 return type
->type
== MONO_TYPE_PTR
;
2573 ICALL_EXPORT MonoBoolean
2574 ves_icall_RuntimeTypeHandle_IsPrimitive (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2577 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2578 return (!type
->byref
&& (((type
->type
>= MONO_TYPE_BOOLEAN
) && (type
->type
<= MONO_TYPE_R8
)) || (type
->type
== MONO_TYPE_I
) || (type
->type
== MONO_TYPE_U
)));
2581 ICALL_EXPORT MonoBoolean
2582 ves_icall_RuntimeTypeHandle_HasReferences (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2585 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2588 klass
= mono_class_from_mono_type (type
);
2589 mono_class_init (klass
);
2590 return klass
->has_references
;
2593 ICALL_EXPORT MonoBoolean
2594 ves_icall_RuntimeTypeHandle_IsByRef (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2597 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2601 ICALL_EXPORT MonoBoolean
2602 ves_icall_RuntimeTypeHandle_IsComObject (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2605 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2606 MonoClass
*klass
= mono_class_from_mono_type (type
);
2607 mono_class_init_checked (klass
, error
);
2611 return mono_class_is_com_object (klass
);
2614 ICALL_EXPORT guint32
2615 ves_icall_reflection_get_token (MonoObjectHandle obj
, MonoError
*error
)
2618 return mono_reflection_get_token_checked (obj
, error
);
2621 ICALL_EXPORT MonoReflectionModuleHandle
2622 ves_icall_RuntimeTypeHandle_GetModule (MonoReflectionTypeHandle type
, MonoError
*error
)
2625 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (type
);
2626 MonoType
*t
= MONO_HANDLE_GETVAL (type
, type
);
2627 MonoClass
*klass
= mono_class_from_mono_type (t
);
2628 return mono_module_get_object_handle (domain
, klass
->image
, error
);
2631 ICALL_EXPORT MonoReflectionAssemblyHandle
2632 ves_icall_RuntimeTypeHandle_GetAssembly (MonoReflectionTypeHandle type
, MonoError
*error
)
2635 MonoDomain
*domain
= mono_domain_get ();
2636 MonoType
*t
= MONO_HANDLE_GETVAL (type
, type
);
2637 MonoClass
*klass
= mono_class_from_mono_type (t
);
2638 return mono_assembly_get_object_handle (domain
, klass
->image
->assembly
, error
);
2641 ICALL_EXPORT MonoReflectionTypeHandle
2642 ves_icall_RuntimeType_get_DeclaringType (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2645 MonoDomain
*domain
= mono_domain_get ();
2646 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2650 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
2651 if (type
->type
== MONO_TYPE_VAR
) {
2652 MonoGenericContainer
*param
= mono_type_get_generic_param_owner (type
);
2653 klass
= param
? param
->owner
.klass
: NULL
;
2654 } else if (type
->type
== MONO_TYPE_MVAR
) {
2655 MonoGenericContainer
*param
= mono_type_get_generic_param_owner (type
);
2656 klass
= param
? param
->owner
.method
->klass
: NULL
;
2658 klass
= mono_class_from_mono_type (type
)->nested_in
;
2662 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
2664 return mono_type_get_object_handle (domain
, &klass
->byval_arg
, error
);
2667 ICALL_EXPORT MonoStringHandle
2668 ves_icall_RuntimeType_get_Name (MonoReflectionTypeHandle reftype
, MonoError
*error
)
2670 MonoDomain
*domain
= mono_domain_get ();
2671 MonoType
*type
= MONO_HANDLE_RAW(reftype
)->type
;
2672 MonoClass
*klass
= mono_class_from_mono_type (type
);
2675 char *n
= g_strdup_printf ("%s&", klass
->name
);
2676 MonoStringHandle res
= mono_string_new_handle (domain
, n
, error
);
2682 return mono_string_new_handle (domain
, klass
->name
, error
);
2686 ICALL_EXPORT MonoStringHandle
2687 ves_icall_RuntimeType_get_Namespace (MonoReflectionTypeHandle type
, MonoError
*error
)
2689 MonoDomain
*domain
= mono_domain_get ();
2690 MonoClass
*klass
= mono_class_from_mono_type_handle (type
);
2692 while (klass
->nested_in
)
2693 klass
= klass
->nested_in
;
2695 if (klass
->name_space
[0] == '\0')
2696 return NULL_HANDLE_STRING
;
2698 return mono_string_new_handle (domain
, klass
->name_space
, error
);
2702 ves_icall_RuntimeTypeHandle_GetArrayRank (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2705 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2707 if (type
->type
!= MONO_TYPE_ARRAY
&& type
->type
!= MONO_TYPE_SZARRAY
) {
2708 mono_error_set_argument (error
, "type", "Type must be an array type");
2712 MonoClass
*klass
= mono_class_from_mono_type (type
);
2717 static MonoArrayHandle
2718 create_type_array (MonoDomain
*domain
, MonoBoolean runtimeTypeArray
, int count
, MonoError
*error
)
2720 return mono_array_new_handle (domain
, runtimeTypeArray
? mono_defaults
.runtimetype_class
: mono_defaults
.systemtype_class
, count
, error
);
2724 set_type_object_in_array (MonoDomain
*domain
, MonoType
*type
, MonoArrayHandle dest
, int i
, MonoError
*error
)
2726 HANDLE_FUNCTION_ENTER();
2728 MonoReflectionTypeHandle rt
= mono_type_get_object_handle (domain
, type
, error
);
2732 MONO_HANDLE_ARRAY_SETREF (dest
, i
, rt
);
2735 HANDLE_FUNCTION_RETURN_VAL (is_ok (error
));
2738 ICALL_EXPORT MonoArrayHandle
2739 ves_icall_RuntimeType_GetGenericArguments (MonoReflectionTypeHandle ref_type
, MonoBoolean runtimeTypeArray
, MonoError
*error
)
2742 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_type
);
2744 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2745 MonoClass
*klass
= mono_class_from_mono_type (type
);
2747 MonoArrayHandle res
= MONO_HANDLE_NEW (MonoArray
, NULL
);
2748 if (mono_class_is_gtd (klass
)) {
2749 MonoGenericContainer
*container
= mono_class_get_generic_container (klass
);
2750 MONO_HANDLE_ASSIGN (res
, create_type_array (domain
, runtimeTypeArray
, container
->type_argc
, error
));
2753 for (int i
= 0; i
< container
->type_argc
; ++i
) {
2754 MonoClass
*pklass
= mono_class_from_generic_parameter_internal (mono_generic_container_get_param (container
, i
));
2756 if (!set_type_object_in_array (domain
, &pklass
->byval_arg
, res
, i
, error
))
2760 } else if (mono_class_is_ginst (klass
)) {
2761 MonoGenericInst
*inst
= mono_class_get_generic_class (klass
)->context
.class_inst
;
2762 MONO_HANDLE_ASSIGN (res
, create_type_array (domain
, runtimeTypeArray
, inst
->type_argc
, error
));
2765 for (int i
= 0; i
< inst
->type_argc
; ++i
) {
2766 if (!set_type_object_in_array (domain
, inst
->type_argv
[i
], res
, i
, error
))
2775 ICALL_EXPORT gboolean
2776 ves_icall_RuntimeTypeHandle_IsGenericTypeDefinition (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2780 if (!IS_MONOTYPE (MONO_HANDLE_RAW(ref_type
)))
2783 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2787 MonoClass
*klass
= mono_class_from_mono_type (type
);
2788 return mono_class_is_gtd (klass
);
2791 ICALL_EXPORT MonoReflectionTypeHandle
2792 ves_icall_RuntimeTypeHandle_GetGenericTypeDefinition_impl (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2795 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2797 MonoReflectionTypeHandle ret
= MONO_HANDLE_NEW (MonoReflectionType
, NULL
);
2802 MonoClass
*klass
= mono_class_from_mono_type (type
);
2804 if (mono_class_is_gtd (klass
)) {
2805 /* check this one */
2806 MONO_HANDLE_ASSIGN (ret
, ref_type
);
2809 if (mono_class_is_ginst (klass
)) {
2810 MonoClass
*generic_class
= mono_class_get_generic_class (klass
)->container_class
;
2812 guint32 ref_info_handle
= mono_class_get_ref_info_handle (generic_class
);
2814 if (generic_class
->wastypebuilder
&& ref_info_handle
) {
2815 MonoObjectHandle tb
= mono_gchandle_get_target_handle (ref_info_handle
);
2816 g_assert (!MONO_HANDLE_IS_NULL (tb
));
2817 MONO_HANDLE_ASSIGN (ret
, tb
);
2819 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_type
);
2820 MONO_HANDLE_ASSIGN (ret
, mono_type_get_object_handle (domain
, &generic_class
->byval_arg
, error
));
2827 ICALL_EXPORT MonoReflectionTypeHandle
2828 ves_icall_RuntimeType_MakeGenericType (MonoReflectionTypeHandle reftype
, MonoArrayHandle type_array
, MonoError
*error
)
2831 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (reftype
);
2833 g_assert (IS_MONOTYPE_HANDLE (reftype
));
2834 MonoType
*type
= MONO_HANDLE_GETVAL (reftype
, type
);
2835 mono_class_init_checked (mono_class_from_mono_type (type
), error
);
2837 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
2839 int count
= mono_array_handle_length (type_array
);
2840 MonoType
**types
= g_new0 (MonoType
*, count
);
2842 MonoReflectionTypeHandle t
= MONO_HANDLE_NEW (MonoReflectionType
, NULL
);
2843 for (int i
= 0; i
< count
; i
++) {
2844 MONO_HANDLE_ARRAY_GETREF (t
, type_array
, i
);
2845 types
[i
] = MONO_HANDLE_GETVAL (t
, type
);
2848 MonoType
*geninst
= mono_reflection_bind_generic_parameters (reftype
, count
, types
, error
);
2851 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
2854 MonoClass
*klass
= mono_class_from_mono_type (geninst
);
2856 /*we might inflate to the GTD*/
2857 if (mono_class_is_ginst (klass
) && !mono_verifier_class_is_valid_generic_instantiation (klass
)) {
2858 mono_error_set_argument (error
, "typeArguments", "Invalid generic arguments");
2859 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
2862 return mono_type_get_object_handle (domain
, geninst
, error
);
2865 ICALL_EXPORT gboolean
2866 ves_icall_RuntimeTypeHandle_HasInstantiation (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2871 if (!IS_MONOTYPE (MONO_HANDLE_RAW (ref_type
)))
2874 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2878 klass
= mono_class_from_mono_type (type
);
2879 return mono_class_is_ginst (klass
) || mono_class_is_gtd (klass
);
2883 ves_icall_RuntimeType_GetGenericParameterPosition (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2886 if (!IS_MONOTYPE_HANDLE (ref_type
))
2888 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2890 if (is_generic_parameter (type
))
2891 return mono_type_get_generic_param_num (type
);
2895 ICALL_EXPORT MonoGenericParamInfo
*
2896 ves_icall_RuntimeTypeHandle_GetGenericParameterInfo (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2899 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2900 return mono_generic_param_info (type
->data
.generic_param
);
2903 ICALL_EXPORT MonoBoolean
2904 ves_icall_RuntimeTypeHandle_IsGenericVariable (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2906 MonoType
*type
= MONO_HANDLE_GETVAL(ref_type
, type
);
2907 return is_generic_parameter (type
);
2910 ICALL_EXPORT MonoReflectionMethodHandle
2911 ves_icall_RuntimeType_GetCorrespondingInflatedMethod (MonoReflectionTypeHandle ref_type
,
2912 MonoReflectionMethodHandle generic
,
2916 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_type
);
2917 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2918 MonoClass
*klass
= mono_class_from_mono_type (type
);
2920 mono_class_init_checked (klass
, error
);
2922 return MONO_HANDLE_CAST (MonoReflectionMethod
, NULL_HANDLE
);
2924 MonoMethod
*generic_method
= MONO_HANDLE_GETVAL (generic
, method
);
2926 MonoReflectionMethodHandle ret
= MONO_HANDLE_CAST (MonoReflectionMethod
, NULL_HANDLE
);
2928 gpointer iter
= NULL
;
2929 while ((method
= mono_class_get_methods (klass
, &iter
))) {
2930 if (method
->token
== generic_method
->token
) {
2931 ret
= mono_method_get_object_handle (domain
, method
, klass
, error
);
2933 return MONO_HANDLE_CAST (MonoReflectionMethod
, NULL_HANDLE
);
2940 ICALL_EXPORT MonoReflectionMethodHandle
2941 ves_icall_RuntimeType_get_DeclaringMethod (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
2944 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
2945 MonoReflectionMethodHandle ret
= MONO_HANDLE_NEW (MonoReflectionMethod
, NULL
);
2947 if (type
->byref
|| (type
->type
!= MONO_TYPE_MVAR
&& type
->type
!= MONO_TYPE_VAR
)) {
2948 mono_error_set_invalid_operation (error
, "DeclaringMethod can only be used on generic arguments");
2951 if (type
->type
== MONO_TYPE_VAR
)
2954 MonoMethod
*method
= mono_type_get_generic_param_owner (type
)->owner
.method
;
2957 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_type
);
2959 MONO_HANDLE_ASSIGN (ret
, mono_method_get_object_handle (domain
, method
, method
->klass
, error
));
2964 ICALL_EXPORT MonoBoolean
2965 ves_icall_System_RuntimeType_IsTypeExportedToWindowsRuntime (MonoError
*error
)
2968 mono_error_set_not_implemented (error
, "%s", "");
2972 ICALL_EXPORT MonoBoolean
2973 ves_icall_System_RuntimeType_IsWindowsRuntimeObjectType (MonoError
*error
)
2976 mono_error_set_not_implemented (error
, "%s", "");
2981 ves_icall_MonoMethod_GetPInvoke (MonoReflectionMethodHandle ref_method
, int* flags
, MonoStringHandleOut entry_point
, MonoStringHandleOut dll_name
, MonoError
*error
)
2983 MonoDomain
*domain
= mono_domain_get ();
2984 MonoMethod
*method
= MONO_HANDLE_GETVAL (ref_method
, method
);
2985 MonoImage
*image
= method
->klass
->image
;
2986 MonoMethodPInvoke
*piinfo
= (MonoMethodPInvoke
*)method
;
2987 MonoTableInfo
*tables
= image
->tables
;
2988 MonoTableInfo
*im
= &tables
[MONO_TABLE_IMPLMAP
];
2989 MonoTableInfo
*mr
= &tables
[MONO_TABLE_MODULEREF
];
2990 guint32 im_cols
[MONO_IMPLMAP_SIZE
];
2991 guint32 scope_token
;
2992 const char *import
= NULL
;
2993 const char *scope
= NULL
;
2997 if (image_is_dynamic (image
)) {
2998 MonoReflectionMethodAux
*method_aux
=
2999 (MonoReflectionMethodAux
*)g_hash_table_lookup (((MonoDynamicImage
*)image
)->method_aux_hash
, method
);
3001 import
= method_aux
->dllentry
;
3002 scope
= method_aux
->dll
;
3005 if (!import
|| !scope
) {
3006 mono_error_set_argument (error
, "method", "System.Refleciton.Emit method with invalid pinvoke information");
3011 if (piinfo
->implmap_idx
) {
3012 mono_metadata_decode_row (im
, piinfo
->implmap_idx
- 1, im_cols
, MONO_IMPLMAP_SIZE
);
3014 piinfo
->piflags
= im_cols
[MONO_IMPLMAP_FLAGS
];
3015 import
= mono_metadata_string_heap (image
, im_cols
[MONO_IMPLMAP_NAME
]);
3016 scope_token
= mono_metadata_decode_row_col (mr
, im_cols
[MONO_IMPLMAP_SCOPE
] - 1, MONO_MODULEREF_NAME
);
3017 scope
= mono_metadata_string_heap (image
, scope_token
);
3021 *flags
= piinfo
->piflags
;
3022 MONO_HANDLE_ASSIGN (entry_point
, mono_string_new_handle (domain
, import
, error
));
3023 return_if_nok (error
);
3024 MONO_HANDLE_ASSIGN (dll_name
, mono_string_new_handle (domain
, scope
, error
));
3027 ICALL_EXPORT MonoReflectionMethodHandle
3028 ves_icall_MonoMethod_GetGenericMethodDefinition (MonoReflectionMethodHandle ref_method
, MonoError
*error
)
3031 MonoMethod
*method
= MONO_HANDLE_GETVAL (ref_method
, method
);
3033 if (method
->is_generic
)
3036 if (!method
->is_inflated
)
3037 return MONO_HANDLE_CAST (MonoReflectionMethod
, NULL_HANDLE
);
3039 MonoMethodInflated
*imethod
= (MonoMethodInflated
*) method
;
3041 MonoMethod
*result
= imethod
->declaring
;
3042 /* Not a generic method. */
3043 if (!result
->is_generic
)
3044 return MONO_HANDLE_CAST (MonoReflectionMethod
, NULL_HANDLE
);
3046 if (image_is_dynamic (method
->klass
->image
)) {
3047 MonoDynamicImage
*image
= (MonoDynamicImage
*)method
->klass
->image
;
3050 * FIXME: Why is this stuff needed at all ? Why can't the code below work for
3051 * the dynamic case as well ?
3053 mono_image_lock ((MonoImage
*)image
);
3054 MonoReflectionMethodHandle res
= MONO_HANDLE_NEW (MonoReflectionMethod
, mono_g_hash_table_lookup (image
->generic_def_objects
, imethod
));
3055 mono_image_unlock ((MonoImage
*)image
);
3057 if (!MONO_HANDLE_IS_NULL (res
))
3061 if (imethod
->context
.class_inst
) {
3062 MonoClass
*klass
= ((MonoMethod
*) imethod
)->klass
;
3063 /*Generic methods gets the context of the GTD.*/
3064 if (mono_class_get_context (klass
)) {
3065 result
= mono_class_inflate_generic_method_full_checked (result
, klass
, mono_class_get_context (klass
), error
);
3066 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoReflectionMethod
, NULL_HANDLE
));
3070 return mono_method_get_object_handle (MONO_HANDLE_DOMAIN (ref_method
), result
, NULL
, error
);
3073 ICALL_EXPORT gboolean
3074 ves_icall_MonoMethod_get_IsGenericMethod (MonoReflectionMethodHandle ref_method
, MonoError
*erro
)
3076 MonoMethod
*method
= MONO_HANDLE_GETVAL (ref_method
, method
);
3077 return mono_method_signature (method
)->generic_param_count
!= 0;
3080 ICALL_EXPORT gboolean
3081 ves_icall_MonoMethod_get_IsGenericMethodDefinition (MonoReflectionMethodHandle ref_method
, MonoError
*Error
)
3083 MonoMethod
*method
= MONO_HANDLE_GETVAL (ref_method
, method
);
3084 return method
->is_generic
;
3088 set_array_generic_argument_handle_inflated (MonoDomain
*domain
, MonoGenericInst
*inst
, int i
, MonoArrayHandle arr
, MonoError
*error
)
3090 HANDLE_FUNCTION_ENTER ();
3092 MonoReflectionTypeHandle rt
= mono_type_get_object_handle (domain
, inst
->type_argv
[i
], error
);
3095 MONO_HANDLE_ARRAY_SETREF (arr
, i
, rt
);
3097 HANDLE_FUNCTION_RETURN_VAL (is_ok (error
));
3101 set_array_generic_argument_handle_gparam (MonoDomain
*domain
, MonoGenericContainer
*container
, int i
, MonoArrayHandle arr
, MonoError
*error
)
3103 HANDLE_FUNCTION_ENTER ();
3105 MonoGenericParam
*param
= mono_generic_container_get_param (container
, i
);
3106 MonoClass
*pklass
= mono_class_from_generic_parameter_internal (param
);
3107 MonoReflectionTypeHandle rt
= mono_type_get_object_handle (domain
, &pklass
->byval_arg
, error
);
3110 MONO_HANDLE_ARRAY_SETREF (arr
, i
, rt
);
3112 HANDLE_FUNCTION_RETURN_VAL (is_ok (error
));
3115 ICALL_EXPORT MonoArrayHandle
3116 ves_icall_MonoMethod_GetGenericArguments (MonoReflectionMethodHandle ref_method
, MonoError
*error
)
3119 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_method
);
3120 MonoMethod
*method
= MONO_HANDLE_GETVAL (ref_method
, method
);
3122 if (method
->is_inflated
) {
3123 MonoGenericInst
*inst
= mono_method_get_context (method
)->method_inst
;
3126 int count
= inst
->type_argc
;
3127 MonoArrayHandle res
= mono_array_new_handle (domain
, mono_defaults
.systemtype_class
, count
, error
);
3128 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
));
3130 for (int i
= 0; i
< count
; i
++) {
3131 if (!set_array_generic_argument_handle_inflated (domain
, inst
, i
, res
, error
))
3134 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
));
3139 int count
= mono_method_signature (method
)->generic_param_count
;
3140 MonoArrayHandle res
= mono_array_new_handle (domain
, mono_defaults
.systemtype_class
, count
, error
);
3141 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
));
3143 MonoGenericContainer
*container
= mono_method_get_generic_container (method
);
3144 for (int i
= 0; i
< count
; i
++) {
3145 if (!set_array_generic_argument_handle_gparam (domain
, container
, i
, res
, error
))
3148 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
));
3152 ICALL_EXPORT MonoObject
*
3153 ves_icall_InternalInvoke (MonoReflectionMethod
*method
, MonoObject
*this_arg
, MonoArray
*params
, MonoException
**exc
)
3157 * Invoke from reflection is supposed to always be a virtual call (the API
3158 * is stupid), mono_runtime_invoke_*() calls the provided method, allowing
3159 * greater flexibility.
3161 MonoMethod
*m
= method
->method
;
3162 MonoMethodSignature
*sig
= mono_method_signature (m
);
3165 void *obj
= this_arg
;
3169 if (mono_security_core_clr_enabled () &&
3170 !mono_security_core_clr_ensure_reflection_access_method (m
, &error
)) {
3171 mono_error_set_pending_exception (&error
);
3175 if (!(m
->flags
& METHOD_ATTRIBUTE_STATIC
)) {
3176 if (!mono_class_vtable_full (mono_object_domain (method
), m
->klass
, &error
)) {
3177 mono_error_cleanup (&error
); /* FIXME does this make sense? */
3178 mono_gc_wbarrier_generic_store (exc
, (MonoObject
*) mono_class_get_exception_for_failure (m
->klass
));
3183 if (!mono_object_isinst_checked (this_arg
, m
->klass
, &error
)) {
3184 if (!is_ok (&error
)) {
3185 mono_gc_wbarrier_generic_store (exc
, (MonoObject
*) mono_error_convert_to_exception (&error
));
3188 char *this_name
= mono_type_get_full_name (mono_object_get_class (this_arg
));
3189 char *target_name
= mono_type_get_full_name (m
->klass
);
3190 char *msg
= g_strdup_printf ("Object of type '%s' doesn't match target type '%s'", this_name
, target_name
);
3191 mono_gc_wbarrier_generic_store (exc
, (MonoObject
*) mono_exception_from_name_msg (mono_defaults
.corlib
, "System.Reflection", "TargetException", msg
));
3193 g_free (target_name
);
3197 m
= mono_object_get_virtual_method (this_arg
, m
);
3198 /* must pass the pointer to the value for valuetype methods */
3199 if (m
->klass
->valuetype
)
3200 obj
= mono_object_unbox (this_arg
);
3201 } else if (strcmp (m
->name
, ".ctor") && !m
->wrapper_type
) {
3202 mono_gc_wbarrier_generic_store (exc
, (MonoObject
*) mono_exception_from_name_msg (mono_defaults
.corlib
, "System.Reflection", "TargetException", "Non-static method requires a target."));
3207 if (sig
->ret
->byref
) {
3208 mono_gc_wbarrier_generic_store (exc
, (MonoObject
*) mono_exception_from_name_msg (mono_defaults
.corlib
, "System", "NotSupportedException", "Cannot invoke method returning ByRef type via reflection"));
3212 pcount
= params
? mono_array_length (params
): 0;
3213 if (pcount
!= sig
->param_count
) {
3214 mono_gc_wbarrier_generic_store (exc
, (MonoObject
*) mono_exception_from_name (mono_defaults
.corlib
, "System.Reflection", "TargetParameterCountException"));
3218 if (mono_class_is_abstract (m
->klass
) && !strcmp (m
->name
, ".ctor") && !this_arg
) {
3219 mono_gc_wbarrier_generic_store (exc
, (MonoObject
*) mono_exception_from_name_msg (mono_defaults
.corlib
, "System.Reflection", "TargetException", "Cannot invoke constructor of an abstract class."));
3223 image
= m
->klass
->image
;
3224 if (image
->assembly
->ref_only
) {
3225 mono_gc_wbarrier_generic_store (exc
, (MonoObject
*) mono_get_exception_invalid_operation ("It is illegal to invoke a method on a type loaded using the ReflectionOnly api."));
3229 if (image_is_dynamic (image
) && !((MonoDynamicImage
*)image
)->run
) {
3230 mono_gc_wbarrier_generic_store (exc
, (MonoObject
*) mono_get_exception_not_supported ("Cannot invoke a method in a dynamic assembly without run access."));
3234 if (m
->klass
->rank
&& !strcmp (m
->name
, ".ctor")) {
3238 intptr_t *lower_bounds
;
3239 pcount
= mono_array_length (params
);
3240 lengths
= (uintptr_t *)alloca (sizeof (uintptr_t) * pcount
);
3241 /* Note: the synthetized array .ctors have int32 as argument type */
3242 for (i
= 0; i
< pcount
; ++i
)
3243 lengths
[i
] = *(int32_t*) ((char*)mono_array_get (params
, gpointer
, i
) + sizeof (MonoObject
));
3245 if (m
->klass
->rank
== 1 && sig
->param_count
== 2 && m
->klass
->element_class
->rank
) {
3246 /* This is a ctor for jagged arrays. MS creates an array of arrays. */
3247 arr
= mono_array_new_full_checked (mono_object_domain (params
), m
->klass
, lengths
, NULL
, &error
);
3248 if (!mono_error_ok (&error
)) {
3249 mono_error_set_pending_exception (&error
);
3253 for (i
= 0; i
< mono_array_length (arr
); ++i
) {
3254 MonoArray
*subarray
= mono_array_new_full_checked (mono_object_domain (params
), m
->klass
->element_class
, &lengths
[1], NULL
, &error
);
3255 if (!mono_error_ok (&error
)) {
3256 mono_error_set_pending_exception (&error
);
3259 mono_array_setref_fast (arr
, i
, subarray
);
3261 return (MonoObject
*)arr
;
3264 if (m
->klass
->rank
== pcount
) {
3265 /* Only lengths provided. */
3266 arr
= mono_array_new_full_checked (mono_object_domain (params
), m
->klass
, lengths
, NULL
, &error
);
3267 if (!mono_error_ok (&error
)) {
3268 mono_error_set_pending_exception (&error
);
3272 return (MonoObject
*)arr
;
3274 g_assert (pcount
== (m
->klass
->rank
* 2));
3275 /* The arguments are lower-bound-length pairs */
3276 lower_bounds
= (intptr_t *)g_alloca (sizeof (intptr_t) * pcount
);
3278 for (i
= 0; i
< pcount
/ 2; ++i
) {
3279 lower_bounds
[i
] = *(int32_t*) ((char*)mono_array_get (params
, gpointer
, (i
* 2)) + sizeof (MonoObject
));
3280 lengths
[i
] = *(int32_t*) ((char*)mono_array_get (params
, gpointer
, (i
* 2) + 1) + sizeof (MonoObject
));
3283 arr
= mono_array_new_full_checked (mono_object_domain (params
), m
->klass
, lengths
, lower_bounds
, &error
);
3284 if (!mono_error_ok (&error
)) {
3285 mono_error_set_pending_exception (&error
);
3289 return (MonoObject
*)arr
;
3292 MonoObject
*result
= mono_runtime_invoke_array_checked (m
, obj
, params
, &error
);
3293 mono_error_set_pending_exception (&error
);
3297 #ifndef DISABLE_REMOTING
3298 ICALL_EXPORT MonoObject
*
3299 ves_icall_InternalExecute (MonoReflectionMethod
*method
, MonoObject
*this_arg
, MonoArray
*params
, MonoArray
**outArgs
)
3302 MonoDomain
*domain
= mono_object_domain (method
);
3303 MonoMethod
*m
= method
->method
;
3304 MonoMethodSignature
*sig
= mono_method_signature (m
);
3305 MonoArray
*out_args
;
3307 int i
, j
, outarg_count
= 0;
3309 if (m
->klass
== mono_defaults
.object_class
) {
3310 if (!strcmp (m
->name
, "FieldGetter")) {
3311 MonoClass
*k
= mono_object_class (this_arg
);
3315 /* If this is a proxy, then it must be a CBO */
3316 if (mono_class_is_transparent_proxy (k
)) {
3317 MonoTransparentProxy
*tp
= (MonoTransparentProxy
*) this_arg
;
3318 this_arg
= tp
->rp
->unwrapped_server
;
3319 g_assert (this_arg
);
3320 k
= mono_object_class (this_arg
);
3323 name
= mono_array_get (params
, MonoString
*, 1);
3324 str
= mono_string_to_utf8_checked (name
, &error
);
3325 if (mono_error_set_pending_exception (&error
))
3329 MonoClassField
* field
= mono_class_get_field_from_name (k
, str
);
3332 MonoClass
*field_klass
= mono_class_from_mono_type (field
->type
);
3333 if (field_klass
->valuetype
) {
3334 result
= mono_value_box_checked (domain
, field_klass
, (char *)this_arg
+ field
->offset
, &error
);
3335 if (mono_error_set_pending_exception (&error
))
3338 result
= (MonoObject
*)*((gpointer
*)((char *)this_arg
+ field
->offset
));
3340 out_args
= mono_array_new_checked (domain
, mono_defaults
.object_class
, 1, &error
);
3341 if (mono_error_set_pending_exception (&error
))
3343 mono_gc_wbarrier_generic_store (outArgs
, (MonoObject
*) out_args
);
3344 mono_array_setref (out_args
, 0, result
);
3351 g_assert_not_reached ();
3353 } else if (!strcmp (m
->name
, "FieldSetter")) {
3354 MonoClass
*k
= mono_object_class (this_arg
);
3360 /* If this is a proxy, then it must be a CBO */
3361 if (mono_class_is_transparent_proxy (k
)) {
3362 MonoTransparentProxy
*tp
= (MonoTransparentProxy
*) this_arg
;
3363 this_arg
= tp
->rp
->unwrapped_server
;
3364 g_assert (this_arg
);
3365 k
= mono_object_class (this_arg
);
3368 name
= mono_array_get (params
, MonoString
*, 1);
3369 str
= mono_string_to_utf8_checked (name
, &error
);
3370 if (mono_error_set_pending_exception (&error
))
3374 MonoClassField
* field
= mono_class_get_field_from_name (k
, str
);
3377 MonoClass
*field_klass
= mono_class_from_mono_type (field
->type
);
3378 MonoObject
*val
= (MonoObject
*)mono_array_get (params
, gpointer
, 2);
3380 if (field_klass
->valuetype
) {
3381 size
= mono_type_size (field
->type
, &align
);
3382 g_assert (size
== mono_class_value_size (field_klass
, NULL
));
3383 mono_gc_wbarrier_value_copy ((char *)this_arg
+ field
->offset
, (char*)val
+ sizeof (MonoObject
), 1, field_klass
);
3385 mono_gc_wbarrier_set_field (this_arg
, (char*)this_arg
+ field
->offset
, val
);
3388 out_args
= mono_array_new_checked (domain
, mono_defaults
.object_class
, 0, &error
);
3389 if (mono_error_set_pending_exception (&error
))
3391 mono_gc_wbarrier_generic_store (outArgs
, (MonoObject
*) out_args
);
3400 g_assert_not_reached ();
3405 for (i
= 0; i
< mono_array_length (params
); i
++) {
3406 if (sig
->params
[i
]->byref
)
3410 out_args
= mono_array_new_checked (domain
, mono_defaults
.object_class
, outarg_count
, &error
);
3411 if (mono_error_set_pending_exception (&error
))
3414 /* handle constructors only for objects already allocated */
3415 if (!strcmp (method
->method
->name
, ".ctor"))
3416 g_assert (this_arg
);
3418 /* This can be called only on MBR objects, so no need to unbox for valuetypes. */
3419 g_assert (!method
->method
->klass
->valuetype
);
3420 result
= mono_runtime_invoke_array_checked (method
->method
, this_arg
, params
, &error
);
3421 if (mono_error_set_pending_exception (&error
))
3424 for (i
= 0, j
= 0; i
< mono_array_length (params
); i
++) {
3425 if (sig
->params
[i
]->byref
) {
3427 arg
= mono_array_get (params
, gpointer
, i
);
3428 mono_array_setref (out_args
, j
, arg
);
3433 mono_gc_wbarrier_generic_store (outArgs
, (MonoObject
*) out_args
);
3440 read_enum_value (const char *mem
, int type
)
3443 case MONO_TYPE_BOOLEAN
:
3445 return *(guint8
*)mem
;
3447 return *(gint8
*)mem
;
3448 case MONO_TYPE_CHAR
:
3450 return read16 (mem
);
3452 return (gint16
) read16 (mem
);
3454 return read32 (mem
);
3456 return (gint32
) read32 (mem
);
3459 return read64 (mem
);
3461 g_assert_not_reached ();
3467 write_enum_value (char *mem
, int type
, guint64 value
)
3471 case MONO_TYPE_I1
: {
3472 guint8
*p
= (guint8
*)mem
;
3478 case MONO_TYPE_CHAR
: {
3479 guint16
*p
= (guint16
*)mem
;
3484 case MONO_TYPE_I4
: {
3485 guint32
*p
= (guint32
*)mem
;
3490 case MONO_TYPE_I8
: {
3491 guint64
*p
= (guint64
*)mem
;
3496 g_assert_not_reached ();
3501 ICALL_EXPORT MonoObject
*
3502 ves_icall_System_Enum_ToObject (MonoReflectionType
*enumType
, guint64 value
)
3510 domain
= mono_object_domain (enumType
);
3511 enumc
= mono_class_from_mono_type (enumType
->type
);
3513 mono_class_init_checked (enumc
, &error
);
3514 if (mono_error_set_pending_exception (&error
))
3517 etype
= mono_class_enum_basetype (enumc
);
3519 res
= mono_object_new_checked (domain
, enumc
, &error
);
3520 if (mono_error_set_pending_exception (&error
))
3522 write_enum_value ((char *)res
+ sizeof (MonoObject
), etype
->type
, value
);
3527 ICALL_EXPORT MonoBoolean
3528 ves_icall_System_Enum_InternalHasFlag (MonoObject
*a
, MonoObject
*b
)
3530 int size
= mono_class_value_size (a
->vtable
->klass
, NULL
);
3531 guint64 a_val
= 0, b_val
= 0;
3533 memcpy (&a_val
, mono_object_unbox (a
), size
);
3534 memcpy (&b_val
, mono_object_unbox (b
), size
);
3536 return (a_val
& b_val
) == b_val
;
3539 ICALL_EXPORT MonoObject
*
3540 ves_icall_System_Enum_get_value (MonoObject
*eobj
)
3552 g_assert (eobj
->vtable
->klass
->enumtype
);
3554 enumc
= mono_class_from_mono_type (mono_class_enum_basetype (eobj
->vtable
->klass
));
3555 res
= mono_object_new_checked (mono_object_domain (eobj
), enumc
, &error
);
3556 if (mono_error_set_pending_exception (&error
))
3558 dst
= (char *)res
+ sizeof (MonoObject
);
3559 src
= (char *)eobj
+ sizeof (MonoObject
);
3560 size
= mono_class_value_size (enumc
, NULL
);
3562 memcpy (dst
, src
, size
);
3567 ICALL_EXPORT MonoReflectionType
*
3568 ves_icall_System_Enum_get_underlying_type (MonoReflectionType
*type
)
3571 MonoReflectionType
*ret
;
3575 klass
= mono_class_from_mono_type (type
->type
);
3576 mono_class_init_checked (klass
, &error
);
3577 if (mono_error_set_pending_exception (&error
))
3580 etype
= mono_class_enum_basetype (klass
);
3582 mono_set_pending_exception (mono_get_exception_argument ("enumType", "Type provided must be an Enum."));
3586 ret
= mono_type_get_object_checked (mono_object_domain (type
), etype
, &error
);
3587 mono_error_set_pending_exception (&error
);
3593 ves_icall_System_Enum_compare_value_to (MonoObject
*eobj
, MonoObject
*other
)
3595 gpointer tdata
= (char *)eobj
+ sizeof (MonoObject
);
3596 gpointer odata
= (char *)other
+ sizeof (MonoObject
);
3597 MonoType
*basetype
= mono_class_enum_basetype (eobj
->vtable
->klass
);
3598 g_assert (basetype
);
3603 if (eobj
->vtable
->klass
!= other
->vtable
->klass
)
3606 #define COMPARE_ENUM_VALUES(ENUM_TYPE) do { \
3607 ENUM_TYPE me = *((ENUM_TYPE*)tdata); \
3608 ENUM_TYPE other = *((ENUM_TYPE*)odata); \
3611 return me > other ? 1 : -1; \
3614 switch (basetype
->type
) {
3616 COMPARE_ENUM_VALUES (guint8
);
3618 COMPARE_ENUM_VALUES (gint8
);
3619 case MONO_TYPE_CHAR
:
3621 COMPARE_ENUM_VALUES (guint16
);
3623 COMPARE_ENUM_VALUES (gint16
);
3625 COMPARE_ENUM_VALUES (guint32
);
3627 COMPARE_ENUM_VALUES (gint32
);
3629 COMPARE_ENUM_VALUES (guint64
);
3631 COMPARE_ENUM_VALUES (gint64
);
3635 #undef COMPARE_ENUM_VALUES
3636 /* indicates that the enum was of an unsupported unerlying type */
3641 ves_icall_System_Enum_get_hashcode (MonoObject
*eobj
)
3643 gpointer data
= (char *)eobj
+ sizeof (MonoObject
);
3644 MonoType
*basetype
= mono_class_enum_basetype (eobj
->vtable
->klass
);
3645 g_assert (basetype
);
3647 switch (basetype
->type
) {
3648 case MONO_TYPE_I1
: {
3649 gint8 value
= *((gint8
*)data
);
3650 return ((int)value
^ (int)value
<< 8);
3653 return *((guint8
*)data
);
3654 case MONO_TYPE_CHAR
:
3656 return *((guint16
*)data
);
3658 case MONO_TYPE_I2
: {
3659 gint16 value
= *((gint16
*)data
);
3660 return ((int)(guint16
)value
| (((int)value
) << 16));
3663 return *((guint32
*)data
);
3665 return *((gint32
*)data
);
3667 case MONO_TYPE_I8
: {
3668 gint64 value
= *((gint64
*)data
);
3669 return (gint
)(value
& 0xffffffff) ^ (int)(value
>> 32);
3672 g_error ("Implement type 0x%02x in get_hashcode", basetype
->type
);
3678 get_enum_field (MonoDomain
*domain
, MonoArrayHandle names
, MonoArrayHandle values
, int base_type
, MonoClassField
*field
, guint
* j
, guint64
*previous_value
, gboolean
*sorted
, MonoError
*error
)
3681 HANDLE_FUNCTION_ENTER();
3682 guint64 field_value
;
3684 MonoTypeEnum def_type
;
3686 if (!(field
->type
->attrs
& FIELD_ATTRIBUTE_STATIC
))
3688 if (strcmp ("value__", mono_field_get_name (field
)) == 0)
3690 if (mono_field_is_deleted (field
))
3692 MonoStringHandle name
= mono_string_new_handle (domain
, mono_field_get_name (field
), error
);
3695 MONO_HANDLE_ARRAY_SETREF (names
, *j
, name
);
3697 p
= mono_class_get_field_default_value (field
, &def_type
);
3698 /* len = */ mono_metadata_decode_blob_size (p
, &p
);
3700 field_value
= read_enum_value (p
, base_type
);
3701 MONO_HANDLE_ARRAY_SETVAL (values
, guint64
, *j
, field_value
);
3703 if (*previous_value
> field_value
)
3706 *previous_value
= field_value
;
3709 HANDLE_FUNCTION_RETURN();
3712 ICALL_EXPORT MonoBoolean
3713 ves_icall_System_Enum_GetEnumValuesAndNames (MonoReflectionTypeHandle type
, MonoArrayHandleOut values
, MonoArrayHandleOut names
, MonoError
*error
)
3715 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (type
);
3716 MonoClass
*enumc
= mono_class_from_mono_type (MONO_HANDLE_RAW(type
)->type
);
3717 guint j
= 0, nvalues
;
3719 MonoClassField
*field
;
3721 guint64 previous_value
= 0;
3722 gboolean sorted
= TRUE
;
3725 mono_class_init_checked (enumc
, error
);
3726 return_val_if_nok (error
, FALSE
);
3728 if (!enumc
->enumtype
) {
3729 mono_error_set_argument (error
, "enumType", "Type provided must be an Enum.");
3733 base_type
= mono_class_enum_basetype (enumc
)->type
;
3735 nvalues
= mono_class_num_fields (enumc
) > 0 ? mono_class_num_fields (enumc
) - 1 : 0;
3736 MONO_HANDLE_ASSIGN(names
, mono_array_new_handle (domain
, mono_defaults
.string_class
, nvalues
, error
));
3737 return_val_if_nok (error
, FALSE
);
3738 MONO_HANDLE_ASSIGN(values
, mono_array_new_handle (domain
, mono_defaults
.uint64_class
, nvalues
, error
));
3739 return_val_if_nok (error
, FALSE
);
3742 while ((field
= mono_class_get_fields (enumc
, &iter
))) {
3743 get_enum_field(domain
, names
, values
, base_type
, field
, &j
, &previous_value
, &sorted
, error
);
3747 return_val_if_nok (error
, FALSE
);
3753 BFLAGS_IgnoreCase
= 1,
3754 BFLAGS_DeclaredOnly
= 2,
3755 BFLAGS_Instance
= 4,
3757 BFLAGS_Public
= 0x10,
3758 BFLAGS_NonPublic
= 0x20,
3759 BFLAGS_FlattenHierarchy
= 0x40,
3760 BFLAGS_InvokeMethod
= 0x100,
3761 BFLAGS_CreateInstance
= 0x200,
3762 BFLAGS_GetField
= 0x400,
3763 BFLAGS_SetField
= 0x800,
3764 BFLAGS_GetProperty
= 0x1000,
3765 BFLAGS_SetProperty
= 0x2000,
3766 BFLAGS_ExactBinding
= 0x10000,
3767 BFLAGS_SuppressChangeType
= 0x20000,
3768 BFLAGS_OptionalParamBinding
= 0x40000
3771 ICALL_EXPORT GPtrArray
*
3772 ves_icall_RuntimeType_GetFields_native (MonoReflectionTypeHandle ref_type
, char *utf8_name
, guint32 bflags
, MonoError
*error
)
3775 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
3778 return g_ptr_array_new ();
3781 int (*compare_func
) (const char *s1
, const char *s2
) = NULL
;
3782 compare_func
= (bflags
& BFLAGS_IgnoreCase
) ? mono_utf8_strcasecmp
: strcmp
;
3784 MonoClass
*startklass
, *klass
;
3785 klass
= startklass
= mono_class_from_mono_type (type
);
3787 GPtrArray
*ptr_array
= g_ptr_array_sized_new (16);
3790 if (mono_class_has_failure (klass
)) {
3791 mono_error_set_for_class_failure (error
, klass
);
3795 MonoClassField
*field
;
3796 gpointer iter
= NULL
;
3797 while ((field
= mono_class_get_fields_lazy (klass
, &iter
))) {
3798 guint32 flags
= mono_field_get_flags (field
);
3800 if (mono_field_is_deleted_with_flags (field
, flags
))
3802 if ((flags
& FIELD_ATTRIBUTE_FIELD_ACCESS_MASK
) == FIELD_ATTRIBUTE_PUBLIC
) {
3803 if (bflags
& BFLAGS_Public
)
3805 } else if ((klass
== startklass
) || (flags
& FIELD_ATTRIBUTE_FIELD_ACCESS_MASK
) != FIELD_ATTRIBUTE_PRIVATE
) {
3806 if (bflags
& BFLAGS_NonPublic
) {
3813 if (flags
& FIELD_ATTRIBUTE_STATIC
) {
3814 if (bflags
& BFLAGS_Static
)
3815 if ((bflags
& BFLAGS_FlattenHierarchy
) || (klass
== startklass
))
3818 if (bflags
& BFLAGS_Instance
)
3825 if (utf8_name
!= NULL
&& compare_func (mono_field_get_name (field
), utf8_name
))
3828 g_ptr_array_add (ptr_array
, field
);
3830 if (!(bflags
& BFLAGS_DeclaredOnly
) && (klass
= klass
->parent
))
3836 g_ptr_array_free (ptr_array
, TRUE
);
3841 method_nonpublic (MonoMethod
* method
, gboolean start_klass
)
3843 switch (method
->flags
& METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK
) {
3844 case METHOD_ATTRIBUTE_ASSEM
:
3845 return (start_klass
|| mono_defaults
.generic_ilist_class
);
3846 case METHOD_ATTRIBUTE_PRIVATE
:
3848 case METHOD_ATTRIBUTE_PUBLIC
:
3856 mono_class_get_methods_by_name (MonoClass
*klass
, const char *name
, guint32 bflags
, gboolean ignore_case
, gboolean allow_ctors
, MonoError
*error
)
3859 MonoClass
*startklass
;
3863 /*FIXME, use MonoBitSet*/
3864 guint32 method_slots_default
[8];
3865 guint32
*method_slots
= NULL
;
3866 int (*compare_func
) (const char *s1
, const char *s2
) = NULL
;
3868 array
= g_ptr_array_new ();
3873 compare_func
= (ignore_case
) ? mono_utf8_strcasecmp
: strcmp
;
3875 /* An optimization for calls made from Delegate:CreateDelegate () */
3876 if (klass
->delegate
&& name
&& !strcmp (name
, "Invoke") && (bflags
== (BFLAGS_Public
| BFLAGS_Static
| BFLAGS_Instance
))) {
3877 method
= mono_get_delegate_invoke (klass
);
3880 g_ptr_array_add (array
, method
);
3884 mono_class_setup_methods (klass
);
3885 mono_class_setup_vtable (klass
);
3886 if (mono_class_has_failure (klass
))
3889 if (is_generic_parameter (&klass
->byval_arg
))
3890 nslots
= mono_class_get_vtable_size (klass
->parent
);
3892 nslots
= MONO_CLASS_IS_INTERFACE (klass
) ? mono_class_num_methods (klass
) : mono_class_get_vtable_size (klass
);
3893 if (nslots
>= sizeof (method_slots_default
) * 8) {
3894 method_slots
= g_new0 (guint32
, nslots
/ 32 + 1);
3896 method_slots
= method_slots_default
;
3897 memset (method_slots
, 0, sizeof (method_slots_default
));
3900 mono_class_setup_methods (klass
);
3901 mono_class_setup_vtable (klass
);
3902 if (mono_class_has_failure (klass
))
3906 while ((method
= mono_class_get_methods (klass
, &iter
))) {
3908 if (method
->slot
!= -1) {
3909 g_assert (method
->slot
< nslots
);
3910 if (method_slots
[method
->slot
>> 5] & (1 << (method
->slot
& 0x1f)))
3912 if (!(method
->flags
& METHOD_ATTRIBUTE_NEW_SLOT
))
3913 method_slots
[method
->slot
>> 5] |= 1 << (method
->slot
& 0x1f);
3916 if (!allow_ctors
&& method
->name
[0] == '.' && (strcmp (method
->name
, ".ctor") == 0 || strcmp (method
->name
, ".cctor") == 0))
3918 if ((method
->flags
& METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK
) == METHOD_ATTRIBUTE_PUBLIC
) {
3919 if (bflags
& BFLAGS_Public
)
3921 } else if ((bflags
& BFLAGS_NonPublic
) && method_nonpublic (method
, (klass
== startklass
))) {
3927 if (method
->flags
& METHOD_ATTRIBUTE_STATIC
) {
3928 if (bflags
& BFLAGS_Static
)
3929 if ((bflags
& BFLAGS_FlattenHierarchy
) || (klass
== startklass
))
3932 if (bflags
& BFLAGS_Instance
)
3940 if (compare_func (name
, method
->name
))
3945 g_ptr_array_add (array
, method
);
3947 if (!(bflags
& BFLAGS_DeclaredOnly
) && (klass
= klass
->parent
))
3949 if (method_slots
!= method_slots_default
)
3950 g_free (method_slots
);
3955 if (method_slots
!= method_slots_default
)
3956 g_free (method_slots
);
3957 g_ptr_array_free (array
, TRUE
);
3959 g_assert (mono_class_has_failure (klass
));
3960 mono_error_set_for_class_failure (error
, klass
);
3964 ICALL_EXPORT GPtrArray
*
3965 ves_icall_RuntimeType_GetMethodsByName_native (MonoReflectionTypeHandle ref_type
, const char *mname
, guint32 bflags
, MonoBoolean ignore_case
, MonoError
*error
)
3968 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
3970 MonoClass
*klass
= mono_class_from_mono_type (type
);
3972 return g_ptr_array_new ();
3975 return mono_class_get_methods_by_name (klass
, mname
, bflags
, ignore_case
, FALSE
, error
);
3978 ICALL_EXPORT GPtrArray
*
3979 ves_icall_RuntimeType_GetConstructors_native (MonoReflectionTypeHandle ref_type
, guint32 bflags
, MonoError
*error
)
3982 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
3984 return g_ptr_array_new ();
3987 MonoClass
*startklass
, *klass
;
3988 klass
= startklass
= mono_class_from_mono_type (type
);
3990 mono_class_setup_methods (klass
);
3991 if (mono_class_has_failure (klass
)) {
3992 mono_error_set_for_class_failure (error
, klass
);
3997 GPtrArray
*res_array
= g_ptr_array_sized_new (4); /* FIXME, guestimating */
4000 gpointer iter
= NULL
;
4001 while ((method
= mono_class_get_methods (klass
, &iter
))) {
4003 if (strcmp (method
->name
, ".ctor") && strcmp (method
->name
, ".cctor"))
4005 if ((method
->flags
& METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK
) == METHOD_ATTRIBUTE_PUBLIC
) {
4006 if (bflags
& BFLAGS_Public
)
4009 if (bflags
& BFLAGS_NonPublic
)
4015 if (method
->flags
& METHOD_ATTRIBUTE_STATIC
) {
4016 if (bflags
& BFLAGS_Static
)
4017 if ((bflags
& BFLAGS_FlattenHierarchy
) || (klass
== startklass
))
4020 if (bflags
& BFLAGS_Instance
)
4026 g_ptr_array_add (res_array
, method
);
4033 property_hash (gconstpointer data
)
4035 MonoProperty
*prop
= (MonoProperty
*)data
;
4037 return g_str_hash (prop
->name
);
4041 property_accessor_override (MonoMethod
*method1
, MonoMethod
*method2
)
4043 if (method1
->slot
!= -1 && method1
->slot
== method2
->slot
)
4046 if (mono_class_get_generic_type_definition (method1
->klass
) == mono_class_get_generic_type_definition (method2
->klass
)) {
4047 if (method1
->is_inflated
)
4048 method1
= ((MonoMethodInflated
*) method1
)->declaring
;
4049 if (method2
->is_inflated
)
4050 method2
= ((MonoMethodInflated
*) method2
)->declaring
;
4053 return mono_metadata_signature_equal (mono_method_signature (method1
), mono_method_signature (method2
));
4057 property_equal (MonoProperty
*prop1
, MonoProperty
*prop2
)
4059 // Properties are hide-by-name-and-signature
4060 if (!g_str_equal (prop1
->name
, prop2
->name
))
4063 /* If we see a property in a generic method, we want to
4064 compare the generic signatures, not the inflated signatures
4065 because we might conflate two properties that were
4069 public T this[T t] { getter { return t; } } // method 1
4070 public U this[U u] { getter { return u; } } // method 2
4073 If we see int Foo<int,int>::Item[int] we need to know if
4074 the indexer came from method 1 or from method 2, and we
4075 shouldn't conflate them. (Bugzilla 36283)
4077 if (prop1
->get
&& prop2
->get
&& !property_accessor_override (prop1
->get
, prop2
->get
))
4080 if (prop1
->set
&& prop2
->set
&& !property_accessor_override (prop1
->set
, prop2
->set
))
4087 property_accessor_nonpublic (MonoMethod
* accessor
, gboolean start_klass
)
4092 return method_nonpublic (accessor
, start_klass
);
4095 ICALL_EXPORT GPtrArray
*
4096 ves_icall_RuntimeType_GetPropertiesByName_native (MonoReflectionTypeHandle ref_type
, gchar
*propname
, guint32 bflags
, MonoBoolean ignore_case
, MonoError
*error
)
4099 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
4103 return g_ptr_array_new ();
4107 MonoClass
*startklass
, *klass
;
4108 klass
= startklass
= mono_class_from_mono_type (type
);
4110 int (*compare_func
) (const char *s1
, const char *s2
) = (ignore_case
) ? mono_utf8_strcasecmp
: strcmp
;
4112 GPtrArray
*res_array
= g_ptr_array_sized_new (8); /*This the average for ASP.NET types*/
4114 GHashTable
*properties
= g_hash_table_new (property_hash
, (GEqualFunc
)property_equal
);
4117 mono_class_setup_methods (klass
);
4118 mono_class_setup_vtable (klass
);
4119 if (mono_class_has_failure (klass
)) {
4120 mono_error_set_for_class_failure (error
, klass
);
4125 gpointer iter
= NULL
;
4126 while ((prop
= mono_class_get_properties (klass
, &iter
))) {
4128 MonoMethod
*method
= prop
->get
;
4133 flags
= method
->flags
;
4134 if ((prop
->get
&& ((prop
->get
->flags
& METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK
) == METHOD_ATTRIBUTE_PUBLIC
)) ||
4135 (prop
->set
&& ((prop
->set
->flags
& METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK
) == METHOD_ATTRIBUTE_PUBLIC
))) {
4136 if (bflags
& BFLAGS_Public
)
4138 } else if (bflags
& BFLAGS_NonPublic
) {
4139 if (property_accessor_nonpublic(prop
->get
, startklass
== klass
) ||
4140 property_accessor_nonpublic(prop
->set
, startklass
== klass
)) {
4147 if (flags
& METHOD_ATTRIBUTE_STATIC
) {
4148 if (bflags
& BFLAGS_Static
)
4149 if ((bflags
& BFLAGS_FlattenHierarchy
) || (klass
== startklass
))
4152 if (bflags
& BFLAGS_Instance
)
4160 if (propname
!= NULL
&& compare_func (propname
, prop
->name
))
4163 if (g_hash_table_lookup (properties
, prop
))
4166 g_ptr_array_add (res_array
, prop
);
4168 g_hash_table_insert (properties
, prop
, prop
);
4170 if (!(bflags
& BFLAGS_DeclaredOnly
) && (klass
= klass
->parent
))
4173 g_hash_table_destroy (properties
);
4180 g_hash_table_destroy (properties
);
4181 g_ptr_array_free (res_array
, TRUE
);
4187 event_hash (gconstpointer data
)
4189 MonoEvent
*event
= (MonoEvent
*)data
;
4191 return g_str_hash (event
->name
);
4195 event_equal (MonoEvent
*event1
, MonoEvent
*event2
)
4197 // Events are hide-by-name
4198 return g_str_equal (event1
->name
, event2
->name
);
4201 ICALL_EXPORT GPtrArray
*
4202 ves_icall_RuntimeType_GetEvents_native (MonoReflectionTypeHandle ref_type
, char *utf8_name
, guint32 bflags
, MonoError
*error
)
4205 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
4208 return g_ptr_array_new ();
4211 int (*compare_func
) (const char *s1
, const char *s2
) = (bflags
& BFLAGS_IgnoreCase
) ? mono_utf8_strcasecmp
: strcmp
;
4213 GPtrArray
*res_array
= g_ptr_array_sized_new (4);
4215 MonoClass
*startklass
, *klass
;
4216 klass
= startklass
= mono_class_from_mono_type (type
);
4218 GHashTable
*events
= g_hash_table_new (event_hash
, (GEqualFunc
)event_equal
);
4220 mono_class_setup_methods (klass
);
4221 mono_class_setup_vtable (klass
);
4222 if (mono_class_has_failure (klass
)) {
4223 mono_error_set_for_class_failure (error
, klass
);
4228 gpointer iter
= NULL
;
4229 while ((event
= mono_class_get_events (klass
, &iter
))) {
4231 MonoMethod
*method
= event
->add
;
4233 method
= event
->remove
;
4235 method
= event
->raise
;
4237 if ((method
->flags
& METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK
) == METHOD_ATTRIBUTE_PUBLIC
) {
4238 if (bflags
& BFLAGS_Public
)
4240 } else if ((klass
== startklass
) || (method
->flags
& METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK
) != METHOD_ATTRIBUTE_PRIVATE
) {
4241 if (bflags
& BFLAGS_NonPublic
)
4246 if (bflags
& BFLAGS_NonPublic
)
4252 if (method
->flags
& METHOD_ATTRIBUTE_STATIC
) {
4253 if (bflags
& BFLAGS_Static
)
4254 if ((bflags
& BFLAGS_FlattenHierarchy
) || (klass
== startklass
))
4257 if (bflags
& BFLAGS_Instance
)
4262 if (bflags
& BFLAGS_Instance
)
4267 if (utf8_name
!= NULL
&& compare_func (event
->name
, utf8_name
))
4270 if (g_hash_table_lookup (events
, event
))
4273 g_ptr_array_add (res_array
, event
);
4275 g_hash_table_insert (events
, event
, event
);
4277 if (!(bflags
& BFLAGS_DeclaredOnly
) && (klass
= klass
->parent
))
4280 g_hash_table_destroy (events
);
4286 g_hash_table_destroy (events
);
4288 g_ptr_array_free (res_array
, TRUE
);
4293 ICALL_EXPORT GPtrArray
*
4294 ves_icall_RuntimeType_GetNestedTypes_native (MonoReflectionTypeHandle ref_type
, char *str
, guint32 bflags
, MonoError
*error
)
4297 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
4300 return g_ptr_array_new ();
4303 MonoClass
*klass
= mono_class_from_mono_type (type
);
4306 * If a nested type is generic, return its generic type definition.
4307 * Note that this means that the return value is essentially the set
4308 * of nested types of the generic type definition of @klass.
4310 * A note in MSDN claims that a generic type definition can have
4311 * nested types that aren't generic. In any case, the container of that
4312 * nested type would be the generic type definition.
4314 if (mono_class_is_ginst (klass
))
4315 klass
= mono_class_get_generic_class (klass
)->container_class
;
4317 GPtrArray
*res_array
= g_ptr_array_new ();
4320 gpointer iter
= NULL
;
4321 while ((nested
= mono_class_get_nested_types (klass
, &iter
))) {
4323 if ((mono_class_get_flags (nested
) & TYPE_ATTRIBUTE_VISIBILITY_MASK
) == TYPE_ATTRIBUTE_NESTED_PUBLIC
) {
4324 if (bflags
& BFLAGS_Public
)
4327 if (bflags
& BFLAGS_NonPublic
)
4333 if (str
!= NULL
&& strcmp (nested
->name
, str
))
4336 g_ptr_array_add (res_array
, &nested
->byval_arg
);
4343 get_type_from_module_builder_module (MonoArrayHandle modules
, int i
, MonoTypeNameParse
*info
, MonoBoolean ignoreCase
, gboolean
*type_resolve
, MonoError
*error
)
4345 HANDLE_FUNCTION_ENTER ();
4347 MonoType
*type
= NULL
;
4348 MonoReflectionModuleBuilderHandle mb
= MONO_HANDLE_NEW (MonoReflectionModuleBuilder
, NULL
);
4349 MONO_HANDLE_ARRAY_GETREF (mb
, modules
, i
);
4350 MonoDynamicImage
*dynamic_image
= MONO_HANDLE_GETVAL (mb
, dynamic_image
);
4351 type
= mono_reflection_get_type_checked (&dynamic_image
->image
, &dynamic_image
->image
, info
, ignoreCase
, type_resolve
, error
);
4352 HANDLE_FUNCTION_RETURN_VAL (type
);
4356 get_type_from_module_builder_loaded_modules (MonoArrayHandle loaded_modules
, int i
, MonoTypeNameParse
*info
, MonoBoolean ignoreCase
, gboolean
*type_resolve
, MonoError
*error
)
4358 HANDLE_FUNCTION_ENTER ();
4360 MonoType
*type
= NULL
;
4361 MonoReflectionModuleHandle mod
= MONO_HANDLE_NEW (MonoReflectionModule
, NULL
);
4362 MONO_HANDLE_ARRAY_GETREF (mod
, loaded_modules
, i
);
4363 MonoImage
*image
= MONO_HANDLE_GETVAL (mod
, image
);
4364 type
= mono_reflection_get_type_checked (image
, image
, info
, ignoreCase
, type_resolve
, error
);
4365 HANDLE_FUNCTION_RETURN_VAL (type
);
4368 ICALL_EXPORT MonoReflectionTypeHandle
4369 ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssemblyHandle assembly_h
, MonoReflectionModuleHandle module
, MonoStringHandle name
, MonoBoolean throwOnError
, MonoBoolean ignoreCase
, MonoError
*error
)
4373 MonoTypeNameParse info
;
4374 gboolean type_resolve
;
4376 /* On MS.NET, this does not fire a TypeResolve event */
4377 type_resolve
= TRUE
;
4378 char *str
= mono_string_handle_to_utf8 (name
, error
);
4382 /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
4383 if (!mono_reflection_parse_type (str
, &info
)) {
4385 mono_reflection_free_type_info (&info
);
4387 mono_error_set_argument (error
, "name", "failed to parse the type");
4390 /*g_print ("failed parse\n");*/
4391 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
4394 if (info
.assembly
.name
) {
4396 mono_reflection_free_type_info (&info
);
4398 /* 1.0 and 2.0 throw different exceptions */
4399 if (mono_defaults
.generic_ilist_class
)
4400 mono_error_set_argument (error
, NULL
, "Type names passed to Assembly.GetType() must not specify an assembly.");
4402 mono_error_set_type_load_name (error
, g_strdup (""), g_strdup (""), "Type names passed to Assembly.GetType() must not specify an assembly.");
4405 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
4408 MonoType
*type
= NULL
;
4409 if (!MONO_HANDLE_IS_NULL (module
)) {
4410 MonoImage
*image
= MONO_HANDLE_GETVAL (module
, image
);
4412 type
= mono_reflection_get_type_checked (image
, image
, &info
, ignoreCase
, &type_resolve
, error
);
4413 if (!is_ok (error
)) {
4415 mono_reflection_free_type_info (&info
);
4421 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (assembly_h
, assembly
);
4422 if (assembly_is_dynamic (assembly
)) {
4423 /* Enumerate all modules */
4424 MonoReflectionAssemblyBuilderHandle abuilder
= MONO_HANDLE_NEW (MonoReflectionAssemblyBuilder
, NULL
);
4425 MONO_HANDLE_ASSIGN (abuilder
, assembly_h
);
4428 MonoArrayHandle modules
= MONO_HANDLE_NEW (MonoArray
, NULL
);
4429 MONO_HANDLE_GET (modules
, abuilder
, modules
);
4430 if (!MONO_HANDLE_IS_NULL (modules
)) {
4431 int n
= mono_array_handle_length (modules
);
4432 for (i
= 0; i
< n
; ++i
) {
4433 type
= get_type_from_module_builder_module (modules
, i
, &info
, ignoreCase
, &type_resolve
, error
);
4434 if (!is_ok (error
)) {
4436 mono_reflection_free_type_info (&info
);
4444 MonoArrayHandle loaded_modules
= MONO_HANDLE_NEW (MonoArray
, NULL
);
4445 MONO_HANDLE_GET (loaded_modules
, abuilder
, loaded_modules
);
4446 if (!type
&& !MONO_HANDLE_IS_NULL (loaded_modules
)) {
4447 int n
= mono_array_handle_length (loaded_modules
);
4448 for (i
= 0; i
< n
; ++i
) {
4449 type
= get_type_from_module_builder_loaded_modules (loaded_modules
, i
, &info
, ignoreCase
, &type_resolve
, error
);
4451 if (!is_ok (error
)) {
4453 mono_reflection_free_type_info (&info
);
4462 type
= mono_reflection_get_type_checked (assembly
->image
, assembly
->image
, &info
, ignoreCase
, &type_resolve
, error
);
4463 if (!is_ok (error
)) {
4465 mono_reflection_free_type_info (&info
);
4471 mono_reflection_free_type_info (&info
);
4475 MonoError inner_error
;
4476 char *typename
= mono_string_handle_to_utf8 (name
, &inner_error
);
4477 mono_error_assert_ok (&inner_error
);
4478 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (assembly_h
, assembly
);
4479 char *assmname
= mono_stringify_assembly_name (&assembly
->aname
);
4480 mono_error_set_type_load_name (error
, typename
, assmname
, "%s", "");
4484 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
4487 if (type
->type
== MONO_TYPE_CLASS
) {
4488 MonoClass
*klass
= mono_type_get_class (type
);
4490 /* need to report exceptions ? */
4491 if (throwOnError
&& mono_class_has_failure (klass
)) {
4492 /* report SecurityException (or others) that occured when loading the assembly */
4493 mono_error_set_for_class_failure (error
, klass
);
4498 /* g_print ("got it\n"); */
4499 return mono_type_get_object_handle (MONO_HANDLE_DOMAIN (assembly_h
), type
, error
);
4501 g_assert (!is_ok (error
));
4502 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
4506 replace_shadow_path (MonoDomain
*domain
, gchar
*dirname
, gchar
**filename
)
4509 gchar
*shadow_ini_file
;
4512 /* Check for shadow-copied assembly */
4513 if (mono_is_shadow_copy_enabled (domain
, dirname
)) {
4514 shadow_ini_file
= g_build_filename (dirname
, "__AssemblyInfo__.ini", NULL
);
4516 if (!g_file_get_contents (shadow_ini_file
, &content
, &len
, NULL
) ||
4517 !g_file_test (content
, G_FILE_TEST_IS_REGULAR
)) {
4523 g_free (shadow_ini_file
);
4524 if (content
!= NULL
) {
4527 *filename
= content
;
4534 ICALL_EXPORT MonoStringHandle
4535 ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssemblyHandle assembly
, MonoBoolean escaped
, MonoError
*error
)
4538 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (assembly
);
4539 MonoAssembly
*mass
= MONO_HANDLE_GETVAL (assembly
, assembly
);
4543 if (g_path_is_absolute (mass
->image
->name
)) {
4544 absolute
= g_strdup (mass
->image
->name
);
4545 dirname
= g_path_get_dirname (absolute
);
4547 absolute
= g_build_filename (mass
->basedir
, mass
->image
->name
, NULL
);
4548 dirname
= g_strdup (mass
->basedir
);
4551 replace_shadow_path (domain
, dirname
, &absolute
);
4554 mono_icall_make_platform_path (absolute
);
4558 uri
= g_filename_to_uri (absolute
, NULL
, NULL
);
4560 const gchar
*prepend
= mono_icall_get_file_path_prefix (absolute
);
4561 uri
= g_strconcat (prepend
, absolute
, NULL
);
4566 MonoStringHandle res
;
4568 res
= mono_string_new_handle (domain
, uri
, error
);
4571 res
= MONO_HANDLE_NEW (MonoString
, NULL
);
4576 ICALL_EXPORT MonoBoolean
4577 ves_icall_System_Reflection_Assembly_get_global_assembly_cache (MonoReflectionAssemblyHandle assembly
, MonoError
*error
)
4580 MonoAssembly
*mass
= MONO_HANDLE_GETVAL (assembly
,assembly
);
4582 return mass
->in_gac
;
4585 ICALL_EXPORT MonoReflectionAssemblyHandle
4586 ves_icall_System_Reflection_Assembly_load_with_partial_name (MonoStringHandle mname
, MonoObjectHandle evidence
, MonoError
*error
)
4589 MonoImageOpenStatus status
;
4590 MonoReflectionAssemblyHandle result
= MONO_HANDLE_CAST (MonoReflectionAssembly
, NULL_HANDLE
);
4592 name
= mono_string_handle_to_utf8 (mname
, error
);
4595 MonoAssembly
*res
= mono_assembly_load_with_partial_name (name
, &status
);
4601 result
= mono_assembly_get_object_handle (mono_domain_get (), res
, error
);
4606 ICALL_EXPORT MonoStringHandle
4607 ves_icall_System_Reflection_Assembly_get_location (MonoReflectionAssemblyHandle refassembly
, MonoError
*error
)
4609 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (refassembly
);
4610 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (refassembly
, assembly
);
4611 return mono_string_new_handle (domain
, mono_image_get_filename (assembly
->image
), error
);
4614 ICALL_EXPORT MonoBoolean
4615 ves_icall_System_Reflection_Assembly_get_ReflectionOnly (MonoReflectionAssemblyHandle assembly_h
, MonoError
*error
)
4618 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (assembly_h
, assembly
);
4619 return assembly
->ref_only
;
4622 ICALL_EXPORT MonoStringHandle
4623 ves_icall_System_Reflection_Assembly_InternalImageRuntimeVersion (MonoReflectionAssemblyHandle refassembly
, MonoError
*error
)
4625 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (refassembly
);
4626 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (refassembly
, assembly
);
4628 return mono_string_new_handle (domain
, assembly
->image
->version
, error
);
4631 ICALL_EXPORT MonoReflectionMethodHandle
4632 ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssemblyHandle assembly_h
, MonoError
*error
)
4635 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (assembly_h
);
4636 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (assembly_h
, assembly
);
4639 MonoReflectionMethodHandle res
= MONO_HANDLE_NEW (MonoReflectionMethod
, NULL
);
4640 guint32 token
= mono_image_get_entry_point (assembly
->image
);
4644 method
= mono_get_method_checked (assembly
->image
, token
, NULL
, NULL
, error
);
4648 MONO_HANDLE_ASSIGN (res
, mono_method_get_object_handle (domain
, method
, NULL
, error
));
4653 ICALL_EXPORT MonoReflectionModuleHandle
4654 ves_icall_System_Reflection_Assembly_GetManifestModuleInternal (MonoReflectionAssemblyHandle assembly
, MonoError
*error
)
4657 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (assembly
);
4658 MonoAssembly
*a
= MONO_HANDLE_GETVAL (assembly
, assembly
);
4659 return mono_module_get_object_handle (domain
, a
->image
, error
);
4663 add_manifest_resource_name_to_array (MonoDomain
*domain
, MonoImage
*image
, MonoTableInfo
*table
, int i
, MonoArrayHandle dest
, MonoError
*error
)
4665 HANDLE_FUNCTION_ENTER ();
4667 const char *val
= mono_metadata_string_heap (image
, mono_metadata_decode_row_col (table
, i
, MONO_MANIFEST_NAME
));
4668 MonoStringHandle str
= mono_string_new_handle (domain
, val
, error
);
4671 MONO_HANDLE_ARRAY_SETREF (dest
, i
, str
);
4673 HANDLE_FUNCTION_RETURN_VAL (is_ok (error
));
4676 ICALL_EXPORT MonoArrayHandle
4677 ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssemblyHandle assembly_h
, MonoError
*error
)
4680 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (assembly_h
);
4681 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (assembly_h
, assembly
);
4682 MonoTableInfo
*table
= &assembly
->image
->tables
[MONO_TABLE_MANIFESTRESOURCE
];
4683 MonoArrayHandle result
= mono_array_new_handle (domain
, mono_defaults
.string_class
, table
->rows
, error
);
4688 for (i
= 0; i
< table
->rows
; ++i
) {
4689 if (!add_manifest_resource_name_to_array (domain
, assembly
->image
, table
, i
, result
, error
))
4694 return MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
);
4697 ICALL_EXPORT MonoStringHandle
4698 ves_icall_System_Reflection_Assembly_GetAotId (MonoError
*error
)
4700 char *guid
= mono_runtime_get_aotid ();
4703 MonoStringHandle res
= mono_string_new_handle (mono_domain_get (), guid
, error
);
4708 static MonoAssemblyName
*
4709 create_referenced_assembly_name (MonoDomain
*domain
, MonoImage
*image
, MonoTableInfo
*t
, int i
, MonoError
*error
)
4712 MonoAssemblyName
*aname
= g_new0 (MonoAssemblyName
, 1);
4714 mono_assembly_get_assemblyref (image
, i
, aname
);
4715 aname
->hash_alg
= ASSEMBLY_HASH_SHA1
/* SHA1 (default) */;
4716 /* name and culture are pointers into the image tables, but we need
4717 * real malloc'd strings (so that we can g_free() them later from
4718 * Mono.RuntimeMarshal.FreeAssemblyName) */
4719 aname
->name
= g_strdup (aname
->name
);
4720 aname
->culture
= g_strdup (aname
->culture
);
4721 /* Don't need the hash value in managed */
4722 aname
->hash_value
= NULL
;
4723 aname
->hash_len
= 0;
4724 g_assert (aname
->public_key
== NULL
);
4726 /* note: this function doesn't return the codebase on purpose (i.e. it can
4727 be used under partial trust as path information isn't present). */
4731 ICALL_EXPORT GPtrArray
*
4732 ves_icall_System_Reflection_Assembly_InternalGetReferencedAssemblies (MonoReflectionAssemblyHandle assembly
, MonoError
*error
)
4735 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (assembly
);
4736 MonoAssembly
*ass
= MONO_HANDLE_GETVAL(assembly
, assembly
);
4737 MonoImage
*image
= ass
->image
;
4739 MonoTableInfo
*t
= &image
->tables
[MONO_TABLE_ASSEMBLYREF
];
4740 int count
= t
->rows
;
4742 GPtrArray
*result
= g_ptr_array_sized_new (count
);
4744 for (int i
= 0; i
< count
; i
++) {
4745 MonoAssemblyName
*aname
= create_referenced_assembly_name (domain
, image
, t
, i
, error
);
4748 g_ptr_array_add (result
, aname
);
4753 /* move this in some file in mono/util/ */
4755 g_concat_dir_and_file (const char *dir
, const char *file
)
4757 g_return_val_if_fail (dir
!= NULL
, NULL
);
4758 g_return_val_if_fail (file
!= NULL
, NULL
);
4761 * If the directory name doesn't have a / on the end, we need
4762 * to add one so we get a proper path to the file
4764 if (dir
[strlen(dir
) - 1] != G_DIR_SEPARATOR
)
4765 return g_strconcat (dir
, G_DIR_SEPARATOR_S
, file
, NULL
);
4767 return g_strconcat (dir
, file
, NULL
);
4771 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssemblyHandle assembly_h
, MonoStringHandle name
, gint32
*size
, MonoReflectionModuleHandleOut ref_module
, MonoError
*error
)
4774 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (assembly_h
);
4775 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (assembly_h
, assembly
);
4776 MonoTableInfo
*table
= &assembly
->image
->tables
[MONO_TABLE_MANIFESTRESOURCE
];
4778 guint32 cols
[MONO_MANIFEST_SIZE
];
4779 guint32 impl
, file_idx
;
4783 char *n
= mono_string_handle_to_utf8 (name
, error
);
4784 return_val_if_nok (error
, NULL
);
4786 for (i
= 0; i
< table
->rows
; ++i
) {
4787 mono_metadata_decode_row (table
, i
, cols
, MONO_MANIFEST_SIZE
);
4788 val
= mono_metadata_string_heap (assembly
->image
, cols
[MONO_MANIFEST_NAME
]);
4789 if (strcmp (val
, n
) == 0)
4793 if (i
== table
->rows
)
4796 impl
= cols
[MONO_MANIFEST_IMPLEMENTATION
];
4799 * this code should only be called after obtaining the
4800 * ResourceInfo and handling the other cases.
4802 g_assert ((impl
& MONO_IMPLEMENTATION_MASK
) == MONO_IMPLEMENTATION_FILE
);
4803 file_idx
= impl
>> MONO_IMPLEMENTATION_BITS
;
4805 module
= mono_image_load_file_for_image_checked (assembly
->image
, file_idx
, error
);
4806 if (!is_ok (error
) || !module
)
4810 module
= assembly
->image
;
4813 MonoReflectionModuleHandle rm
= mono_module_get_object_handle (domain
, module
, error
);
4816 MONO_HANDLE_ASSIGN (ref_module
, rm
);
4818 return (void*)mono_image_get_resource (module
, cols
[MONO_MANIFEST_OFFSET
], (guint32
*)size
);
4822 get_manifest_resource_info_internal (MonoReflectionAssemblyHandle assembly_h
, MonoStringHandle name
, MonoManifestResourceInfoHandle info
, MonoError
*error
)
4824 HANDLE_FUNCTION_ENTER ();
4825 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (assembly_h
);
4826 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (assembly_h
, assembly
);
4827 MonoTableInfo
*table
= &assembly
->image
->tables
[MONO_TABLE_MANIFESTRESOURCE
];
4829 guint32 cols
[MONO_MANIFEST_SIZE
];
4830 guint32 file_cols
[MONO_FILE_SIZE
];
4834 gboolean result
= FALSE
;
4836 n
= mono_string_handle_to_utf8 (name
, error
);
4840 for (i
= 0; i
< table
->rows
; ++i
) {
4841 mono_metadata_decode_row (table
, i
, cols
, MONO_MANIFEST_SIZE
);
4842 val
= mono_metadata_string_heap (assembly
->image
, cols
[MONO_MANIFEST_NAME
]);
4843 if (strcmp (val
, n
) == 0)
4847 if (i
== table
->rows
)
4850 if (!cols
[MONO_MANIFEST_IMPLEMENTATION
]) {
4851 MONO_HANDLE_SETVAL (info
, location
, guint32
, RESOURCE_LOCATION_EMBEDDED
| RESOURCE_LOCATION_IN_MANIFEST
);
4854 switch (cols
[MONO_MANIFEST_IMPLEMENTATION
] & MONO_IMPLEMENTATION_MASK
) {
4855 case MONO_IMPLEMENTATION_FILE
:
4856 i
= cols
[MONO_MANIFEST_IMPLEMENTATION
] >> MONO_IMPLEMENTATION_BITS
;
4857 table
= &assembly
->image
->tables
[MONO_TABLE_FILE
];
4858 mono_metadata_decode_row (table
, i
- 1, file_cols
, MONO_FILE_SIZE
);
4859 val
= mono_metadata_string_heap (assembly
->image
, file_cols
[MONO_FILE_NAME
]);
4860 MONO_HANDLE_SET (info
, filename
, mono_string_new_handle (domain
, val
, error
));
4861 if (file_cols
[MONO_FILE_FLAGS
] & FILE_CONTAINS_NO_METADATA
)
4862 MONO_HANDLE_SETVAL (info
, location
, guint32
, 0);
4864 MONO_HANDLE_SETVAL (info
, location
, guint32
, RESOURCE_LOCATION_EMBEDDED
);
4867 case MONO_IMPLEMENTATION_ASSEMBLYREF
:
4868 i
= cols
[MONO_MANIFEST_IMPLEMENTATION
] >> MONO_IMPLEMENTATION_BITS
;
4869 mono_assembly_load_reference (assembly
->image
, i
- 1);
4870 if (assembly
->image
->references
[i
- 1] == REFERENCE_MISSING
) {
4871 mono_error_set_assembly_load (error
, NULL
, "Assembly %d referenced from assembly %s not found ", i
- 1, assembly
->image
->name
);
4874 MonoReflectionAssemblyHandle assm_obj
= mono_assembly_get_object_handle (mono_domain_get (), assembly
->image
->references
[i
- 1], error
);
4877 MONO_HANDLE_SET (info
, assembly
, assm_obj
);
4879 /* Obtain info recursively */
4880 get_manifest_resource_info_internal (assm_obj
, name
, info
, error
);
4883 guint32 location
= MONO_HANDLE_GETVAL (info
, location
);
4884 location
|= RESOURCE_LOCATION_ANOTHER_ASSEMBLY
;
4885 MONO_HANDLE_SETVAL (info
, location
, guint32
, location
);
4888 case MONO_IMPLEMENTATION_EXP_TYPE
:
4889 g_assert_not_reached ();
4896 HANDLE_FUNCTION_RETURN_VAL (result
);
4899 ICALL_EXPORT gboolean
4900 ves_icall_System_Reflection_Assembly_GetManifestResourceInfoInternal (MonoReflectionAssemblyHandle assembly_h
, MonoStringHandle name
, MonoManifestResourceInfoHandle info_h
, MonoError
*error
)
4903 return get_manifest_resource_info_internal (assembly_h
, name
, info_h
, error
);
4907 add_filename_to_files_array (MonoDomain
*domain
, MonoAssembly
* assembly
, MonoTableInfo
*table
, int i
, MonoArrayHandle dest
, int dest_idx
, MonoError
*error
)
4909 HANDLE_FUNCTION_ENTER();
4911 const char *val
= mono_metadata_string_heap (assembly
->image
, mono_metadata_decode_row_col (table
, i
, MONO_FILE_NAME
));
4912 char *n
= g_concat_dir_and_file (assembly
->basedir
, val
);
4913 MonoStringHandle str
= mono_string_new_handle (domain
, n
, error
);
4917 MONO_HANDLE_ARRAY_SETREF (dest
, dest_idx
, str
);
4919 HANDLE_FUNCTION_RETURN_VAL (is_ok (error
));
4922 ICALL_EXPORT MonoObjectHandle
4923 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssemblyHandle assembly_h
, MonoStringHandle name
, MonoBoolean resource_modules
, MonoError
*error
)
4926 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (assembly_h
);
4927 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (assembly_h
, assembly
);
4928 MonoTableInfo
*table
= &assembly
->image
->tables
[MONO_TABLE_FILE
];
4931 /* check hash if needed */
4932 if (!MONO_HANDLE_IS_NULL(name
)) {
4933 char *n
= mono_string_handle_to_utf8 (name
, error
);
4937 for (i
= 0; i
< table
->rows
; ++i
) {
4938 const char *val
= mono_metadata_string_heap (assembly
->image
, mono_metadata_decode_row_col (table
, i
, MONO_FILE_NAME
));
4939 if (strcmp (val
, n
) == 0) {
4941 n
= g_concat_dir_and_file (assembly
->basedir
, val
);
4942 MonoStringHandle fn
= mono_string_new_handle (domain
, n
, error
);
4946 return MONO_HANDLE_CAST (MonoObject
, fn
);
4954 for (i
= 0; i
< table
->rows
; ++i
) {
4955 if (resource_modules
|| !(mono_metadata_decode_row_col (table
, i
, MONO_FILE_FLAGS
) & FILE_CONTAINS_NO_METADATA
))
4959 MonoArrayHandle result
= mono_array_new_handle (domain
, mono_defaults
.string_class
, count
, error
);
4964 for (i
= 0; i
< table
->rows
; ++i
) {
4965 if (resource_modules
|| !(mono_metadata_decode_row_col (table
, i
, MONO_FILE_FLAGS
) & FILE_CONTAINS_NO_METADATA
)) {
4966 if (!add_filename_to_files_array (domain
, assembly
, table
, i
, result
, count
, error
))
4971 return MONO_HANDLE_CAST (MonoObject
, result
);
4977 add_module_to_modules_array (MonoDomain
*domain
, MonoArrayHandle dest
, int *dest_idx
, MonoImage
* module
, MonoError
*error
)
4979 HANDLE_FUNCTION_ENTER ();
4982 MonoReflectionModuleHandle rm
= mono_module_get_object_handle (domain
, module
, error
);
4986 MONO_HANDLE_ARRAY_SETREF (dest
, *dest_idx
, rm
);
4991 HANDLE_FUNCTION_RETURN_VAL (is_ok (error
));
4995 add_file_to_modules_array (MonoDomain
*domain
, MonoArrayHandle dest
, int dest_idx
, MonoImage
*image
, MonoTableInfo
*table
, int table_idx
, MonoError
*error
)
4997 HANDLE_FUNCTION_ENTER ();
5000 guint32 cols
[MONO_FILE_SIZE
];
5001 mono_metadata_decode_row (table
, table_idx
, cols
, MONO_FILE_SIZE
);
5002 if (cols
[MONO_FILE_FLAGS
] & FILE_CONTAINS_NO_METADATA
) {
5003 MonoReflectionModuleHandle rm
= mono_module_file_get_object_handle (domain
, image
, table_idx
, error
);
5006 MONO_HANDLE_ARRAY_SETREF (dest
, dest_idx
, rm
);
5008 MonoImage
*m
= mono_image_load_file_for_image_checked (image
, table_idx
+ 1, error
);
5012 const char *filename
= mono_metadata_string_heap (image
, cols
[MONO_FILE_NAME
]);
5013 mono_error_set_assembly_load (error
, g_strdup (filename
), "%s", "");
5016 MonoReflectionModuleHandle rm
= mono_module_get_object_handle (domain
, m
, error
);
5019 MONO_HANDLE_ARRAY_SETREF (dest
, dest_idx
, rm
);
5023 HANDLE_FUNCTION_RETURN_VAL (is_ok (error
));
5026 ICALL_EXPORT MonoArrayHandle
5027 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssemblyHandle assembly_h
, MonoError
*error
)
5030 MonoDomain
*domain
= mono_domain_get();
5031 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (assembly_h
, assembly
);
5033 int i
, j
, file_count
= 0;
5034 MonoImage
**modules
;
5035 guint32 module_count
, real_module_count
;
5036 MonoTableInfo
*table
;
5037 MonoImage
*image
= assembly
->image
;
5039 g_assert (image
!= NULL
);
5040 g_assert (!assembly_is_dynamic (assembly
));
5042 table
= &image
->tables
[MONO_TABLE_FILE
];
5043 file_count
= table
->rows
;
5045 modules
= image
->modules
;
5046 module_count
= image
->module_count
;
5048 real_module_count
= 0;
5049 for (i
= 0; i
< module_count
; ++i
)
5051 real_module_count
++;
5053 klass
= mono_class_get_module_class ();
5054 MonoArrayHandle res
= mono_array_new_handle (domain
, klass
, 1 + real_module_count
+ file_count
, error
);
5058 MonoReflectionModuleHandle image_obj
= mono_module_get_object_handle (domain
, image
, error
);
5062 MONO_HANDLE_ARRAY_SETREF (res
, 0, image_obj
);
5065 for (i
= 0; i
< module_count
; ++i
)
5066 if (!add_module_to_modules_array (domain
, res
, &j
, modules
[i
], error
))
5069 for (i
= 0; i
< file_count
; ++i
, ++j
) {
5070 if (!add_file_to_modules_array (domain
, res
, j
, image
, table
, i
, error
))
5076 return MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
);
5079 ICALL_EXPORT MonoReflectionMethodHandle
5080 ves_icall_GetCurrentMethod (MonoError
*error
)
5084 MonoMethod
*m
= mono_method_get_last_managed ();
5087 mono_error_set_not_supported (error
, "Stack walks are not supported on this platform.");
5088 return MONO_HANDLE_CAST (MonoReflectionMethod
, NULL_HANDLE
);
5091 while (m
->is_inflated
)
5092 m
= ((MonoMethodInflated
*)m
)->declaring
;
5094 return mono_method_get_object_handle (mono_domain_get (), m
, NULL
, error
);
5099 mono_method_get_equivalent_method (MonoMethod
*method
, MonoClass
*klass
)
5102 if (method
->is_inflated
&& ((MonoMethodInflated
*)method
)->context
.method_inst
) {
5105 MonoMethodInflated
*inflated
= (MonoMethodInflated
*)method
;
5106 //method is inflated, we should inflate it on the other class
5107 MonoGenericContext ctx
;
5108 ctx
.method_inst
= inflated
->context
.method_inst
;
5109 ctx
.class_inst
= inflated
->context
.class_inst
;
5110 if (mono_class_is_ginst (klass
))
5111 ctx
.class_inst
= mono_class_get_generic_class (klass
)->context
.class_inst
;
5112 else if (mono_class_is_gtd (klass
))
5113 ctx
.class_inst
= mono_class_get_generic_container (klass
)->context
.class_inst
;
5114 result
= mono_class_inflate_generic_method_full_checked (inflated
->declaring
, klass
, &ctx
, &error
);
5115 g_assert (mono_error_ok (&error
)); /* FIXME don't swallow the error */
5119 mono_class_setup_methods (method
->klass
);
5120 if (mono_class_has_failure (method
->klass
))
5122 int mcount
= mono_class_get_method_count (method
->klass
);
5123 for (i
= 0; i
< mcount
; ++i
) {
5124 if (method
->klass
->methods
[i
] == method
) {
5129 mono_class_setup_methods (klass
);
5130 if (mono_class_has_failure (klass
))
5132 g_assert (offset
>= 0 && offset
< mono_class_get_method_count (klass
));
5133 return klass
->methods
[offset
];
5136 ICALL_EXPORT MonoReflectionMethodHandle
5137 ves_icall_System_Reflection_MethodBase_GetMethodFromHandleInternalType_native (MonoMethod
*method
, MonoType
*type
, MonoBoolean generic_check
, MonoError
*error
)
5141 if (type
&& generic_check
) {
5142 klass
= mono_class_from_mono_type (type
);
5143 if (mono_class_get_generic_type_definition (method
->klass
) != mono_class_get_generic_type_definition (klass
))
5144 return MONO_HANDLE_CAST (MonoReflectionMethod
, NULL_HANDLE
);
5146 if (method
->klass
!= klass
) {
5147 method
= mono_method_get_equivalent_method (method
, klass
);
5149 return MONO_HANDLE_CAST (MonoReflectionMethod
, NULL_HANDLE
);
5152 klass
= mono_class_from_mono_type (type
);
5154 klass
= method
->klass
;
5155 return mono_method_get_object_handle (mono_domain_get (), method
, klass
, error
);
5158 ICALL_EXPORT MonoReflectionMethodBodyHandle
5159 ves_icall_System_Reflection_MethodBase_GetMethodBodyInternal (MonoMethod
*method
, MonoError
*error
)
5162 return mono_method_body_get_object_handle (mono_domain_get (), method
, error
);
5165 ICALL_EXPORT MonoReflectionAssemblyHandle
5166 ves_icall_System_Reflection_Assembly_GetExecutingAssembly (MonoError
*error
)
5170 MonoMethod
*dest
= NULL
;
5171 mono_stack_walk_no_il (get_executing
, &dest
);
5173 return mono_assembly_get_object_handle (mono_domain_get (), dest
->klass
->image
->assembly
, error
);
5177 ICALL_EXPORT MonoReflectionAssemblyHandle
5178 ves_icall_System_Reflection_Assembly_GetEntryAssembly (MonoError
*error
)
5182 MonoDomain
* domain
= mono_domain_get ();
5184 if (!domain
->entry_assembly
)
5185 return MONO_HANDLE_CAST (MonoReflectionAssembly
, NULL_HANDLE
);
5187 return mono_assembly_get_object_handle (domain
, domain
->entry_assembly
, error
);
5190 ICALL_EXPORT MonoReflectionAssemblyHandle
5191 ves_icall_System_Reflection_Assembly_GetCallingAssembly (MonoError
*error
)
5198 mono_stack_walk_no_il (get_executing
, &dest
);
5200 mono_stack_walk_no_il (get_caller_no_reflection
, &dest
);
5204 mono_error_set_not_supported (error
, "Stack walks are not supported on this platform.");
5205 return MONO_HANDLE_CAST (MonoReflectionAssembly
, NULL_HANDLE
);
5207 return mono_assembly_get_object_handle (mono_domain_get (), dest
->klass
->image
->assembly
, error
);
5210 ICALL_EXPORT MonoStringHandle
5211 ves_icall_System_RuntimeType_getFullName (MonoReflectionTypeHandle object
, gboolean full_name
,
5212 gboolean assembly_qualified
, MonoError
*error
)
5214 MonoDomain
*domain
= mono_object_domain (MONO_HANDLE_RAW (object
));
5215 MonoType
*type
= MONO_HANDLE_RAW (object
)->type
;
5216 MonoTypeNameFormat format
;
5217 MonoStringHandle res
;
5221 format
= assembly_qualified
?
5222 MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED
:
5223 MONO_TYPE_NAME_FORMAT_FULL_NAME
;
5225 format
= MONO_TYPE_NAME_FORMAT_REFLECTION
;
5227 name
= mono_type_get_name_full (type
, format
);
5229 return NULL_HANDLE_STRING
;
5231 if (full_name
&& (type
->type
== MONO_TYPE_VAR
|| type
->type
== MONO_TYPE_MVAR
)) {
5233 return NULL_HANDLE_STRING
;
5236 res
= mono_string_new_handle (domain
, name
, error
);
5243 vell_icall_RuntimeType_get_core_clr_security_level (MonoReflectionTypeHandle rfield
, MonoError
*error
)
5246 MonoType
*type
= MONO_HANDLE_GETVAL (rfield
, type
);
5247 MonoClass
*klass
= mono_class_from_mono_type (type
);
5249 mono_class_init_checked (klass
, error
);
5252 return mono_security_core_clr_class_level (klass
);
5256 ves_icall_MonoField_get_core_clr_security_level (MonoReflectionField
*rfield
)
5258 MonoClassField
*field
= rfield
->field
;
5259 return mono_security_core_clr_field_level (field
, TRUE
);
5263 ves_icall_MonoMethod_get_core_clr_security_level (MonoReflectionMethodHandle rfield
, MonoError
*error
)
5266 MonoMethod
*method
= MONO_HANDLE_GETVAL (rfield
, method
);
5267 return mono_security_core_clr_method_level (method
, TRUE
);
5270 ICALL_EXPORT MonoStringHandle
5271 ves_icall_System_Reflection_Assembly_get_fullName (MonoReflectionAssemblyHandle assembly
, MonoError
*error
)
5274 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (assembly
);
5275 MonoAssembly
*mass
= MONO_HANDLE_GETVAL (assembly
, assembly
);
5278 name
= mono_stringify_assembly_name (&mass
->aname
);
5279 MonoStringHandle res
= mono_string_new_handle (domain
, name
, error
);
5284 ICALL_EXPORT MonoAssemblyName
*
5285 ves_icall_System_Reflection_AssemblyName_GetNativeName (MonoAssembly
*mass
)
5287 return &mass
->aname
;
5291 ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoStringHandle fname
, MonoAssemblyName
*name
, MonoStringHandleOut normalized_codebase
, MonoError
*error
)
5294 MonoImageOpenStatus status
= MONO_IMAGE_OK
;
5295 char *codebase
= NULL
;
5302 filename
= mono_string_handle_to_utf8 (fname
, error
);
5303 return_if_nok (error
);
5305 dirname
= g_path_get_dirname (filename
);
5306 replace_shadow_path (mono_domain_get (), dirname
, &filename
);
5309 image
= mono_image_open_full (filename
, &status
, TRUE
);
5312 if (status
== MONO_IMAGE_IMAGE_INVALID
)
5313 mono_error_set_bad_image_name (error
, g_strdup (filename
), "%s", "");
5315 mono_error_set_assembly_load (error
, g_strdup (filename
), "%s", "");
5320 res
= mono_assembly_fill_assembly_name_full (image
, name
, TRUE
);
5322 mono_image_close (image
);
5324 mono_error_set_argument (error
, "assemblyFile", "The file does not contain a manifest");
5328 if (filename
!= NULL
&& *filename
!= '\0') {
5331 codebase
= g_strdup (filename
);
5333 mono_icall_make_platform_path (codebase
);
5335 const gchar
*prepend
= mono_icall_get_file_path_prefix (codebase
);
5337 result
= g_strconcat (prepend
, codebase
, NULL
);
5341 MONO_HANDLE_ASSIGN (normalized_codebase
, mono_string_new_handle (mono_domain_get (), codebase
, error
));
5344 mono_image_close (image
);
5348 ICALL_EXPORT MonoBoolean
5349 ves_icall_System_Reflection_Assembly_LoadPermissions (MonoReflectionAssemblyHandle assembly_h
,
5350 char **minimum
, guint32
*minLength
, char **optional
, guint32
*optLength
, char **refused
, guint32
*refLength
, MonoError
*error
)
5353 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (assembly_h
, assembly
);
5354 MonoBoolean result
= FALSE
;
5355 MonoDeclSecurityEntry entry
;
5357 /* SecurityAction.RequestMinimum */
5358 if (mono_declsec_get_assembly_action (assembly
, SECURITY_ACTION_REQMIN
, &entry
)) {
5359 *minimum
= entry
.blob
;
5360 *minLength
= entry
.size
;
5363 /* SecurityAction.RequestOptional */
5364 if (mono_declsec_get_assembly_action (assembly
, SECURITY_ACTION_REQOPT
, &entry
)) {
5365 *optional
= entry
.blob
;
5366 *optLength
= entry
.size
;
5369 /* SecurityAction.RequestRefuse */
5370 if (mono_declsec_get_assembly_action (assembly
, SECURITY_ACTION_REQREFUSE
, &entry
)) {
5371 *refused
= entry
.blob
;
5372 *refLength
= entry
.size
;
5380 mono_module_type_is_visible (MonoTableInfo
*tdef
, MonoImage
*image
, int type
)
5382 guint32 attrs
, visibility
;
5384 attrs
= mono_metadata_decode_row_col (tdef
, type
- 1, MONO_TYPEDEF_FLAGS
);
5385 visibility
= attrs
& TYPE_ATTRIBUTE_VISIBILITY_MASK
;
5386 if (visibility
!= TYPE_ATTRIBUTE_PUBLIC
&& visibility
!= TYPE_ATTRIBUTE_NESTED_PUBLIC
)
5389 } while ((type
= mono_metadata_token_index (mono_metadata_nested_in_typedef (image
, type
))));
5395 image_get_type (MonoDomain
*domain
, MonoImage
*image
, MonoTableInfo
*tdef
, int table_idx
, int count
, MonoArrayHandle res
, MonoArrayHandle exceptions
, MonoBoolean exportedOnly
, MonoError
*error
)
5398 HANDLE_FUNCTION_ENTER ();
5399 MonoError klass_error
;
5400 MonoClass
*klass
= mono_class_get_checked (image
, table_idx
| MONO_TOKEN_TYPE_DEF
, &klass_error
);
5403 MonoReflectionTypeHandle rt
= mono_type_get_object_handle (domain
, &klass
->byval_arg
, error
);
5404 return_if_nok (error
);
5406 MONO_HANDLE_ARRAY_SETREF (res
, count
, rt
);
5408 MonoException
*ex
= mono_error_convert_to_exception (error
);
5409 MONO_HANDLE_ARRAY_SETRAW (exceptions
, count
, ex
);
5411 HANDLE_FUNCTION_RETURN ();
5414 static MonoArrayHandle
5415 mono_module_get_types (MonoDomain
*domain
, MonoImage
*image
, MonoArrayHandleOut exceptions
, MonoBoolean exportedOnly
, MonoError
*error
)
5417 MonoTableInfo
*tdef
= &image
->tables
[MONO_TABLE_TYPEDEF
];
5422 /* we start the count from 1 because we skip the special type <Module> */
5425 for (i
= 1; i
< tdef
->rows
; ++i
) {
5426 if (mono_module_type_is_visible (tdef
, image
, i
+ 1))
5430 count
= tdef
->rows
- 1;
5432 MonoArrayHandle res
= mono_array_new_handle (domain
, mono_defaults
.runtimetype_class
, count
, error
);
5433 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
));
5434 MONO_HANDLE_ASSIGN (exceptions
, mono_array_new_handle (domain
, mono_defaults
.exception_class
, count
, error
));
5435 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
));
5437 for (i
= 1; i
< tdef
->rows
; ++i
) {
5438 if (!exportedOnly
|| mono_module_type_is_visible (tdef
, image
, i
+1)) {
5439 image_get_type (domain
, image
, tdef
, i
+ 1, count
, res
, exceptions
, exportedOnly
, error
);
5440 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
));
5449 append_module_types (MonoDomain
*domain
, MonoArrayHandleOut res
, MonoArrayHandleOut exceptions
, MonoImage
*image
, MonoBoolean exportedOnly
, MonoError
*error
)
5451 HANDLE_FUNCTION_ENTER ();
5453 MonoArrayHandle ex2
= MONO_HANDLE_NEW (MonoArray
, NULL
);
5454 MonoArrayHandle res2
= mono_module_get_types (domain
, image
, ex2
, exportedOnly
, error
);
5458 /* Append the new types to the end of the array */
5459 if (mono_array_handle_length (res2
) > 0) {
5462 len1
= mono_array_handle_length (res
);
5463 len2
= mono_array_handle_length (res2
);
5465 MonoArrayHandle res3
= mono_array_new_handle (domain
, mono_defaults
.runtimetype_class
, len1
+ len2
, error
);
5469 mono_array_handle_memcpy_refs (res3
, 0, res
, 0, len1
);
5470 mono_array_handle_memcpy_refs (res3
, len1
, res2
, 0, len2
);
5471 MONO_HANDLE_ASSIGN (res
, res3
);
5473 MonoArrayHandle ex3
= mono_array_new_handle (domain
, mono_defaults
.runtimetype_class
, len1
+ len2
, error
);
5477 mono_array_handle_memcpy_refs (ex3
, 0, exceptions
, 0, len1
);
5478 mono_array_handle_memcpy_refs (ex3
, len1
, ex2
, 0, len2
);
5479 MONO_HANDLE_ASSIGN (exceptions
, ex3
);
5482 HANDLE_FUNCTION_RETURN ();
5486 set_class_failure_in_array (MonoArrayHandle exl
, int i
, MonoClass
*klass
)
5488 HANDLE_FUNCTION_ENTER ();
5489 MonoError unboxed_error
;
5490 error_init (&unboxed_error
);
5491 mono_error_set_for_class_failure (&unboxed_error
, klass
);
5493 MonoExceptionHandle exc
= MONO_HANDLE_NEW (MonoException
, mono_error_convert_to_exception (&unboxed_error
));
5494 MONO_HANDLE_ARRAY_SETREF (exl
, i
, exc
);
5495 HANDLE_FUNCTION_RETURN ();
5498 ICALL_EXPORT MonoArrayHandle
5499 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssemblyHandle assembly_handle
, MonoBoolean exportedOnly
, MonoError
*error
)
5501 MonoArrayHandle exceptions
= MONO_HANDLE_NEW(MonoArray
, NULL
);
5504 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (assembly_handle
);
5505 MonoAssembly
*assembly
= MONO_HANDLE_GETVAL (assembly_handle
, assembly
);
5507 g_assert (!assembly_is_dynamic (assembly
));
5508 MonoImage
*image
= assembly
->image
;
5509 MonoTableInfo
*table
= &image
->tables
[MONO_TABLE_FILE
];
5510 MonoArrayHandle res
= mono_module_get_types (domain
, image
, exceptions
, exportedOnly
, error
);
5511 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
));
5513 /* Append data from all modules in the assembly */
5514 for (i
= 0; i
< table
->rows
; ++i
) {
5515 if (!(mono_metadata_decode_row_col (table
, i
, MONO_FILE_FLAGS
) & FILE_CONTAINS_NO_METADATA
)) {
5516 MonoImage
*loaded_image
= mono_assembly_load_module_checked (image
->assembly
, i
+ 1, error
);
5517 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
));
5520 append_module_types (domain
, res
, exceptions
, loaded_image
, exportedOnly
, error
);
5521 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
));
5526 /* the ReflectionTypeLoadException must have all the types (Types property),
5527 * NULL replacing types which throws an exception. The LoaderException must
5528 * contain all exceptions for NULL items.
5531 int len
= mono_array_handle_length (res
);
5535 MonoReflectionTypeHandle t
= MONO_HANDLE_NEW (MonoReflectionType
, NULL
);
5536 for (i
= 0; i
< len
; i
++) {
5537 MONO_HANDLE_ARRAY_GETREF (t
, res
, i
);
5539 if (!MONO_HANDLE_IS_NULL (t
)) {
5540 MonoClass
*klass
= mono_type_get_class (MONO_HANDLE_GETVAL (t
, type
));
5541 if ((klass
!= NULL
) && mono_class_has_failure (klass
)) {
5542 /* keep the class in the list */
5543 list
= g_list_append (list
, klass
);
5544 /* and replace Type with NULL */
5545 MONO_HANDLE_ARRAY_SETRAW (res
, i
, NULL
);
5552 if (list
|| ex_count
) {
5554 int j
, length
= g_list_length (list
) + ex_count
;
5556 MonoArrayHandle exl
= mono_array_new_handle (domain
, mono_defaults
.exception_class
, length
, error
);
5557 if (!is_ok (error
)) {
5559 return MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
);
5561 /* Types for which mono_class_get_checked () succeeded */
5562 MonoExceptionHandle exc
= MONO_HANDLE_NEW (MonoException
, NULL
);
5563 for (i
= 0, tmp
= list
; tmp
; i
++, tmp
= tmp
->next
) {
5564 set_class_failure_in_array (exl
, i
, (MonoClass
*)tmp
->data
);
5566 /* Types for which it don't */
5567 for (j
= 0; j
< mono_array_handle_length (exceptions
); ++j
) {
5568 MONO_HANDLE_ARRAY_GETREF (exc
, exceptions
, j
);
5569 if (!MONO_HANDLE_IS_NULL (exc
)) {
5570 g_assert (i
< length
);
5571 MONO_HANDLE_ARRAY_SETREF (exl
, i
, exc
);
5578 MONO_HANDLE_ASSIGN (exc
, mono_get_exception_reflection_type_load_checked (res
, exl
, error
));
5579 if (!is_ok (error
)) {
5580 return MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
);
5582 mono_error_set_exception_handle (error
, exc
);
5583 return MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
);
5590 ves_icall_Mono_RuntimeMarshal_FreeAssemblyName (MonoAssemblyName
*aname
, gboolean free_struct
)
5592 mono_assembly_name_free (aname
);
5597 ICALL_EXPORT gboolean
5598 ves_icall_System_Reflection_AssemblyName_ParseAssemblyName (const char *name
, MonoAssemblyName
*aname
, gboolean
*is_version_definited
, gboolean
*is_token_defined
)
5600 *is_version_definited
= *is_token_defined
= FALSE
;
5602 return mono_assembly_name_parse_full (name
, aname
, TRUE
, is_version_definited
, is_token_defined
);
5605 ICALL_EXPORT MonoReflectionTypeHandle
5606 ves_icall_System_Reflection_Module_GetGlobalType (MonoReflectionModuleHandle module
, MonoError
*error
)
5608 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (module
);
5609 MonoImage
*image
= MONO_HANDLE_GETVAL (module
, image
);
5614 MonoReflectionTypeHandle ret
= MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
5616 if (image_is_dynamic (image
) && ((MonoDynamicImage
*)image
)->initial_image
)
5617 /* These images do not have a global type */
5620 klass
= mono_class_get_checked (image
, 1 | MONO_TOKEN_TYPE_DEF
, error
);
5624 ret
= mono_type_get_object_handle (domain
, &klass
->byval_arg
, error
);
5630 ves_icall_System_Reflection_Module_Close (MonoReflectionModuleHandle module
, MonoError
*error
)
5632 /*if (module->image)
5633 mono_image_close (module->image);*/
5636 ICALL_EXPORT MonoStringHandle
5637 ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModuleHandle refmodule
, MonoError
*error
)
5639 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (refmodule
);
5640 MonoImage
*image
= MONO_HANDLE_GETVAL (refmodule
, image
);
5643 return mono_string_new_handle (domain
, image
->guid
, error
);
5647 static inline gpointer
5648 mono_icall_module_get_hinstance (MonoReflectionModuleHandle module
)
5650 return (gpointer
) (-1);
5652 #endif /* HOST_WIN32 */
5654 ICALL_EXPORT gpointer
5655 ves_icall_System_Reflection_Module_GetHINSTANCE (MonoReflectionModuleHandle module
, MonoError
*error
)
5657 return mono_icall_module_get_hinstance (module
);
5661 ves_icall_System_Reflection_Module_GetPEKind (MonoImage
*image
, gint32
*pe_kind
, gint32
*machine
, MonoError
*error
)
5663 if (image_is_dynamic (image
)) {
5664 MonoDynamicImage
*dyn
= (MonoDynamicImage
*)image
;
5665 *pe_kind
= dyn
->pe_kind
;
5666 *machine
= dyn
->machine
;
5669 *pe_kind
= ((MonoCLIImageInfo
*)(image
->image_info
))->cli_cli_header
.ch_flags
& 0x3;
5670 *machine
= ((MonoCLIImageInfo
*)(image
->image_info
))->cli_header
.coff
.coff_machine
;
5675 ves_icall_System_Reflection_Module_GetMDStreamVersion (MonoImage
*image
, MonoError
*error
)
5677 return (image
->md_version_major
<< 16) | (image
->md_version_minor
);
5680 ICALL_EXPORT MonoArrayHandle
5681 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModuleHandle module
, MonoError
*error
)
5685 MonoImage
*image
= MONO_HANDLE_GETVAL (module
, image
);
5686 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (module
);
5689 MonoArrayHandle arr
= mono_array_new_handle (domain
, mono_defaults
.runtimetype_class
, 0, error
);
5692 MonoArrayHandle exceptions
= MONO_HANDLE_NEW (MonoArray
, NULL
);
5693 MonoArrayHandle res
= mono_module_get_types (domain
, image
, exceptions
, FALSE
, error
);
5694 return_val_if_nok (error
, MONO_HANDLE_CAST(MonoArray
, NULL_HANDLE
));
5696 int n
= mono_array_handle_length (exceptions
);
5697 MonoExceptionHandle ex
= MONO_HANDLE_NEW (MonoException
, NULL
);
5698 for (int i
= 0; i
< n
; ++i
) {
5699 MONO_HANDLE_ARRAY_GETREF(ex
, exceptions
, i
);
5700 if (!MONO_HANDLE_IS_NULL (ex
)) {
5701 mono_error_set_exception_handle (error
, ex
);
5702 return MONO_HANDLE_CAST(MonoArray
, NULL_HANDLE
);
5710 mono_memberref_is_method (MonoImage
*image
, guint32 token
)
5712 if (!image_is_dynamic (image
)) {
5713 guint32 cols
[MONO_MEMBERREF_SIZE
];
5715 mono_metadata_decode_row (&image
->tables
[MONO_TABLE_MEMBERREF
], mono_metadata_token_index (token
) - 1, cols
, MONO_MEMBERREF_SIZE
);
5716 sig
= mono_metadata_blob_heap (image
, cols
[MONO_MEMBERREF_SIGNATURE
]);
5717 mono_metadata_decode_blob_size (sig
, &sig
);
5718 return (*sig
!= 0x6);
5721 MonoClass
*handle_class
;
5723 if (!mono_lookup_dynamic_token_class (image
, token
, FALSE
, &handle_class
, NULL
, &error
)) {
5724 mono_error_cleanup (&error
); /* just probing, ignore error */
5728 return mono_defaults
.methodhandle_class
== handle_class
;
5732 static MonoGenericInst
*
5733 get_generic_inst_from_array_handle (MonoArrayHandle type_args
)
5735 int type_argc
= mono_array_handle_length (type_args
);
5736 int size
= MONO_SIZEOF_GENERIC_INST
+ type_argc
* sizeof (MonoType
*);
5738 MonoGenericInst
*ginst
= (MonoGenericInst
*)g_alloca (size
);
5739 memset (ginst
, 0, sizeof (MonoGenericInst
));
5740 ginst
->type_argc
= type_argc
;
5741 for (int i
= 0; i
< type_argc
; i
++) {
5742 MONO_HANDLE_ARRAY_GETVAL (ginst
->type_argv
[i
], type_args
, MonoType
*, i
);
5744 ginst
->is_open
= FALSE
;
5745 for (int i
= 0; i
< type_argc
; i
++) {
5746 if (mono_class_is_open_constructed_type (ginst
->type_argv
[i
])) {
5747 ginst
->is_open
= TRUE
;
5752 return mono_metadata_get_canonical_generic_inst (ginst
);
5756 init_generic_context_from_args_handles (MonoGenericContext
*context
, MonoArrayHandle type_args
, MonoArrayHandle method_args
)
5758 if (!MONO_HANDLE_IS_NULL (type_args
)) {
5759 context
->class_inst
= get_generic_inst_from_array_handle (type_args
);
5761 context
->class_inst
= NULL
;
5763 if (!MONO_HANDLE_IS_NULL (method_args
)) {
5764 context
->method_inst
= get_generic_inst_from_array_handle (method_args
);
5766 context
->method_inst
= NULL
;
5772 module_resolve_type_token (MonoImage
*image
, guint32 token
, MonoArrayHandle type_args
, MonoArrayHandle method_args
, MonoResolveTokenError
*resolve_error
, MonoError
*error
)
5774 HANDLE_FUNCTION_ENTER ();
5776 MonoType
*result
= NULL
;
5778 int table
= mono_metadata_token_table (token
);
5779 int index
= mono_metadata_token_index (token
);
5780 MonoGenericContext context
;
5782 *resolve_error
= ResolveTokenError_Other
;
5784 /* Validate token */
5785 if ((table
!= MONO_TABLE_TYPEDEF
) && (table
!= MONO_TABLE_TYPEREF
) &&
5786 (table
!= MONO_TABLE_TYPESPEC
)) {
5787 *resolve_error
= ResolveTokenError_BadTable
;
5791 if (image_is_dynamic (image
)) {
5792 if ((table
== MONO_TABLE_TYPEDEF
) || (table
== MONO_TABLE_TYPEREF
)) {
5793 MonoError inner_error
;
5794 klass
= (MonoClass
*)mono_lookup_dynamic_token_class (image
, token
, FALSE
, NULL
, NULL
, &inner_error
);
5795 mono_error_cleanup (&inner_error
);
5796 result
= klass
? &klass
->byval_arg
: NULL
;
5800 init_generic_context_from_args_handles (&context
, type_args
, method_args
);
5801 MonoError inner_error
;
5802 klass
= (MonoClass
*)mono_lookup_dynamic_token_class (image
, token
, FALSE
, NULL
, &context
, &inner_error
);
5803 mono_error_cleanup (&inner_error
);
5804 result
= klass
? &klass
->byval_arg
: NULL
;
5808 if ((index
<= 0) || (index
> image
->tables
[table
].rows
)) {
5809 *resolve_error
= ResolveTokenError_OutOfRange
;
5813 init_generic_context_from_args_handles (&context
, type_args
, method_args
);
5814 klass
= mono_class_get_checked (image
, token
, error
);
5816 klass
= mono_class_inflate_generic_class_checked (klass
, &context
, error
);
5821 result
= &klass
->byval_arg
;
5823 HANDLE_FUNCTION_RETURN_VAL (result
);
5826 ICALL_EXPORT MonoType
*
5827 ves_icall_System_Reflection_Module_ResolveTypeToken (MonoImage
*image
, guint32 token
, MonoArrayHandle type_args
, MonoArrayHandle method_args
, MonoResolveTokenError
*resolve_error
, MonoError
*error
)
5829 return module_resolve_type_token (image
, token
, type_args
, method_args
, resolve_error
, error
);
5833 module_resolve_method_token (MonoImage
*image
, guint32 token
, MonoArrayHandle type_args
, MonoArrayHandle method_args
, MonoResolveTokenError
*resolve_error
, MonoError
*error
)
5835 HANDLE_FUNCTION_ENTER ();
5837 MonoMethod
*method
= NULL
;
5838 int table
= mono_metadata_token_table (token
);
5839 int index
= mono_metadata_token_index (token
);
5840 MonoGenericContext context
;
5842 *resolve_error
= ResolveTokenError_Other
;
5844 /* Validate token */
5845 if ((table
!= MONO_TABLE_METHOD
) && (table
!= MONO_TABLE_METHODSPEC
) &&
5846 (table
!= MONO_TABLE_MEMBERREF
)) {
5847 *resolve_error
= ResolveTokenError_BadTable
;
5851 if (image_is_dynamic (image
)) {
5852 if (table
== MONO_TABLE_METHOD
) {
5853 MonoError inner_error
;
5854 method
= (MonoMethod
*)mono_lookup_dynamic_token_class (image
, token
, FALSE
, NULL
, NULL
, &inner_error
);
5855 mono_error_cleanup (&inner_error
);
5859 if ((table
== MONO_TABLE_MEMBERREF
) && !(mono_memberref_is_method (image
, token
))) {
5860 *resolve_error
= ResolveTokenError_BadTable
;
5864 init_generic_context_from_args_handles (&context
, type_args
, method_args
);
5865 MonoError inner_error
;
5866 method
= (MonoMethod
*)mono_lookup_dynamic_token_class (image
, token
, FALSE
, NULL
, &context
, &inner_error
);
5867 mono_error_cleanup (&inner_error
);
5871 if ((index
<= 0) || (index
> image
->tables
[table
].rows
)) {
5872 *resolve_error
= ResolveTokenError_OutOfRange
;
5875 if ((table
== MONO_TABLE_MEMBERREF
) && (!mono_memberref_is_method (image
, token
))) {
5876 *resolve_error
= ResolveTokenError_BadTable
;
5880 init_generic_context_from_args_handles (&context
, type_args
, method_args
);
5881 method
= mono_get_method_checked (image
, token
, NULL
, &context
, error
);
5884 HANDLE_FUNCTION_RETURN_VAL (method
);
5887 ICALL_EXPORT MonoMethod
*
5888 ves_icall_System_Reflection_Module_ResolveMethodToken (MonoImage
*image
, guint32 token
, MonoArrayHandle type_args
, MonoArrayHandle method_args
, MonoResolveTokenError
*resolve_error
, MonoError
*error
)
5890 return module_resolve_method_token (image
, token
, type_args
, method_args
, resolve_error
, error
);
5893 ICALL_EXPORT MonoString
*
5894 ves_icall_System_Reflection_Module_ResolveStringToken (MonoImage
*image
, guint32 token
, MonoResolveTokenError
*resolve_error
)
5897 int index
= mono_metadata_token_index (token
);
5899 *resolve_error
= ResolveTokenError_Other
;
5901 /* Validate token */
5902 if (mono_metadata_token_code (token
) != MONO_TOKEN_STRING
) {
5903 *resolve_error
= ResolveTokenError_BadTable
;
5907 if (image_is_dynamic (image
)) {
5908 MonoString
* result
= (MonoString
*)mono_lookup_dynamic_token_class (image
, token
, FALSE
, NULL
, NULL
, &error
);
5909 mono_error_cleanup (&error
);
5913 if ((index
<= 0) || (index
>= image
->heap_us
.size
)) {
5914 *resolve_error
= ResolveTokenError_OutOfRange
;
5918 /* FIXME: What to do if the index points into the middle of a string ? */
5920 MonoString
*result
= mono_ldstr_checked (mono_domain_get (), image
, index
, &error
);
5921 mono_error_set_pending_exception (&error
);
5925 static MonoClassField
*
5926 module_resolve_field_token (MonoImage
*image
, guint32 token
, MonoArrayHandle type_args
, MonoArrayHandle method_args
, MonoResolveTokenError
*resolve_error
, MonoError
*error
)
5928 HANDLE_FUNCTION_ENTER ();
5930 int table
= mono_metadata_token_table (token
);
5931 int index
= mono_metadata_token_index (token
);
5932 MonoGenericContext context
;
5933 MonoClassField
*field
= NULL
;
5936 *resolve_error
= ResolveTokenError_Other
;
5938 /* Validate token */
5939 if ((table
!= MONO_TABLE_FIELD
) && (table
!= MONO_TABLE_MEMBERREF
)) {
5940 *resolve_error
= ResolveTokenError_BadTable
;
5944 if (image_is_dynamic (image
)) {
5945 if (table
== MONO_TABLE_FIELD
) {
5946 MonoError inner_error
;
5947 field
= (MonoClassField
*)mono_lookup_dynamic_token_class (image
, token
, FALSE
, NULL
, NULL
, &inner_error
);
5948 mono_error_cleanup (&inner_error
);
5952 if (mono_memberref_is_method (image
, token
)) {
5953 *resolve_error
= ResolveTokenError_BadTable
;
5957 init_generic_context_from_args_handles (&context
, type_args
, method_args
);
5958 MonoError inner_error
;
5959 field
= (MonoClassField
*)mono_lookup_dynamic_token_class (image
, token
, FALSE
, NULL
, &context
, &inner_error
);
5960 mono_error_cleanup (&inner_error
);
5964 if ((index
<= 0) || (index
> image
->tables
[table
].rows
)) {
5965 *resolve_error
= ResolveTokenError_OutOfRange
;
5968 if ((table
== MONO_TABLE_MEMBERREF
) && (mono_memberref_is_method (image
, token
))) {
5969 *resolve_error
= ResolveTokenError_BadTable
;
5973 init_generic_context_from_args_handles (&context
, type_args
, method_args
);
5974 field
= mono_field_from_token_checked (image
, token
, &klass
, &context
, error
);
5977 HANDLE_FUNCTION_RETURN_VAL (field
);
5980 ICALL_EXPORT MonoClassField
*
5981 ves_icall_System_Reflection_Module_ResolveFieldToken (MonoImage
*image
, guint32 token
, MonoArrayHandle type_args
, MonoArrayHandle method_args
, MonoResolveTokenError
*resolve_error
, MonoError
*error
)
5983 return module_resolve_field_token (image
, token
, type_args
, method_args
, resolve_error
, error
);
5986 ICALL_EXPORT MonoObjectHandle
5987 ves_icall_System_Reflection_Module_ResolveMemberToken (MonoImage
*image
, guint32 token
, MonoArrayHandle type_args
, MonoArrayHandle method_args
, MonoResolveTokenError
*error
, MonoError
*merror
)
5989 int table
= mono_metadata_token_table (token
);
5991 error_init (merror
);
5992 *error
= ResolveTokenError_Other
;
5995 case MONO_TABLE_TYPEDEF
:
5996 case MONO_TABLE_TYPEREF
:
5997 case MONO_TABLE_TYPESPEC
: {
5998 MonoType
*t
= module_resolve_type_token (image
, token
, type_args
, method_args
, error
, merror
);
6000 return MONO_HANDLE_CAST (MonoObject
, mono_type_get_object_handle (mono_domain_get (), t
, merror
));
6005 case MONO_TABLE_METHOD
:
6006 case MONO_TABLE_METHODSPEC
: {
6007 MonoMethod
*m
= module_resolve_method_token (image
, token
, type_args
, method_args
, error
, merror
);
6009 return MONO_HANDLE_CAST (MonoObject
, mono_method_get_object_handle (mono_domain_get (), m
, m
->klass
, merror
));
6013 case MONO_TABLE_FIELD
: {
6014 MonoClassField
*f
= module_resolve_field_token (image
, token
, type_args
, method_args
, error
, merror
);
6016 return MONO_HANDLE_CAST (MonoObject
, mono_field_get_object_handle (mono_domain_get (), f
->parent
, f
, merror
));
6021 case MONO_TABLE_MEMBERREF
:
6022 if (mono_memberref_is_method (image
, token
)) {
6023 MonoMethod
*m
= module_resolve_method_token (image
, token
, type_args
, method_args
, error
, merror
);
6025 return MONO_HANDLE_CAST (MonoObject
, mono_method_get_object_handle (mono_domain_get (), m
, m
->klass
, merror
));
6030 MonoClassField
*f
= module_resolve_field_token (image
, token
, type_args
, method_args
, error
, merror
);
6032 return MONO_HANDLE_CAST (MonoObject
, mono_field_get_object_handle (mono_domain_get (), f
->parent
, f
, merror
));
6040 *error
= ResolveTokenError_BadTable
;
6046 ICALL_EXPORT MonoArrayHandle
6047 ves_icall_System_Reflection_Module_ResolveSignature (MonoImage
*image
, guint32 token
, MonoResolveTokenError
*resolve_error
, MonoError
*error
)
6050 int table
= mono_metadata_token_table (token
);
6051 int idx
= mono_metadata_token_index (token
);
6052 MonoTableInfo
*tables
= image
->tables
;
6056 *resolve_error
= ResolveTokenError_OutOfRange
;
6058 /* FIXME: Support other tables ? */
6059 if (table
!= MONO_TABLE_STANDALONESIG
)
6060 return MONO_HANDLE_CAST (MonoArray
, NULL
);
6062 if (image_is_dynamic (image
))
6063 return MONO_HANDLE_CAST (MonoArray
, NULL
);
6065 if ((idx
== 0) || (idx
> tables
[MONO_TABLE_STANDALONESIG
].rows
))
6066 return MONO_HANDLE_CAST (MonoArray
, NULL
);
6068 sig
= mono_metadata_decode_row_col (&tables
[MONO_TABLE_STANDALONESIG
], idx
- 1, 0);
6070 ptr
= mono_metadata_blob_heap (image
, sig
);
6071 len
= mono_metadata_decode_blob_size (ptr
, &ptr
);
6073 MonoArrayHandle res
= mono_array_new_handle (mono_domain_get (), mono_defaults
.byte_class
, len
, error
);
6075 return MONO_HANDLE_CAST (MonoArray
, NULL
);
6077 gpointer array_base
= MONO_ARRAY_HANDLE_PIN (res
, guint8
, 0, &h
);
6078 memcpy (array_base
, ptr
, len
);
6079 mono_gchandle_free (h
);
6083 ICALL_EXPORT MonoBoolean
6084 ves_icall_RuntimeTypeHandle_IsArray (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
6087 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
6089 MonoBoolean res
= !type
->byref
&& (type
->type
== MONO_TYPE_ARRAY
|| type
->type
== MONO_TYPE_SZARRAY
);
6095 check_for_invalid_type (MonoClass
*klass
, MonoError
*error
)
6101 if (klass
->byval_arg
.type
!= MONO_TYPE_TYPEDBYREF
)
6104 name
= mono_type_get_full_name (klass
);
6105 mono_error_set_type_load_name (error
, name
, g_strdup (""), "");
6108 ICALL_EXPORT MonoReflectionTypeHandle
6109 ves_icall_RuntimeType_make_array_type (MonoReflectionTypeHandle ref_type
, int rank
, MonoError
*error
)
6112 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
6114 MonoClass
*klass
= mono_class_from_mono_type (type
);
6115 check_for_invalid_type (klass
, error
);
6117 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
6120 if (rank
== 0) //single dimentional array
6121 aklass
= mono_array_class_get (klass
, 1);
6123 aklass
= mono_bounded_array_class_get (klass
, rank
, TRUE
);
6125 if (mono_class_has_failure (aklass
)) {
6126 mono_error_set_for_class_failure (error
, aklass
);
6127 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
6130 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_type
);
6131 return mono_type_get_object_handle (domain
, &aklass
->byval_arg
, error
);
6134 ICALL_EXPORT MonoReflectionTypeHandle
6135 ves_icall_RuntimeType_make_byref_type (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
6138 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
6140 MonoClass
*klass
= mono_class_from_mono_type (type
);
6141 mono_class_init_checked (klass
, error
);
6143 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
6145 check_for_invalid_type (klass
, error
);
6147 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
6149 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_type
);
6150 return mono_type_get_object_handle (domain
, &klass
->this_arg
, error
);
6153 ICALL_EXPORT MonoReflectionTypeHandle
6154 ves_icall_RuntimeType_MakePointerType (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
6157 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_type
);
6158 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
6159 MonoClass
*klass
= mono_class_from_mono_type (type
);
6160 mono_class_init_checked (klass
, error
);
6162 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
6164 check_for_invalid_type (klass
, error
);
6166 return MONO_HANDLE_CAST (MonoReflectionType
, NULL_HANDLE
);
6168 MonoClass
*pklass
= mono_ptr_class_get (type
);
6170 return mono_type_get_object_handle (domain
, &pklass
->byval_arg
, error
);
6173 ICALL_EXPORT MonoObject
*
6174 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType
*type
, MonoObject
*target
,
6175 MonoReflectionMethod
*info
, MonoBoolean throwOnBindFailure
)
6178 MonoClass
*delegate_class
= mono_class_from_mono_type (type
->type
);
6179 MonoObject
*delegate
;
6181 MonoMethod
*method
= info
->method
;
6182 MonoMethodSignature
*sig
= mono_method_signature(method
);
6184 mono_class_init_checked (delegate_class
, &error
);
6185 if (mono_error_set_pending_exception (&error
))
6188 if (!(delegate_class
->parent
== mono_defaults
.multicastdelegate_class
)) {
6189 /* FIXME improve this exception message */
6190 mono_error_set_execution_engine (&error
, "file %s: line %d (%s): assertion failed: (%s)", __FILE__
, __LINE__
,
6192 "delegate_class->parent == mono_defaults.multicastdelegate_class");
6193 mono_error_set_pending_exception (&error
);
6197 if (mono_security_core_clr_enabled ()) {
6198 if (!mono_security_core_clr_ensure_delegate_creation (method
, &error
)) {
6199 if (throwOnBindFailure
)
6200 mono_error_set_pending_exception (&error
);
6202 mono_error_cleanup (&error
);
6207 if (sig
->generic_param_count
&& method
->wrapper_type
== MONO_WRAPPER_NONE
) {
6208 if (!method
->is_inflated
) {
6209 mono_set_pending_exception(mono_get_exception_argument("method", " Cannot bind to the target method because its signature differs from that of the delegate type"));
6214 delegate
= mono_object_new_checked (mono_object_domain (type
), delegate_class
, &error
);
6215 if (mono_error_set_pending_exception (&error
))
6218 if (method_is_dynamic (method
)) {
6219 /* Creating a trampoline would leak memory */
6220 func
= mono_compile_method_checked (method
, &error
);
6221 if (mono_error_set_pending_exception (&error
))
6224 if (target
&& method
->flags
& METHOD_ATTRIBUTE_VIRTUAL
&& method
->klass
!= mono_object_class (target
))
6225 method
= mono_object_get_virtual_method (target
, method
);
6226 gpointer trampoline
= mono_runtime_create_jump_trampoline (mono_domain_get (), method
, TRUE
, &error
);
6227 if (mono_error_set_pending_exception (&error
))
6229 func
= mono_create_ftnptr (mono_domain_get (), trampoline
);
6232 mono_delegate_ctor_with_method (delegate
, target
, func
, method
, &error
);
6233 if (mono_error_set_pending_exception (&error
))
6238 ICALL_EXPORT MonoMulticastDelegate
*
6239 ves_icall_System_Delegate_AllocDelegateLike_internal (MonoDelegate
*delegate
)
6242 MonoMulticastDelegate
*ret
;
6244 g_assert (mono_class_has_parent (mono_object_class (delegate
), mono_defaults
.multicastdelegate_class
));
6246 ret
= (MonoMulticastDelegate
*) mono_object_new_checked (mono_object_domain (delegate
), mono_object_class (delegate
), &error
);
6247 if (mono_error_set_pending_exception (&error
))
6250 ret
->delegate
.invoke_impl
= mono_runtime_create_delegate_trampoline (mono_object_class (delegate
));
6255 ICALL_EXPORT MonoReflectionMethod
*
6256 ves_icall_System_Delegate_GetVirtualMethod_internal (MonoDelegate
*delegate
)
6258 MonoReflectionMethod
*ret
= NULL
;
6262 m
= mono_object_get_virtual_method (delegate
->target
, delegate
->method
);
6263 ret
= mono_method_get_object_checked (mono_domain_get (), m
, m
->klass
, &error
);
6264 mono_error_set_pending_exception (&error
);
6270 static inline gint32
6271 mono_array_get_byte_length (MonoArray
*array
)
6277 klass
= array
->obj
.vtable
->klass
;
6279 if (array
->bounds
== NULL
)
6280 length
= array
->max_length
;
6283 for (i
= 0; i
< klass
->rank
; ++ i
)
6284 length
*= array
->bounds
[i
].length
;
6287 switch (klass
->element_class
->byval_arg
.type
) {
6290 case MONO_TYPE_BOOLEAN
:
6294 case MONO_TYPE_CHAR
:
6302 return length
* sizeof (gpointer
);
6313 ves_icall_System_Buffer_ByteLengthInternal (MonoArray
*array
)
6315 return mono_array_get_byte_length (array
);
6319 ves_icall_System_Buffer_GetByteInternal (MonoArray
*array
, gint32 idx
)
6321 return mono_array_get (array
, gint8
, idx
);
6325 ves_icall_System_Buffer_SetByteInternal (MonoArray
*array
, gint32 idx
, gint8 value
)
6327 mono_array_set (array
, gint8
, idx
, value
);
6330 ICALL_EXPORT MonoBoolean
6331 ves_icall_System_Buffer_BlockCopyInternal (MonoArray
*src
, gint32 src_offset
, MonoArray
*dest
, gint32 dest_offset
, gint32 count
)
6333 guint8
*src_buf
, *dest_buf
;
6336 mono_set_pending_exception (mono_get_exception_argument ("count", "is negative"));
6340 g_assert (count
>= 0);
6342 /* This is called directly from the class libraries without going through the managed wrapper */
6343 MONO_CHECK_ARG_NULL (src
, FALSE
);
6344 MONO_CHECK_ARG_NULL (dest
, FALSE
);
6346 /* watch out for integer overflow */
6347 if ((src_offset
> mono_array_get_byte_length (src
) - count
) || (dest_offset
> mono_array_get_byte_length (dest
) - count
))
6350 src_buf
= (guint8
*)src
->vector
+ src_offset
;
6351 dest_buf
= (guint8
*)dest
->vector
+ dest_offset
;
6354 memcpy (dest_buf
, src_buf
, count
);
6356 memmove (dest_buf
, src_buf
, count
); /* Source and dest are the same array */
6361 #ifndef DISABLE_REMOTING
6362 ICALL_EXPORT MonoObjectHandle
6363 ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObjectHandle this_obj
, MonoStringHandle class_name
, MonoError
*error
)
6366 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (this_obj
);
6367 MonoRealProxyHandle rp
= MONO_HANDLE_CAST (MonoRealProxy
, this_obj
);
6369 MonoObjectHandle res
= MONO_HANDLE_NEW (MonoObject
, mono_object_new_checked (domain
, mono_defaults
.transparent_proxy_class
, error
));
6373 MonoTransparentProxyHandle tp
= MONO_HANDLE_CAST (MonoTransparentProxy
, res
);
6375 MONO_HANDLE_SET (tp
, rp
, rp
);
6377 MonoReflectionTypeHandle reftype
= MONO_HANDLE_NEW (MonoReflectionType
, NULL
);
6378 MONO_HANDLE_GET (reftype
, rp
, class_to_proxy
);
6379 MonoType
*type
= MONO_HANDLE_GETVAL (reftype
, type
);
6380 MonoClass
*klass
= mono_class_from_mono_type (type
);
6382 // mono_remote_class_vtable cannot handle errors well, so force any loading error to occur early
6383 mono_class_setup_vtable (klass
);
6384 if (mono_class_has_failure (klass
)) {
6385 mono_error_set_for_class_failure (error
, klass
);
6389 MonoObjectHandle remoting_obj
= mono_object_handle_isinst (this_obj
, mono_defaults
.iremotingtypeinfo_class
, error
);
6392 MONO_HANDLE_SETVAL (tp
, custom_type_info
, MonoBoolean
, !MONO_HANDLE_IS_NULL (remoting_obj
));
6394 MonoRemoteClass
*remote_class
= mono_remote_class (domain
, class_name
, klass
, error
);
6397 MONO_HANDLE_SETVAL (tp
, remote_class
, MonoRemoteClass
*, remote_class
);
6399 MONO_HANDLE_SETVAL (res
, vtable
, MonoVTable
*, mono_remote_class_vtable (domain
, remote_class
, rp
, error
));
6405 ICALL_EXPORT MonoReflectionType
*
6406 ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy
*tp
)
6409 g_assert (tp
!= NULL
&& mono_object_class (tp
) == mono_defaults
.transparent_proxy_class
);
6410 g_assert (tp
->remote_class
!= NULL
&& tp
->remote_class
->proxy_class
!= NULL
);
6411 MonoReflectionType
*ret
= mono_type_get_object_checked (mono_object_domain (tp
), &tp
->remote_class
->proxy_class
->byval_arg
, &error
);
6412 mono_error_set_pending_exception (&error
);
6418 /* System.Environment */
6421 ves_icall_System_Environment_get_UserName (MonoError
*error
)
6424 /* using glib is more portable */
6425 return mono_string_new_handle (mono_domain_get (), g_get_user_name (), error
);
6429 static MonoStringHandle
6430 mono_icall_get_machine_name (MonoError
*error
)
6433 #if !defined(DISABLE_SOCKETS)
6434 MonoStringHandle result
;
6437 #if defined _SC_HOST_NAME_MAX
6438 n
= sysconf (_SC_HOST_NAME_MAX
);
6442 buf
= g_malloc (n
+1);
6444 if (gethostname (buf
, n
) == 0){
6446 result
= mono_string_new_handle (mono_domain_get (), buf
, error
);
6448 result
= MONO_HANDLE_CAST (MonoString
, NULL_HANDLE
);
6453 return mono_string_new_handle (mono_domain_get (), "mono", error
);
6456 #endif /* !HOST_WIN32 */
6458 ICALL_EXPORT MonoStringHandle
6459 ves_icall_System_Environment_get_MachineName (MonoError
*error
)
6462 return mono_icall_get_machine_name (error
);
6467 mono_icall_get_platform (void)
6469 #if defined(__MACH__)
6472 // Notice that the value is hidden from user code, and only exposed
6473 // to mscorlib. This is due to Mono's Unix/MacOS code predating the
6474 // define and making assumptions based on Unix/128/4 values before there
6475 // was a MacOS define. Lots of code would assume that not-Unix meant
6476 // Windows, but in this case, it would be OSX.
6484 #endif /* !HOST_WIN32 */
6487 ves_icall_System_Environment_get_Platform (void)
6489 return mono_icall_get_platform ();
6493 static inline MonoStringHandle
6494 mono_icall_get_new_line (MonoError
*error
)
6497 return mono_string_new_handle (mono_domain_get (), "\n", error
);
6499 #endif /* !HOST_WIN32 */
6501 ICALL_EXPORT MonoStringHandle
6502 ves_icall_System_Environment_get_NewLine (MonoError
*error
)
6504 return mono_icall_get_new_line (error
);
6508 static inline MonoBoolean
6509 mono_icall_is_64bit_os (void)
6511 #if SIZEOF_VOID_P == 8
6514 #if defined(HAVE_SYS_UTSNAME_H)
6515 struct utsname name
;
6517 if (uname (&name
) >= 0) {
6518 return strcmp (name
.machine
, "x86_64") == 0 || strncmp (name
.machine
, "aarch64", 7) == 0 || strncmp (name
.machine
, "ppc64", 5) == 0;
6524 #endif /* !HOST_WIN32 */
6526 ICALL_EXPORT MonoBoolean
6527 ves_icall_System_Environment_GetIs64BitOperatingSystem (void)
6529 return mono_icall_is_64bit_os ();
6532 ICALL_EXPORT MonoStringHandle
6533 ves_icall_System_Environment_GetEnvironmentVariable_native (const gchar
*utf8_name
, MonoError
*error
)
6537 if (utf8_name
== NULL
)
6538 return NULL_HANDLE_STRING
;
6540 value
= g_getenv (utf8_name
);
6543 return NULL_HANDLE_STRING
;
6545 MonoStringHandle res
= mono_string_new_handle (mono_domain_get (), value
, error
);
6551 * There is no standard way to get at environ.
6554 #ifndef __MINGW32_VERSION
6555 #if defined(__APPLE__)
6556 #if defined (TARGET_OSX)
6557 /* Apple defines this in crt_externs.h but doesn't provide that header for
6558 * arm-apple-darwin9. We'll manually define the symbol on Apple as it does
6559 * in fact exist on all implementations (so far)
6561 gchar
***_NSGetEnviron(void);
6562 #define environ (*_NSGetEnviron())
6564 static char *mono_environ
[1] = { NULL
};
6565 #define environ mono_environ
6566 #endif /* defined (TARGET_OSX) */
6574 ICALL_EXPORT MonoArray
*
6575 ves_icall_System_Environment_GetCommandLineArgs (void)
6578 MonoArray
*result
= mono_runtime_get_main_args_checked (&error
);
6579 mono_error_set_pending_exception (&error
);
6585 mono_icall_get_environment_variable_names (MonoError
*error
)
6595 for (e
= environ
; *e
!= 0; ++ e
)
6598 domain
= mono_domain_get ();
6599 names
= mono_array_new_checked (domain
, mono_defaults
.string_class
, n
, error
);
6600 return_val_if_nok (error
, NULL
);
6603 for (e
= environ
; *e
!= 0; ++ e
) {
6604 parts
= g_strsplit (*e
, "=", 2);
6606 str
= mono_string_new_checked (domain
, *parts
, error
);
6607 if (!is_ok (error
)) {
6611 mono_array_setref (names
, n
, str
);
6621 #endif /* !HOST_WIN32 */
6623 ICALL_EXPORT MonoArray
*
6624 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
6627 MonoArray
*result
= mono_icall_get_environment_variable_names (&error
);
6628 mono_error_set_pending_exception (&error
);
6634 mono_icall_set_environment_variable (MonoString
*name
, MonoString
*value
)
6636 gchar
*utf8_name
, *utf8_value
;
6639 utf8_name
= mono_string_to_utf8_checked (name
, &error
); /* FIXME: this should be ascii */
6640 if (mono_error_set_pending_exception (&error
))
6643 if ((value
== NULL
) || (mono_string_length (value
) == 0) || (mono_string_chars (value
)[0] == 0)) {
6644 g_unsetenv (utf8_name
);
6649 utf8_value
= mono_string_to_utf8_checked (value
, &error
);
6650 if (!mono_error_ok (&error
)) {
6652 mono_error_set_pending_exception (&error
);
6655 g_setenv (utf8_name
, utf8_value
, TRUE
);
6658 g_free (utf8_value
);
6660 #endif /* !HOST_WIN32 */
6663 ves_icall_System_Environment_InternalSetEnvironmentVariable (MonoString
*name
, MonoString
*value
)
6665 mono_icall_set_environment_variable (name
, value
);
6669 ves_icall_System_Environment_Exit (int result
)
6671 mono_environment_exitcode_set (result
);
6673 /* FIXME: There are some cleanup hangs that should be worked out, but
6674 * if the program is going to exit, everything will be cleaned up when
6675 * NaCl exits anyway.
6677 #ifndef __native_client__
6678 if (!mono_runtime_try_shutdown ())
6679 mono_thread_exit ();
6681 /* Suspend all managed threads since the runtime is going away */
6682 mono_thread_suspend_all_other_threads ();
6684 mono_runtime_quit ();
6687 /* we may need to do some cleanup here... */
6691 ICALL_EXPORT MonoStringHandle
6692 ves_icall_System_Environment_GetGacPath (MonoError
*error
)
6694 return mono_string_new_handle (mono_domain_get (), mono_assembly_getrootdir (), error
);
6698 static inline MonoStringHandle
6699 mono_icall_get_windows_folder_path (int folder
, MonoError
*error
)
6702 g_warning ("ves_icall_System_Environment_GetWindowsFolderPath should only be called on Windows!");
6703 return mono_string_new_handle (mono_domain_get (), "", error
);
6705 #endif /* !HOST_WIN32 */
6707 ICALL_EXPORT MonoStringHandle
6708 ves_icall_System_Environment_GetWindowsFolderPath (int folder
, MonoError
*error
)
6710 return mono_icall_get_windows_folder_path (folder
, error
);
6713 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
6715 mono_icall_get_logical_drives (void)
6718 gunichar2 buf
[256], *ptr
, *dname
;
6720 guint initial_size
= 127, size
= 128;
6723 MonoString
*drivestr
;
6724 MonoDomain
*domain
= mono_domain_get ();
6730 while (size
> initial_size
) {
6731 size
= (guint
) mono_w32file_get_logical_drive (initial_size
, ptr
);
6732 if (size
> initial_size
) {
6735 ptr
= (gunichar2
*)g_malloc0 ((size
+ 1) * sizeof (gunichar2
));
6736 initial_size
= size
;
6750 result
= mono_array_new_checked (domain
, mono_defaults
.string_class
, ndrives
, &error
);
6751 if (mono_error_set_pending_exception (&error
))
6758 while (*u16
) { u16
++; len
++; }
6759 drivestr
= mono_string_new_utf16_checked (domain
, dname
, len
, &error
);
6760 if (mono_error_set_pending_exception (&error
))
6763 mono_array_setref (result
, ndrives
++, drivestr
);
6773 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
6775 ICALL_EXPORT MonoArray
*
6776 ves_icall_System_Environment_GetLogicalDrives (void)
6778 return mono_icall_get_logical_drives ();
6781 ICALL_EXPORT MonoString
*
6782 ves_icall_System_IO_DriveInfo_GetDriveFormat (MonoString
*path
)
6785 gunichar2 volume_name
[MAX_PATH
+ 1];
6787 if (mono_w32file_get_volume_information (mono_string_chars (path
), NULL
, 0, NULL
, NULL
, NULL
, volume_name
, MAX_PATH
+ 1) == FALSE
)
6789 MonoString
*result
= mono_string_from_utf16_checked (volume_name
, &error
);
6790 mono_error_set_pending_exception (&error
);
6794 ICALL_EXPORT MonoStringHandle
6795 ves_icall_System_Environment_InternalGetHome (MonoError
*error
)
6797 return mono_string_new_handle (mono_domain_get (), g_get_home_dir (), error
);
6800 static const char *encodings
[] = {
6802 "ascii", "us_ascii", "us", "ansi_x3.4_1968",
6803 "ansi_x3.4_1986", "cp367", "csascii", "ibm367",
6804 "iso_ir_6", "iso646_us", "iso_646.irv:1991",
6806 "utf_7", "csunicode11utf7", "unicode_1_1_utf_7",
6807 "unicode_2_0_utf_7", "x_unicode_1_1_utf_7",
6808 "x_unicode_2_0_utf_7",
6810 "utf_8", "unicode_1_1_utf_8", "unicode_2_0_utf_8",
6811 "x_unicode_1_1_utf_8", "x_unicode_2_0_utf_8",
6813 "utf_16", "UTF_16LE", "ucs_2", "unicode",
6816 "unicodefffe", "utf_16be",
6823 * Returns the internal codepage, if the value of "int_code_page" is
6824 * 1 at entry, and we can not compute a suitable code page number,
6825 * returns the code page as a string
6827 ICALL_EXPORT MonoStringHandle
6828 ves_icall_System_Text_EncodingHelper_InternalCodePage (gint32
*int_code_page
, MonoError
*error
)
6834 char *codepage
= NULL
;
6836 int want_name
= *int_code_page
;
6839 *int_code_page
= -1;
6841 g_get_charset (&cset
);
6842 c
= codepage
= g_strdup (cset
);
6843 for (c
= codepage
; *c
; c
++){
6844 if (isascii (*c
) && isalpha (*c
))
6849 /* g_print ("charset: %s\n", cset); */
6851 /* handle some common aliases */
6854 for (i
= 0; p
!= 0; ){
6857 p
= encodings
[++i
];
6860 if (strcmp (p
, codepage
) == 0){
6861 *int_code_page
= code
;
6864 p
= encodings
[++i
];
6867 if (strstr (codepage
, "utf_8") != NULL
)
6868 *int_code_page
|= 0x10000000;
6871 if (want_name
&& *int_code_page
== -1)
6872 return mono_string_new_handle (mono_domain_get (), cset
, error
);
6874 return MONO_HANDLE_CAST (MonoString
, NULL_HANDLE
);
6877 ICALL_EXPORT MonoBoolean
6878 ves_icall_System_Environment_get_HasShutdownStarted (void)
6880 if (mono_runtime_is_shutting_down ())
6883 if (mono_domain_is_unloading (mono_domain_get ()))
6890 static inline MonoBoolean
6891 mono_icall_broadcast_setting_change (MonoError
*error
)
6896 #endif /* !HOST_WIN32 */
6899 ves_icall_System_Environment_BroadcastSettingChange (MonoError
*error
)
6902 mono_icall_broadcast_setting_change (error
);
6907 ves_icall_System_Environment_get_TickCount (void)
6909 /* this will overflow after ~24 days */
6910 return (gint32
) (mono_msec_boottime () & 0xffffffff);
6914 ves_icall_System_Runtime_Versioning_VersioningHelper_GetRuntimeId (void)
6919 #ifndef DISABLE_REMOTING
6920 ICALL_EXPORT MonoBoolean
6921 ves_icall_IsTransparentProxy (MonoObject
*proxy
)
6926 if (mono_object_is_transparent_proxy (proxy
))
6932 ICALL_EXPORT MonoReflectionMethod
*
6933 ves_icall_Remoting_RemotingServices_GetVirtualMethod (
6934 MonoReflectionType
*rtype
, MonoReflectionMethod
*rmethod
)
6936 MonoReflectionMethod
*ret
= NULL
;
6941 MonoMethod
**vtable
;
6942 MonoMethod
*res
= NULL
;
6944 MONO_CHECK_ARG_NULL (rtype
, NULL
);
6945 MONO_CHECK_ARG_NULL (rmethod
, NULL
);
6947 method
= rmethod
->method
;
6948 klass
= mono_class_from_mono_type (rtype
->type
);
6949 mono_class_init_checked (klass
, &error
);
6950 if (mono_error_set_pending_exception (&error
))
6953 if (MONO_CLASS_IS_INTERFACE (klass
))
6956 if (method
->flags
& METHOD_ATTRIBUTE_STATIC
)
6959 if ((method
->flags
& METHOD_ATTRIBUTE_FINAL
) || !(method
->flags
& METHOD_ATTRIBUTE_VIRTUAL
)) {
6960 if (klass
== method
->klass
|| mono_class_is_subclass_of (klass
, method
->klass
, FALSE
))
6966 mono_class_setup_vtable (klass
);
6967 vtable
= klass
->vtable
;
6969 if (mono_class_is_interface (method
->klass
)) {
6970 gboolean variance_used
= FALSE
;
6971 /*MS fails with variant interfaces but it's the right thing to do anyway.*/
6972 int offs
= mono_class_interface_offset_with_variance (klass
, method
->klass
, &variance_used
);
6974 res
= vtable
[offs
+ method
->slot
];
6976 if (!(klass
== method
->klass
|| mono_class_is_subclass_of (klass
, method
->klass
, FALSE
)))
6979 if (method
->slot
!= -1)
6980 res
= vtable
[method
->slot
];
6986 ret
= mono_method_get_object_checked (mono_domain_get (), res
, NULL
, &error
);
6987 mono_error_set_pending_exception (&error
);
6992 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType
*type
, MonoBoolean enable
)
6998 klass
= mono_class_from_mono_type (type
->type
);
6999 vtable
= mono_class_vtable_full (mono_domain_get (), klass
, &error
);
7000 if (!is_ok (&error
)) {
7001 mono_error_set_pending_exception (&error
);
7005 mono_vtable_set_is_remote (vtable
, enable
);
7008 #else /* DISABLE_REMOTING */
7011 ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType
*type
, MonoBoolean enable
)
7013 g_assert_not_reached ();
7018 ICALL_EXPORT MonoObject
*
7019 ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType
*type
)
7026 domain
= mono_object_domain (type
);
7027 klass
= mono_class_from_mono_type (type
->type
);
7028 mono_class_init_checked (klass
, &error
);
7029 if (mono_error_set_pending_exception (&error
))
7032 if (MONO_CLASS_IS_INTERFACE (klass
) || mono_class_is_abstract (klass
)) {
7033 mono_set_pending_exception (mono_get_exception_argument ("type", "Type cannot be instantiated"));
7037 if (klass
->rank
>= 1) {
7038 g_assert (klass
->rank
== 1);
7039 ret
= (MonoObject
*) mono_array_new_checked (domain
, klass
->element_class
, 0, &error
);
7040 mono_error_set_pending_exception (&error
);
7043 MonoVTable
*vtable
= mono_class_vtable_full (domain
, klass
, &error
);
7044 if (!is_ok (&error
)) {
7045 mono_error_set_pending_exception (&error
);
7048 /* Bypass remoting object creation check */
7049 ret
= mono_object_new_alloc_specific_checked (vtable
, &error
);
7050 mono_error_set_pending_exception (&error
);
7056 ICALL_EXPORT MonoStringHandle
7057 ves_icall_System_IO_get_temp_path (MonoError
*error
)
7059 return mono_string_new_handle (mono_domain_get (), g_get_tmp_dir (), error
);
7062 #ifndef PLATFORM_NO_DRIVEINFO
7063 ICALL_EXPORT MonoBoolean
7064 ves_icall_System_IO_DriveInfo_GetDiskFreeSpace (MonoString
*path_name
, guint64
*free_bytes_avail
,
7065 guint64
*total_number_of_bytes
, guint64
*total_number_of_free_bytes
,
7070 *error
= ERROR_SUCCESS
;
7072 result
= mono_w32file_get_disk_free_space (mono_string_chars (path_name
), free_bytes_avail
, total_number_of_bytes
, total_number_of_free_bytes
);
7074 *error
= mono_w32error_get_last ();
7079 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
7080 static inline guint32
7081 mono_icall_drive_info_get_drive_type (MonoString
*root_path_name
)
7083 return mono_w32file_get_drive_type (mono_string_chars (root_path_name
));
7085 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
7087 ICALL_EXPORT guint32
7088 ves_icall_System_IO_DriveInfo_GetDriveType (MonoString
*root_path_name
)
7090 return mono_icall_drive_info_get_drive_type (root_path_name
);
7093 #endif /* PLATFORM_NO_DRIVEINFO */
7095 ICALL_EXPORT gpointer
7096 ves_icall_RuntimeMethodHandle_GetFunctionPointer (MonoMethod
*method
, MonoError
*error
)
7099 return mono_compile_method_checked (method
, error
);
7102 ICALL_EXPORT MonoStringHandle
7103 ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (MonoError
*error
)
7108 path
= g_build_path (G_DIR_SEPARATOR_S
, mono_get_config_dir (), "mono", mono_get_runtime_info ()->framework_version
, "machine.config", NULL
);
7110 mono_icall_make_platform_path (path
);
7112 MonoStringHandle mcpath
= mono_string_new_handle (mono_domain_get (), path
, error
);
7115 mono_error_assert_ok (error
);
7120 static MonoStringHandle
7121 ves_icall_System_Configuration_InternalConfigurationHost_get_bundled_app_config (MonoError
*error
)
7124 const gchar
*app_config
;
7126 gchar
*config_file_name
, *config_file_path
;
7127 gsize len
, config_file_path_length
, config_ext_length
;
7130 domain
= mono_domain_get ();
7131 MonoStringHandle file
= MONO_HANDLE_NEW (MonoString
, domain
->setup
->configuration_file
);
7132 if (MONO_HANDLE_IS_NULL (file
) || MONO_HANDLE_GETVAL (file
, length
) == 0)
7135 // Retrieve config file and remove the extension
7136 config_file_name
= mono_string_handle_to_utf8 (file
, error
);
7137 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoString
, NULL_HANDLE
));
7139 config_file_path
= mono_portability_find_file (config_file_name
, TRUE
);
7140 if (!config_file_path
)
7141 config_file_path
= config_file_name
;
7143 config_file_path_length
= strlen (config_file_path
);
7144 config_ext_length
= strlen (".config");
7145 if (config_file_path_length
<= config_ext_length
) {
7146 if (config_file_name
!= config_file_path
)
7147 g_free (config_file_name
);
7148 return MONO_HANDLE_CAST (MonoString
, NULL_HANDLE
);
7151 len
= config_file_path_length
- config_ext_length
;
7152 module
= (gchar
*)g_malloc0 (len
+ 1);
7153 memcpy (module
, config_file_path
, len
);
7154 // Get the config file from the module name
7155 app_config
= mono_config_string_for_assembly_file (module
);
7158 if (config_file_name
!= config_file_path
)
7159 g_free (config_file_name
);
7160 g_free (config_file_path
);
7163 return MONO_HANDLE_CAST (MonoString
, NULL_HANDLE
);
7165 return mono_string_new_handle (mono_domain_get (), app_config
, error
);
7168 static MonoStringHandle
7169 get_bundled_machine_config (MonoError
*error
)
7171 const gchar
*machine_config
;
7173 machine_config
= mono_get_machine_config ();
7175 if (!machine_config
)
7176 return NULL_HANDLE_STRING
;
7178 return mono_string_new_handle (mono_domain_get (), machine_config
, error
);
7181 ICALL_EXPORT MonoStringHandle
7182 ves_icall_System_Environment_get_bundled_machine_config (MonoError
*error
)
7184 return get_bundled_machine_config (error
);
7188 ICALL_EXPORT MonoStringHandle
7189 ves_icall_System_Configuration_DefaultConfig_get_bundled_machine_config (MonoError
*error
)
7191 return get_bundled_machine_config (error
);
7194 ICALL_EXPORT MonoStringHandle
7195 ves_icall_System_Configuration_InternalConfigurationHost_get_bundled_machine_config (MonoError
*error
)
7197 return get_bundled_machine_config (error
);
7201 ICALL_EXPORT MonoStringHandle
7202 ves_icall_System_Web_Util_ICalls_get_machine_install_dir (MonoError
*error
)
7207 path
= g_path_get_dirname (mono_get_config_dir ());
7209 mono_icall_make_platform_path (path
);
7211 MonoStringHandle ipath
= mono_string_new_handle (mono_domain_get (), path
, error
);
7217 ICALL_EXPORT gboolean
7218 ves_icall_get_resources_ptr (MonoReflectionAssemblyHandle assembly
, gpointer
*result
, gint32
*size
, MonoError
*error
)
7221 MonoPEResourceDataEntry
*entry
;
7224 if (!assembly
|| !result
|| !size
)
7229 MonoAssembly
*assm
= MONO_HANDLE_GETVAL (assembly
, assembly
);
7230 image
= assm
->image
;
7231 entry
= (MonoPEResourceDataEntry
*)mono_image_lookup_resource (image
, MONO_PE_RESOURCE_ID_ASPNET_STRING
, 0, NULL
);
7235 *result
= mono_image_rva_map (image
, entry
->rde_data_offset
);
7240 *size
= entry
->rde_size
;
7245 ICALL_EXPORT MonoBoolean
7246 ves_icall_System_Diagnostics_Debugger_IsAttached_internal (void)
7248 return mono_is_debugger_attached ();
7251 ICALL_EXPORT MonoBoolean
7252 ves_icall_System_Diagnostics_Debugger_IsLogging (void)
7254 if (mono_get_runtime_callbacks ()->debug_log_is_enabled
)
7255 return mono_get_runtime_callbacks ()->debug_log_is_enabled ();
7261 ves_icall_System_Diagnostics_Debugger_Log (int level
, MonoString
*category
, MonoString
*message
)
7263 if (mono_get_runtime_callbacks ()->debug_log
)
7264 mono_get_runtime_callbacks ()->debug_log (level
, category
, message
);
7269 mono_icall_write_windows_debug_string (MonoString
*message
)
7271 g_warning ("WriteWindowsDebugString called and HOST_WIN32 not defined!\n");
7273 #endif /* !HOST_WIN32 */
7276 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString
*message
)
7278 mono_icall_write_windows_debug_string (message
);
7281 /* Only used for value types */
7282 ICALL_EXPORT MonoObjectHandle
7283 ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionTypeHandle ref_type
, MonoError
*error
)
7286 MonoDomain
*domain
= MONO_HANDLE_DOMAIN (ref_type
);
7287 MonoType
*type
= MONO_HANDLE_GETVAL (ref_type
, type
);
7288 MonoClass
*klass
= mono_class_from_mono_type (type
);
7290 mono_class_init_checked (klass
, error
);
7294 if (mono_class_is_nullable (klass
))
7295 /* No arguments -> null */
7298 return MONO_HANDLE_NEW (MonoObject
, mono_object_new_checked (domain
, klass
, error
));
7301 ICALL_EXPORT MonoReflectionMethodHandle
7302 ves_icall_MonoMethod_get_base_method (MonoReflectionMethodHandle m
, gboolean definition
, MonoError
*error
)
7305 MonoMethod
*method
= MONO_HANDLE_GETVAL (m
, method
);
7307 MonoMethod
*base
= mono_method_get_base_method (method
, definition
, error
);
7308 return_val_if_nok (error
, MONO_HANDLE_CAST (MonoReflectionMethod
, NULL_HANDLE
));
7309 if (base
== method
) {
7310 /* we want to short-circuit and return 'm' here. But we should
7311 return the same method object that
7312 mono_method_get_object_handle, below would return. Since
7313 that call takes NULL for the reftype argument, it will take
7314 base->klass as the reflected type for the MonoMethod. So we
7315 need to check that m also has base->klass as the reflected
7317 MonoReflectionTypeHandle orig_reftype
= MONO_HANDLE_NEW_GET (MonoReflectionType
, m
, reftype
);
7318 MonoClass
*orig_klass
= mono_class_from_mono_type (MONO_HANDLE_GETVAL (orig_reftype
, type
));
7319 if (base
->klass
== orig_klass
)
7322 return mono_method_get_object_handle (mono_domain_get (), base
, NULL
, error
);
7325 ICALL_EXPORT MonoStringHandle
7326 ves_icall_MonoMethod_get_name (MonoReflectionMethodHandle m
, MonoError
*error
)
7329 MonoMethod
*method
= MONO_HANDLE_GETVAL (m
, method
);
7331 MonoStringHandle s
= mono_string_new_handle (MONO_HANDLE_DOMAIN (m
), method
->name
, error
);
7333 return NULL_HANDLE_STRING
;
7334 MONO_HANDLE_SET (m
, name
, s
);
7339 mono_ArgIterator_Setup (MonoArgIterator
*iter
, char* argsp
, char* start
)
7341 iter
->sig
= *(MonoMethodSignature
**)argsp
;
7343 g_assert (iter
->sig
->sentinelpos
<= iter
->sig
->param_count
);
7344 g_assert (iter
->sig
->call_convention
== MONO_CALL_VARARG
);
7347 /* FIXME: it's not documented what start is exactly... */
7351 iter
->args
= argsp
+ sizeof (gpointer
);
7353 iter
->num_args
= iter
->sig
->param_count
- iter
->sig
->sentinelpos
;
7355 /* g_print ("sig %p, param_count: %d, sent: %d\n", iter->sig, iter->sig->param_count, iter->sig->sentinelpos); */
7358 ICALL_EXPORT MonoTypedRef
7359 mono_ArgIterator_IntGetNextArg (MonoArgIterator
*iter
)
7361 guint32 i
, arg_size
;
7365 i
= iter
->sig
->sentinelpos
+ iter
->next_arg
;
7367 g_assert (i
< iter
->sig
->param_count
);
7369 res
.type
= iter
->sig
->params
[i
];
7370 res
.klass
= mono_class_from_mono_type (res
.type
);
7371 arg_size
= mono_type_stack_size (res
.type
, &align
);
7372 #if defined(__arm__) || defined(__mips__)
7373 iter
->args
= (guint8
*)(((gsize
)iter
->args
+ (align
) - 1) & ~(align
- 1));
7375 res
.value
= iter
->args
;
7376 #if defined(__native_client__) && SIZEOF_REGISTER == 8
7377 /* Values are stored as 8 byte register sized objects, but 'value'
7378 * is dereferenced as a pointer in other routines.
7380 res
.value
= (char*)res
.value
+ 4;
7382 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
7383 if (arg_size
<= sizeof (gpointer
)) {
7385 int padding
= arg_size
- mono_type_size (res
.type
, &dummy
);
7386 res
.value
= (guint8
*)res
.value
+ padding
;
7389 iter
->args
= (char*)iter
->args
+ arg_size
;
7392 /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
7397 ICALL_EXPORT MonoTypedRef
7398 mono_ArgIterator_IntGetNextArgT (MonoArgIterator
*iter
, MonoType
*type
)
7400 guint32 i
, arg_size
;
7404 i
= iter
->sig
->sentinelpos
+ iter
->next_arg
;
7406 g_assert (i
< iter
->sig
->param_count
);
7408 while (i
< iter
->sig
->param_count
) {
7409 if (!mono_metadata_type_equal (type
, iter
->sig
->params
[i
]))
7411 res
.type
= iter
->sig
->params
[i
];
7412 res
.klass
= mono_class_from_mono_type (res
.type
);
7413 /* FIXME: endianess issue... */
7414 arg_size
= mono_type_stack_size (res
.type
, &align
);
7415 #if defined(__arm__) || defined(__mips__)
7416 iter
->args
= (guint8
*)(((gsize
)iter
->args
+ (align
) - 1) & ~(align
- 1));
7418 res
.value
= iter
->args
;
7419 iter
->args
= (char*)iter
->args
+ arg_size
;
7421 /* g_print ("returning arg %d, type 0x%02x of size %d at %p\n", i, res.type->type, arg_size, res.value); */
7424 /* g_print ("arg type 0x%02x not found\n", res.type->type); */
7432 ICALL_EXPORT MonoType
*
7433 mono_ArgIterator_IntGetNextArgType (MonoArgIterator
*iter
)
7437 i
= iter
->sig
->sentinelpos
+ iter
->next_arg
;
7439 g_assert (i
< iter
->sig
->param_count
);
7441 return iter
->sig
->params
[i
];
7444 ICALL_EXPORT MonoObject
*
7445 mono_TypedReference_ToObject (MonoTypedRef
* tref
)
7448 MonoObject
*result
= NULL
;
7449 if (MONO_TYPE_IS_REFERENCE (tref
->type
)) {
7450 MonoObject
** objp
= (MonoObject
**)tref
->value
;
7454 result
= mono_value_box_checked (mono_domain_get (), tref
->klass
, tref
->value
, &error
);
7455 mono_error_set_pending_exception (&error
);
7459 ICALL_EXPORT MonoTypedRef
7460 mono_TypedReference_MakeTypedReferenceInternal (MonoObject
*target
, MonoArray
*fields
)
7463 MonoReflectionField
*f
;
7465 MonoType
*ftype
= NULL
;
7469 memset (&res
, 0, sizeof (res
));
7472 g_assert (mono_array_length (fields
) > 0);
7474 klass
= target
->vtable
->klass
;
7476 for (i
= 0; i
< mono_array_length (fields
); ++i
) {
7477 f
= mono_array_get (fields
, MonoReflectionField
*, i
);
7479 mono_set_pending_exception (mono_get_exception_argument_null ("field"));
7482 if (f
->field
->parent
!= klass
) {
7483 mono_set_pending_exception (mono_get_exception_argument ("field", ""));
7487 p
= (guint8
*)target
+ f
->field
->offset
;
7489 p
+= f
->field
->offset
- sizeof (MonoObject
);
7490 klass
= mono_class_from_mono_type (f
->field
->type
);
7491 ftype
= f
->field
->type
;
7495 res
.klass
= mono_class_from_mono_type (ftype
);
7502 prelink_method (MonoMethod
*method
, MonoError
*error
)
7504 const char *exc_class
, *exc_arg
;
7507 if (!(method
->flags
& METHOD_ATTRIBUTE_PINVOKE_IMPL
))
7509 mono_lookup_pinvoke_call (method
, &exc_class
, &exc_arg
);
7511 mono_error_set_exception_instance (error
,
7512 mono_exception_from_name_msg (mono_defaults
.corlib
, "System", exc_class
, exc_arg
));
7515 /* create the wrapper, too? */
7519 ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethod
*method
)
7523 prelink_method (method
->method
, &error
);
7524 mono_error_set_pending_exception (&error
);
7528 ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionType
*type
)
7531 MonoClass
*klass
= mono_class_from_mono_type (type
->type
);
7533 gpointer iter
= NULL
;
7535 mono_class_init_checked (klass
, &error
);
7536 if (mono_error_set_pending_exception (&error
))
7539 while ((m
= mono_class_get_methods (klass
, &iter
))) {
7540 prelink_method (m
, &error
);
7541 if (mono_error_set_pending_exception (&error
))
7546 /* These parameters are "readonly" in corlib/System/NumberFormatter.cs */
7548 ves_icall_System_NumberFormatter_GetFormatterTables (guint64
const **mantissas
,
7549 gint32
const **exponents
,
7550 gunichar2
const **digitLowerTable
,
7551 gunichar2
const **digitUpperTable
,
7552 gint64
const **tenPowersList
,
7553 gint32
const **decHexDigits
)
7555 *mantissas
= Formatter_MantissaBitsTable
;
7556 *exponents
= Formatter_TensExponentTable
;
7557 *digitLowerTable
= Formatter_DigitLowerTable
;
7558 *digitUpperTable
= Formatter_DigitUpperTable
;
7559 *tenPowersList
= Formatter_TenPowersList
;
7560 *decHexDigits
= Formatter_DecHexDigits
;
7564 add_modifier_to_array (MonoDomain
*domain
, MonoImage
*image
, MonoCustomMod
*modifier
, MonoArrayHandle dest
, int dest_idx
, MonoError
*error
)
7566 HANDLE_FUNCTION_ENTER ();
7568 MonoClass
*klass
= mono_class_get_checked (image
, modifier
->token
, error
);
7572 MonoReflectionTypeHandle rt
= mono_type_get_object_handle (domain
, &klass
->byval_arg
, error
);
7576 MONO_HANDLE_ARRAY_SETREF (dest
, dest_idx
, rt
);
7578 HANDLE_FUNCTION_RETURN_VAL (is_ok (error
));
7582 * We return NULL for no modifiers so the corlib code can return Type.EmptyTypes
7583 * and avoid useless allocations.
7585 static MonoArrayHandle
7586 type_array_from_modifiers (MonoImage
*image
, MonoType
*type
, int optional
, MonoError
*error
)
7589 MonoDomain
*domain
= mono_domain_get ();
7592 for (i
= 0; i
< type
->num_mods
; ++i
) {
7593 if ((optional
&& !type
->modifiers
[i
].required
) || (!optional
&& type
->modifiers
[i
].required
))
7597 return MONO_HANDLE_NEW (MonoArray
, NULL
);
7599 MonoArrayHandle res
= mono_array_new_handle (domain
, mono_defaults
.systemtype_class
, count
, error
);
7603 for (i
= 0; i
< type
->num_mods
; ++i
) {
7604 if ((optional
&& !type
->modifiers
[i
].required
) || (!optional
&& type
->modifiers
[i
].required
)) {
7605 if (!add_modifier_to_array (domain
, image
, &type
->modifiers
[i
], res
, count
, error
))
7612 return MONO_HANDLE_NEW (MonoArray
, NULL
);
7615 ICALL_EXPORT MonoArrayHandle
7616 ves_icall_ParameterInfo_GetTypeModifiers (MonoReflectionParameterHandle param
, MonoBoolean optional
, MonoError
*error
)
7619 MonoReflectionTypeHandle rt
= MONO_HANDLE_NEW (MonoReflectionType
, NULL
);
7620 MONO_HANDLE_GET (rt
, param
, ClassImpl
);
7621 MonoType
*type
= MONO_HANDLE_GETVAL (rt
, type
);
7622 MonoObjectHandle member
= MONO_HANDLE_NEW (MonoObject
, NULL
);
7623 MONO_HANDLE_GET (member
, param
, MemberImpl
);
7624 MonoClass
*member_class
= mono_handle_class (member
);
7625 MonoMethod
*method
= NULL
;
7628 MonoMethodSignature
*sig
;
7630 if (mono_class_is_reflection_method_or_constructor (member_class
)) {
7631 method
= MONO_HANDLE_GETVAL (MONO_HANDLE_CAST (MonoReflectionMethod
, member
), method
);
7632 } else if (member_class
->image
== mono_defaults
.corlib
&& !strcmp ("MonoProperty", member_class
->name
)) {
7633 MonoProperty
*prop
= MONO_HANDLE_GETVAL (MONO_HANDLE_CAST (MonoReflectionProperty
, member
), property
);
7634 if (!(method
= prop
->get
))
7638 char *type_name
= mono_type_get_full_name (member_class
);
7639 mono_error_set_not_supported (error
, "Custom modifiers on a ParamInfo with member %s are not supported", type_name
);
7641 return MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
);
7644 image
= method
->klass
->image
;
7645 pos
= MONO_HANDLE_GETVAL (param
, PositionImpl
);
7646 sig
= mono_method_signature (method
);
7650 type
= sig
->params
[pos
];
7652 return type_array_from_modifiers (image
, type
, optional
, error
);
7656 get_property_type (MonoProperty
*prop
)
7658 MonoMethodSignature
*sig
;
7660 sig
= mono_method_signature (prop
->get
);
7662 } else if (prop
->set
) {
7663 sig
= mono_method_signature (prop
->set
);
7664 return sig
->params
[sig
->param_count
- 1];
7669 ICALL_EXPORT MonoArrayHandle
7670 ves_icall_MonoPropertyInfo_GetTypeModifiers (MonoReflectionPropertyHandle property
, MonoBoolean optional
, MonoError
*error
)
7673 MonoProperty
*prop
= MONO_HANDLE_GETVAL (property
, property
);
7674 MonoClass
*klass
= MONO_HANDLE_GETVAL (property
, klass
);
7675 MonoType
*type
= get_property_type (prop
);
7676 MonoImage
*image
= klass
->image
;
7679 return MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
);
7680 return type_array_from_modifiers (image
, type
, optional
, error
);
7684 *Construct a MonoType suited to be used to decode a constant blob object.
7686 * @type is the target type which will be constructed
7687 * @blob_type is the blob type, for example, that comes from the constant table
7688 * @real_type is the expected constructed type.
7691 mono_type_from_blob_type (MonoType
*type
, MonoTypeEnum blob_type
, MonoType
*real_type
)
7693 type
->type
= blob_type
;
7694 type
->data
.klass
= NULL
;
7695 if (blob_type
== MONO_TYPE_CLASS
)
7696 type
->data
.klass
= mono_defaults
.object_class
;
7697 else if (real_type
->type
== MONO_TYPE_VALUETYPE
&& real_type
->data
.klass
->enumtype
) {
7698 /* For enums, we need to use the base type */
7699 type
->type
= MONO_TYPE_VALUETYPE
;
7700 type
->data
.klass
= mono_class_from_mono_type (real_type
);
7702 type
->data
.klass
= mono_class_from_mono_type (real_type
);
7705 ICALL_EXPORT MonoObject
*
7706 property_info_get_default_value (MonoReflectionProperty
*property
)
7710 MonoProperty
*prop
= property
->property
;
7711 MonoType
*type
= get_property_type (prop
);
7712 MonoDomain
*domain
= mono_object_domain (property
);
7713 MonoTypeEnum def_type
;
7714 const char *def_value
;
7717 mono_class_init (prop
->parent
);
7719 if (!(prop
->attrs
& PROPERTY_ATTRIBUTE_HAS_DEFAULT
)) {
7720 mono_set_pending_exception (mono_get_exception_invalid_operation (NULL
));
7724 def_value
= mono_class_get_property_default_value (prop
, &def_type
);
7726 mono_type_from_blob_type (&blob_type
, def_type
, type
);
7727 o
= mono_get_object_from_blob (domain
, &blob_type
, def_value
, &error
);
7729 mono_error_set_pending_exception (&error
);
7733 ICALL_EXPORT MonoBoolean
7734 ves_icall_MonoCustomAttrs_IsDefinedInternal (MonoObjectHandle obj
, MonoReflectionTypeHandle attr_type
, MonoError
*error
)
7737 MonoClass
*attr_class
= mono_class_from_mono_type (MONO_HANDLE_GETVAL (attr_type
, type
));
7739 mono_class_init_checked (attr_class
, error
);
7740 return_val_if_nok (error
, FALSE
);
7742 MonoCustomAttrInfo
*cinfo
= mono_reflection_get_custom_attrs_info_checked (obj
, error
);
7743 return_val_if_nok (error
, FALSE
);
7747 gboolean found
= mono_custom_attrs_has_attr (cinfo
, attr_class
);
7749 mono_custom_attrs_free (cinfo
);
7753 ICALL_EXPORT MonoArrayHandle
7754 ves_icall_MonoCustomAttrs_GetCustomAttributesInternal (MonoObjectHandle obj
, MonoReflectionTypeHandle attr_type
, mono_bool pseudoattrs
, MonoError
*error
)
7756 MonoClass
*attr_class
;
7757 if (MONO_HANDLE_IS_NULL (attr_type
))
7760 attr_class
= mono_class_from_mono_type (MONO_HANDLE_GETVAL (attr_type
, type
));
7763 mono_class_init_checked (attr_class
, error
);
7765 return MONO_HANDLE_CAST (MonoArray
, NULL_HANDLE
);
7768 return mono_reflection_get_custom_attrs_by_type_handle (obj
, attr_class
, error
);
7771 ICALL_EXPORT MonoArrayHandle
7772 ves_icall_MonoCustomAttrs_GetCustomAttributesDataInternal (MonoObjectHandle obj
, MonoError
*error
)
7775 return mono_reflection_get_custom_attrs_data_checked (obj
, error
);
7779 ICALL_EXPORT MonoStringHandle
7780 ves_icall_Mono_Runtime_GetDisplayName (MonoError
*error
)
7783 MonoStringHandle display_name
;
7786 info
= mono_get_runtime_callbacks ()->get_runtime_build_info ();
7787 display_name
= mono_string_new_handle (mono_domain_get (), info
, error
);
7789 return display_name
;
7793 static inline gint32
7794 mono_icall_wait_for_input_idle (gpointer handle
, gint32 milliseconds
)
7796 return WAIT_TIMEOUT
;
7798 #endif /* !HOST_WIN32 */
7801 ves_icall_Microsoft_Win32_NativeMethods_WaitForInputIdle (gpointer handle
, gint32 milliseconds
)
7803 return mono_icall_wait_for_input_idle (handle
, milliseconds
);
7807 ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcessId (void)
7809 return mono_process_current_pid ();
7812 ICALL_EXPORT MonoBoolean
7813 ves_icall_Mono_TlsProviderFactory_IsBtlsSupported (void)
7825 ves_icall_System_Runtime_InteropServices_Marshal_GetHRForException_WinRT(MonoException
* ex
)
7827 mono_set_pending_exception(mono_get_exception_not_implemented("System.Runtime.InteropServices.Marshal.GetHRForException_WinRT internal call is not implemented."));
7831 ICALL_EXPORT MonoObject
*
7832 ves_icall_System_Runtime_InteropServices_Marshal_GetNativeActivationFactory(MonoObject
* type
)
7834 mono_set_pending_exception(mono_get_exception_not_implemented("System.Runtime.InteropServices.Marshal.GetNativeActivationFactory internal call is not implemented."));
7839 ves_icall_System_Runtime_InteropServices_Marshal_GetRawIUnknownForComObjectNoAddRef(MonoObject
* obj
)
7841 mono_set_pending_exception(mono_get_exception_not_implemented("System.Runtime.InteropServices.Marshal.GetRawIUnknownForComObjectNoAddRef internal call is not implemented."));
7845 ICALL_EXPORT MonoObject
*
7846 ves_icall_System_Runtime_InteropServices_WindowsRuntime_UnsafeNativeMethods_GetRestrictedErrorInfo()
7848 mono_set_pending_exception(mono_get_exception_not_implemented("System.Runtime.InteropServices.WindowsRuntime.UnsafeNativeMethods.GetRestrictedErrorInfo internal call is not implemented."));
7852 ICALL_EXPORT MonoBoolean
7853 ves_icall_System_Runtime_InteropServices_WindowsRuntime_UnsafeNativeMethods_RoOriginateLanguageException(int error
, MonoString
* message
, void* languageException
)
7855 mono_set_pending_exception(mono_get_exception_not_implemented("System.Runtime.InteropServices.WindowsRuntime.UnsafeNativeMethods.RoOriginateLanguageException internal call is not implemented."));
7860 ves_icall_System_Runtime_InteropServices_WindowsRuntime_UnsafeNativeMethods_RoReportUnhandledError(MonoObject
* error
)
7862 mono_set_pending_exception(mono_get_exception_not_implemented("System.Runtime.InteropServices.WindowsRuntime.UnsafeNativeMethods.RoReportUnhandledError internal call is not implemented."));
7866 ves_icall_System_Runtime_InteropServices_WindowsRuntime_UnsafeNativeMethods_WindowsCreateString(MonoString
* sourceString
, int length
, void** hstring
)
7868 mono_set_pending_exception(mono_get_exception_not_implemented("System.Runtime.InteropServices.WindowsRuntime.UnsafeNativeMethods.WindowsCreateString internal call is not implemented."));
7873 ves_icall_System_Runtime_InteropServices_WindowsRuntime_UnsafeNativeMethods_WindowsDeleteString(void* hstring
)
7875 mono_set_pending_exception(mono_get_exception_not_implemented("System.Runtime.InteropServices.WindowsRuntime.UnsafeNativeMethods.WindowsDeleteString internal call is not implemented."));
7879 ICALL_EXPORT mono_unichar2
*
7880 ves_icall_System_Runtime_InteropServices_WindowsRuntime_UnsafeNativeMethods_WindowsGetStringRawBuffer(void* hstring
, unsigned* length
)
7882 mono_set_pending_exception(mono_get_exception_not_implemented("System.Runtime.InteropServices.WindowsRuntime.UnsafeNativeMethods.WindowsGetStringRawBuffer internal call is not implemented."));
7889 #ifndef DISABLE_ICALL_TABLES
7891 #define ICALL_TYPE(id,name,first)
7892 #define ICALL(id,name,func) Icall_ ## id,
7893 #define HANDLES(inner) inner
7896 #include "metadata/icall-def.h"
7902 #define ICALL_TYPE(id,name,first) Icall_type_ ## id,
7903 #define ICALL(id,name,func)
7905 #define HANDLES(inner) inner
7907 #include "metadata/icall-def.h"
7913 #define ICALL_TYPE(id,name,firstic) {(Icall_ ## firstic)},
7914 #define ICALL(id,name,func)
7916 #define HANDLES(inner) inner
7918 guint16 first_icall
;
7921 static const IcallTypeDesc
7922 icall_type_descs
[] = {
7923 #include "metadata/icall-def.h"
7927 #define icall_desc_num_icalls(desc) ((desc) [1].first_icall - (desc) [0].first_icall)
7930 #define HANDLES(inner) inner
7932 #define ICALL_TYPE(id,name,first)
7935 #ifdef HAVE_ARRAY_ELEM_INIT
7936 #define MSGSTRFIELD(line) MSGSTRFIELD1(line)
7937 #define MSGSTRFIELD1(line) str##line
7939 static const struct msgstrtn_t
{
7940 #define ICALL(id,name,func)
7942 #define ICALL_TYPE(id,name,first) char MSGSTRFIELD(__LINE__) [sizeof (name)];
7943 #include "metadata/icall-def.h"
7945 } icall_type_names_str
= {
7946 #define ICALL_TYPE(id,name,first) (name),
7947 #include "metadata/icall-def.h"
7950 static const guint16 icall_type_names_idx
[] = {
7951 #define ICALL_TYPE(id,name,first) [Icall_type_ ## id] = offsetof (struct msgstrtn_t, MSGSTRFIELD(__LINE__)),
7952 #include "metadata/icall-def.h"
7955 #define icall_type_name_get(id) ((const char*)&icall_type_names_str + icall_type_names_idx [(id)])
7957 static const struct msgstr_t
{
7959 #define ICALL_TYPE(id,name,first)
7960 #define ICALL(id,name,func) char MSGSTRFIELD(__LINE__) [sizeof (name)];
7961 #include "metadata/icall-def.h"
7963 } icall_names_str
= {
7964 #define ICALL(id,name,func) (name),
7965 #include "metadata/icall-def.h"
7968 static const guint16 icall_names_idx
[] = {
7969 #define ICALL(id,name,func) [Icall_ ## id] = offsetof (struct msgstr_t, MSGSTRFIELD(__LINE__)),
7970 #include "metadata/icall-def.h"
7973 #define icall_name_get(id) ((const char*)&icall_names_str + icall_names_idx [(id)])
7979 #define ICALL_TYPE(id,name,first) name,
7980 #define ICALL(id,name,func)
7981 static const char* const
7982 icall_type_names
[] = {
7983 #include "metadata/icall-def.h"
7987 #define icall_type_name_get(id) (icall_type_names [(id)])
7991 #define ICALL_TYPE(id,name,first)
7992 #define ICALL(id,name,func) name,
7993 static const char* const
7995 #include "metadata/icall-def.h"
7998 #define icall_name_get(id) icall_names [(id)]
8000 #endif /* !HAVE_ARRAY_ELEM_INIT */
8003 #define HANDLES(inner) inner
8006 #define ICALL_TYPE(id,name,first)
8007 #define ICALL(id,name,func) func,
8008 static const gconstpointer
8009 icall_functions
[] = {
8010 #include "metadata/icall-def.h"
8014 #ifdef ENABLE_ICALL_SYMBOL_MAP
8016 #define HANDLES(inner) inner
8019 #define ICALL_TYPE(id,name,first)
8020 #define ICALL(id,name,func) #func,
8021 static const gconstpointer
8022 icall_symbols
[] = {
8023 #include "metadata/icall-def.h"
8030 #define ICALL_TYPE(id,name,first)
8031 #define ICALL(id,name,func) 0,
8033 #define HANDLES(inner) 1,
8035 icall_uses_handles
[] = {
8036 #include "metadata/icall-def.h"
8041 #endif /* DISABLE_ICALL_TABLES */
8043 static mono_mutex_t icall_mutex
;
8044 static GHashTable
*icall_hash
= NULL
;
8045 static GHashTable
*jit_icall_hash_name
= NULL
;
8046 static GHashTable
*jit_icall_hash_addr
= NULL
;
8049 mono_icall_init (void)
8051 #ifndef DISABLE_ICALL_TABLES
8054 /* check that tables are sorted: disable in release */
8057 const char *prev_class
= NULL
;
8058 const char *prev_method
;
8060 for (i
= 0; i
< Icall_type_num
; ++i
) {
8061 const IcallTypeDesc
*desc
;
8064 if (prev_class
&& strcmp (prev_class
, icall_type_name_get (i
)) >= 0)
8065 g_print ("class %s should come before class %s\n", icall_type_name_get (i
), prev_class
);
8066 prev_class
= icall_type_name_get (i
);
8067 desc
= &icall_type_descs
[i
];
8068 num_icalls
= icall_desc_num_icalls (desc
);
8069 /*g_print ("class %s has %d icalls starting at %d\n", prev_class, num_icalls, desc->first_icall);*/
8070 for (j
= 0; j
< num_icalls
; ++j
) {
8071 const char *methodn
= icall_name_get (desc
->first_icall
+ j
);
8072 if (prev_method
&& strcmp (prev_method
, methodn
) >= 0)
8073 g_print ("method %s should come before method %s\n", methodn
, prev_method
);
8074 prev_method
= methodn
;
8080 icall_hash
= g_hash_table_new_full (g_str_hash
, g_str_equal
, g_free
, NULL
);
8081 mono_os_mutex_init (&icall_mutex
);
8085 mono_icall_lock (void)
8087 mono_locks_os_acquire (&icall_mutex
, IcallLock
);
8091 mono_icall_unlock (void)
8093 mono_locks_os_release (&icall_mutex
, IcallLock
);
8097 mono_icall_cleanup (void)
8099 g_hash_table_destroy (icall_hash
);
8100 g_hash_table_destroy (jit_icall_hash_name
);
8101 g_hash_table_destroy (jit_icall_hash_addr
);
8102 mono_os_mutex_destroy (&icall_mutex
);
8106 * mono_add_internal_call:
8107 * \param name method specification to surface to the managed world
8108 * \param method pointer to a C method to invoke when the method is called
8110 * This method surfaces the C function pointed by \p method as a method
8111 * that has been surfaced in managed code with the method specified in
8112 * \p name as an internal call.
8114 * Internal calls are surfaced to all app domains loaded and they are
8115 * accessibly by a type with the specified name.
8117 * You must provide a fully qualified type name, that is namespaces
8118 * and type name, followed by a colon and the method name, with an
8119 * optional signature to bind.
8121 * For example, the following are all valid declarations:
8123 * \c MyApp.Services.ScriptService:Accelerate
8125 * \c MyApp.Services.ScriptService:Slowdown(int,bool)
8127 * You use method parameters in cases where there might be more than
8128 * one surface method to managed code. That way you can register different
8129 * internal calls for different method overloads.
8131 * The internal calls are invoked with no marshalling. This means that .NET
8132 * types like \c System.String are exposed as \c MonoString* parameters. This is
8133 * different than the way that strings are surfaced in P/Invoke.
8135 * For more information on how the parameters are marshalled, see the
8136 * <a href="http://www.mono-project.com/docs/advanced/embedding/">Mono Embedding</a>
8139 * See the <a href="mono-api-methods.html#method-desc">Method Description</a>
8140 * reference for more information on the format of method descriptions.
8143 mono_add_internal_call (const char *name
, gconstpointer method
)
8147 g_hash_table_insert (icall_hash
, g_strdup (name
), (gpointer
) method
);
8149 mono_icall_unlock ();
8152 #ifndef DISABLE_ICALL_TABLES
8154 #ifdef HAVE_ARRAY_ELEM_INIT
8156 compare_method_imap (const void *key
, const void *elem
)
8158 const char* method_name
= (const char*)&icall_names_str
+ (*(guint16
*)elem
);
8159 return strcmp (key
, method_name
);
8163 find_slot_icall (const IcallTypeDesc
*imap
, const char *name
)
8165 const guint16
*nameslot
= (const guint16
*)mono_binary_search (name
, icall_names_idx
+ imap
->first_icall
, icall_desc_num_icalls (imap
), sizeof (icall_names_idx
[0]), compare_method_imap
);
8168 return (nameslot
- &icall_names_idx
[0]);
8172 find_uses_handles_icall (const IcallTypeDesc
*imap
, const char *name
)
8174 gsize slotnum
= find_slot_icall (imap
, name
);
8177 return (gboolean
)icall_uses_handles
[slotnum
];
8181 find_method_icall (const IcallTypeDesc
*imap
, const char *name
)
8183 gsize slotnum
= find_slot_icall (imap
, name
);
8186 return (gpointer
)icall_functions
[slotnum
];
8190 compare_class_imap (const void *key
, const void *elem
)
8192 const char* class_name
= (const char*)&icall_type_names_str
+ (*(guint16
*)elem
);
8193 return strcmp (key
, class_name
);
8196 static const IcallTypeDesc
*
8197 find_class_icalls (const char *name
)
8199 const guint16
*nameslot
= (const guint16
*)mono_binary_search (name
, icall_type_names_idx
, Icall_type_num
, sizeof (icall_type_names_idx
[0]), compare_class_imap
);
8202 return &icall_type_descs
[nameslot
- &icall_type_names_idx
[0]];
8205 #else /* HAVE_ARRAY_ELEM_INIT */
8208 compare_method_imap (const void *key
, const void *elem
)
8210 const char** method_name
= (const char**)elem
;
8211 return strcmp (key
, *method_name
);
8215 find_slot_icall (const IcallTypeDesc
*imap
, const char *name
)
8217 const char **nameslot
= mono_binary_search (name
, icall_names
+ imap
->first_icall
, icall_desc_num_icalls (imap
), sizeof (icall_names
[0]), compare_method_imap
);
8220 return nameslot
- icall_names
;
8224 find_method_icall (const IcallTypeDesc
*imap
, const char *name
)
8226 gsize slotnum
= find_slot_icall (imap
, name
);
8229 return (gpointer
)icall_functions
[slotnum
];
8233 find_uses_handles_icall (const IcallTypeDesc
*imap
, const char *name
)
8235 gsize slotnum
= find_slot_icall (imap
, name
);
8238 return (gboolean
)icall_uses_handles
[slotnum
];
8242 compare_class_imap (const void *key
, const void *elem
)
8244 const char** class_name
= (const char**)elem
;
8245 return strcmp (key
, *class_name
);
8248 static const IcallTypeDesc
*
8249 find_class_icalls (const char *name
)
8251 const char **nameslot
= mono_binary_search (name
, icall_type_names
, Icall_type_num
, sizeof (icall_type_names
[0]), compare_class_imap
);
8254 return &icall_type_descs
[nameslot
- icall_type_names
];
8257 #endif /* HAVE_ARRAY_ELEM_INIT */
8259 #endif /* DISABLE_ICALL_TABLES */
8262 * we should probably export this as an helper (handle nested types).
8263 * Returns the number of chars written in buf.
8266 concat_class_name (char *buf
, int bufsize
, MonoClass
*klass
)
8268 int nspacelen
, cnamelen
;
8269 nspacelen
= strlen (klass
->name_space
);
8270 cnamelen
= strlen (klass
->name
);
8271 if (nspacelen
+ cnamelen
+ 2 > bufsize
)
8274 memcpy (buf
, klass
->name_space
, nspacelen
);
8275 buf
[nspacelen
++] = '.';
8277 memcpy (buf
+ nspacelen
, klass
->name
, cnamelen
);
8278 buf
[nspacelen
+ cnamelen
] = 0;
8279 return nspacelen
+ cnamelen
;
8282 #ifdef DISABLE_ICALL_TABLES
8284 no_icall_table (void)
8286 g_assert_not_reached ();
8291 * mono_lookup_internal_call_full:
8292 * \param method the method to look up
8293 * \param uses_handles out argument if method needs handles around managed objects.
8294 * \returns a pointer to the icall code for the given method. If
8295 * \p uses_handles is not NULL, it will be set to TRUE if the method
8296 * needs managed objects wrapped using the infrastructure in handle.h
8298 * If the method is not found, warns and returns NULL.
8301 mono_lookup_internal_call_full (MonoMethod
*method
, mono_bool
*uses_handles
)
8306 int typelen
= 0, mlen
, siglen
;
8308 #ifndef DISABLE_ICALL_TABLES
8309 const IcallTypeDesc
*imap
= NULL
;
8312 g_assert (method
!= NULL
);
8314 if (method
->is_inflated
)
8315 method
= ((MonoMethodInflated
*) method
)->declaring
;
8317 if (method
->klass
->nested_in
) {
8318 int pos
= concat_class_name (mname
, sizeof (mname
)-2, method
->klass
->nested_in
);
8322 mname
[pos
++] = '/';
8325 typelen
= concat_class_name (mname
+pos
, sizeof (mname
)-pos
-1, method
->klass
);
8331 typelen
= concat_class_name (mname
, sizeof (mname
), method
->klass
);
8336 #ifndef DISABLE_ICALL_TABLES
8337 imap
= find_class_icalls (mname
);
8340 mname
[typelen
] = ':';
8341 mname
[typelen
+ 1] = ':';
8343 mlen
= strlen (method
->name
);
8344 memcpy (mname
+ typelen
+ 2, method
->name
, mlen
);
8345 sigstart
= mname
+ typelen
+ 2 + mlen
;
8348 tmpsig
= mono_signature_get_desc (mono_method_signature (method
), TRUE
);
8349 siglen
= strlen (tmpsig
);
8350 if (typelen
+ mlen
+ siglen
+ 6 > sizeof (mname
))
8353 memcpy (sigstart
+ 1, tmpsig
, siglen
);
8354 sigstart
[siglen
+ 1] = ')';
8355 sigstart
[siglen
+ 2] = 0;
8360 res
= g_hash_table_lookup (icall_hash
, mname
);
8363 *uses_handles
= FALSE
;
8364 mono_icall_unlock ();;
8367 /* try without signature */
8369 res
= g_hash_table_lookup (icall_hash
, mname
);
8372 *uses_handles
= FALSE
;
8373 mono_icall_unlock ();
8377 #ifdef DISABLE_ICALL_TABLES
8378 mono_icall_unlock ();
8379 /* Fail only when the result is actually used */
8380 /* mono_marshal_get_native_wrapper () depends on this */
8381 if (method
->klass
== mono_defaults
.string_class
&& !strcmp (method
->name
, ".ctor"))
8382 return ves_icall_System_String_ctor_RedirectToCreateString
;
8384 return no_icall_table
;
8386 /* it wasn't found in the static call tables */
8389 *uses_handles
= FALSE
;
8390 mono_icall_unlock ();
8393 res
= find_method_icall (imap
, sigstart
- mlen
);
8396 *uses_handles
= find_uses_handles_icall (imap
, sigstart
- mlen
);
8397 mono_icall_unlock ();
8400 /* try _with_ signature */
8402 res
= find_method_icall (imap
, sigstart
- mlen
);
8405 *uses_handles
= find_uses_handles_icall (imap
, sigstart
- mlen
);
8406 mono_icall_unlock ();
8410 g_warning ("cant resolve internal call to \"%s\" (tested without signature also)", mname
);
8411 g_print ("\nYour mono runtime and class libraries are out of sync.\n");
8412 g_print ("The out of sync library is: %s\n", method
->klass
->image
->name
);
8413 g_print ("\nWhen you update one from git you need to update, compile and install\nthe other too.\n");
8414 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");
8415 g_print ("If you see other errors or faults after this message they are probably related\n");
8416 g_print ("and you need to fix your mono install first.\n");
8418 mono_icall_unlock ();
8425 * mono_lookup_internal_call:
8428 mono_lookup_internal_call (MonoMethod
*method
)
8430 return mono_lookup_internal_call_full (method
, NULL
);
8433 #ifdef ENABLE_ICALL_SYMBOL_MAP
8435 func_cmp (gconstpointer key
, gconstpointer p
)
8437 return (gsize
)key
- (gsize
)*(gsize
*)p
;
8442 * mono_lookup_icall_symbol:
8444 * Given the icall METHOD, returns its C symbol.
8447 mono_lookup_icall_symbol (MonoMethod
*m
)
8449 #ifdef DISABLE_ICALL_TABLES
8450 g_assert_not_reached ();
8453 #ifdef ENABLE_ICALL_SYMBOL_MAP
8457 static gconstpointer
*functions_sorted
;
8458 static const char**symbols_sorted
;
8459 static gboolean inited
;
8464 functions_sorted
= g_malloc (G_N_ELEMENTS (icall_functions
) * sizeof (gpointer
));
8465 memcpy (functions_sorted
, icall_functions
, G_N_ELEMENTS (icall_functions
) * sizeof (gpointer
));
8466 symbols_sorted
= g_malloc (G_N_ELEMENTS (icall_functions
) * sizeof (gpointer
));
8467 memcpy (symbols_sorted
, icall_symbols
, G_N_ELEMENTS (icall_functions
) * sizeof (gpointer
));
8468 /* Bubble sort the two arrays */
8472 for (i
= 0; i
< G_N_ELEMENTS (icall_functions
) - 1; ++i
) {
8473 if (functions_sorted
[i
] > functions_sorted
[i
+ 1]) {
8476 tmp
= functions_sorted
[i
];
8477 functions_sorted
[i
] = functions_sorted
[i
+ 1];
8478 functions_sorted
[i
+ 1] = tmp
;
8479 tmp
= symbols_sorted
[i
];
8480 symbols_sorted
[i
] = symbols_sorted
[i
+ 1];
8481 symbols_sorted
[i
+ 1] = tmp
;
8488 func
= mono_lookup_internal_call (m
);
8491 slot
= mono_binary_search (func
, functions_sorted
, G_N_ELEMENTS (icall_functions
), sizeof (gpointer
), func_cmp
);
8495 return symbols_sorted
[(gpointer
*)slot
- (gpointer
*)functions_sorted
];
8497 fprintf (stderr
, "icall symbol maps not enabled, pass --enable-icall-symbol-map to configure.\n");
8498 g_assert_not_reached ();
8505 type_from_typename (char *type_name
)
8507 MonoClass
*klass
= NULL
; /* assignment to shut GCC warning up */
8509 if (!strcmp (type_name
, "int"))
8510 klass
= mono_defaults
.int_class
;
8511 else if (!strcmp (type_name
, "ptr"))
8512 klass
= mono_defaults
.int_class
;
8513 else if (!strcmp (type_name
, "void"))
8514 klass
= mono_defaults
.void_class
;
8515 else if (!strcmp (type_name
, "int32"))
8516 klass
= mono_defaults
.int32_class
;
8517 else if (!strcmp (type_name
, "uint32"))
8518 klass
= mono_defaults
.uint32_class
;
8519 else if (!strcmp (type_name
, "int8"))
8520 klass
= mono_defaults
.sbyte_class
;
8521 else if (!strcmp (type_name
, "uint8"))
8522 klass
= mono_defaults
.byte_class
;
8523 else if (!strcmp (type_name
, "int16"))
8524 klass
= mono_defaults
.int16_class
;
8525 else if (!strcmp (type_name
, "uint16"))
8526 klass
= mono_defaults
.uint16_class
;
8527 else if (!strcmp (type_name
, "long"))
8528 klass
= mono_defaults
.int64_class
;
8529 else if (!strcmp (type_name
, "ulong"))
8530 klass
= mono_defaults
.uint64_class
;
8531 else if (!strcmp (type_name
, "float"))
8532 klass
= mono_defaults
.single_class
;
8533 else if (!strcmp (type_name
, "double"))
8534 klass
= mono_defaults
.double_class
;
8535 else if (!strcmp (type_name
, "object"))
8536 klass
= mono_defaults
.object_class
;
8537 else if (!strcmp (type_name
, "obj"))
8538 klass
= mono_defaults
.object_class
;
8539 else if (!strcmp (type_name
, "string"))
8540 klass
= mono_defaults
.string_class
;
8541 else if (!strcmp (type_name
, "bool"))
8542 klass
= mono_defaults
.boolean_class
;
8543 else if (!strcmp (type_name
, "boolean"))
8544 klass
= mono_defaults
.boolean_class
;
8546 g_error ("%s", type_name
);
8547 g_assert_not_reached ();
8549 return &klass
->byval_arg
;
8553 * LOCKING: Take the corlib image lock.
8555 MonoMethodSignature
*
8556 mono_create_icall_signature (const char *sigstr
)
8561 MonoMethodSignature
*res
, *res2
;
8562 MonoImage
*corlib
= mono_defaults
.corlib
;
8564 mono_image_lock (corlib
);
8565 res
= (MonoMethodSignature
*)g_hash_table_lookup (corlib
->helper_signatures
, sigstr
);
8566 mono_image_unlock (corlib
);
8571 parts
= g_strsplit (sigstr
, " ", 256);
8580 res
= mono_metadata_signature_alloc (corlib
, len
- 1);
8585 * Under windows, the default pinvoke calling convention is STDCALL but
8588 res
->call_convention
= MONO_CALL_C
;
8591 res
->ret
= type_from_typename (parts
[0]);
8592 for (i
= 1; i
< len
; ++i
) {
8593 res
->params
[i
- 1] = type_from_typename (parts
[i
]);
8598 mono_image_lock (corlib
);
8599 res2
= (MonoMethodSignature
*)g_hash_table_lookup (corlib
->helper_signatures
, sigstr
);
8601 res
= res2
; /*Value is allocated in the image pool*/
8603 g_hash_table_insert (corlib
->helper_signatures
, (gpointer
)sigstr
, res
);
8604 mono_image_unlock (corlib
);
8610 mono_find_jit_icall_by_name (const char *name
)
8612 MonoJitICallInfo
*info
;
8613 g_assert (jit_icall_hash_name
);
8616 info
= (MonoJitICallInfo
*)g_hash_table_lookup (jit_icall_hash_name
, name
);
8617 mono_icall_unlock ();
8622 mono_find_jit_icall_by_addr (gconstpointer addr
)
8624 MonoJitICallInfo
*info
;
8625 g_assert (jit_icall_hash_addr
);
8628 info
= (MonoJitICallInfo
*)g_hash_table_lookup (jit_icall_hash_addr
, (gpointer
)addr
);
8629 mono_icall_unlock ();
8635 * mono_get_jit_icall_info:
8637 * Return the hashtable mapping JIT icall names to MonoJitICallInfo structures. The
8638 * caller should access it while holding the icall lock.
8641 mono_get_jit_icall_info (void)
8643 return jit_icall_hash_name
;
8647 * mono_lookup_jit_icall_symbol:
8649 * Given the jit icall NAME, returns its C symbol if possible, or NULL.
8652 mono_lookup_jit_icall_symbol (const char *name
)
8654 MonoJitICallInfo
*info
;
8655 const char *res
= NULL
;
8658 info
= (MonoJitICallInfo
*)g_hash_table_lookup (jit_icall_hash_name
, name
);
8660 res
= info
->c_symbol
;
8661 mono_icall_unlock ();
8666 mono_register_jit_icall_wrapper (MonoJitICallInfo
*info
, gconstpointer wrapper
)
8669 g_hash_table_insert (jit_icall_hash_addr
, (gpointer
)wrapper
, info
);
8670 mono_icall_unlock ();
8674 * If NO_RAISE is set, that means the icall is not calling mono_raise_exception () directly or indirectly. The JIT might be able to call these
8675 * icalls without wrappers in some cases.
8678 mono_register_jit_icall_full (gconstpointer func
, const char *name
, MonoMethodSignature
*sig
, gboolean is_save
, gboolean no_raise
, const char *c_symbol
)
8680 MonoJitICallInfo
*info
;
8687 if (!jit_icall_hash_name
) {
8688 jit_icall_hash_name
= g_hash_table_new_full (g_str_hash
, g_str_equal
, NULL
, g_free
);
8689 jit_icall_hash_addr
= g_hash_table_new (NULL
, NULL
);
8692 if (g_hash_table_lookup (jit_icall_hash_name
, name
)) {
8693 g_warning ("jit icall already defined \"%s\"\n", name
);
8694 g_assert_not_reached ();
8697 info
= g_new0 (MonoJitICallInfo
, 1);
8702 info
->c_symbol
= c_symbol
;
8703 info
->no_raise
= no_raise
;
8706 info
->wrapper
= func
;
8708 info
->wrapper
= NULL
;
8711 g_hash_table_insert (jit_icall_hash_name
, (gpointer
)info
->name
, info
);
8712 g_hash_table_insert (jit_icall_hash_addr
, (gpointer
)func
, info
);
8714 mono_icall_unlock ();
8719 mono_register_jit_icall (gconstpointer func
, const char *name
, MonoMethodSignature
*sig
, gboolean is_save
)
8721 return mono_register_jit_icall_full (func
, name
, sig
, is_save
, FALSE
, NULL
);