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;
258 /* Dynamic methods referenced by the stack trace */
259 MonoObject *dynamic_methods;
264 } MonoSystemException;
267 MonoSystemException base;
268 MonoString *param_name;
269 } MonoArgumentException;
273 MonoObject *async_state;
275 MonoObject *async_delegate;
277 MonoObject *object_data;
278 MonoBoolean sync_completed;
279 MonoBoolean completed;
280 MonoBoolean endinvoke_called;
281 MonoObject *async_callback;
282 MonoObject *execution_context;
283 MonoObject *original_context;
288 MonoMarshalByRefObject object;
290 MonoBoolean disposed;
293 /* This is a copy of System.Runtime.Remoting.Messaging.CallType */
296 CallType_BeginInvoke = 1,
297 CallType_EndInvoke = 2,
301 /* This corresponds to System.Type */
302 struct _MonoReflectionType {
308 MonoReflectionType type;
309 MonoObject *type_info;
310 } MonoReflectionMonoType;
314 MonoReflectionType *class_to_proxy;
316 MonoObject *unwrapped_server;
317 gint32 target_domain_id;
318 MonoString *target_uri;
319 MonoObject *object_identity;
321 MonoObject *stub_data;
325 MonoMarshalByRefObject object;
327 GHashTable* itf_hash;
328 MonoObject *synchronization_context;
332 MonoRealProxy real_proxy;
333 MonoComObject *com_object;
335 } MonoComInteropProxy;
340 MonoRemoteClass *remote_class;
341 MonoBoolean custom_type_info;
342 } MonoTransparentProxy;
346 MonoReflectionMethod *method;
349 MonoArray *arg_types;
353 MonoAsyncResult *async_result;
357 /* Keep in sync with the System.MonoAsyncCall */
360 MonoMethodMessage *msg;
361 MonoMethod *cb_method;
362 MonoDelegate *cb_target;
371 gint32 native_offset;
372 gint64 method_address;
374 MonoReflectionMethod *method;
375 MonoString *filename;
378 MonoString *internal_method_name;
382 MONO_THREAD_FLAG_DONT_MANAGE = 1, // Don't wait for or abort this thread
383 MONO_THREAD_FLAG_NAME_SET = 2, // Thread name set from managed code
386 struct _MonoInternalThread {
388 volatile int lock_thread_id; /* to be used as the pre-shifted thread id in thin locks. Used for appdomain_ref push/pop */
390 MonoArray *cached_culture_info;
394 MonoException *abort_exc;
395 int abort_state_handle;
396 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 */
399 gpointer *static_data;
400 void *thread_info; /*This is MonoThreadInfo*, but to simplify dependencies, let's make it a void* here. */
401 MonoAppContext *current_appcontext;
402 MonoException *pending_exception;
403 MonoThread *root_domain_thread;
404 MonoObject *_serialized_principal;
405 int _serialized_principal_version;
406 gpointer appdomain_refs;
407 /* This is modified using atomic ops, so keep it a gint32 */
408 gint32 interruption_requested;
409 mono_mutex_t *synch_cs;
410 MonoBoolean threadpool_thread;
411 MonoBoolean thread_interrupt_requested;
413 guint8 apartment_state;
414 gint32 critical_region_level;
417 MonoThreadManageCallback manage_callback;
418 gpointer interrupt_on_stop;
420 gpointer thread_pinning_ref;
422 * These fields are used to avoid having to increment corlib versions
423 * when a new field is added to this structure.
424 * Please synchronize any changes with InternalThread in Thread.cs, i.e. add the
433 struct _MonoInternalThread *internal_thread;
434 MonoObject *start_obj;
439 MonoObject *additional;
440 } MonoStreamingContext;
444 MonoBoolean readOnly;
445 MonoString *AMDesignator;
446 MonoString *PMDesignator;
447 MonoString *DateSeparator;
448 MonoString *TimeSeparator;
449 MonoString *ShortDatePattern;
450 MonoString *LongDatePattern;
451 MonoString *ShortTimePattern;
452 MonoString *LongTimePattern;
453 MonoString *MonthDayPattern;
454 MonoString *YearMonthPattern;
455 guint32 FirstDayOfWeek;
456 guint32 CalendarWeekRule;
457 MonoArray *AbbreviatedDayNames;
459 MonoArray *MonthNames;
460 MonoArray *GenitiveMonthNames;
461 MonoArray *AbbreviatedMonthNames;
462 MonoArray *GenitiveAbbreviatedMonthNames;
463 MonoArray *ShortDatePatterns;
464 MonoArray *LongDatePatterns;
465 MonoArray *ShortTimePatterns;
466 MonoArray *LongTimePatterns;
467 MonoArray *MonthDayPatterns;
468 MonoArray *YearMonthPatterns;
469 MonoArray *ShortestDayNames;
470 } MonoDateTimeFormatInfo;
475 MonoArray *numberGroupSizes;
476 MonoArray *currencyGroupSizes;
477 MonoArray *percentGroupSizes;
478 MonoString *positiveSign;
479 MonoString *negativeSign;
480 MonoString *numberDecimalSeparator;
481 MonoString *numberGroupSeparator;
482 MonoString *currencyGroupSeparator;
483 MonoString *currencyDecimalSeparator;
484 MonoString *currencySymbol;
485 MonoString *ansiCurrencySymbol; /* unused */
486 MonoString *naNSymbol;
487 MonoString *positiveInfinitySymbol;
488 MonoString *negativeInfinitySymbol;
489 MonoString *percentDecimalSeparator;
490 MonoString *percentGroupSeparator;
491 MonoString *percentSymbol;
492 MonoString *perMilleSymbol;
493 MonoString *nativeDigits; /* unused */
494 gint32 dataItem; /* unused */
495 guint32 numberDecimalDigits;
496 gint32 currencyDecimalDigits;
497 gint32 currencyPositivePattern;
498 gint32 currencyNegativePattern;
499 gint32 numberNegativePattern;
500 gint32 percentPositivePattern;
501 gint32 percentNegativePattern;
502 gint32 percentDecimalDigits;
503 } MonoNumberFormatInfo;
508 MonoString *icu_name;
509 gpointer ICU_collator;
514 MonoString *NativeName;
515 MonoArray *ShortDatePatterns;
516 MonoArray *YearMonthPatterns;
517 MonoArray *LongDatePatterns;
518 MonoString *MonthDayPattern;
521 MonoArray *AbbreviatedEraNames;
522 MonoArray *AbbreviatedEnglishEraNames;
524 MonoArray *AbbreviatedDayNames;
525 MonoArray *SuperShortDayNames;
526 MonoArray *MonthNames;
527 MonoArray *AbbreviatedMonthNames;
528 MonoArray *GenitiveMonthNames;
529 MonoArray *GenitiveAbbreviatedMonthNames;
534 MonoString *AMDesignator;
535 MonoString *PMDesignator;
536 MonoString *TimeSeparator;
537 MonoArray *LongTimePatterns;
538 MonoArray *ShortTimePatterns;
539 guint32 FirstDayOfWeek;
540 guint32 CalendarWeekRule;
545 MonoBoolean is_read_only;
548 gint32 datetime_index;
550 gint32 calendar_type;
551 MonoBoolean use_user_override;
552 MonoNumberFormatInfo *number_format;
553 MonoDateTimeFormatInfo *datetime_format;
554 MonoObject *textinfo;
556 MonoString *englishname;
557 MonoString *nativename;
558 MonoString *iso3lang;
559 MonoString *iso2lang;
560 MonoString *win3lang;
561 MonoString *territory;
562 MonoArray *native_calendar_names;
563 MonoCompareInfo *compareinfo;
564 const void* text_info_data;
570 MonoString *iso2name;
571 MonoString *iso3name;
572 MonoString *win3name;
573 MonoString *english_name;
574 MonoString *native_name;
575 MonoString *currency_symbol;
576 MonoString *iso_currency_symbol;
577 MonoString *currency_english_name;
578 MonoString *currency_native_name;
592 } MonoInterfaceTypeAttribute;
595 * Callbacks supplied by the runtime and called by the modules in metadata/
596 * This interface is easier to extend than adding a new function type +
597 * a new 'install' function for every callback.
600 gpointer (*create_ftnptr) (MonoDomain *domain, gpointer addr);
601 gpointer (*get_addr_from_ftnptr) (gpointer descr);
602 char* (*get_runtime_build_info) (void);
603 gpointer (*get_vtable_trampoline) (int slot_index);
604 gpointer (*get_imt_trampoline) (int imt_slot_index);
605 void (*set_cast_details) (MonoClass *from, MonoClass *to);
606 void (*debug_log) (int level, MonoString *category, MonoString *message);
607 gboolean (*debug_log_is_enabled) (void);
608 gboolean (*tls_key_supported) (MonoTlsKey key);
609 } MonoRuntimeCallbacks;
611 typedef gboolean (*MonoInternalStackWalk) (MonoStackFrameInfo *frame, MonoContext *ctx, gpointer data);
612 typedef gboolean (*MonoInternalExceptionFrameWalk) (MonoMethod *method, gpointer ip, size_t native_offset, gboolean managed, gpointer user_data);
615 void (*mono_walk_stack_with_ctx) (MonoInternalStackWalk func, MonoContext *ctx, MonoUnwindOptions options, void *user_data);
616 void (*mono_walk_stack_with_state) (MonoInternalStackWalk func, MonoThreadUnwindState *state, MonoUnwindOptions options, void *user_data);
617 void (*mono_raise_exception) (MonoException *ex);
618 void (*mono_raise_exception_with_ctx) (MonoException *ex, MonoContext *ctx);
619 gboolean (*mono_exception_walk_trace) (MonoException *ex, MonoInternalExceptionFrameWalk func, gpointer user_data);
620 gboolean (*mono_install_handler_block_guard) (MonoThreadUnwindState *unwind_state);
621 } MonoRuntimeExceptionHandlingCallbacks;
624 /* used to free a dynamic method */
625 typedef void (*MonoFreeMethodFunc) (MonoDomain *domain, MonoMethod *method);
627 /* Used to initialize the method pointers inside vtables */
628 typedef gboolean (*MonoInitVTableFunc) (MonoVTable *vtable);
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_runtime_invoke (MonoInvokeFunc func);
678 mono_install_compile_method (MonoCompileFunc func);
681 mono_install_free_method (MonoFreeMethodFunc func);
684 mono_install_callbacks (MonoRuntimeCallbacks *cbs);
686 MonoRuntimeCallbacks*
687 mono_get_runtime_callbacks (void);
690 mono_install_eh_callbacks (MonoRuntimeExceptionHandlingCallbacks *cbs);
692 MonoRuntimeExceptionHandlingCallbacks *
693 mono_get_eh_callbacks (void);
696 mono_raise_exception_with_context (MonoException *ex, MonoContext *ctx);
699 mono_type_initialization_init (void);
702 mono_type_initialization_cleanup (void);
705 mono_thread_kill (MonoInternalThread *thread, int signal);
708 mono_thread_get_tls_key (void);
711 mono_thread_get_tls_offset (void);
714 mono_domain_get_tls_key (void);
717 mono_domain_get_tls_offset (void);
719 /* Reflection and Reflection.Emit support */
722 * Handling System.Type objects:
724 * Fields defined as System.Type in managed code should be defined as MonoObject*
725 * in unmanaged structures, and the monotype_cast () function should be used for
726 * casting them to MonoReflectionType* to avoid crashes/security issues when
727 * encountering instances of user defined subclasses of System.Type.
730 #define IS_MONOTYPE(obj) (!(obj) || (((MonoObject*)(obj))->vtable->klass->image == mono_defaults.corlib && ((MonoReflectionType*)(obj))->type != NULL))
733 * Make sure the argument, which should be a System.Type is a System.MonoType object
734 * or equivalent, and not an instance of
735 * a user defined subclass of System.Type. This should be used in places were throwing
736 * an exception is safe.
738 #define CHECK_MONOTYPE(obj) do { \
739 if (!IS_MONOTYPE (obj)) \
740 mono_raise_exception (mono_get_exception_not_supported ("User defined subclasses of System.Type are not yet supported")); \
743 /* This should be used for accessing members of Type[] arrays */
744 #define mono_type_array_get(arr,index) monotype_cast (mono_array_get ((arr), gpointer, (index)))
747 * Cast an object to MonoReflectionType, making sure it is a System.MonoType or
750 static inline MonoReflectionType*
751 monotype_cast (MonoObject *obj)
753 g_assert (IS_MONOTYPE (obj));
755 return (MonoReflectionType*)obj;
759 * The following structure must match the C# implementation in our corlib.
762 struct _MonoReflectionMethod {
766 MonoReflectionType *reftype;
769 typedef struct _MonoReflectionGenericMethod MonoReflectionGenericMethod;
770 struct _MonoReflectionGenericMethod {
771 MonoReflectionMethod method;
774 struct _MonoDelegate {
776 /* The compiled code of the target method */
778 /* The invoke code */
779 gpointer invoke_impl;
782 gpointer delegate_trampoline;
784 * If non-NULL, this points to a memory location which stores the address of
785 * the compiled code of the method, or NULL if it is not yet compiled.
787 guint8 **method_code;
788 MonoReflectionMethod *method_info;
789 MonoReflectionMethod *original_method_info;
793 typedef struct _MonoMulticastDelegate MonoMulticastDelegate;
794 struct _MonoMulticastDelegate {
795 MonoDelegate delegate;
796 MonoArray *delegates;
799 struct _MonoReflectionField {
802 MonoClassField *field;
804 MonoReflectionType *type;
808 struct _MonoReflectionProperty {
811 MonoProperty *property;
814 /*This is System.EventInfo*/
815 struct _MonoReflectionEvent {
817 MonoObject *cached_add_event;
821 MonoReflectionEvent object;
824 } MonoReflectionMonoEvent;
828 MonoReflectionType *ClassImpl;
829 MonoObject *DefaultValueImpl;
830 MonoObject *MemberImpl;
831 MonoString *NameImpl;
834 MonoObject *MarshalAsImpl;
835 } MonoReflectionParameter;
837 struct _MonoReflectionMethodBody {
842 MonoBoolean init_locals;
843 guint32 local_var_sig_token;
847 struct _MonoReflectionAssembly {
849 MonoAssembly *assembly;
850 MonoObject *resolve_event_holder;
852 MonoObject *evidence; /* Evidence */
853 MonoObject *minimum; /* PermissionSet - for SecurityAction.RequestMinimum */
854 MonoObject *optional; /* PermissionSet - for SecurityAction.RequestOptional */
855 MonoObject *refuse; /* PermissionSet - for SecurityAction.RequestRefuse */
856 MonoObject *granted; /* PermissionSet - for the resolved assembly granted permissions */
857 MonoObject *denied; /* PermissionSet - for the resolved assembly denied permissions */
859 MonoBoolean from_byte_array;
864 MonoReflectionType *utype;
870 MonoReflectionType *parent;
871 MonoReflectionType *ret;
878 MonoReflectionType *parent;
879 MonoReflectionType *declaring_type;
881 MonoReflectionMethod *get;
882 MonoReflectionMethod *set;
887 MonoReflectionType *declaring_type;
888 MonoReflectionType *reflected_type;
890 MonoReflectionMethod *add_method;
891 MonoReflectionMethod *remove_method;
892 MonoReflectionMethod *raise_method;
894 MonoArray *other_methods;
899 MonoString *name_space;
900 MonoReflectionType *etype;
901 MonoReflectionType *nested_in;
902 MonoReflectionAssembly *assembly;
904 MonoBoolean isprimitive;
910 } MonoReflectionILTokenInfo;
919 MonoArray *ex_handlers;
920 gint32 num_token_fixups;
921 MonoArray *token_fixups;
922 } MonoReflectionILGen;
929 } MonoILExceptionInfo;
936 gint32 filter_offset;
937 } MonoILExceptionBlock;
941 MonoObject *catch_type;
942 gint32 filter_offset;
946 gint32 handler_offset;
947 gint32 handler_length;
948 } MonoReflectionExceptionHandlingClause;
952 MonoReflectionType *local_type;
953 MonoBoolean is_pinned;
955 } MonoReflectionLocalVariableInfo;
959 * Must have the same layout as MonoReflectionLocalVariableInfo, since
960 * LocalBuilder inherits from it under net 2.0.
964 MonoBoolean is_pinned;
967 } MonoReflectionLocalBuilder;
976 MonoString *marshaltype;
977 MonoObject *marshaltyperef;
979 MonoBoolean has_size;
980 } MonoReflectionMarshal;
987 MonoReflectionMarshal *marshal_info;
991 MonoObject *def_value;
992 } MonoReflectionParamBuilder;
997 MonoReflectionILGen *ilgen;
998 MonoArray *parameters;
1006 MonoBoolean init_locals;
1007 MonoArray *param_modreq;
1008 MonoArray *param_modopt;
1009 MonoArray *permissions;
1010 } MonoReflectionCtorBuilder;
1014 MonoMethod *mhandle;
1016 MonoArray *parameters;
1022 MonoReflectionILGen *ilgen;
1026 MonoArray *override_methods;
1028 MonoString *dllentry;
1030 guint32 extra_flags;
1033 MonoBoolean init_locals;
1034 MonoGenericContainer *generic_container;
1035 MonoArray *generic_params;
1036 MonoArray *return_modreq;
1037 MonoArray *return_modopt;
1038 MonoArray *param_modreq;
1039 MonoArray *param_modopt;
1040 MonoArray *permissions;
1041 } MonoReflectionMethodBuilder;
1045 MonoMethod *mhandle;
1046 MonoReflectionType *parent;
1047 MonoReflectionType *ret;
1048 MonoArray *parameters;
1052 } MonoReflectionArrayMethod;
1057 MonoString *filename;
1061 } MonoReflectionResource;
1067 MonoArray *res_data;
1068 } MonoReflectionWin32Resource;
1073 } MonoReflectionPermissionSet;
1076 MonoReflectionAssembly assembly;
1077 MonoDynamicAssembly *dynamic_assembly;
1078 MonoReflectionMethod *entry_point;
1083 MonoArray *resources;
1084 MonoArray *public_key;
1085 MonoString *version;
1086 MonoString *culture;
1090 MonoBoolean delay_sign;
1092 MonoArray *loaded_modules;
1093 MonoArray *win32_resources;
1095 MonoArray *permissions_minimum;
1096 MonoArray *permissions_optional;
1097 MonoArray *permissions_refused;
1100 MonoBoolean corlib_internal;
1101 MonoArray *type_forwarders;
1102 MonoArray *pktoken; /* as hexadecimal byte[] */
1103 } MonoReflectionAssemblyBuilder;
1110 MonoObject *def_value;
1113 MonoReflectionType *typeb;
1114 MonoArray *rva_data;
1116 MonoReflectionMarshal *marshal_info;
1117 MonoClassField *handle;
1120 } MonoReflectionFieldBuilder;
1127 MonoArray *parameters;
1129 MonoObject *def_value;
1130 MonoReflectionMethodBuilder *set_method;
1131 MonoReflectionMethodBuilder *get_method;
1133 MonoObject *type_builder;
1134 MonoArray *returnModReq;
1135 MonoArray *returnModOpt;
1136 MonoArray *paramModReq;
1137 MonoArray *paramModOpt;
1139 } MonoReflectionPropertyBuilder;
1141 struct _MonoReflectionModule {
1144 MonoReflectionAssembly *assembly;
1147 MonoString *scopename;
1148 MonoBoolean is_resource;
1153 MonoReflectionModule module;
1154 MonoDynamicImage *dynamic_image;
1160 MonoReflectionAssemblyBuilder *assemblyb;
1161 MonoArray *global_methods;
1162 MonoArray *global_fields;
1164 MonoArray *resources;
1165 } MonoReflectionModuleBuilder;
1168 MonoReflectionType type;
1172 MonoReflectionType *nesting_type;
1173 MonoArray *interfaces;
1177 MonoArray *properties;
1182 MonoArray *subtypes;
1185 MonoReflectionModuleBuilder *module;
1187 gint32 packing_size;
1188 MonoGenericContainer *generic_container;
1189 MonoArray *generic_params;
1190 MonoArray *permissions;
1191 MonoReflectionType *created;
1192 } MonoReflectionTypeBuilder;
1195 MonoReflectionType type;
1196 MonoReflectionType *element_type;
1198 } MonoReflectionArrayType;
1201 MonoReflectionType type;
1202 MonoReflectionType *element_type;
1203 } MonoReflectionDerivedType;
1206 MonoReflectionType type;
1207 MonoReflectionTypeBuilder *tbuilder;
1208 MonoReflectionMethodBuilder *mbuilder;
1211 MonoReflectionType *base_type;
1212 MonoArray *iface_constraints;
1215 } MonoReflectionGenericParam;
1217 typedef struct _MonoReflectionGenericClass MonoReflectionGenericClass;
1218 struct _MonoReflectionGenericClass {
1219 MonoReflectionType type;
1220 MonoReflectionType *generic_type; /*Can be either a MonoType or a TypeBuilder*/
1221 MonoArray *type_arguments;
1222 guint32 initialized;
1228 MonoString *codebase;
1229 gint32 major, minor, build, revision;
1230 MonoObject *cultureInfo;
1233 MonoObject *keypair;
1234 MonoArray *publicKey;
1235 MonoArray *keyToken;
1236 guint32 versioncompat;
1237 MonoObject *version;
1238 guint32 processor_architecture;
1239 } MonoReflectionAssemblyName;
1244 MonoReflectionType *type;
1245 MonoReflectionTypeBuilder *typeb;
1247 MonoReflectionMethodBuilder *add_method;
1248 MonoReflectionMethodBuilder *remove_method;
1249 MonoReflectionMethodBuilder *raise_method;
1250 MonoArray *other_methods;
1253 } MonoReflectionEventBuilder;
1257 MonoReflectionMethod *ctor;
1259 } MonoReflectionCustomAttr;
1263 MonoString *marshal_cookie;
1264 MonoString *marshal_type;
1265 MonoReflectionType *marshal_type_ref;
1266 MonoReflectionType *marshal_safe_array_user_defined_subtype;
1268 guint32 array_subtype;
1269 gint32 safe_array_subtype;
1271 gint32 IidParameterIndex;
1272 gint16 size_param_index;
1273 } MonoReflectionMarshalAsAttribute;
1279 MonoBoolean best_fit_mapping;
1280 MonoBoolean throw_on_unmappable;
1281 MonoBoolean set_last_error;
1282 } MonoReflectionUnmanagedFunctionPointerAttribute;
1287 } MonoReflectionGuidAttribute;
1291 MonoMethod *mhandle;
1293 MonoReflectionType *rtype;
1294 MonoArray *parameters;
1297 MonoReflectionModule *module;
1298 MonoBoolean skip_visibility;
1299 MonoBoolean init_locals;
1300 MonoReflectionILGen *ilgen;
1303 GSList *referenced_by;
1304 MonoReflectionType *owner;
1305 } MonoReflectionDynamicMethod;
1309 MonoReflectionModuleBuilder *module;
1310 MonoArray *arguments;
1312 MonoReflectionType *return_type;
1314 guint32 unmanaged_call_conv;
1317 } MonoReflectionSigHelper;
1321 MonoReflectionGenericClass *inst;
1322 MonoObject *fb; /*can be either a MonoField or a FieldBuilder*/
1323 } MonoReflectionFieldOnTypeBuilderInst;
1327 MonoReflectionGenericClass *inst;
1328 MonoObject *cb; /*can be either a MonoCMethod or ConstructorBuilder*/
1329 } MonoReflectionCtorOnTypeBuilderInst;
1333 MonoReflectionType *inst;
1334 MonoObject *mb; /*can be either a MonoMethod or MethodBuilder*/
1335 MonoArray *method_args;
1336 MonoReflectionMethodBuilder *generic_method_definition;
1337 } MonoReflectionMethodOnTypeBuilderInst;
1341 MonoBoolean visible;
1342 } MonoReflectionComVisibleAttribute;
1345 RESOURCE_LOCATION_EMBEDDED = 1,
1346 RESOURCE_LOCATION_ANOTHER_ASSEMBLY = 2,
1347 RESOURCE_LOCATION_IN_MANIFEST = 4
1352 MonoReflectionAssembly *assembly;
1353 MonoString *filename;
1355 } MonoManifestResourceInfo;
1357 /* A boxed IntPtr */
1363 /* Keep in sync with System.GenericParameterAttributes */
1365 GENERIC_PARAMETER_ATTRIBUTE_NON_VARIANT = 0,
1366 GENERIC_PARAMETER_ATTRIBUTE_COVARIANT = 1,
1367 GENERIC_PARAMETER_ATTRIBUTE_CONTRAVARIANT = 2,
1368 GENERIC_PARAMETER_ATTRIBUTE_VARIANCE_MASK = 3,
1370 GENERIC_PARAMETER_ATTRIBUTE_NO_SPECIAL_CONSTRAINT = 0,
1371 GENERIC_PARAMETER_ATTRIBUTE_REFERENCE_TYPE_CONSTRAINT = 4,
1372 GENERIC_PARAMETER_ATTRIBUTE_VALUE_TYPE_CONSTRAINT = 8,
1373 GENERIC_PARAMETER_ATTRIBUTE_CONSTRUCTOR_CONSTRAINT = 16,
1374 GENERIC_PARAMETER_ATTRIBUTE_SPECIAL_CONSTRAINTS_MASK = 28
1375 } GenericParameterAttributes;
1379 MonoClassField *field;
1383 void mono_image_create_pefile (MonoReflectionModuleBuilder *module, HANDLE file);
1384 void mono_image_basic_init (MonoReflectionAssemblyBuilder *assembly);
1385 MonoReflectionModule * mono_image_load_module_dynamic (MonoReflectionAssemblyBuilder *assembly, MonoString *file_name);
1386 guint32 mono_image_insert_string (MonoReflectionModuleBuilder *module, MonoString *str);
1387 guint32 mono_image_create_token (MonoDynamicImage *assembly, MonoObject *obj, gboolean create_methodspec, gboolean register_token);
1388 guint32 mono_image_create_method_token (MonoDynamicImage *assembly, MonoObject *obj, MonoArray *opt_param_types);
1389 void mono_image_module_basic_init (MonoReflectionModuleBuilder *module);
1390 void mono_image_register_token (MonoDynamicImage *assembly, guint32 token, MonoObject *obj);
1391 void mono_dynamic_image_free (MonoDynamicImage *image);
1392 void mono_dynamic_image_free_image (MonoDynamicImage *image);
1393 void mono_image_set_wrappers_type (MonoReflectionModuleBuilder *mb, MonoReflectionType *type);
1394 void mono_dynamic_image_release_gc_roots (MonoDynamicImage *image);
1396 void mono_reflection_setup_internal_class (MonoReflectionTypeBuilder *tb);
1398 void mono_reflection_create_internal_class (MonoReflectionTypeBuilder *tb);
1400 void mono_reflection_setup_generic_class (MonoReflectionTypeBuilder *tb);
1402 void mono_reflection_create_generic_class (MonoReflectionTypeBuilder *tb);
1404 MonoReflectionType* mono_reflection_create_runtime_class (MonoReflectionTypeBuilder *tb);
1406 void mono_reflection_get_dynamic_overrides (MonoClass *klass, MonoMethod ***overrides, int *num_overrides);
1408 void mono_reflection_create_dynamic_method (MonoReflectionDynamicMethod *m);
1409 void mono_reflection_destroy_dynamic_method (MonoReflectionDynamicMethod *mb);
1411 void mono_reflection_initialize_generic_parameter (MonoReflectionGenericParam *gparam);
1412 void mono_reflection_create_unmanaged_type (MonoReflectionType *type);
1413 void mono_reflection_register_with_runtime (MonoReflectionType *type);
1415 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);
1416 MonoMethodSignature * mono_reflection_lookup_signature (MonoImage *image, MonoMethod *method, guint32 token, MonoError *error);
1418 MonoArray* mono_param_get_objects_internal (MonoDomain *domain, MonoMethod *method, MonoClass *refclass);
1421 mono_class_bind_generic_parameters (MonoClass *klass, int type_argc, MonoType **types, gboolean is_dynamic);
1423 mono_reflection_bind_generic_parameters (MonoReflectionType *type, int type_argc, MonoType **types);
1424 MonoReflectionMethod*
1425 mono_reflection_bind_generic_method_parameters (MonoReflectionMethod *method, MonoArray *types);
1427 mono_reflection_generic_class_initialize (MonoReflectionGenericClass *type, MonoArray *fields);
1428 MonoReflectionEvent *
1429 mono_reflection_event_builder_get_event_info (MonoReflectionTypeBuilder *tb, MonoReflectionEventBuilder *eb);
1431 MonoArray *mono_reflection_sighelper_get_signature_local (MonoReflectionSigHelper *sig);
1433 MonoArray *mono_reflection_sighelper_get_signature_field (MonoReflectionSigHelper *sig);
1435 MonoReflectionMarshalAsAttribute* mono_reflection_marshal_as_attribute_from_marshal_spec (MonoDomain *domain, MonoClass *klass, MonoMarshalSpec *spec);
1438 mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context);
1441 mono_reflection_call_is_assignable_to (MonoClass *klass, MonoClass *oklass);
1444 mono_reflection_is_valid_dynamic_token (MonoDynamicImage *image, guint32 token);
1447 mono_reflection_resolve_custom_attribute_data (MonoReflectionMethod *method, MonoReflectionAssembly *assembly, gpointer data, guint32 data_length, MonoArray **ctor_args, MonoArray ** named_args);
1450 mono_reflection_type_get_handle (MonoReflectionType *ref);
1453 mono_reflection_free_dynamic_generic_class (MonoGenericClass *gclass);
1456 mono_image_build_metadata (MonoReflectionModuleBuilder *module);
1459 mono_get_constant_value_from_blob (MonoDomain* domain, MonoTypeEnum type, const char *blob, void *value);
1462 mono_release_type_locks (MonoInternalThread *thread);
1465 mono_string_to_utf8_mp (MonoMemPool *mp, MonoString *s, MonoError *error);
1468 mono_string_to_utf8_image (MonoImage *image, MonoString *s, MonoError *error);
1472 mono_array_clone_in_domain (MonoDomain *domain, MonoArray *array);
1475 mono_array_full_copy (MonoArray *src, MonoArray *dest);
1478 mono_array_calc_byte_len (MonoClass *klass, uintptr_t len, uintptr_t *res);
1480 #ifndef DISABLE_REMOTING
1482 mono_remoting_invoke (MonoObject *real_proxy, MonoMethodMessage *msg,
1483 MonoObject **exc, MonoArray **out_args);
1486 mono_remote_class_vtable (MonoDomain *domain, MonoRemoteClass *remote_class, MonoRealProxy *real_proxy);
1489 mono_upgrade_remote_class (MonoDomain *domain, MonoObject *tproxy, MonoClass *klass);
1493 mono_create_ftnptr (MonoDomain *domain, gpointer addr);
1496 mono_get_addr_from_ftnptr (gpointer descr);
1499 mono_nullable_init (guint8 *buf, MonoObject *value, MonoClass *klass);
1502 mono_nullable_box (guint8 *buf, MonoClass *klass);
1504 #ifdef MONO_SMALL_CONFIG
1505 #define MONO_IMT_SIZE 9
1507 #define MONO_IMT_SIZE 19
1512 gpointer target_code;
1515 typedef struct _MonoImtBuilderEntry {
1517 struct _MonoImtBuilderEntry *next;
1518 MonoImtItemValue value;
1520 guint8 has_target_code : 1;
1521 } MonoImtBuilderEntry;
1523 typedef struct _MonoIMTCheckItem MonoIMTCheckItem;
1525 struct _MonoIMTCheckItem {
1527 int check_target_idx;
1528 MonoImtItemValue value;
1530 guint8 *code_target;
1532 guint8 compare_done;
1534 guint8 short_branch;
1535 guint8 has_target_code;
1538 typedef gpointer (*MonoImtThunkBuilder) (MonoVTable *vtable, MonoDomain *domain,
1539 MonoIMTCheckItem **imt_entries, int count, gpointer fail_trunk);
1542 mono_install_imt_thunk_builder (MonoImtThunkBuilder func);
1545 mono_vtable_build_imt_slot (MonoVTable* vtable, int imt_slot);
1548 mono_method_get_imt_slot (MonoMethod *method);
1551 mono_method_add_generic_virtual_invocation (MonoDomain *domain, MonoVTable *vtable,
1552 gpointer *vtable_slot,
1553 MonoMethod *method, gpointer code);
1556 mono_method_alloc_generic_virtual_thunk (MonoDomain *domain, int size);
1559 MONO_UNHANDLED_POLICY_LEGACY,
1560 MONO_UNHANDLED_POLICY_CURRENT
1561 } MonoRuntimeUnhandledExceptionPolicy;
1563 MonoRuntimeUnhandledExceptionPolicy
1564 mono_runtime_unhandled_exception_policy_get (void);
1566 mono_runtime_unhandled_exception_policy_set (MonoRuntimeUnhandledExceptionPolicy policy);
1569 mono_class_try_get_vtable (MonoDomain *domain, MonoClass *klass);
1572 mono_runtime_class_init_full (MonoVTable *vtable, gboolean raise_exception);
1575 mono_method_clear_object (MonoDomain *domain, MonoMethod *method);
1578 mono_class_compute_gc_descriptor (MonoClass *klass);
1581 mono_class_compute_bitmap (MonoClass *klass, gsize *bitmap, int size, int offset, int *max_set, gboolean static_fields);
1584 mono_object_xdomain_representation (MonoObject *obj, MonoDomain *target_domain, MonoObject **exc);
1587 mono_class_is_reflection_method_or_constructor (MonoClass *klass);
1590 mono_get_object_from_blob (MonoDomain *domain, MonoType *type, const char *blob);
1593 mono_class_get_ref_info (MonoClass *klass);
1596 mono_class_set_ref_info (MonoClass *klass, gpointer obj);
1599 mono_class_free_ref_info (MonoClass *klass);
1602 mono_object_new_pinned (MonoDomain *domain, MonoClass *klass);
1605 mono_field_static_get_value_for_thread (MonoInternalThread *thread, MonoVTable *vt, MonoClassField *field, void *value);
1607 /* exported, used by the debugger */
1609 mono_vtable_get_static_field_data (MonoVTable *vt);
1612 mono_string_to_utf8_ignore (MonoString *s);
1615 mono_string_to_utf8_image_ignore (MonoImage *image, MonoString *s);
1618 mono_string_to_utf8_mp_ignore (MonoMemPool *mp, MonoString *s);
1621 mono_monitor_is_il_fastpath_wrapper (MonoMethod *method);
1624 mono_exception_get_native_backtrace (MonoException *exc);
1627 ves_icall_Mono_Runtime_GetNativeStackTrace (MonoException *exc);
1630 mono_exception_get_managed_backtrace (MonoException *exc);
1633 mono_copy_value (MonoType *type, void *dest, void *value, int deref_pointer);
1636 mono_error_raise_exception (MonoError *target_error);
1639 mono_error_set_pending_exception (MonoError *error);
1641 #endif /* __MONO_OBJECT_INTERNALS_H__ */