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/io-layer/io-layer.h>
11 #include "mono/utils/mono-compiler.h"
12 #include "mono/utils/mono-error.h"
13 #include "mono/utils/mono-stack-unwinding.h"
14 #include "mono/utils/mono-tls.h"
18 #define mono_assert(expr) G_STMT_START{ \
22 char *msg = g_strdup_printf ("file %s: line %d (%s): " \
23 "assertion failed: (%s)", __FILE__, __LINE__, \
24 __PRETTY_FUNCTION__, #expr); \
25 ex = mono_get_exception_execution_engine (msg); \
27 mono_raise_exception (ex); \
30 #define mono_assert_not_reached() G_STMT_START{ \
32 char *msg = g_strdup_printf ("file %s: line %d (%s): " \
33 "should not be reached", __FILE__, __LINE__, __PRETTY_FUNCTION__); \
34 ex = mono_get_exception_execution_engine (msg); \
36 mono_raise_exception (ex); \
39 #define mono_assert(expr) G_STMT_START{ \
43 char *msg = g_strdup_printf ("file %s: line %d: " \
44 "assertion failed: (%s)", __FILE__, __LINE__, \
46 ex = mono_get_exception_execution_engine (msg); \
48 mono_raise_exception (ex); \
51 #define mono_assert_not_reached() G_STMT_START{ \
53 char *msg = g_strdup_printf ("file %s: line %d): " \
54 "should not be reached", __FILE__, __LINE__); \
55 ex = mono_get_exception_execution_engine (msg); \
57 mono_raise_exception (ex); \
61 #define mono_assert(expr) g_assert(expr)
62 #define mono_assert_not_reached() g_assert_not_reached()
65 /* Use this as MONO_CHECK_ARG_NULL (arg,expr,) in functions returning void */
66 #define MONO_CHECK_ARG(arg, expr, retval) G_STMT_START{ \
67 if (G_UNLIKELY (!(expr))) \
70 char *msg = g_strdup_printf ("assertion `%s' failed", \
72 if (arg) {} /* check if the name exists */ \
73 ex = mono_get_exception_argument (#arg, msg); \
75 mono_set_pending_exception (ex); \
79 /* Use this as MONO_CHECK_ARG_NULL (arg,) in functions returning void */
80 #define MONO_CHECK_ARG_NULL(arg, retval) G_STMT_START{ \
81 if (G_UNLIKELY (arg == NULL)) \
84 if (arg) {} /* check if the name exists */ \
85 ex = mono_get_exception_argument_null (#arg); \
86 mono_set_pending_exception (ex); \
90 #define mono_string_builder_capacity(sb) sb->chunkOffset + sb->chunkChars->max_length
91 #define mono_string_builder_string_length(sb) sb->chunkOffset + sb->chunkLength
94 * Macros which cache the results of lookups locally.
95 * These should be used instead of the original versions, if the __GNUC__
96 * restriction is acceptable.
101 /* namespace and name should be a constant */
102 /* image must be mscorlib since other assemblies can be unloaded */
103 #define mono_class_from_name_cached(image,namespace,name) ({ \
104 static MonoClass *tmp_klass; \
106 g_assert (image == mono_defaults.corlib); \
107 tmp_klass = mono_class_from_name ((image), (namespace), (name)); \
108 g_assert (tmp_klass); \
111 /* name should be a compile-time constant */
112 #define mono_class_get_field_from_name_cached(klass,name) ({ \
113 static MonoClassField *tmp_field; \
115 tmp_field = mono_class_get_field_from_name ((klass), (name)); \
116 g_assert (tmp_field); \
119 /* eclass should be a run-time constant */
120 #define mono_array_class_get_cached(eclass,rank) ({ \
121 static MonoClass *tmp_klass; \
123 tmp_klass = mono_array_class_get ((eclass), (rank)); \
124 g_assert (tmp_klass); \
127 /* eclass should be a run-time constant */
128 #define mono_array_new_cached(domain, eclass, size) mono_array_new_specific (mono_class_vtable ((domain), mono_array_class_get_cached ((eclass), 1)), (size))
132 #define mono_class_from_name_cached(image,namespace,name) mono_class_from_name ((image), (namespace), (name))
133 #define mono_class_get_field_from_name_cached(klass,name) mono_class_get_field_from_name ((klass), (name))
134 #define mono_array_class_get_cached(eclass,rank) mono_array_class_get ((eclass), (rank))
135 #define mono_array_new_cached(domain, eclass, size) mono_array_new_specific (mono_class_vtable ((domain), mono_array_class_get_cached ((eclass), 1)), (size))
139 #ifdef MONO_BIG_ARRAYS
140 typedef uint64_t mono_array_size_t;
141 typedef int64_t mono_array_lower_bound_t;
142 #define MONO_ARRAY_MAX_INDEX G_MAXINT64
143 #define MONO_ARRAY_MAX_SIZE G_MAXUINT64
145 typedef uint32_t mono_array_size_t;
146 typedef int32_t mono_array_lower_bound_t;
147 #define MONO_ARRAY_MAX_INDEX ((int32_t) 0x7fffffff)
148 #define MONO_ARRAY_MAX_SIZE ((uint32_t) 0xffffffff)
152 mono_array_size_t length;
153 mono_array_lower_bound_t lower_bound;
158 /* bounds is NULL for szarrays */
159 MonoArrayBounds *bounds;
160 /* total number of elements of the array */
161 mono_array_size_t max_length;
162 /* we use double to ensure proper alignment on platforms that need it */
163 double vector [MONO_ZERO_LEN_ARRAY];
169 mono_unichar2 chars [MONO_ZERO_LEN_ARRAY];
172 #define mono_object_class(obj) (((MonoObject*)(obj))->vtable->klass)
173 #define mono_object_domain(obj) (((MonoObject*)(obj))->vtable->domain)
175 #define mono_string_chars_fast(s) ((mono_unichar2*)(s)->chars)
176 #define mono_string_length_fast(s) ((s)->length)
178 #define mono_array_length_fast(array) ((array)->max_length)
179 #define mono_array_addr_with_size_fast(array,size,index) ( ((char*)(array)->vector) + (size) * (index) )
181 #define mono_array_addr_fast(array,type,index) ((type*)(void*) mono_array_addr_with_size_fast (array, sizeof (type), index))
182 #define mono_array_get_fast(array,type,index) ( *(type*)mono_array_addr_fast ((array), type, (index)) )
183 #define mono_array_set_fast(array,type,index,value) \
185 type *__p = (type *) mono_array_addr_fast ((array), type, (index)); \
188 #define mono_array_setref_fast(array,index,value) \
190 void **__p = (void **) mono_array_addr_fast ((array), void*, (index)); \
191 mono_gc_wbarrier_set_arrayref ((array), __p, (MonoObject*)(value)); \
192 /* *__p = (value);*/ \
194 #define mono_array_memcpy_refs_fast(dest,destidx,src,srcidx,count) \
196 void **__p = (void **) mono_array_addr_fast ((dest), void*, (destidx)); \
197 void **__s = mono_array_addr_fast ((src), void*, (srcidx)); \
198 mono_gc_wbarrier_arrayref_copy (__p, __s, (count)); \
204 MonoObject *identity;
205 } MonoMarshalByRefObject;
207 /* This is a copy of System.AppDomain */
208 struct _MonoAppDomain {
209 MonoMarshalByRefObject mbr;
213 typedef struct _MonoStringBuilder MonoStringBuilder;
215 struct _MonoStringBuilder {
217 MonoArray *chunkChars;
218 MonoStringBuilder* chunkPrevious; // Link to the block logically before this block
219 int chunkLength; // The index in ChunkChars that represent the end of the block
220 int chunkOffset; // The logial offset (sum of all characters in previous blocks)
232 } MonoArgumentHandle;
235 MonoMethodSignature *sig;
241 struct _MonoException {
243 /* Stores the IPs and the generic sharing infos
244 (vtable/MRGCTX) of the frames. */
245 MonoArray *trace_ips;
246 MonoObject *inner_ex;
248 MonoString *help_link;
249 MonoString *class_name;
250 MonoString *stack_trace;
251 MonoString *remote_stack_trace;
252 gint32 remote_stack_index;
256 MonoObject *captured_traces;
257 MonoArray *native_trace_ips;
262 } MonoSystemException;
265 MonoSystemException base;
266 MonoString *param_name;
267 } MonoArgumentException;
271 MonoObject *async_state;
273 MonoObject *async_delegate;
275 MonoObject *object_data;
276 MonoBoolean sync_completed;
277 MonoBoolean completed;
278 MonoBoolean endinvoke_called;
279 MonoObject *async_callback;
280 MonoObject *execution_context;
281 MonoObject *original_context;
286 MonoMarshalByRefObject object;
288 MonoBoolean disposed;
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 gpointer dead_field_remove_me; /* This used to be jit_data, but that was moved to MonoThreadInfo. */
399 void *thread_info; /*This is MonoThreadInfo*, but to simplify dependencies, let's make it a void* here. */
400 MonoAppContext *current_appcontext;
401 MonoException *pending_exception;
402 MonoThread *root_domain_thread;
403 MonoObject *_serialized_principal;
404 int _serialized_principal_version;
405 gpointer appdomain_refs;
406 /* This is modified using atomic ops, so keep it a gint32 */
407 gint32 interruption_requested;
408 gpointer suspend_event;
409 gpointer suspended_event;
410 gpointer resume_event;
411 mono_mutex_t *synch_cs;
412 MonoBoolean threadpool_thread;
413 MonoBoolean thread_dump_requested;
414 MonoBoolean thread_interrupt_requested;
415 gpointer end_stack; /* This is only used when running in the debugger. */
417 guint8 apartment_state;
418 gint32 critical_region_level;
421 MonoThreadManageCallback manage_callback;
422 gpointer interrupt_on_stop;
424 gpointer android_tid;
425 gpointer thread_pinning_ref;
426 gint32 ignore_next_signal;
427 MonoMethod *async_invoke_method;
429 * These fields are used to avoid having to increment corlib versions
430 * when a new field is added to this structure.
431 * Please synchronize any changes with InternalThread in Thread.cs, i.e. add the
440 struct _MonoInternalThread *internal_thread;
441 MonoObject *start_obj;
442 MonoObject *ec_to_set;
447 MonoObject *additional;
448 } MonoStreamingContext;
452 MonoBoolean readOnly;
453 MonoString *AMDesignator;
454 MonoString *PMDesignator;
455 MonoString *DateSeparator;
456 MonoString *TimeSeparator;
457 MonoString *ShortDatePattern;
458 MonoString *LongDatePattern;
459 MonoString *ShortTimePattern;
460 MonoString *LongTimePattern;
461 MonoString *MonthDayPattern;
462 MonoString *YearMonthPattern;
463 guint32 FirstDayOfWeek;
464 guint32 CalendarWeekRule;
465 MonoArray *AbbreviatedDayNames;
467 MonoArray *MonthNames;
468 MonoArray *GenitiveMonthNames;
469 MonoArray *AbbreviatedMonthNames;
470 MonoArray *GenitiveAbbreviatedMonthNames;
471 MonoArray *ShortDatePatterns;
472 MonoArray *LongDatePatterns;
473 MonoArray *ShortTimePatterns;
474 MonoArray *LongTimePatterns;
475 MonoArray *MonthDayPatterns;
476 MonoArray *YearMonthPatterns;
477 MonoArray *ShortestDayNames;
478 } MonoDateTimeFormatInfo;
483 MonoArray *numberGroupSizes;
484 MonoArray *currencyGroupSizes;
485 MonoArray *percentGroupSizes;
486 MonoString *positiveSign;
487 MonoString *negativeSign;
488 MonoString *numberDecimalSeparator;
489 MonoString *numberGroupSeparator;
490 MonoString *currencyGroupSeparator;
491 MonoString *currencyDecimalSeparator;
492 MonoString *currencySymbol;
493 MonoString *ansiCurrencySymbol; /* unused */
494 MonoString *naNSymbol;
495 MonoString *positiveInfinitySymbol;
496 MonoString *negativeInfinitySymbol;
497 MonoString *percentDecimalSeparator;
498 MonoString *percentGroupSeparator;
499 MonoString *percentSymbol;
500 MonoString *perMilleSymbol;
501 MonoString *nativeDigits; /* unused */
502 gint32 dataItem; /* unused */
503 guint32 numberDecimalDigits;
504 gint32 currencyDecimalDigits;
505 gint32 currencyPositivePattern;
506 gint32 currencyNegativePattern;
507 gint32 numberNegativePattern;
508 gint32 percentPositivePattern;
509 gint32 percentNegativePattern;
510 gint32 percentDecimalDigits;
511 } MonoNumberFormatInfo;
516 MonoString *icu_name;
517 gpointer ICU_collator;
522 MonoString *NativeName;
523 MonoArray *ShortDatePatterns;
524 MonoArray *YearMonthPatterns;
525 MonoArray *LongDatePatterns;
526 MonoString *MonthDayPattern;
529 MonoArray *AbbreviatedEraNames;
530 MonoArray *AbbreviatedEnglishEraNames;
532 MonoArray *AbbreviatedDayNames;
533 MonoArray *SuperShortDayNames;
534 MonoArray *MonthNames;
535 MonoArray *AbbreviatedMonthNames;
536 MonoArray *GenitiveMonthNames;
537 MonoArray *GenitiveAbbreviatedMonthNames;
542 MonoString *AMDesignator;
543 MonoString *PMDesignator;
544 MonoString *TimeSeparator;
545 MonoArray *LongTimePatterns;
546 MonoArray *ShortTimePatterns;
547 guint32 FirstDayOfWeek;
548 guint32 CalendarWeekRule;
553 MonoBoolean is_read_only;
556 gint32 datetime_index;
558 gint32 calendar_type;
559 MonoBoolean use_user_override;
560 MonoNumberFormatInfo *number_format;
561 MonoDateTimeFormatInfo *datetime_format;
562 MonoObject *textinfo;
564 MonoString *englishname;
565 MonoString *nativename;
566 MonoString *iso3lang;
567 MonoString *iso2lang;
568 MonoString *win3lang;
569 MonoString *territory;
570 MonoArray *native_calendar_names;
571 MonoCompareInfo *compareinfo;
572 const void* text_info_data;
578 MonoString *iso2name;
579 MonoString *iso3name;
580 MonoString *win3name;
581 MonoString *english_name;
582 MonoString *native_name;
583 MonoString *currency_symbol;
584 MonoString *iso_currency_symbol;
585 MonoString *currency_english_name;
586 MonoString *currency_native_name;
600 } MonoInterfaceTypeAttribute;
603 * Callbacks supplied by the runtime and called by the modules in metadata/
604 * This interface is easier to extend than adding a new function type +
605 * a new 'install' function for every callback.
608 gpointer (*create_ftnptr) (MonoDomain *domain, gpointer addr);
609 gpointer (*get_addr_from_ftnptr) (gpointer descr);
610 char* (*get_runtime_build_info) (void);
611 gpointer (*get_vtable_trampoline) (int slot_index);
612 gpointer (*get_imt_trampoline) (int imt_slot_index);
613 void (*set_cast_details) (MonoClass *from, MonoClass *to);
614 void (*debug_log) (int level, MonoString *category, MonoString *message);
615 gboolean (*debug_log_is_enabled) (void);
616 gboolean (*tls_key_supported) (MonoTlsKey key);
617 } MonoRuntimeCallbacks;
619 typedef gboolean (*MonoInternalStackWalk) (MonoStackFrameInfo *frame, MonoContext *ctx, gpointer data);
620 typedef gboolean (*MonoInternalExceptionFrameWalk) (MonoMethod *method, gpointer ip, size_t native_offset, gboolean managed, gpointer user_data);
623 void (*mono_walk_stack_with_ctx) (MonoInternalStackWalk func, MonoContext *ctx, MonoUnwindOptions options, void *user_data);
624 void (*mono_walk_stack_with_state) (MonoInternalStackWalk func, MonoThreadUnwindState *state, MonoUnwindOptions options, void *user_data);
625 void (*mono_raise_exception) (MonoException *ex);
626 void (*mono_raise_exception_with_ctx) (MonoException *ex, MonoContext *ctx);
627 gboolean (*mono_exception_walk_trace) (MonoException *ex, MonoInternalExceptionFrameWalk func, gpointer user_data);
628 gboolean (*mono_install_handler_block_guard) (MonoThreadUnwindState *unwind_state);
629 } MonoRuntimeExceptionHandlingCallbacks;
632 /* used to free a dynamic method */
633 typedef void (*MonoFreeMethodFunc) (MonoDomain *domain, MonoMethod *method);
635 /* Used to initialize the method pointers inside vtables */
636 typedef gboolean (*MonoInitVTableFunc) (MonoVTable *vtable);
638 MONO_COLD void mono_set_pending_exception (MonoException *exc);
640 /* remoting and async support */
643 mono_async_result_new (MonoDomain *domain, HANDLE handle,
644 MonoObject *state, gpointer data, MonoObject *object_data);
647 mono_async_result_invoke (MonoAsyncResult *ares, MonoObject **exc);
650 mono_wait_handle_new (MonoDomain *domain, HANDLE handle);
653 mono_wait_handle_get_handle (MonoWaitHandle *handle);
656 mono_message_init (MonoDomain *domain, MonoMethodMessage *this_obj,
657 MonoReflectionMethod *method, MonoArray *out_args);
660 mono_message_invoke (MonoObject *target, MonoMethodMessage *msg,
661 MonoObject **exc, MonoArray **out_args);
664 mono_method_call_message_new (MonoMethod *method, gpointer *params, MonoMethod *invoke,
665 MonoDelegate **cb, MonoObject **state);
668 mono_method_return_message_restore (MonoMethod *method, gpointer *params, MonoArray *out_args);
671 mono_delegate_ctor_with_method (MonoObject *this_obj, MonoObject *target, gpointer addr, MonoMethod *method);
674 mono_delegate_ctor (MonoObject *this_obj, MonoObject *target, gpointer addr);
677 mono_class_get_allocation_ftn (MonoVTable *vtable, gboolean for_box, gboolean *pass_size_in_words);
680 mono_runtime_free_method (MonoDomain *domain, MonoMethod *method);
683 mono_install_runtime_invoke (MonoInvokeFunc func);
686 mono_install_compile_method (MonoCompileFunc func);
689 mono_install_free_method (MonoFreeMethodFunc func);
692 mono_install_callbacks (MonoRuntimeCallbacks *cbs);
694 MonoRuntimeCallbacks*
695 mono_get_runtime_callbacks (void);
698 mono_install_eh_callbacks (MonoRuntimeExceptionHandlingCallbacks *cbs);
700 MonoRuntimeExceptionHandlingCallbacks *
701 mono_get_eh_callbacks (void);
704 mono_raise_exception_with_context (MonoException *ex, MonoContext *ctx);
707 mono_type_initialization_init (void);
710 mono_type_initialization_cleanup (void);
713 mono_thread_kill (MonoInternalThread *thread, int signal);
716 mono_thread_get_tls_key (void);
719 mono_thread_get_tls_offset (void);
722 mono_domain_get_tls_key (void);
725 mono_domain_get_tls_offset (void);
727 /* Reflection and Reflection.Emit support */
730 * Handling System.Type objects:
732 * Fields defined as System.Type in managed code should be defined as MonoObject*
733 * in unmanaged structures, and the monotype_cast () function should be used for
734 * casting them to MonoReflectionType* to avoid crashes/security issues when
735 * encountering instances of user defined subclasses of System.Type.
738 #define IS_MONOTYPE(obj) (!(obj) || (((MonoObject*)(obj))->vtable->klass->image == mono_defaults.corlib && ((MonoReflectionType*)(obj))->type != NULL))
741 * Make sure the argument, which should be a System.Type is a System.MonoType object
742 * or equivalent, and not an instance of
743 * a user defined subclass of System.Type. This should be used in places were throwing
744 * an exception is safe.
746 #define CHECK_MONOTYPE(obj) do { \
747 if (!IS_MONOTYPE (obj)) \
748 mono_raise_exception (mono_get_exception_not_supported ("User defined subclasses of System.Type are not yet supported")); \
751 /* This should be used for accessing members of Type[] arrays */
752 #define mono_type_array_get(arr,index) monotype_cast (mono_array_get ((arr), gpointer, (index)))
755 * Cast an object to MonoReflectionType, making sure it is a System.MonoType or
758 static inline MonoReflectionType*
759 monotype_cast (MonoObject *obj)
761 g_assert (IS_MONOTYPE (obj));
763 return (MonoReflectionType*)obj;
767 * The following structure must match the C# implementation in our corlib.
770 struct _MonoReflectionMethod {
774 MonoReflectionType *reftype;
777 typedef struct _MonoReflectionGenericMethod MonoReflectionGenericMethod;
778 struct _MonoReflectionGenericMethod {
779 MonoReflectionMethod method;
782 struct _MonoDelegate {
784 /* The compiled code of the target method */
786 /* The invoke code */
787 gpointer invoke_impl;
790 gpointer delegate_trampoline;
792 * If non-NULL, this points to a memory location which stores the address of
793 * the compiled code of the method, or NULL if it is not yet compiled.
795 guint8 **method_code;
796 MonoReflectionMethod *method_info;
797 MonoReflectionMethod *original_method_info;
801 typedef struct _MonoMulticastDelegate MonoMulticastDelegate;
802 struct _MonoMulticastDelegate {
803 MonoDelegate delegate;
804 MonoMulticastDelegate *prev;
807 struct _MonoReflectionField {
810 MonoClassField *field;
812 MonoReflectionType *type;
816 struct _MonoReflectionProperty {
819 MonoProperty *property;
822 /*This is System.EventInfo*/
823 struct _MonoReflectionEvent {
825 MonoObject *cached_add_event;
829 MonoReflectionEvent object;
832 } MonoReflectionMonoEvent;
836 MonoReflectionType *ClassImpl;
837 MonoObject *DefaultValueImpl;
838 MonoObject *MemberImpl;
839 MonoString *NameImpl;
842 MonoObject *MarshalAsImpl;
843 } MonoReflectionParameter;
845 struct _MonoReflectionMethodBody {
850 MonoBoolean init_locals;
851 guint32 local_var_sig_token;
855 struct _MonoReflectionAssembly {
857 MonoAssembly *assembly;
858 MonoObject *resolve_event_holder;
860 MonoObject *evidence; /* Evidence */
861 MonoObject *minimum; /* PermissionSet - for SecurityAction.RequestMinimum */
862 MonoObject *optional; /* PermissionSet - for SecurityAction.RequestOptional */
863 MonoObject *refuse; /* PermissionSet - for SecurityAction.RequestRefuse */
864 MonoObject *granted; /* PermissionSet - for the resolved assembly granted permissions */
865 MonoObject *denied; /* PermissionSet - for the resolved assembly denied permissions */
867 MonoBoolean from_byte_array;
872 MonoReflectionType *utype;
878 MonoReflectionType *parent;
879 MonoReflectionType *ret;
886 MonoReflectionType *parent;
887 MonoReflectionType *declaring_type;
889 MonoReflectionMethod *get;
890 MonoReflectionMethod *set;
895 MonoReflectionType *declaring_type;
896 MonoReflectionType *reflected_type;
898 MonoReflectionMethod *add_method;
899 MonoReflectionMethod *remove_method;
900 MonoReflectionMethod *raise_method;
902 MonoArray *other_methods;
907 MonoString *name_space;
908 MonoReflectionType *etype;
909 MonoReflectionType *nested_in;
910 MonoReflectionAssembly *assembly;
912 MonoBoolean isprimitive;
918 } MonoReflectionILTokenInfo;
927 MonoArray *ex_handlers;
928 gint32 num_token_fixups;
929 MonoArray *token_fixups;
930 } MonoReflectionILGen;
937 } MonoILExceptionInfo;
944 gint32 filter_offset;
945 } MonoILExceptionBlock;
949 MonoObject *catch_type;
950 gint32 filter_offset;
954 gint32 handler_offset;
955 gint32 handler_length;
956 } MonoReflectionExceptionHandlingClause;
960 MonoReflectionType *local_type;
961 MonoBoolean is_pinned;
963 } MonoReflectionLocalVariableInfo;
967 * Must have the same layout as MonoReflectionLocalVariableInfo, since
968 * LocalBuilder inherits from it under net 2.0.
972 MonoBoolean is_pinned;
975 } MonoReflectionLocalBuilder;
984 MonoString *marshaltype;
985 MonoObject *marshaltyperef;
987 MonoBoolean has_size;
988 } MonoReflectionMarshal;
995 MonoReflectionMarshal *marshal_info;
999 MonoObject *def_value;
1000 } MonoReflectionParamBuilder;
1004 MonoMethod *mhandle;
1005 MonoReflectionILGen *ilgen;
1006 MonoArray *parameters;
1014 MonoBoolean init_locals;
1015 MonoArray *param_modreq;
1016 MonoArray *param_modopt;
1017 MonoArray *permissions;
1018 } MonoReflectionCtorBuilder;
1022 MonoMethod *mhandle;
1024 MonoArray *parameters;
1030 MonoReflectionILGen *ilgen;
1034 MonoArray *override_methods;
1036 MonoString *dllentry;
1038 guint32 extra_flags;
1041 MonoBoolean init_locals;
1042 MonoGenericContainer *generic_container;
1043 MonoArray *generic_params;
1044 MonoArray *return_modreq;
1045 MonoArray *return_modopt;
1046 MonoArray *param_modreq;
1047 MonoArray *param_modopt;
1048 MonoArray *permissions;
1049 } MonoReflectionMethodBuilder;
1053 MonoMethod *mhandle;
1054 MonoReflectionType *parent;
1055 MonoReflectionType *ret;
1056 MonoArray *parameters;
1060 } MonoReflectionArrayMethod;
1065 MonoString *filename;
1069 } MonoReflectionResource;
1075 MonoArray *res_data;
1076 } MonoReflectionWin32Resource;
1081 } MonoReflectionPermissionSet;
1084 MonoReflectionAssembly assembly;
1085 MonoDynamicAssembly *dynamic_assembly;
1086 MonoReflectionMethod *entry_point;
1091 MonoArray *resources;
1092 MonoArray *public_key;
1093 MonoString *version;
1094 MonoString *culture;
1098 MonoBoolean delay_sign;
1100 MonoArray *loaded_modules;
1101 MonoArray *win32_resources;
1103 MonoArray *permissions_minimum;
1104 MonoArray *permissions_optional;
1105 MonoArray *permissions_refused;
1108 MonoBoolean corlib_internal;
1109 MonoArray *type_forwarders;
1110 MonoArray *pktoken; /* as hexadecimal byte[] */
1111 } MonoReflectionAssemblyBuilder;
1118 MonoObject *def_value;
1121 MonoReflectionType *typeb;
1122 MonoArray *rva_data;
1124 MonoReflectionMarshal *marshal_info;
1125 MonoClassField *handle;
1128 } MonoReflectionFieldBuilder;
1135 MonoArray *parameters;
1137 MonoObject *def_value;
1138 MonoReflectionMethodBuilder *set_method;
1139 MonoReflectionMethodBuilder *get_method;
1141 MonoObject *type_builder;
1142 MonoArray *returnModReq;
1143 MonoArray *returnModOpt;
1144 MonoArray *paramModReq;
1145 MonoArray *paramModOpt;
1147 } MonoReflectionPropertyBuilder;
1149 struct _MonoReflectionModule {
1152 MonoReflectionAssembly *assembly;
1155 MonoString *scopename;
1156 MonoBoolean is_resource;
1161 MonoReflectionModule module;
1162 MonoDynamicImage *dynamic_image;
1168 MonoReflectionAssemblyBuilder *assemblyb;
1169 MonoArray *global_methods;
1170 MonoArray *global_fields;
1172 MonoArray *resources;
1173 } MonoReflectionModuleBuilder;
1176 MonoReflectionType type;
1180 MonoReflectionType *nesting_type;
1181 MonoArray *interfaces;
1185 MonoArray *properties;
1190 MonoArray *subtypes;
1193 MonoReflectionModuleBuilder *module;
1195 gint32 packing_size;
1196 MonoGenericContainer *generic_container;
1197 MonoArray *generic_params;
1198 MonoArray *permissions;
1199 MonoReflectionType *created;
1200 } MonoReflectionTypeBuilder;
1203 MonoReflectionType type;
1204 MonoReflectionType *element_type;
1206 } MonoReflectionArrayType;
1209 MonoReflectionType type;
1210 MonoReflectionType *element_type;
1211 } MonoReflectionDerivedType;
1214 MonoReflectionType type;
1215 MonoReflectionTypeBuilder *tbuilder;
1216 MonoReflectionMethodBuilder *mbuilder;
1219 MonoReflectionType *base_type;
1220 MonoArray *iface_constraints;
1223 } MonoReflectionGenericParam;
1225 typedef struct _MonoReflectionGenericClass MonoReflectionGenericClass;
1226 struct _MonoReflectionGenericClass {
1227 MonoReflectionType type;
1228 MonoReflectionType *generic_type; /*Can be either a MonoType or a TypeBuilder*/
1229 MonoArray *type_arguments;
1230 guint32 initialized;
1236 MonoString *codebase;
1237 gint32 major, minor, build, revision;
1238 MonoObject *cultureInfo;
1241 MonoObject *keypair;
1242 MonoArray *publicKey;
1243 MonoArray *keyToken;
1244 guint32 versioncompat;
1245 MonoObject *version;
1246 guint32 processor_architecture;
1247 } MonoReflectionAssemblyName;
1252 MonoReflectionType *type;
1253 MonoReflectionTypeBuilder *typeb;
1255 MonoReflectionMethodBuilder *add_method;
1256 MonoReflectionMethodBuilder *remove_method;
1257 MonoReflectionMethodBuilder *raise_method;
1258 MonoArray *other_methods;
1261 } MonoReflectionEventBuilder;
1265 MonoReflectionMethod *ctor;
1267 } MonoReflectionCustomAttr;
1271 MonoString *marshal_cookie;
1272 MonoString *marshal_type;
1273 MonoReflectionType *marshal_type_ref;
1274 MonoReflectionType *marshal_safe_array_user_defined_subtype;
1276 guint32 array_subtype;
1277 gint32 safe_array_subtype;
1279 gint32 IidParameterIndex;
1280 gint16 size_param_index;
1281 } MonoReflectionMarshalAsAttribute;
1289 MonoString *entry_point;
1290 MonoBoolean exact_spelling;
1291 MonoBoolean preserve_sig;
1292 MonoBoolean set_last_error;
1293 MonoBoolean best_fit_mapping;
1294 MonoBoolean throw_on_unmappable;
1295 } MonoReflectionDllImportAttribute;
1301 MonoBoolean set_last_error;
1302 MonoBoolean best_fit_mapping;
1303 MonoBoolean throw_on_unmappable;
1304 } MonoReflectionUnmanagedFunctionPointerAttribute;
1309 } MonoReflectionGuidAttribute;
1313 MonoMethod *mhandle;
1315 MonoReflectionType *rtype;
1316 MonoArray *parameters;
1319 MonoReflectionModule *module;
1320 MonoBoolean skip_visibility;
1321 MonoBoolean init_locals;
1322 MonoReflectionILGen *ilgen;
1325 GSList *referenced_by;
1326 MonoReflectionType *owner;
1327 } MonoReflectionDynamicMethod;
1331 MonoReflectionModuleBuilder *module;
1332 MonoArray *arguments;
1334 MonoReflectionType *return_type;
1336 guint32 unmanaged_call_conv;
1339 } MonoReflectionSigHelper;
1343 MonoReflectionGenericClass *inst;
1344 MonoObject *fb; /*can be either a MonoField or a FieldBuilder*/
1345 } MonoReflectionFieldOnTypeBuilderInst;
1349 MonoReflectionGenericClass *inst;
1350 MonoObject *cb; /*can be either a MonoCMethod or ConstructorBuilder*/
1351 } MonoReflectionCtorOnTypeBuilderInst;
1355 MonoReflectionType *inst;
1356 MonoObject *mb; /*can be either a MonoMethod or MethodBuilder*/
1357 MonoArray *method_args;
1358 MonoReflectionMethodBuilder *generic_method_definition;
1359 } MonoReflectionMethodOnTypeBuilderInst;
1363 MonoBoolean visible;
1364 } MonoReflectionComVisibleAttribute;
1367 RESOURCE_LOCATION_EMBEDDED = 1,
1368 RESOURCE_LOCATION_ANOTHER_ASSEMBLY = 2,
1369 RESOURCE_LOCATION_IN_MANIFEST = 4
1374 MonoReflectionAssembly *assembly;
1375 MonoString *filename;
1377 } MonoManifestResourceInfo;
1379 /* A boxed IntPtr */
1385 /* Keep in sync with System.GenericParameterAttributes */
1387 GENERIC_PARAMETER_ATTRIBUTE_NON_VARIANT = 0,
1388 GENERIC_PARAMETER_ATTRIBUTE_COVARIANT = 1,
1389 GENERIC_PARAMETER_ATTRIBUTE_CONTRAVARIANT = 2,
1390 GENERIC_PARAMETER_ATTRIBUTE_VARIANCE_MASK = 3,
1392 GENERIC_PARAMETER_ATTRIBUTE_NO_SPECIAL_CONSTRAINT = 0,
1393 GENERIC_PARAMETER_ATTRIBUTE_REFERENCE_TYPE_CONSTRAINT = 4,
1394 GENERIC_PARAMETER_ATTRIBUTE_VALUE_TYPE_CONSTRAINT = 8,
1395 GENERIC_PARAMETER_ATTRIBUTE_CONSTRUCTOR_CONSTRAINT = 16,
1396 GENERIC_PARAMETER_ATTRIBUTE_SPECIAL_CONSTRAINTS_MASK = 28
1397 } GenericParameterAttributes;
1401 MonoClassField *field;
1405 void mono_image_create_pefile (MonoReflectionModuleBuilder *module, HANDLE file);
1406 void mono_image_basic_init (MonoReflectionAssemblyBuilder *assembly);
1407 MonoReflectionModule * mono_image_load_module_dynamic (MonoReflectionAssemblyBuilder *assembly, MonoString *file_name);
1408 guint32 mono_image_insert_string (MonoReflectionModuleBuilder *module, MonoString *str);
1409 guint32 mono_image_create_token (MonoDynamicImage *assembly, MonoObject *obj, gboolean create_methodspec, gboolean register_token);
1410 guint32 mono_image_create_method_token (MonoDynamicImage *assembly, MonoObject *obj, MonoArray *opt_param_types);
1411 void mono_image_module_basic_init (MonoReflectionModuleBuilder *module);
1412 void mono_image_register_token (MonoDynamicImage *assembly, guint32 token, MonoObject *obj);
1413 void mono_dynamic_image_free (MonoDynamicImage *image);
1414 void mono_dynamic_image_free_image (MonoDynamicImage *image);
1415 void mono_image_set_wrappers_type (MonoReflectionModuleBuilder *mb, MonoReflectionType *type);
1416 void mono_dynamic_image_release_gc_roots (MonoDynamicImage *image);
1418 void mono_reflection_setup_internal_class (MonoReflectionTypeBuilder *tb);
1420 void mono_reflection_create_internal_class (MonoReflectionTypeBuilder *tb);
1422 void mono_reflection_setup_generic_class (MonoReflectionTypeBuilder *tb);
1424 void mono_reflection_create_generic_class (MonoReflectionTypeBuilder *tb);
1426 MonoReflectionType* mono_reflection_create_runtime_class (MonoReflectionTypeBuilder *tb);
1428 void mono_reflection_get_dynamic_overrides (MonoClass *klass, MonoMethod ***overrides, int *num_overrides);
1430 void mono_reflection_create_dynamic_method (MonoReflectionDynamicMethod *m);
1431 void mono_reflection_destroy_dynamic_method (MonoReflectionDynamicMethod *mb);
1433 void mono_reflection_initialize_generic_parameter (MonoReflectionGenericParam *gparam);
1434 void mono_reflection_create_unmanaged_type (MonoReflectionType *type);
1435 void mono_reflection_register_with_runtime (MonoReflectionType *type);
1437 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);
1438 MonoMethodSignature * mono_reflection_lookup_signature (MonoImage *image, MonoMethod *method, guint32 token, MonoError *error);
1440 MonoArray* mono_param_get_objects_internal (MonoDomain *domain, MonoMethod *method, MonoClass *refclass);
1443 mono_class_bind_generic_parameters (MonoClass *klass, int type_argc, MonoType **types, gboolean is_dynamic);
1445 mono_reflection_bind_generic_parameters (MonoReflectionType *type, int type_argc, MonoType **types);
1446 MonoReflectionMethod*
1447 mono_reflection_bind_generic_method_parameters (MonoReflectionMethod *method, MonoArray *types);
1449 mono_reflection_generic_class_initialize (MonoReflectionGenericClass *type, MonoArray *fields);
1450 MonoReflectionEvent *
1451 mono_reflection_event_builder_get_event_info (MonoReflectionTypeBuilder *tb, MonoReflectionEventBuilder *eb);
1453 MonoArray *mono_reflection_sighelper_get_signature_local (MonoReflectionSigHelper *sig);
1455 MonoArray *mono_reflection_sighelper_get_signature_field (MonoReflectionSigHelper *sig);
1457 MonoReflectionMarshalAsAttribute* mono_reflection_marshal_as_attribute_from_marshal_spec (MonoDomain *domain, MonoClass *klass, MonoMarshalSpec *spec);
1460 mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context);
1463 mono_reflection_call_is_assignable_to (MonoClass *klass, MonoClass *oklass);
1466 mono_reflection_is_valid_dynamic_token (MonoDynamicImage *image, guint32 token);
1469 mono_reflection_resolve_custom_attribute_data (MonoReflectionMethod *method, MonoReflectionAssembly *assembly, gpointer data, guint32 data_length, MonoArray **ctor_args, MonoArray ** named_args);
1472 mono_reflection_type_get_handle (MonoReflectionType *ref);
1475 mono_reflection_free_dynamic_generic_class (MonoGenericClass *gclass);
1478 mono_image_build_metadata (MonoReflectionModuleBuilder *module);
1481 mono_get_constant_value_from_blob (MonoDomain* domain, MonoTypeEnum type, const char *blob, void *value);
1484 mono_release_type_locks (MonoInternalThread *thread);
1487 mono_string_to_utf8_mp (MonoMemPool *mp, MonoString *s, MonoError *error);
1490 mono_string_to_utf8_image (MonoImage *image, MonoString *s, MonoError *error);
1494 mono_array_clone_in_domain (MonoDomain *domain, MonoArray *array);
1497 mono_array_full_copy (MonoArray *src, MonoArray *dest);
1500 mono_array_calc_byte_len (MonoClass *klass, uintptr_t len, uintptr_t *res);
1502 #ifndef DISABLE_REMOTING
1504 mono_remoting_invoke (MonoObject *real_proxy, MonoMethodMessage *msg,
1505 MonoObject **exc, MonoArray **out_args);
1508 mono_remote_class_vtable (MonoDomain *domain, MonoRemoteClass *remote_class, MonoRealProxy *real_proxy);
1511 mono_upgrade_remote_class (MonoDomain *domain, MonoObject *tproxy, MonoClass *klass);
1515 mono_create_ftnptr (MonoDomain *domain, gpointer addr);
1518 mono_get_addr_from_ftnptr (gpointer descr);
1521 mono_nullable_init (guint8 *buf, MonoObject *value, MonoClass *klass);
1524 mono_nullable_box (guint8 *buf, MonoClass *klass);
1526 #ifdef MONO_SMALL_CONFIG
1527 #define MONO_IMT_SIZE 9
1529 #define MONO_IMT_SIZE 19
1534 gpointer target_code;
1537 typedef struct _MonoImtBuilderEntry {
1539 struct _MonoImtBuilderEntry *next;
1540 MonoImtItemValue value;
1542 guint8 has_target_code : 1;
1543 } MonoImtBuilderEntry;
1545 typedef struct _MonoIMTCheckItem MonoIMTCheckItem;
1547 struct _MonoIMTCheckItem {
1549 int check_target_idx;
1550 MonoImtItemValue value;
1552 guint8 *code_target;
1554 guint8 compare_done;
1556 guint8 short_branch;
1557 guint8 has_target_code;
1560 typedef gpointer (*MonoImtThunkBuilder) (MonoVTable *vtable, MonoDomain *domain,
1561 MonoIMTCheckItem **imt_entries, int count, gpointer fail_trunk);
1564 mono_install_imt_thunk_builder (MonoImtThunkBuilder func);
1567 mono_vtable_build_imt_slot (MonoVTable* vtable, int imt_slot);
1570 mono_method_get_imt_slot (MonoMethod *method);
1573 mono_method_add_generic_virtual_invocation (MonoDomain *domain, MonoVTable *vtable,
1574 gpointer *vtable_slot,
1575 MonoMethod *method, gpointer code);
1578 mono_method_alloc_generic_virtual_thunk (MonoDomain *domain, int size);
1581 MONO_UNHANDLED_POLICY_LEGACY,
1582 MONO_UNHANDLED_POLICY_CURRENT
1583 } MonoRuntimeUnhandledExceptionPolicy;
1585 MonoRuntimeUnhandledExceptionPolicy
1586 mono_runtime_unhandled_exception_policy_get (void);
1588 mono_runtime_unhandled_exception_policy_set (MonoRuntimeUnhandledExceptionPolicy policy);
1591 mono_class_try_get_vtable (MonoDomain *domain, MonoClass *klass);
1594 mono_runtime_class_init_full (MonoVTable *vtable, gboolean raise_exception);
1597 mono_method_clear_object (MonoDomain *domain, MonoMethod *method);
1600 mono_class_compute_gc_descriptor (MonoClass *klass);
1603 mono_class_compute_bitmap (MonoClass *klass, gsize *bitmap, int size, int offset, int *max_set, gboolean static_fields);
1606 mono_object_xdomain_representation (MonoObject *obj, MonoDomain *target_domain, MonoObject **exc);
1609 mono_class_is_reflection_method_or_constructor (MonoClass *klass);
1612 mono_get_object_from_blob (MonoDomain *domain, MonoType *type, const char *blob);
1615 mono_class_get_ref_info (MonoClass *klass);
1618 mono_class_set_ref_info (MonoClass *klass, gpointer obj);
1621 mono_class_free_ref_info (MonoClass *klass);
1624 mono_object_new_pinned (MonoDomain *domain, MonoClass *klass);
1627 mono_field_static_get_value_for_thread (MonoInternalThread *thread, MonoVTable *vt, MonoClassField *field, void *value);
1629 /* exported, used by the debugger */
1631 mono_vtable_get_static_field_data (MonoVTable *vt);
1634 mono_string_to_utf8_ignore (MonoString *s);
1637 mono_string_to_utf8_image_ignore (MonoImage *image, MonoString *s);
1640 mono_string_to_utf8_mp_ignore (MonoMemPool *mp, MonoString *s);
1643 mono_monitor_is_il_fastpath_wrapper (MonoMethod *method);
1646 mono_exception_get_native_backtrace (MonoException *exc);
1649 ves_icall_Mono_Runtime_GetNativeStackTrace (MonoException *exc);
1652 mono_exception_get_managed_backtrace (MonoException *exc);
1655 mono_copy_value (MonoType *type, void *dest, void *value, int deref_pointer);
1658 mono_error_raise_exception (MonoError *target_error);
1661 mono_error_set_pending_exception (MonoError *error);
1663 #endif /* __MONO_OBJECT_INTERNALS_H__ */