1 #ifndef __MONO_OBJECT_INTERNALS_H__
2 #define __MONO_OBJECT_INTERNALS_H__
4 #include <mono/metadata/object.h>
5 #include <mono/metadata/threads.h>
6 #include <mono/metadata/reflection.h>
7 #include <mono/metadata/mempool.h>
8 #include <mono/metadata/class-internals.h>
9 #include <mono/metadata/threads-types.h>
10 #include <mono/metadata/handle.h>
11 #include <mono/io-layer/io-layer.h>
12 #include "mono/utils/mono-compiler.h"
13 #include "mono/utils/mono-error.h"
14 #include "mono/utils/mono-error-internals.h"
15 #include "mono/utils/mono-stack-unwinding.h"
16 #include "mono/utils/mono-tls.h"
17 #include "mono/utils/mono-coop-mutex.h"
21 #define mono_assert(expr) G_STMT_START{ \
25 char *msg = g_strdup_printf ("file %s: line %d (%s): " \
26 "assertion failed: (%s)", __FILE__, __LINE__, \
27 __PRETTY_FUNCTION__, #expr); \
28 ex = mono_get_exception_execution_engine (msg); \
30 mono_raise_exception (ex); \
33 #define mono_assert_not_reached() G_STMT_START{ \
35 char *msg = g_strdup_printf ("file %s: line %d (%s): " \
36 "should not be reached", __FILE__, __LINE__, __PRETTY_FUNCTION__); \
37 ex = mono_get_exception_execution_engine (msg); \
39 mono_raise_exception (ex); \
42 #define mono_assert(expr) G_STMT_START{ \
46 char *msg = g_strdup_printf ("file %s: line %d: " \
47 "assertion failed: (%s)", __FILE__, __LINE__, \
49 ex = mono_get_exception_execution_engine (msg); \
51 mono_raise_exception (ex); \
54 #define mono_assert_not_reached() G_STMT_START{ \
56 char *msg = g_strdup_printf ("file %s: line %d): " \
57 "should not be reached", __FILE__, __LINE__); \
58 ex = mono_get_exception_execution_engine (msg); \
60 mono_raise_exception (ex); \
64 #define mono_assert(expr) g_assert(expr)
65 #define mono_assert_not_reached() g_assert_not_reached()
68 /* Use this as MONO_CHECK_ARG_NULL (arg,expr,) in functions returning void */
69 #define MONO_CHECK_ARG(arg, expr, retval) G_STMT_START{ \
70 if (G_UNLIKELY (!(expr))) \
73 char *msg = g_strdup_printf ("assertion `%s' failed", \
75 if (arg) {} /* check if the name exists */ \
76 ex = mono_get_exception_argument (#arg, msg); \
78 mono_set_pending_exception (ex); \
82 /* Use this as MONO_CHECK_ARG_NULL (arg,) in functions returning void */
83 #define MONO_CHECK_ARG_NULL(arg, retval) G_STMT_START{ \
84 if (G_UNLIKELY (arg == NULL)) \
87 if (arg) {} /* check if the name exists */ \
88 ex = mono_get_exception_argument_null (#arg); \
89 mono_set_pending_exception (ex); \
93 #define mono_string_builder_capacity(sb) sb->chunkOffset + sb->chunkChars->max_length
94 #define mono_string_builder_string_length(sb) sb->chunkOffset + sb->chunkLength
97 * Macros which cache the results of lookups locally.
98 * These should be used instead of the original versions, if the __GNUC__
99 * restriction is acceptable.
104 /* name should be a compile-time constant */
105 #define mono_class_get_field_from_name_cached(klass,name) ({ \
106 static MonoClassField *tmp_field; \
108 tmp_field = mono_class_get_field_from_name ((klass), (name)); \
109 g_assert (tmp_field); \
112 /* eclass should be a run-time constant */
113 #define mono_array_class_get_cached(eclass,rank) ({ \
114 static MonoClass *tmp_klass; \
116 tmp_klass = mono_array_class_get ((eclass), (rank)); \
117 g_assert (tmp_klass); \
120 /* eclass should be a run-time constant */
121 #define mono_array_new_cached(domain, eclass, size) ({ \
123 MonoVTable *__vtable = mono_class_vtable ((domain), mono_array_class_get_cached ((eclass), 1)); \
124 MonoArray *__arr = mono_array_new_specific_checked (__vtable, (size), &__error); \
125 mono_error_raise_exception (&__error); /* FIXME don't raise here */ \
130 #define mono_class_get_field_from_name_cached(klass,name) mono_class_get_field_from_name ((klass), (name))
131 #define mono_array_class_get_cached(eclass,rank) mono_array_class_get ((eclass), (rank))
132 #define mono_array_new_cached(domain, eclass, size) mono_array_new_specific (mono_class_vtable ((domain), mono_array_class_get_cached ((eclass), 1)), (size))
136 #ifdef MONO_BIG_ARRAYS
137 typedef uint64_t mono_array_size_t;
138 typedef int64_t mono_array_lower_bound_t;
139 #define MONO_ARRAY_MAX_INDEX G_MAXINT64
140 #define MONO_ARRAY_MAX_SIZE G_MAXUINT64
142 typedef uint32_t mono_array_size_t;
143 typedef int32_t mono_array_lower_bound_t;
144 #define MONO_ARRAY_MAX_INDEX ((int32_t) 0x7fffffff)
145 #define MONO_ARRAY_MAX_SIZE ((uint32_t) 0xffffffff)
149 mono_array_size_t length;
150 mono_array_lower_bound_t lower_bound;
155 /* bounds is NULL for szarrays */
156 MonoArrayBounds *bounds;
157 /* total number of elements of the array */
158 mono_array_size_t max_length;
159 /* we use double to ensure proper alignment on platforms that need it */
160 double vector [MONO_ZERO_LEN_ARRAY];
163 #define MONO_SIZEOF_MONO_ARRAY (sizeof (MonoArray) - MONO_ZERO_LEN_ARRAY * sizeof (double))
168 mono_unichar2 chars [MONO_ZERO_LEN_ARRAY];
171 #define mono_object_class(obj) (((MonoObject*)(obj))->vtable->klass)
172 #define mono_object_domain(obj) (((MonoObject*)(obj))->vtable->domain)
174 #define mono_string_chars_fast(s) ((mono_unichar2*)(s)->chars)
175 #define mono_string_length_fast(s) ((s)->length)
177 #define mono_array_length_fast(array) ((array)->max_length)
178 #define mono_array_addr_with_size_fast(array,size,index) ( ((char*)(array)->vector) + (size) * (index) )
180 #define mono_array_addr_fast(array,type,index) ((type*)(void*) mono_array_addr_with_size_fast (array, sizeof (type), index))
181 #define mono_array_get_fast(array,type,index) ( *(type*)mono_array_addr_fast ((array), type, (index)) )
182 #define mono_array_set_fast(array,type,index,value) \
184 type *__p = (type *) mono_array_addr_fast ((array), type, (index)); \
187 #define mono_array_setref_fast(array,index,value) \
189 void **__p = (void **) mono_array_addr_fast ((array), void*, (index)); \
190 mono_gc_wbarrier_set_arrayref ((array), __p, (MonoObject*)(value)); \
191 /* *__p = (value);*/ \
193 #define mono_array_memcpy_refs_fast(dest,destidx,src,srcidx,count) \
195 void **__p = (void **) mono_array_addr_fast ((dest), void*, (destidx)); \
196 void **__s = mono_array_addr_fast ((src), void*, (srcidx)); \
197 mono_gc_wbarrier_arrayref_copy (__p, __s, (count)); \
203 MonoObject *identity;
204 } MonoMarshalByRefObject;
206 /* This is a copy of System.AppDomain */
207 struct _MonoAppDomain {
208 MonoMarshalByRefObject mbr;
212 typedef struct _MonoStringBuilder MonoStringBuilder;
214 struct _MonoStringBuilder {
216 MonoArray *chunkChars;
217 MonoStringBuilder* chunkPrevious; // Link to the block logically before this block
218 int chunkLength; // The index in ChunkChars that represent the end of the block
219 int chunkOffset; // The logial offset (sum of all characters in previous blocks)
231 } MonoArgumentHandle;
234 MonoMethodSignature *sig;
240 struct _MonoException {
242 /* Stores the IPs and the generic sharing infos
243 (vtable/MRGCTX) of the frames. */
244 MonoArray *trace_ips;
245 MonoObject *inner_ex;
247 MonoString *help_link;
248 MonoString *class_name;
249 MonoString *stack_trace;
250 MonoString *remote_stack_trace;
251 gint32 remote_stack_index;
255 MonoObject *captured_traces;
256 MonoArray *native_trace_ips;
257 /* Dynamic methods referenced by the stack trace */
258 MonoObject *dynamic_methods;
263 } MonoSystemException;
266 MonoSystemException base;
267 MonoString *param_name;
268 } MonoArgumentException;
272 MonoObject *async_state;
274 MonoObject *async_delegate;
276 MonoObject *object_data;
277 MonoBoolean sync_completed;
278 MonoBoolean completed;
279 MonoBoolean endinvoke_called;
280 MonoObject *async_callback;
281 MonoObject *execution_context;
282 MonoObject *original_context;
287 MonoMarshalByRefObject object;
291 /* This is a copy of System.Runtime.Remoting.Messaging.CallType */
294 CallType_BeginInvoke = 1,
295 CallType_EndInvoke = 2,
299 /* This corresponds to System.Type */
300 struct _MonoReflectionType {
306 MonoReflectionType type;
307 MonoObject *type_info;
308 } MonoReflectionMonoType;
312 MonoReflectionType *class_to_proxy;
314 MonoObject *unwrapped_server;
315 gint32 target_domain_id;
316 MonoString *target_uri;
317 MonoObject *object_identity;
319 MonoObject *stub_data;
323 MonoMarshalByRefObject object;
325 GHashTable* itf_hash;
326 MonoObject *synchronization_context;
330 MonoRealProxy real_proxy;
331 MonoComObject *com_object;
333 } MonoComInteropProxy;
338 MonoRemoteClass *remote_class;
339 MonoBoolean custom_type_info;
340 } MonoTransparentProxy;
344 MonoReflectionMethod *method;
347 MonoArray *arg_types;
351 MonoAsyncResult *async_result;
355 /* Keep in sync with the System.MonoAsyncCall */
358 MonoMethodMessage *msg;
359 MonoMethod *cb_method;
360 MonoDelegate *cb_target;
369 gint32 native_offset;
370 gint64 method_address;
372 MonoReflectionMethod *method;
373 MonoString *filename;
376 MonoString *internal_method_name;
380 MONO_THREAD_FLAG_DONT_MANAGE = 1, // Don't wait for or abort this thread
381 MONO_THREAD_FLAG_NAME_SET = 2, // Thread name set from managed code
384 struct _MonoInternalThread {
386 volatile int lock_thread_id; /* to be used as the pre-shifted thread id in thin locks. Used for appdomain_ref push/pop */
388 MonoArray *cached_culture_info;
392 MonoException *abort_exc;
393 int abort_state_handle;
394 guint64 tid; /* This is accessed as a gsize in the code (so it can hold a 64bit pointer on systems that need it), but needs to reserve 64 bits of space on all machines as it corresponds to a field in managed code */
397 gpointer *static_data;
398 void *thread_info; /*This is MonoThreadInfo*, but to simplify dependencies, let's make it a void* here. */
399 MonoAppContext *current_appcontext;
400 MonoThread *root_domain_thread;
401 MonoObject *_serialized_principal;
402 int _serialized_principal_version;
403 gpointer appdomain_refs;
404 /* This is modified using atomic ops, so keep it a gint32 */
405 gint32 interruption_requested;
406 MonoCoopMutex *synch_cs;
407 MonoBoolean threadpool_thread;
408 MonoBoolean thread_interrupt_requested;
410 guint8 apartment_state;
411 gint32 critical_region_level;
414 MonoThreadManageCallback manage_callback;
415 gpointer interrupt_on_stop;
417 gpointer thread_pinning_ref;
419 * These fields are used to avoid having to increment corlib versions
420 * when a new field is added to this structure.
421 * Please synchronize any changes with InternalThread in Thread.cs, i.e. add the
430 struct _MonoInternalThread *internal_thread;
431 MonoObject *start_obj;
432 MonoException *pending_exception;
437 MonoObject *additional;
438 } MonoStreamingContext;
442 MonoBoolean readOnly;
443 MonoString *AMDesignator;
444 MonoString *PMDesignator;
445 MonoString *DateSeparator;
446 MonoString *TimeSeparator;
447 MonoString *ShortDatePattern;
448 MonoString *LongDatePattern;
449 MonoString *ShortTimePattern;
450 MonoString *LongTimePattern;
451 MonoString *MonthDayPattern;
452 MonoString *YearMonthPattern;
453 guint32 FirstDayOfWeek;
454 guint32 CalendarWeekRule;
455 MonoArray *AbbreviatedDayNames;
457 MonoArray *MonthNames;
458 MonoArray *GenitiveMonthNames;
459 MonoArray *AbbreviatedMonthNames;
460 MonoArray *GenitiveAbbreviatedMonthNames;
461 MonoArray *ShortDatePatterns;
462 MonoArray *LongDatePatterns;
463 MonoArray *ShortTimePatterns;
464 MonoArray *LongTimePatterns;
465 MonoArray *MonthDayPatterns;
466 MonoArray *YearMonthPatterns;
467 MonoArray *ShortestDayNames;
468 } MonoDateTimeFormatInfo;
473 MonoArray *numberGroupSizes;
474 MonoArray *currencyGroupSizes;
475 MonoArray *percentGroupSizes;
476 MonoString *positiveSign;
477 MonoString *negativeSign;
478 MonoString *numberDecimalSeparator;
479 MonoString *numberGroupSeparator;
480 MonoString *currencyGroupSeparator;
481 MonoString *currencyDecimalSeparator;
482 MonoString *currencySymbol;
483 MonoString *ansiCurrencySymbol; /* unused */
484 MonoString *naNSymbol;
485 MonoString *positiveInfinitySymbol;
486 MonoString *negativeInfinitySymbol;
487 MonoString *percentDecimalSeparator;
488 MonoString *percentGroupSeparator;
489 MonoString *percentSymbol;
490 MonoString *perMilleSymbol;
491 MonoString *nativeDigits; /* unused */
492 gint32 dataItem; /* unused */
493 guint32 numberDecimalDigits;
494 gint32 currencyDecimalDigits;
495 gint32 currencyPositivePattern;
496 gint32 currencyNegativePattern;
497 gint32 numberNegativePattern;
498 gint32 percentPositivePattern;
499 gint32 percentNegativePattern;
500 gint32 percentDecimalDigits;
501 } MonoNumberFormatInfo;
506 MonoString *icu_name;
507 gpointer ICU_collator;
512 MonoString *NativeName;
513 MonoArray *ShortDatePatterns;
514 MonoArray *YearMonthPatterns;
515 MonoArray *LongDatePatterns;
516 MonoString *MonthDayPattern;
519 MonoArray *AbbreviatedEraNames;
520 MonoArray *AbbreviatedEnglishEraNames;
522 MonoArray *AbbreviatedDayNames;
523 MonoArray *SuperShortDayNames;
524 MonoArray *MonthNames;
525 MonoArray *AbbreviatedMonthNames;
526 MonoArray *GenitiveMonthNames;
527 MonoArray *GenitiveAbbreviatedMonthNames;
532 MonoString *AMDesignator;
533 MonoString *PMDesignator;
534 MonoString *TimeSeparator;
535 MonoArray *LongTimePatterns;
536 MonoArray *ShortTimePatterns;
537 guint32 FirstDayOfWeek;
538 guint32 CalendarWeekRule;
543 MonoBoolean is_read_only;
546 gint32 datetime_index;
548 gint32 calendar_type;
549 MonoBoolean use_user_override;
550 MonoNumberFormatInfo *number_format;
551 MonoDateTimeFormatInfo *datetime_format;
552 MonoObject *textinfo;
554 MonoString *englishname;
555 MonoString *nativename;
556 MonoString *iso3lang;
557 MonoString *iso2lang;
558 MonoString *win3lang;
559 MonoString *territory;
560 MonoArray *native_calendar_names;
561 MonoCompareInfo *compareinfo;
562 const void* text_info_data;
568 MonoString *iso2name;
569 MonoString *iso3name;
570 MonoString *win3name;
571 MonoString *english_name;
572 MonoString *native_name;
573 MonoString *currency_symbol;
574 MonoString *iso_currency_symbol;
575 MonoString *currency_english_name;
576 MonoString *currency_native_name;
590 } MonoInterfaceTypeAttribute;
593 * Callbacks supplied by the runtime and called by the modules in metadata/
594 * This interface is easier to extend than adding a new function type +
595 * a new 'install' function for every callback.
598 gpointer (*create_ftnptr) (MonoDomain *domain, gpointer addr);
599 gpointer (*get_addr_from_ftnptr) (gpointer descr);
600 char* (*get_runtime_build_info) (void);
601 gpointer (*get_vtable_trampoline) (MonoVTable *vtable, int slot_index);
602 gpointer (*get_imt_trampoline) (MonoVTable *vtable, int imt_slot_index);
603 gboolean (*imt_entry_inited) (MonoVTable *vtable, int imt_slot_index);
604 void (*set_cast_details) (MonoClass *from, MonoClass *to);
605 void (*debug_log) (int level, MonoString *category, MonoString *message);
606 gboolean (*debug_log_is_enabled) (void);
607 gboolean (*tls_key_supported) (MonoTlsKey key);
608 void (*init_delegate) (MonoDelegate *del);
609 MonoObject* (*runtime_invoke) (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error);
610 void* (*compile_method) (MonoMethod *method, MonoError *error);
611 gpointer (*create_jump_trampoline) (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper, MonoError *error);
612 gpointer (*create_jit_trampoline) (MonoDomain *domain, MonoMethod *method, MonoError *error);
613 } MonoRuntimeCallbacks;
615 typedef gboolean (*MonoInternalStackWalk) (MonoStackFrameInfo *frame, MonoContext *ctx, gpointer data);
616 typedef gboolean (*MonoInternalExceptionFrameWalk) (MonoMethod *method, gpointer ip, size_t native_offset, gboolean managed, gpointer user_data);
619 void (*mono_walk_stack_with_ctx) (MonoInternalStackWalk func, MonoContext *ctx, MonoUnwindOptions options, void *user_data);
620 void (*mono_walk_stack_with_state) (MonoInternalStackWalk func, MonoThreadUnwindState *state, MonoUnwindOptions options, void *user_data);
621 void (*mono_raise_exception) (MonoException *ex);
622 void (*mono_raise_exception_with_ctx) (MonoException *ex, MonoContext *ctx);
623 gboolean (*mono_exception_walk_trace) (MonoException *ex, MonoInternalExceptionFrameWalk func, gpointer user_data);
624 gboolean (*mono_install_handler_block_guard) (MonoThreadUnwindState *unwind_state);
625 } MonoRuntimeExceptionHandlingCallbacks;
627 /* used to free a dynamic method */
628 typedef void (*MonoFreeMethodFunc) (MonoDomain *domain, MonoMethod *method);
630 MONO_COLD void mono_set_pending_exception (MonoException *exc);
632 /* remoting and async support */
635 mono_async_result_new (MonoDomain *domain, HANDLE handle,
636 MonoObject *state, gpointer data, MonoObject *object_data);
639 ves_icall_System_Runtime_Remoting_Messaging_AsyncResult_Invoke (MonoAsyncResult *ares);
642 mono_wait_handle_new (MonoDomain *domain, HANDLE handle);
645 mono_wait_handle_get_handle (MonoWaitHandle *handle);
648 mono_message_init (MonoDomain *domain, MonoMethodMessage *this_obj,
649 MonoReflectionMethod *method, MonoArray *out_args);
652 mono_message_invoke (MonoObject *target, MonoMethodMessage *msg,
653 MonoObject **exc, MonoArray **out_args);
656 mono_method_call_message_new (MonoMethod *method, gpointer *params, MonoMethod *invoke,
657 MonoDelegate **cb, MonoObject **state);
660 mono_method_return_message_restore (MonoMethod *method, gpointer *params, MonoArray *out_args);
663 mono_delegate_ctor_with_method (MonoObject *this_obj, MonoObject *target, gpointer addr, MonoMethod *method);
666 mono_delegate_ctor (MonoObject *this_obj, MonoObject *target, gpointer addr);
669 mono_class_get_allocation_ftn (MonoVTable *vtable, gboolean for_box, gboolean *pass_size_in_words);
672 mono_runtime_free_method (MonoDomain *domain, MonoMethod *method);
675 mono_install_free_method (MonoFreeMethodFunc func);
678 mono_install_callbacks (MonoRuntimeCallbacks *cbs);
680 MonoRuntimeCallbacks*
681 mono_get_runtime_callbacks (void);
684 mono_install_eh_callbacks (MonoRuntimeExceptionHandlingCallbacks *cbs);
686 MonoRuntimeExceptionHandlingCallbacks *
687 mono_get_eh_callbacks (void);
690 mono_raise_exception_with_context (MonoException *ex, MonoContext *ctx);
693 mono_type_initialization_init (void);
696 mono_type_initialization_cleanup (void);
699 mono_thread_kill (MonoInternalThread *thread, int signal);
702 mono_thread_get_tls_key (void);
705 mono_thread_get_tls_offset (void);
708 mono_domain_get_tls_key (void);
711 mono_domain_get_tls_offset (void);
713 /* Reflection and Reflection.Emit support */
716 * Handling System.Type objects:
718 * Fields defined as System.Type in managed code should be defined as MonoObject*
719 * in unmanaged structures, and the monotype_cast () function should be used for
720 * casting them to MonoReflectionType* to avoid crashes/security issues when
721 * encountering instances of user defined subclasses of System.Type.
724 #define IS_MONOTYPE(obj) (!(obj) || (((MonoObject*)(obj))->vtable->klass->image == mono_defaults.corlib && ((MonoReflectionType*)(obj))->type != NULL))
727 * Make sure the argument, which should be a System.Type is a System.MonoType object
728 * or equivalent, and not an instance of
729 * a user defined subclass of System.Type. This should be used in places were throwing
730 * an exception is safe.
732 #define CHECK_MONOTYPE(obj) do { \
733 if (!IS_MONOTYPE (obj)) \
734 mono_raise_exception (mono_get_exception_not_supported ("User defined subclasses of System.Type are not yet supported")); \
737 /* This should be used for accessing members of Type[] arrays */
738 #define mono_type_array_get(arr,index) monotype_cast (mono_array_get ((arr), gpointer, (index)))
741 * Cast an object to MonoReflectionType, making sure it is a System.MonoType or
744 static inline MonoReflectionType*
745 monotype_cast (MonoObject *obj)
747 g_assert (IS_MONOTYPE (obj));
749 return (MonoReflectionType*)obj;
753 * The following structure must match the C# implementation in our corlib.
756 struct _MonoReflectionMethod {
760 MonoReflectionType *reftype;
763 typedef struct _MonoReflectionGenericMethod MonoReflectionGenericMethod;
764 struct _MonoReflectionGenericMethod {
765 MonoReflectionMethod method;
768 struct _MonoDelegate {
770 /* The compiled code of the target method */
772 /* The invoke code */
773 gpointer invoke_impl;
776 gpointer delegate_trampoline;
777 /* Extra argument passed to the target method in llvmonly mode */
780 * If non-NULL, this points to a memory location which stores the address of
781 * the compiled code of the method, or NULL if it is not yet compiled.
783 guint8 **method_code;
784 MonoReflectionMethod *method_info;
785 MonoReflectionMethod *original_method_info;
787 MonoBoolean method_is_virtual;
790 typedef struct _MonoMulticastDelegate MonoMulticastDelegate;
791 struct _MonoMulticastDelegate {
792 MonoDelegate delegate;
793 MonoArray *delegates;
796 struct _MonoReflectionField {
799 MonoClassField *field;
801 MonoReflectionType *type;
805 struct _MonoReflectionProperty {
808 MonoProperty *property;
811 /*This is System.EventInfo*/
812 struct _MonoReflectionEvent {
814 MonoObject *cached_add_event;
818 MonoReflectionEvent object;
821 } MonoReflectionMonoEvent;
825 MonoReflectionType *ClassImpl;
826 MonoObject *DefaultValueImpl;
827 MonoObject *MemberImpl;
828 MonoString *NameImpl;
831 MonoObject *MarshalAsImpl;
832 } MonoReflectionParameter;
834 struct _MonoReflectionMethodBody {
839 MonoBoolean init_locals;
840 guint32 local_var_sig_token;
844 struct _MonoReflectionAssembly {
846 MonoAssembly *assembly;
847 MonoObject *resolve_event_holder;
849 MonoObject *evidence; /* Evidence */
850 MonoObject *minimum; /* PermissionSet - for SecurityAction.RequestMinimum */
851 MonoObject *optional; /* PermissionSet - for SecurityAction.RequestOptional */
852 MonoObject *refuse; /* PermissionSet - for SecurityAction.RequestRefuse */
853 MonoObject *granted; /* PermissionSet - for the resolved assembly granted permissions */
854 MonoObject *denied; /* PermissionSet - for the resolved assembly denied permissions */
856 MonoBoolean from_byte_array;
861 MonoReflectionType *utype;
867 MonoReflectionType *parent;
868 MonoReflectionType *ret;
875 MonoReflectionType *parent;
876 MonoReflectionType *declaring_type;
878 MonoReflectionMethod *get;
879 MonoReflectionMethod *set;
884 MonoReflectionType *declaring_type;
885 MonoReflectionType *reflected_type;
887 MonoReflectionMethod *add_method;
888 MonoReflectionMethod *remove_method;
889 MonoReflectionMethod *raise_method;
891 MonoArray *other_methods;
896 MonoString *name_space;
897 MonoReflectionType *etype;
898 MonoReflectionType *nested_in;
899 MonoReflectionAssembly *assembly;
901 MonoBoolean isprimitive;
907 } MonoReflectionILTokenInfo;
916 MonoArray *ex_handlers;
917 gint32 num_token_fixups;
918 MonoArray *token_fixups;
919 } MonoReflectionILGen;
926 } MonoILExceptionInfo;
933 gint32 filter_offset;
934 } MonoILExceptionBlock;
938 MonoObject *catch_type;
939 gint32 filter_offset;
943 gint32 handler_offset;
944 gint32 handler_length;
945 } MonoReflectionExceptionHandlingClause;
949 MonoReflectionType *local_type;
950 MonoBoolean is_pinned;
952 } MonoReflectionLocalVariableInfo;
956 * Must have the same layout as MonoReflectionLocalVariableInfo, since
957 * LocalBuilder inherits from it under net 2.0.
961 MonoBoolean is_pinned;
964 } MonoReflectionLocalBuilder;
973 MonoString *marshaltype;
974 MonoObject *marshaltyperef;
976 MonoBoolean has_size;
977 } MonoReflectionMarshal;
984 MonoReflectionMarshal *marshal_info;
988 MonoObject *def_value;
989 } MonoReflectionParamBuilder;
994 MonoReflectionILGen *ilgen;
995 MonoArray *parameters;
1003 MonoBoolean init_locals;
1004 MonoArray *param_modreq;
1005 MonoArray *param_modopt;
1006 MonoArray *permissions;
1007 } MonoReflectionCtorBuilder;
1011 MonoMethod *mhandle;
1013 MonoArray *parameters;
1019 MonoReflectionILGen *ilgen;
1023 MonoArray *override_methods;
1025 MonoString *dllentry;
1027 guint32 extra_flags;
1030 MonoBoolean init_locals;
1031 MonoGenericContainer *generic_container;
1032 MonoArray *generic_params;
1033 MonoArray *return_modreq;
1034 MonoArray *return_modopt;
1035 MonoArray *param_modreq;
1036 MonoArray *param_modopt;
1037 MonoArray *permissions;
1038 } MonoReflectionMethodBuilder;
1042 MonoMethod *mhandle;
1043 MonoReflectionType *parent;
1044 MonoReflectionType *ret;
1045 MonoArray *parameters;
1049 } MonoReflectionArrayMethod;
1054 MonoString *filename;
1058 } MonoReflectionResource;
1064 MonoArray *res_data;
1065 } MonoReflectionWin32Resource;
1070 } MonoReflectionPermissionSet;
1073 MonoReflectionAssembly assembly;
1074 MonoDynamicAssembly *dynamic_assembly;
1075 MonoReflectionMethod *entry_point;
1080 MonoArray *resources;
1081 MonoArray *public_key;
1082 MonoString *version;
1083 MonoString *culture;
1087 MonoBoolean delay_sign;
1089 MonoArray *loaded_modules;
1090 MonoArray *win32_resources;
1092 MonoArray *permissions_minimum;
1093 MonoArray *permissions_optional;
1094 MonoArray *permissions_refused;
1097 MonoBoolean corlib_internal;
1098 MonoArray *type_forwarders;
1099 MonoArray *pktoken; /* as hexadecimal byte[] */
1100 } MonoReflectionAssemblyBuilder;
1107 MonoObject *def_value;
1110 MonoReflectionType *typeb;
1111 MonoArray *rva_data;
1113 MonoReflectionMarshal *marshal_info;
1114 MonoClassField *handle;
1117 } MonoReflectionFieldBuilder;
1124 MonoArray *parameters;
1126 MonoObject *def_value;
1127 MonoReflectionMethodBuilder *set_method;
1128 MonoReflectionMethodBuilder *get_method;
1130 MonoObject *type_builder;
1131 MonoArray *returnModReq;
1132 MonoArray *returnModOpt;
1133 MonoArray *paramModReq;
1134 MonoArray *paramModOpt;
1136 } MonoReflectionPropertyBuilder;
1138 struct _MonoReflectionModule {
1141 MonoReflectionAssembly *assembly;
1144 MonoString *scopename;
1145 MonoBoolean is_resource;
1150 MonoReflectionModule module;
1151 MonoDynamicImage *dynamic_image;
1157 MonoReflectionAssemblyBuilder *assemblyb;
1158 MonoArray *global_methods;
1159 MonoArray *global_fields;
1161 MonoArray *resources;
1162 } MonoReflectionModuleBuilder;
1165 MonoReflectionType type;
1169 MonoReflectionType *nesting_type;
1170 MonoArray *interfaces;
1174 MonoArray *properties;
1179 MonoArray *subtypes;
1182 MonoReflectionModuleBuilder *module;
1184 gint32 packing_size;
1185 MonoGenericContainer *generic_container;
1186 MonoArray *generic_params;
1187 MonoArray *permissions;
1188 MonoReflectionType *created;
1189 } MonoReflectionTypeBuilder;
1192 MonoReflectionType type;
1193 MonoReflectionType *element_type;
1195 } MonoReflectionArrayType;
1198 MonoReflectionType type;
1199 MonoReflectionType *element_type;
1200 } MonoReflectionDerivedType;
1203 MonoReflectionType type;
1204 MonoReflectionTypeBuilder *tbuilder;
1205 MonoReflectionMethodBuilder *mbuilder;
1208 MonoReflectionType *base_type;
1209 MonoArray *iface_constraints;
1212 } MonoReflectionGenericParam;
1214 typedef struct _MonoReflectionGenericClass MonoReflectionGenericClass;
1215 struct _MonoReflectionGenericClass {
1216 MonoReflectionType type;
1217 MonoReflectionType *generic_type; /*Can be either a MonoType or a TypeBuilder*/
1218 MonoArray *type_arguments;
1219 guint32 initialized;
1225 MonoString *codebase;
1226 gint32 major, minor, build, revision;
1227 MonoObject *cultureInfo;
1230 MonoObject *keypair;
1231 MonoArray *publicKey;
1232 MonoArray *keyToken;
1233 guint32 versioncompat;
1234 MonoObject *version;
1235 guint32 processor_architecture;
1236 } MonoReflectionAssemblyName;
1241 MonoReflectionType *type;
1242 MonoReflectionTypeBuilder *typeb;
1244 MonoReflectionMethodBuilder *add_method;
1245 MonoReflectionMethodBuilder *remove_method;
1246 MonoReflectionMethodBuilder *raise_method;
1247 MonoArray *other_methods;
1250 } MonoReflectionEventBuilder;
1254 MonoReflectionMethod *ctor;
1256 } MonoReflectionCustomAttr;
1260 MonoString *marshal_cookie;
1261 MonoString *marshal_type;
1262 MonoReflectionType *marshal_type_ref;
1263 MonoReflectionType *marshal_safe_array_user_defined_subtype;
1265 guint32 array_subtype;
1266 gint32 safe_array_subtype;
1268 gint32 IidParameterIndex;
1269 gint16 size_param_index;
1270 } MonoReflectionMarshalAsAttribute;
1276 MonoBoolean best_fit_mapping;
1277 MonoBoolean throw_on_unmappable;
1278 MonoBoolean set_last_error;
1279 } MonoReflectionUnmanagedFunctionPointerAttribute;
1284 } MonoReflectionGuidAttribute;
1288 MonoMethod *mhandle;
1290 MonoReflectionType *rtype;
1291 MonoArray *parameters;
1294 MonoReflectionModule *module;
1295 MonoBoolean skip_visibility;
1296 MonoBoolean init_locals;
1297 MonoReflectionILGen *ilgen;
1300 GSList *referenced_by;
1301 MonoReflectionType *owner;
1302 } MonoReflectionDynamicMethod;
1306 MonoReflectionModuleBuilder *module;
1307 MonoArray *arguments;
1309 MonoReflectionType *return_type;
1311 guint32 unmanaged_call_conv;
1314 } MonoReflectionSigHelper;
1318 MonoReflectionGenericClass *inst;
1319 MonoObject *fb; /*can be either a MonoField or a FieldBuilder*/
1320 } MonoReflectionFieldOnTypeBuilderInst;
1324 MonoReflectionGenericClass *inst;
1325 MonoObject *cb; /*can be either a MonoCMethod or ConstructorBuilder*/
1326 } MonoReflectionCtorOnTypeBuilderInst;
1330 MonoReflectionType *inst;
1331 MonoObject *mb; /*can be either a MonoMethod or MethodBuilder*/
1332 MonoArray *method_args;
1333 MonoReflectionMethodBuilder *generic_method_definition;
1334 } MonoReflectionMethodOnTypeBuilderInst;
1338 MonoBoolean visible;
1339 } MonoReflectionComVisibleAttribute;
1342 RESOURCE_LOCATION_EMBEDDED = 1,
1343 RESOURCE_LOCATION_ANOTHER_ASSEMBLY = 2,
1344 RESOURCE_LOCATION_IN_MANIFEST = 4
1349 MonoReflectionAssembly *assembly;
1350 MonoString *filename;
1352 } MonoManifestResourceInfo;
1354 /* A boxed IntPtr */
1360 /* Keep in sync with System.GenericParameterAttributes */
1362 GENERIC_PARAMETER_ATTRIBUTE_NON_VARIANT = 0,
1363 GENERIC_PARAMETER_ATTRIBUTE_COVARIANT = 1,
1364 GENERIC_PARAMETER_ATTRIBUTE_CONTRAVARIANT = 2,
1365 GENERIC_PARAMETER_ATTRIBUTE_VARIANCE_MASK = 3,
1367 GENERIC_PARAMETER_ATTRIBUTE_NO_SPECIAL_CONSTRAINT = 0,
1368 GENERIC_PARAMETER_ATTRIBUTE_REFERENCE_TYPE_CONSTRAINT = 4,
1369 GENERIC_PARAMETER_ATTRIBUTE_VALUE_TYPE_CONSTRAINT = 8,
1370 GENERIC_PARAMETER_ATTRIBUTE_CONSTRUCTOR_CONSTRAINT = 16,
1371 GENERIC_PARAMETER_ATTRIBUTE_SPECIAL_CONSTRAINTS_MASK = 28
1372 } GenericParameterAttributes;
1376 MonoClassField *field;
1380 gboolean mono_image_create_pefile (MonoReflectionModuleBuilder *module, HANDLE file, MonoError *error);
1381 void mono_image_basic_init (MonoReflectionAssemblyBuilder *assembly);
1382 MonoReflectionModule * mono_image_load_module_dynamic (MonoReflectionAssemblyBuilder *assembly, MonoString *file_name);
1383 guint32 mono_image_insert_string (MonoReflectionModuleBuilder *module, MonoString *str);
1384 guint32 mono_image_create_token (MonoDynamicImage *assembly, MonoObject *obj, gboolean create_methodspec, gboolean register_token, MonoError *error);
1385 guint32 mono_image_create_method_token (MonoDynamicImage *assembly, MonoObject *obj, MonoArray *opt_param_types, MonoError *error);
1386 void mono_image_module_basic_init (MonoReflectionModuleBuilder *module);
1387 void mono_image_register_token (MonoDynamicImage *assembly, guint32 token, MonoObject *obj);
1388 void mono_dynamic_image_free (MonoDynamicImage *image);
1389 void mono_dynamic_image_free_image (MonoDynamicImage *image);
1390 void mono_image_set_wrappers_type (MonoReflectionModuleBuilder *mb, MonoReflectionType *type);
1391 void mono_dynamic_image_release_gc_roots (MonoDynamicImage *image);
1393 void mono_reflection_setup_internal_class (MonoReflectionTypeBuilder *tb);
1395 void mono_reflection_create_internal_class (MonoReflectionTypeBuilder *tb);
1397 void mono_reflection_setup_generic_class (MonoReflectionTypeBuilder *tb);
1399 void mono_reflection_create_generic_class (MonoReflectionTypeBuilder *tb);
1401 MonoReflectionType* mono_reflection_create_runtime_class (MonoReflectionTypeBuilder *tb);
1403 void mono_reflection_get_dynamic_overrides (MonoClass *klass, MonoMethod ***overrides, int *num_overrides);
1405 void mono_reflection_create_dynamic_method (MonoReflectionDynamicMethod *m);
1406 void mono_reflection_destroy_dynamic_method (MonoReflectionDynamicMethod *mb);
1408 void mono_reflection_initialize_generic_parameter (MonoReflectionGenericParam *gparam);
1409 void mono_reflection_create_unmanaged_type (MonoReflectionType *type);
1410 void mono_reflection_register_with_runtime (MonoReflectionType *type);
1412 void mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len, MonoArray **typed_args, MonoArray **named_args, CattrNamedArg **named_arg_info, MonoError *error);
1413 MonoMethodSignature * mono_reflection_lookup_signature (MonoImage *image, MonoMethod *method, guint32 token, MonoError *error);
1415 MonoArray* mono_param_get_objects_internal (MonoDomain *domain, MonoMethod *method, MonoClass *refclass);
1418 mono_class_bind_generic_parameters (MonoClass *klass, int type_argc, MonoType **types, gboolean is_dynamic);
1420 mono_reflection_bind_generic_parameters (MonoReflectionType *type, int type_argc, MonoType **types);
1421 MonoReflectionMethod*
1422 mono_reflection_bind_generic_method_parameters (MonoReflectionMethod *method, MonoArray *types);
1424 mono_reflection_generic_class_initialize (MonoReflectionGenericClass *type, MonoArray *fields);
1425 MonoReflectionEvent *
1426 mono_reflection_event_builder_get_event_info (MonoReflectionTypeBuilder *tb, MonoReflectionEventBuilder *eb);
1428 MonoArray *mono_reflection_sighelper_get_signature_local (MonoReflectionSigHelper *sig);
1430 MonoArray *mono_reflection_sighelper_get_signature_field (MonoReflectionSigHelper *sig);
1432 MonoReflectionMarshalAsAttribute* mono_reflection_marshal_as_attribute_from_marshal_spec (MonoDomain *domain, MonoClass *klass, MonoMarshalSpec *spec, MonoError *error);
1435 mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context);
1438 mono_reflection_call_is_assignable_to (MonoClass *klass, MonoClass *oklass);
1441 mono_reflection_is_valid_dynamic_token (MonoDynamicImage *image, guint32 token);
1444 mono_reflection_resolve_custom_attribute_data (MonoReflectionMethod *method, MonoReflectionAssembly *assembly, gpointer data, guint32 data_length, MonoArray **ctor_args, MonoArray ** named_args);
1447 mono_reflection_type_get_handle (MonoReflectionType *ref);
1450 mono_reflection_free_dynamic_generic_class (MonoGenericClass *gclass);
1453 mono_image_build_metadata (MonoReflectionModuleBuilder *module, MonoError *error);
1456 mono_get_constant_value_from_blob (MonoDomain* domain, MonoTypeEnum type, const char *blob, void *value);
1459 mono_release_type_locks (MonoInternalThread *thread);
1462 mono_string_to_utf8_mp (MonoMemPool *mp, MonoString *s, MonoError *error);
1465 mono_string_to_utf8_image (MonoImage *image, MonoString *s, MonoError *error);
1469 mono_array_clone_in_domain (MonoDomain *domain, MonoArray *array);
1472 mono_array_full_copy (MonoArray *src, MonoArray *dest);
1475 mono_array_calc_byte_len (MonoClass *klass, uintptr_t len, uintptr_t *res);
1478 mono_array_new_full_checked (MonoDomain *domain, MonoClass *array_class, uintptr_t *lengths, intptr_t *lower_bounds, MonoError *error);
1481 mono_array_new_specific_checked (MonoVTable *vtable, uintptr_t n, MonoError *error);
1484 ves_icall_array_new_specific (MonoVTable *vtable, uintptr_t n);
1486 #ifndef DISABLE_REMOTING
1488 mono_remoting_invoke (MonoObject *real_proxy, MonoMethodMessage *msg, MonoObject **exc, MonoArray **out_args, MonoError *error);
1491 mono_remote_class_vtable (MonoDomain *domain, MonoRemoteClass *remote_class, MonoRealProxy *real_proxy);
1494 mono_upgrade_remote_class (MonoDomain *domain, MonoObject *tproxy, MonoClass *klass);
1498 mono_create_ftnptr (MonoDomain *domain, gpointer addr);
1501 mono_get_addr_from_ftnptr (gpointer descr);
1504 mono_nullable_init (guint8 *buf, MonoObject *value, MonoClass *klass);
1507 mono_nullable_box (guint8 *buf, MonoClass *klass);
1509 #ifdef MONO_SMALL_CONFIG
1510 #define MONO_IMT_SIZE 9
1512 #define MONO_IMT_SIZE 19
1517 gpointer target_code;
1520 typedef struct _MonoImtBuilderEntry {
1522 struct _MonoImtBuilderEntry *next;
1523 MonoImtItemValue value;
1525 guint8 has_target_code : 1;
1526 } MonoImtBuilderEntry;
1528 typedef struct _MonoIMTCheckItem MonoIMTCheckItem;
1530 struct _MonoIMTCheckItem {
1532 int check_target_idx;
1533 MonoImtItemValue value;
1535 guint8 *code_target;
1537 guint8 compare_done;
1539 guint8 short_branch;
1540 guint8 has_target_code;
1543 typedef gpointer (*MonoImtThunkBuilder) (MonoVTable *vtable, MonoDomain *domain,
1544 MonoIMTCheckItem **imt_entries, int count, gpointer fail_trunk);
1547 mono_install_imt_thunk_builder (MonoImtThunkBuilder func);
1550 mono_set_always_build_imt_thunks (gboolean value);
1553 mono_vtable_build_imt_slot (MonoVTable* vtable, int imt_slot);
1556 mono_method_get_imt_slot (MonoMethod *method);
1559 mono_method_add_generic_virtual_invocation (MonoDomain *domain, MonoVTable *vtable,
1560 gpointer *vtable_slot,
1561 MonoMethod *method, gpointer code);
1564 mono_method_alloc_generic_virtual_thunk (MonoDomain *domain, int size);
1567 MONO_UNHANDLED_POLICY_LEGACY,
1568 MONO_UNHANDLED_POLICY_CURRENT
1569 } MonoRuntimeUnhandledExceptionPolicy;
1571 MonoRuntimeUnhandledExceptionPolicy
1572 mono_runtime_unhandled_exception_policy_get (void);
1574 mono_runtime_unhandled_exception_policy_set (MonoRuntimeUnhandledExceptionPolicy policy);
1577 mono_class_try_get_vtable (MonoDomain *domain, MonoClass *klass);
1580 mono_runtime_class_init_full (MonoVTable *vtable, MonoError *error);
1583 mono_method_clear_object (MonoDomain *domain, MonoMethod *method);
1586 mono_class_compute_gc_descriptor (MonoClass *klass);
1589 mono_class_compute_bitmap (MonoClass *klass, gsize *bitmap, int size, int offset, int *max_set, gboolean static_fields);
1592 mono_object_xdomain_representation (MonoObject *obj, MonoDomain *target_domain, MonoObject **exc);
1595 mono_class_is_reflection_method_or_constructor (MonoClass *klass);
1598 mono_get_object_from_blob (MonoDomain *domain, MonoType *type, const char *blob);
1601 mono_class_get_ref_info (MonoClass *klass);
1604 mono_class_set_ref_info (MonoClass *klass, gpointer obj);
1607 mono_class_free_ref_info (MonoClass *klass);
1610 mono_object_new_pinned (MonoDomain *domain, MonoClass *klass, MonoError *error);
1613 mono_object_new_specific_checked (MonoVTable *vtable, MonoError *error);
1616 ves_icall_object_new (MonoDomain *domain, MonoClass *klass);
1619 ves_icall_object_new_specific (MonoVTable *vtable);
1622 mono_object_new_alloc_specific_checked (MonoVTable *vtable, MonoError *error);
1625 mono_field_static_get_value_for_thread (MonoInternalThread *thread, MonoVTable *vt, MonoClassField *field, void *value);
1627 /* exported, used by the debugger */
1629 mono_vtable_get_static_field_data (MonoVTable *vt);
1632 mono_string_to_utf8_ignore (MonoString *s);
1635 mono_string_to_utf8_image_ignore (MonoImage *image, MonoString *s);
1638 mono_string_to_utf8_mp_ignore (MonoMemPool *mp, MonoString *s);
1641 mono_monitor_is_il_fastpath_wrapper (MonoMethod *method);
1644 mono_string_intern_checked (MonoString *str, MonoError *error);
1647 mono_exception_get_native_backtrace (MonoException *exc);
1650 ves_icall_Mono_Runtime_GetNativeStackTrace (MonoException *exc);
1653 mono_exception_get_managed_backtrace (MonoException *exc);
1656 mono_copy_value (MonoType *type, void *dest, void *value, int deref_pointer);
1659 mono_error_raise_exception (MonoError *target_error);
1662 mono_error_set_pending_exception (MonoError *error);
1665 mono_glist_to_array (GList *list, MonoClass *eclass);
1668 mono_object_new_checked (MonoDomain *domain, MonoClass *klass, MonoError *error);
1671 mono_object_new_mature (MonoVTable *vtable, MonoError *error);
1674 mono_object_new_fast_checked (MonoVTable *vtable, MonoError *error);
1677 ves_icall_object_new_fast (MonoVTable *vtable);
1680 mono_object_clone_checked (MonoObject *obj, MonoError *error);
1683 mono_string_new_size_checked (MonoDomain *domain, gint32 len, MonoError *error);
1686 mono_string_new_checked (MonoDomain *domain, const char *text, MonoError *merror);
1689 mono_string_new_utf16_checked (MonoDomain *domain, const guint16 *text, gint32 len, MonoError *error);
1692 mono_runtime_try_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error);
1695 mono_runtime_invoke_checked (MonoMethod *method, void *obj, void **params, MonoError *error);
1698 #endif /* __MONO_OBJECT_INTERNALS_H__ */