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;
270 MonoSystemException base;
272 MonoString *type_name;
273 } MonoTypeLoadException;
277 MonoObject *async_state;
279 MonoObject *async_delegate;
281 MonoObject *object_data;
282 MonoBoolean sync_completed;
283 MonoBoolean completed;
284 MonoBoolean endinvoke_called;
285 MonoObject *async_callback;
286 MonoObject *execution_context;
287 MonoObject *original_context;
292 MonoMarshalByRefObject object;
294 MonoBoolean disposed;
297 /* This is a copy of System.Runtime.Remoting.Messaging.CallType */
300 CallType_BeginInvoke = 1,
301 CallType_EndInvoke = 2,
305 /* This corresponds to System.Type */
306 struct _MonoReflectionType {
312 MonoReflectionType type;
313 MonoObject *type_info;
314 } MonoReflectionMonoType;
318 MonoReflectionType *class_to_proxy;
320 MonoObject *unwrapped_server;
321 gint32 target_domain_id;
322 MonoString *target_uri;
323 MonoObject *object_identity;
325 MonoObject *stub_data;
329 MonoMarshalByRefObject object;
331 GHashTable* itf_hash;
332 MonoObject *synchronization_context;
336 MonoRealProxy real_proxy;
337 MonoComObject *com_object;
339 } MonoComInteropProxy;
344 MonoRemoteClass *remote_class;
345 MonoBoolean custom_type_info;
346 } MonoTransparentProxy;
350 MonoReflectionMethod *method;
353 MonoArray *arg_types;
357 MonoAsyncResult *async_result;
364 gint32 native_offset;
365 gint64 method_address;
366 MonoReflectionMethod *method;
367 MonoString *filename;
370 MonoString *internal_method_name;
374 MONO_THREAD_FLAG_DONT_MANAGE = 1, // Don't wait for or abort this thread
375 MONO_THREAD_FLAG_NAME_SET = 2, // Thread name set from managed code
378 struct _MonoInternalThread {
380 volatile int lock_thread_id; /* to be used as the pre-shifted thread id in thin locks. Used for appdomain_ref push/pop */
382 MonoArray *cached_culture_info;
386 MonoException *abort_exc;
387 int abort_state_handle;
388 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 */
391 gpointer *static_data;
393 void *thread_info; /*This is MonoThreadInfo*, but to simplify dependencies, let's make it a void* here. */
394 MonoAppContext *current_appcontext;
395 MonoException *pending_exception;
396 MonoThread *root_domain_thread;
397 MonoObject *_serialized_principal;
398 int _serialized_principal_version;
399 gpointer appdomain_refs;
400 /* This is modified using atomic ops, so keep it a gint32 */
401 gint32 interruption_requested;
402 gpointer suspend_event;
403 gpointer suspended_event;
404 gpointer resume_event;
405 mono_mutex_t *synch_cs;
406 MonoBoolean threadpool_thread;
407 MonoBoolean thread_dump_requested;
408 MonoBoolean thread_interrupt_requested;
409 gpointer end_stack; /* This is only used when running in the debugger. */
411 guint8 apartment_state;
412 gint32 critical_region_level;
415 MonoThreadManageCallback manage_callback;
416 gpointer interrupt_on_stop;
418 gpointer android_tid;
419 gpointer thread_pinning_ref;
420 gint32 ignore_next_signal;
421 MonoMethod *async_invoke_method;
423 * These fields are used to avoid having to increment corlib versions
424 * when a new field is added to this structure.
425 * Please synchronize any changes with InternalThread in Thread.cs, i.e. add the
434 struct _MonoInternalThread *internal_thread;
435 MonoObject *start_obj;
436 MonoObject *ec_to_set;
441 MonoObject *additional;
442 } MonoStreamingContext;
446 MonoBoolean readOnly;
447 MonoString *AMDesignator;
448 MonoString *PMDesignator;
449 MonoString *DateSeparator;
450 MonoString *TimeSeparator;
451 MonoString *ShortDatePattern;
452 MonoString *LongDatePattern;
453 MonoString *ShortTimePattern;
454 MonoString *LongTimePattern;
455 MonoString *MonthDayPattern;
456 MonoString *YearMonthPattern;
457 guint32 FirstDayOfWeek;
458 guint32 CalendarWeekRule;
459 MonoArray *AbbreviatedDayNames;
461 MonoArray *MonthNames;
462 MonoArray *GenitiveMonthNames;
463 MonoArray *AbbreviatedMonthNames;
464 MonoArray *GenitiveAbbreviatedMonthNames;
465 MonoArray *ShortDatePatterns;
466 MonoArray *LongDatePatterns;
467 MonoArray *ShortTimePatterns;
468 MonoArray *LongTimePatterns;
469 MonoArray *MonthDayPatterns;
470 MonoArray *YearMonthPatterns;
471 MonoArray *ShortestDayNames;
472 } MonoDateTimeFormatInfo;
477 MonoBoolean readOnly;
478 MonoString *decimalFormats;
479 MonoString *currencyFormats;
480 MonoString *percentFormats;
481 MonoString *digitPattern;
482 MonoString *zeroPattern;
483 gint32 currencyDecimalDigits;
484 MonoString *currencyDecimalSeparator;
485 MonoString *currencyGroupSeparator;
486 MonoArray *currencyGroupSizes;
487 gint32 currencyNegativePattern;
488 gint32 currencyPositivePattern;
489 MonoString *currencySymbol;
490 MonoString *naNSymbol;
491 MonoString *negativeInfinitySymbol;
492 MonoString *negativeSign;
493 guint32 numberDecimalDigits;
494 MonoString *numberDecimalSeparator;
495 MonoString *numberGroupSeparator;
496 MonoArray *numberGroupSizes;
497 gint32 numberNegativePattern;
498 gint32 percentDecimalDigits;
499 MonoString *percentDecimalSeparator;
500 MonoString *percentGroupSeparator;
501 MonoArray *percentGroupSizes;
502 gint32 percentNegativePattern;
503 gint32 percentPositivePattern;
504 MonoString *percentSymbol;
505 MonoString *perMilleSymbol;
506 MonoString *positiveInfinitySymbol;
507 MonoString *positiveSign;
508 } MonoNumberFormatInfo;
513 MonoString *icu_name;
514 gpointer ICU_collator;
519 MonoString *NativeName;
520 MonoArray *ShortDatePatterns;
521 MonoArray *YearMonthPatterns;
522 MonoArray *LongDatePatterns;
523 MonoString *MonthDayPattern;
526 MonoArray *AbbreviatedEraNames;
527 MonoArray *AbbreviatedEnglishEraNames;
529 MonoArray *AbbreviatedDayNames;
530 MonoArray *SuperShortDayNames;
531 MonoArray *MonthNames;
532 MonoArray *AbbreviatedMonthNames;
533 MonoArray *GenitiveMonthNames;
534 MonoArray *GenitiveAbbreviatedMonthNames;
539 MonoString *AMDesignator;
540 MonoString *PMDesignator;
541 MonoString *TimeSeparator;
542 MonoArray *LongTimePatterns;
543 MonoArray *ShortTimePatterns;
544 guint32 FirstDayOfWeek;
545 guint32 CalendarWeekRule;
550 MonoBoolean is_read_only;
553 gint32 datetime_index;
555 gint32 calendar_type;
556 MonoBoolean use_user_override;
557 MonoNumberFormatInfo *number_format;
558 MonoDateTimeFormatInfo *datetime_format;
559 MonoObject *textinfo;
561 MonoString *englishname;
562 MonoString *nativename;
563 MonoString *iso3lang;
564 MonoString *iso2lang;
565 MonoString *win3lang;
566 MonoString *territory;
567 MonoArray *native_calendar_names;
568 MonoCompareInfo *compareinfo;
569 const void* text_info_data;
575 MonoString *iso2name;
576 MonoString *iso3name;
577 MonoString *win3name;
578 MonoString *english_name;
579 MonoString *native_name;
580 MonoString *currency_symbol;
581 MonoString *iso_currency_symbol;
582 MonoString *currency_english_name;
583 MonoString *currency_native_name;
597 } MonoInterfaceTypeAttribute;
600 * Callbacks supplied by the runtime and called by the modules in metadata/
601 * This interface is easier to extend than adding a new function type +
602 * a new 'install' function for every callback.
605 gpointer (*create_ftnptr) (MonoDomain *domain, gpointer addr);
606 gpointer (*get_addr_from_ftnptr) (gpointer descr);
607 char* (*get_runtime_build_info) (void);
608 gpointer (*get_vtable_trampoline) (int slot_index);
609 gpointer (*get_imt_trampoline) (int imt_slot_index);
610 void (*set_cast_details) (MonoClass *from, MonoClass *to);
611 void (*debug_log) (int level, MonoString *category, MonoString *message);
612 gboolean (*debug_log_is_enabled) (void);
613 gboolean (*tls_key_supported) (MonoTlsKey key);
614 } MonoRuntimeCallbacks;
616 typedef gboolean (*MonoInternalStackWalk) (MonoStackFrameInfo *frame, MonoContext *ctx, gpointer data);
617 typedef gboolean (*MonoInternalExceptionFrameWalk) (MonoMethod *method, gpointer ip, size_t native_offset, gboolean managed, gpointer user_data);
620 void (*mono_walk_stack_with_ctx) (MonoInternalStackWalk func, MonoContext *ctx, MonoUnwindOptions options, void *user_data);
621 void (*mono_walk_stack_with_state) (MonoInternalStackWalk func, MonoThreadUnwindState *state, MonoUnwindOptions options, void *user_data);
622 void (*mono_raise_exception) (MonoException *ex);
623 void (*mono_raise_exception_with_ctx) (MonoException *ex, MonoContext *ctx);
624 gboolean (*mono_exception_walk_trace) (MonoException *ex, MonoInternalExceptionFrameWalk func, gpointer user_data);
625 gboolean (*mono_install_handler_block_guard) (MonoThreadUnwindState *unwind_state);
626 } MonoRuntimeExceptionHandlingCallbacks;
629 /* used to free a dynamic method */
630 typedef void (*MonoFreeMethodFunc) (MonoDomain *domain, MonoMethod *method);
632 /* Used to initialize the method pointers inside vtables */
633 typedef gboolean (*MonoInitVTableFunc) (MonoVTable *vtable);
635 MONO_COLD void mono_set_pending_exception (MonoException *exc);
637 /* remoting and async support */
640 mono_async_result_new (MonoDomain *domain, HANDLE handle,
641 MonoObject *state, gpointer data, MonoObject *object_data);
644 mono_wait_handle_new (MonoDomain *domain, HANDLE handle);
647 mono_wait_handle_get_handle (MonoWaitHandle *handle);
650 mono_message_init (MonoDomain *domain, MonoMethodMessage *this_obj,
651 MonoReflectionMethod *method, MonoArray *out_args);
654 mono_message_invoke (MonoObject *target, MonoMethodMessage *msg,
655 MonoObject **exc, MonoArray **out_args);
658 mono_method_call_message_new (MonoMethod *method, gpointer *params, MonoMethod *invoke,
659 MonoDelegate **cb, MonoObject **state);
662 mono_method_return_message_restore (MonoMethod *method, gpointer *params, MonoArray *out_args);
665 mono_delegate_ctor_with_method (MonoObject *this_obj, MonoObject *target, gpointer addr, MonoMethod *method);
668 mono_delegate_ctor (MonoObject *this_obj, MonoObject *target, gpointer addr);
671 mono_class_get_allocation_ftn (MonoVTable *vtable, gboolean for_box, gboolean *pass_size_in_words);
674 mono_runtime_free_method (MonoDomain *domain, MonoMethod *method);
677 mono_install_runtime_invoke (MonoInvokeFunc func);
680 mono_install_compile_method (MonoCompileFunc func);
683 mono_install_free_method (MonoFreeMethodFunc func);
686 mono_install_callbacks (MonoRuntimeCallbacks *cbs);
688 MonoRuntimeCallbacks*
689 mono_get_runtime_callbacks (void);
692 mono_install_eh_callbacks (MonoRuntimeExceptionHandlingCallbacks *cbs);
694 MonoRuntimeExceptionHandlingCallbacks *
695 mono_get_eh_callbacks (void);
698 mono_raise_exception_with_context (MonoException *ex, MonoContext *ctx);
701 mono_type_initialization_init (void);
704 mono_type_initialization_cleanup (void);
707 mono_thread_kill (MonoInternalThread *thread, int signal);
710 mono_thread_get_tls_key (void);
713 mono_thread_get_tls_offset (void);
716 mono_domain_get_tls_key (void);
719 mono_domain_get_tls_offset (void);
721 /* Reflection and Reflection.Emit support */
724 * Handling System.Type objects:
726 * Fields defined as System.Type in managed code should be defined as MonoObject*
727 * in unmanaged structures, and the monotype_cast () function should be used for
728 * casting them to MonoReflectionType* to avoid crashes/security issues when
729 * encountering instances of user defined subclasses of System.Type.
732 #define IS_MONOTYPE(obj) (!(obj) || (((MonoObject*)(obj))->vtable->klass->image == mono_defaults.corlib && ((MonoReflectionType*)(obj))->type != NULL))
735 * Make sure the argument, which should be a System.Type is a System.MonoType object
736 * or equivalent, and not an instance of
737 * a user defined subclass of System.Type. This should be used in places were throwing
738 * an exception is safe.
740 #define CHECK_MONOTYPE(obj) do { \
741 if (!IS_MONOTYPE (obj)) \
742 mono_raise_exception (mono_get_exception_not_supported ("User defined subclasses of System.Type are not yet supported")); \
745 /* This should be used for accessing members of Type[] arrays */
746 #define mono_type_array_get(arr,index) monotype_cast (mono_array_get ((arr), gpointer, (index)))
749 * Cast an object to MonoReflectionType, making sure it is a System.MonoType or
752 static inline MonoReflectionType*
753 monotype_cast (MonoObject *obj)
755 g_assert (IS_MONOTYPE (obj));
757 return (MonoReflectionType*)obj;
761 * The following structure must match the C# implementation in our corlib.
764 struct _MonoReflectionMethod {
768 MonoReflectionType *reftype;
771 typedef struct _MonoReflectionGenericMethod MonoReflectionGenericMethod;
772 struct _MonoReflectionGenericMethod {
773 MonoReflectionMethod method;
776 struct _MonoDelegate {
778 /* The compiled code of the target method */
780 /* The invoke code */
781 gpointer invoke_impl;
784 gpointer delegate_trampoline;
786 * If non-NULL, this points to a memory location which stores the address of
787 * the compiled code of the method, or NULL if it is not yet compiled.
789 guint8 **method_code;
790 MonoReflectionMethod *method_info;
791 MonoReflectionMethod *original_method_info;
795 typedef struct _MonoMulticastDelegate MonoMulticastDelegate;
796 struct _MonoMulticastDelegate {
797 MonoDelegate delegate;
798 MonoMulticastDelegate *prev;
801 struct _MonoReflectionField {
804 MonoClassField *field;
806 MonoReflectionType *type;
810 struct _MonoReflectionProperty {
813 MonoProperty *property;
816 /*This is System.EventInfo*/
817 struct _MonoReflectionEvent {
819 MonoObject *cached_add_event;
823 MonoReflectionEvent object;
826 } MonoReflectionMonoEvent;
830 MonoReflectionType *ClassImpl;
831 MonoObject *DefaultValueImpl;
832 MonoObject *MemberImpl;
833 MonoString *NameImpl;
836 MonoObject *MarshalAsImpl;
837 } MonoReflectionParameter;
839 struct _MonoReflectionMethodBody {
844 MonoBoolean init_locals;
845 guint32 local_var_sig_token;
849 struct _MonoReflectionAssembly {
851 MonoAssembly *assembly;
852 MonoObject *resolve_event_holder;
854 MonoObject *evidence; /* Evidence */
855 MonoObject *minimum; /* PermissionSet - for SecurityAction.RequestMinimum */
856 MonoObject *optional; /* PermissionSet - for SecurityAction.RequestOptional */
857 MonoObject *refuse; /* PermissionSet - for SecurityAction.RequestRefuse */
858 MonoObject *granted; /* PermissionSet - for the resolved assembly granted permissions */
859 MonoObject *denied; /* PermissionSet - for the resolved assembly denied permissions */
861 MonoBoolean from_byte_array;
866 MonoReflectionType *utype;
872 MonoReflectionType *parent;
873 MonoReflectionType *ret;
880 MonoReflectionType *parent;
881 MonoReflectionType *declaring_type;
883 MonoReflectionMethod *get;
884 MonoReflectionMethod *set;
889 MonoReflectionType *declaring_type;
890 MonoReflectionType *reflected_type;
892 MonoReflectionMethod *add_method;
893 MonoReflectionMethod *remove_method;
894 MonoReflectionMethod *raise_method;
896 MonoArray *other_methods;
901 MonoString *name_space;
902 MonoReflectionType *etype;
903 MonoReflectionType *nested_in;
904 MonoReflectionAssembly *assembly;
906 MonoBoolean isprimitive;
912 } MonoReflectionILTokenInfo;
921 MonoArray *ex_handlers;
922 gint32 num_token_fixups;
923 MonoArray *token_fixups;
924 } MonoReflectionILGen;
931 } MonoILExceptionInfo;
938 gint32 filter_offset;
939 } MonoILExceptionBlock;
943 MonoObject *catch_type;
944 gint32 filter_offset;
948 gint32 handler_offset;
949 gint32 handler_length;
950 } MonoReflectionExceptionHandlingClause;
954 MonoReflectionType *local_type;
955 MonoBoolean is_pinned;
957 } MonoReflectionLocalVariableInfo;
961 * Must have the same layout as MonoReflectionLocalVariableInfo, since
962 * LocalBuilder inherits from it under net 2.0.
966 MonoBoolean is_pinned;
969 } MonoReflectionLocalBuilder;
978 MonoString *marshaltype;
979 MonoObject *marshaltyperef;
981 MonoBoolean has_size;
982 } MonoReflectionMarshal;
989 MonoReflectionMarshal *marshal_info;
993 MonoObject *def_value;
994 } MonoReflectionParamBuilder;
999 MonoReflectionILGen *ilgen;
1000 MonoArray *parameters;
1008 MonoBoolean init_locals;
1009 MonoArray *param_modreq;
1010 MonoArray *param_modopt;
1011 MonoArray *permissions;
1012 } MonoReflectionCtorBuilder;
1016 MonoMethod *mhandle;
1018 MonoArray *parameters;
1024 MonoReflectionILGen *ilgen;
1028 MonoArray *override_methods;
1030 MonoString *dllentry;
1032 guint32 extra_flags;
1035 MonoBoolean init_locals;
1036 MonoGenericContainer *generic_container;
1037 MonoArray *generic_params;
1038 MonoArray *return_modreq;
1039 MonoArray *return_modopt;
1040 MonoArray *param_modreq;
1041 MonoArray *param_modopt;
1042 MonoArray *permissions;
1043 } MonoReflectionMethodBuilder;
1047 MonoMethod *mhandle;
1048 MonoReflectionType *parent;
1049 MonoReflectionType *ret;
1050 MonoArray *parameters;
1054 } MonoReflectionArrayMethod;
1059 MonoString *filename;
1063 } MonoReflectionResource;
1069 MonoArray *res_data;
1070 } MonoReflectionWin32Resource;
1075 } MonoReflectionPermissionSet;
1078 MonoReflectionAssembly assembly;
1079 MonoDynamicAssembly *dynamic_assembly;
1080 MonoReflectionMethod *entry_point;
1085 MonoArray *resources;
1086 MonoArray *public_key;
1087 MonoString *version;
1088 MonoString *culture;
1092 MonoBoolean delay_sign;
1094 MonoArray *loaded_modules;
1095 MonoArray *win32_resources;
1097 MonoArray *permissions_minimum;
1098 MonoArray *permissions_optional;
1099 MonoArray *permissions_refused;
1102 MonoBoolean corlib_internal;
1103 MonoArray *type_forwarders;
1104 MonoArray *pktoken; /* as hexadecimal byte[] */
1105 } MonoReflectionAssemblyBuilder;
1112 MonoObject *def_value;
1115 MonoReflectionType *typeb;
1116 MonoArray *rva_data;
1118 MonoReflectionMarshal *marshal_info;
1119 MonoClassField *handle;
1122 } MonoReflectionFieldBuilder;
1129 MonoArray *parameters;
1131 MonoObject *def_value;
1132 MonoReflectionMethodBuilder *set_method;
1133 MonoReflectionMethodBuilder *get_method;
1135 MonoObject *type_builder;
1136 MonoArray *returnModReq;
1137 MonoArray *returnModOpt;
1138 MonoArray *paramModReq;
1139 MonoArray *paramModOpt;
1141 } MonoReflectionPropertyBuilder;
1143 struct _MonoReflectionModule {
1146 MonoReflectionAssembly *assembly;
1149 MonoString *scopename;
1150 MonoBoolean is_resource;
1155 MonoReflectionModule module;
1156 MonoDynamicImage *dynamic_image;
1162 MonoReflectionAssemblyBuilder *assemblyb;
1163 MonoArray *global_methods;
1164 MonoArray *global_fields;
1166 MonoArray *resources;
1167 } MonoReflectionModuleBuilder;
1170 MonoReflectionType type;
1174 MonoReflectionType *nesting_type;
1175 MonoArray *interfaces;
1179 MonoArray *properties;
1184 MonoArray *subtypes;
1187 MonoReflectionModuleBuilder *module;
1189 gint32 packing_size;
1190 MonoGenericContainer *generic_container;
1191 MonoArray *generic_params;
1192 MonoArray *permissions;
1193 MonoReflectionType *created;
1194 } MonoReflectionTypeBuilder;
1197 MonoReflectionType type;
1198 MonoReflectionType *element_type;
1200 } MonoReflectionArrayType;
1203 MonoReflectionType type;
1204 MonoReflectionType *element_type;
1205 } MonoReflectionDerivedType;
1208 MonoReflectionType type;
1209 MonoReflectionTypeBuilder *tbuilder;
1210 MonoReflectionMethodBuilder *mbuilder;
1213 MonoReflectionType *base_type;
1214 MonoArray *iface_constraints;
1217 } MonoReflectionGenericParam;
1219 typedef struct _MonoReflectionGenericClass MonoReflectionGenericClass;
1220 struct _MonoReflectionGenericClass {
1221 MonoReflectionType type;
1222 MonoReflectionType *generic_type; /*Can be either a MonoType or a TypeBuilder*/
1223 MonoArray *type_arguments;
1224 guint32 initialized;
1230 MonoString *codebase;
1231 gint32 major, minor, build, revision;
1232 MonoObject *cultureInfo;
1235 MonoObject *keypair;
1236 MonoArray *publicKey;
1237 MonoArray *keyToken;
1238 guint32 versioncompat;
1239 MonoObject *version;
1240 guint32 processor_architecture;
1241 } MonoReflectionAssemblyName;
1246 MonoReflectionType *type;
1247 MonoReflectionTypeBuilder *typeb;
1249 MonoReflectionMethodBuilder *add_method;
1250 MonoReflectionMethodBuilder *remove_method;
1251 MonoReflectionMethodBuilder *raise_method;
1252 MonoArray *other_methods;
1255 } MonoReflectionEventBuilder;
1259 MonoReflectionMethod *ctor;
1261 } MonoReflectionCustomAttr;
1265 MonoString *marshal_cookie;
1266 MonoString *marshal_type;
1267 MonoReflectionType *marshal_type_ref;
1268 MonoReflectionType *marshal_safe_array_user_defined_subtype;
1270 guint32 array_subtype;
1271 gint32 safe_array_subtype;
1273 gint32 IidParameterIndex;
1274 gint16 size_param_index;
1275 } MonoReflectionMarshalAsAttribute;
1283 MonoString *entry_point;
1284 MonoBoolean exact_spelling;
1285 MonoBoolean preserve_sig;
1286 MonoBoolean set_last_error;
1287 MonoBoolean best_fit_mapping;
1288 MonoBoolean throw_on_unmappable;
1289 } MonoReflectionDllImportAttribute;
1295 MonoBoolean set_last_error;
1296 MonoBoolean best_fit_mapping;
1297 MonoBoolean throw_on_unmappable;
1298 } MonoReflectionUnmanagedFunctionPointerAttribute;
1303 } MonoReflectionGuidAttribute;
1307 MonoMethod *mhandle;
1309 MonoReflectionType *rtype;
1310 MonoArray *parameters;
1313 MonoReflectionModule *module;
1314 MonoBoolean skip_visibility;
1315 MonoBoolean init_locals;
1316 MonoReflectionILGen *ilgen;
1319 GSList *referenced_by;
1320 MonoReflectionType *owner;
1321 } MonoReflectionDynamicMethod;
1325 MonoReflectionModuleBuilder *module;
1326 MonoArray *arguments;
1328 MonoReflectionType *return_type;
1330 guint32 unmanaged_call_conv;
1333 } MonoReflectionSigHelper;
1337 MonoReflectionGenericClass *inst;
1338 MonoObject *fb; /*can be either a MonoField or a FieldBuilder*/
1339 } MonoReflectionFieldOnTypeBuilderInst;
1343 MonoReflectionGenericClass *inst;
1344 MonoObject *cb; /*can be either a MonoCMethod or ConstructorBuilder*/
1345 } MonoReflectionCtorOnTypeBuilderInst;
1349 MonoReflectionType *inst;
1350 MonoObject *mb; /*can be either a MonoMethod or MethodBuilder*/
1351 MonoArray *method_args;
1352 MonoReflectionMethodBuilder *generic_method_definition;
1353 } MonoReflectionMethodOnTypeBuilderInst;
1357 MonoBoolean visible;
1358 } MonoReflectionComVisibleAttribute;
1361 RESOURCE_LOCATION_EMBEDDED = 1,
1362 RESOURCE_LOCATION_ANOTHER_ASSEMBLY = 2,
1363 RESOURCE_LOCATION_IN_MANIFEST = 4
1368 MonoReflectionAssembly *assembly;
1369 MonoString *filename;
1371 } MonoManifestResourceInfo;
1373 /* A boxed IntPtr */
1379 /* Keep in sync with System.GenericParameterAttributes */
1381 GENERIC_PARAMETER_ATTRIBUTE_NON_VARIANT = 0,
1382 GENERIC_PARAMETER_ATTRIBUTE_COVARIANT = 1,
1383 GENERIC_PARAMETER_ATTRIBUTE_CONTRAVARIANT = 2,
1384 GENERIC_PARAMETER_ATTRIBUTE_VARIANCE_MASK = 3,
1386 GENERIC_PARAMETER_ATTRIBUTE_NO_SPECIAL_CONSTRAINT = 0,
1387 GENERIC_PARAMETER_ATTRIBUTE_REFERENCE_TYPE_CONSTRAINT = 4,
1388 GENERIC_PARAMETER_ATTRIBUTE_VALUE_TYPE_CONSTRAINT = 8,
1389 GENERIC_PARAMETER_ATTRIBUTE_CONSTRUCTOR_CONSTRAINT = 16,
1390 GENERIC_PARAMETER_ATTRIBUTE_SPECIAL_CONSTRAINTS_MASK = 28
1391 } GenericParameterAttributes;
1395 MonoClassField *field;
1399 void mono_image_create_pefile (MonoReflectionModuleBuilder *module, HANDLE file);
1400 void mono_image_basic_init (MonoReflectionAssemblyBuilder *assembly);
1401 MonoReflectionModule * mono_image_load_module_dynamic (MonoReflectionAssemblyBuilder *assembly, MonoString *file_name);
1402 guint32 mono_image_insert_string (MonoReflectionModuleBuilder *module, MonoString *str);
1403 guint32 mono_image_create_token (MonoDynamicImage *assembly, MonoObject *obj, gboolean create_methodspec, gboolean register_token);
1404 guint32 mono_image_create_method_token (MonoDynamicImage *assembly, MonoObject *obj, MonoArray *opt_param_types);
1405 void mono_image_module_basic_init (MonoReflectionModuleBuilder *module);
1406 void mono_image_register_token (MonoDynamicImage *assembly, guint32 token, MonoObject *obj);
1407 void mono_dynamic_image_free (MonoDynamicImage *image);
1408 void mono_dynamic_image_free_image (MonoDynamicImage *image);
1409 void mono_image_set_wrappers_type (MonoReflectionModuleBuilder *mb, MonoReflectionType *type);
1410 void mono_dynamic_image_release_gc_roots (MonoDynamicImage *image);
1412 void mono_reflection_setup_internal_class (MonoReflectionTypeBuilder *tb);
1414 void mono_reflection_create_internal_class (MonoReflectionTypeBuilder *tb);
1416 void mono_reflection_setup_generic_class (MonoReflectionTypeBuilder *tb);
1418 void mono_reflection_create_generic_class (MonoReflectionTypeBuilder *tb);
1420 MonoReflectionType* mono_reflection_create_runtime_class (MonoReflectionTypeBuilder *tb);
1422 void mono_reflection_get_dynamic_overrides (MonoClass *klass, MonoMethod ***overrides, int *num_overrides);
1424 void mono_reflection_create_dynamic_method (MonoReflectionDynamicMethod *m);
1425 void mono_reflection_destroy_dynamic_method (MonoReflectionDynamicMethod *mb);
1427 void mono_reflection_initialize_generic_parameter (MonoReflectionGenericParam *gparam);
1428 void mono_reflection_create_unmanaged_type (MonoReflectionType *type);
1429 void mono_reflection_register_with_runtime (MonoReflectionType *type);
1431 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);
1432 MonoMethodSignature * mono_reflection_lookup_signature (MonoImage *image, MonoMethod *method, guint32 token, MonoError *error);
1434 MonoArray* mono_param_get_objects_internal (MonoDomain *domain, MonoMethod *method, MonoClass *refclass);
1437 mono_class_bind_generic_parameters (MonoClass *klass, int type_argc, MonoType **types, gboolean is_dynamic);
1439 mono_reflection_bind_generic_parameters (MonoReflectionType *type, int type_argc, MonoType **types);
1440 MonoReflectionMethod*
1441 mono_reflection_bind_generic_method_parameters (MonoReflectionMethod *method, MonoArray *types);
1443 mono_reflection_generic_class_initialize (MonoReflectionGenericClass *type, MonoArray *fields);
1444 MonoReflectionEvent *
1445 mono_reflection_event_builder_get_event_info (MonoReflectionTypeBuilder *tb, MonoReflectionEventBuilder *eb);
1447 MonoArray *mono_reflection_sighelper_get_signature_local (MonoReflectionSigHelper *sig);
1449 MonoArray *mono_reflection_sighelper_get_signature_field (MonoReflectionSigHelper *sig);
1451 MonoReflectionMarshalAsAttribute* mono_reflection_marshal_as_attribute_from_marshal_spec (MonoDomain *domain, MonoClass *klass, MonoMarshalSpec *spec);
1454 mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context);
1457 mono_reflection_call_is_assignable_to (MonoClass *klass, MonoClass *oklass);
1460 mono_reflection_is_valid_dynamic_token (MonoDynamicImage *image, guint32 token);
1463 mono_reflection_resolve_custom_attribute_data (MonoReflectionMethod *method, MonoReflectionAssembly *assembly, gpointer data, guint32 data_length, MonoArray **ctor_args, MonoArray ** named_args);
1466 mono_reflection_type_get_handle (MonoReflectionType *ref);
1469 mono_reflection_free_dynamic_generic_class (MonoGenericClass *gclass);
1472 mono_image_build_metadata (MonoReflectionModuleBuilder *module);
1475 mono_get_constant_value_from_blob (MonoDomain* domain, MonoTypeEnum type, const char *blob, void *value);
1478 mono_release_type_locks (MonoInternalThread *thread);
1481 mono_string_to_utf8_mp (MonoMemPool *mp, MonoString *s, MonoError *error);
1484 mono_string_to_utf8_image (MonoImage *image, MonoString *s, MonoError *error);
1488 mono_array_clone_in_domain (MonoDomain *domain, MonoArray *array);
1491 mono_array_full_copy (MonoArray *src, MonoArray *dest);
1494 mono_array_calc_byte_len (MonoClass *klass, uintptr_t len, uintptr_t *res);
1496 #ifndef DISABLE_REMOTING
1498 mono_remoting_invoke (MonoObject *real_proxy, MonoMethodMessage *msg,
1499 MonoObject **exc, MonoArray **out_args);
1502 mono_remote_class_vtable (MonoDomain *domain, MonoRemoteClass *remote_class, MonoRealProxy *real_proxy);
1505 mono_upgrade_remote_class (MonoDomain *domain, MonoObject *tproxy, MonoClass *klass);
1509 mono_create_ftnptr (MonoDomain *domain, gpointer addr);
1512 mono_get_addr_from_ftnptr (gpointer descr);
1515 mono_nullable_init (guint8 *buf, MonoObject *value, MonoClass *klass);
1518 mono_nullable_box (guint8 *buf, MonoClass *klass);
1520 #ifdef MONO_SMALL_CONFIG
1521 #define MONO_IMT_SIZE 9
1523 #define MONO_IMT_SIZE 19
1528 gpointer target_code;
1531 typedef struct _MonoImtBuilderEntry {
1533 struct _MonoImtBuilderEntry *next;
1534 MonoImtItemValue value;
1536 guint8 has_target_code : 1;
1537 } MonoImtBuilderEntry;
1539 typedef struct _MonoIMTCheckItem MonoIMTCheckItem;
1541 struct _MonoIMTCheckItem {
1543 int check_target_idx;
1544 MonoImtItemValue value;
1546 guint8 *code_target;
1548 guint8 compare_done;
1550 guint8 short_branch;
1551 guint8 has_target_code;
1554 typedef gpointer (*MonoImtThunkBuilder) (MonoVTable *vtable, MonoDomain *domain,
1555 MonoIMTCheckItem **imt_entries, int count, gpointer fail_trunk);
1558 mono_install_imt_thunk_builder (MonoImtThunkBuilder func);
1561 mono_vtable_build_imt_slot (MonoVTable* vtable, int imt_slot);
1564 mono_method_get_imt_slot (MonoMethod *method);
1567 mono_method_add_generic_virtual_invocation (MonoDomain *domain, MonoVTable *vtable,
1568 gpointer *vtable_slot,
1569 MonoMethod *method, gpointer code);
1572 mono_method_alloc_generic_virtual_thunk (MonoDomain *domain, int size);
1575 MONO_UNHANDLED_POLICY_LEGACY,
1576 MONO_UNHANDLED_POLICY_CURRENT
1577 } MonoRuntimeUnhandledExceptionPolicy;
1579 MonoRuntimeUnhandledExceptionPolicy
1580 mono_runtime_unhandled_exception_policy_get (void);
1582 mono_runtime_unhandled_exception_policy_set (MonoRuntimeUnhandledExceptionPolicy policy);
1585 mono_class_try_get_vtable (MonoDomain *domain, MonoClass *klass);
1588 mono_runtime_class_init_full (MonoVTable *vtable, gboolean raise_exception);
1591 mono_method_clear_object (MonoDomain *domain, MonoMethod *method);
1594 mono_class_compute_gc_descriptor (MonoClass *klass);
1597 mono_class_compute_bitmap (MonoClass *klass, gsize *bitmap, int size, int offset, int *max_set, gboolean static_fields);
1600 mono_object_xdomain_representation (MonoObject *obj, MonoDomain *target_domain, MonoObject **exc);
1603 mono_class_is_reflection_method_or_constructor (MonoClass *klass);
1606 mono_get_object_from_blob (MonoDomain *domain, MonoType *type, const char *blob);
1609 mono_class_get_ref_info (MonoClass *klass);
1612 mono_class_set_ref_info (MonoClass *klass, gpointer obj);
1615 mono_class_free_ref_info (MonoClass *klass);
1618 mono_object_new_pinned (MonoDomain *domain, MonoClass *klass);
1621 mono_field_static_get_value_for_thread (MonoInternalThread *thread, MonoVTable *vt, MonoClassField *field, void *value);
1623 /* exported, used by the debugger */
1625 mono_vtable_get_static_field_data (MonoVTable *vt);
1628 mono_string_to_utf8_ignore (MonoString *s);
1631 mono_string_to_utf8_image_ignore (MonoImage *image, MonoString *s);
1634 mono_string_to_utf8_mp_ignore (MonoMemPool *mp, MonoString *s);
1637 mono_monitor_is_il_fastpath_wrapper (MonoMethod *method);
1640 mono_exception_get_native_backtrace (MonoException *exc);
1643 ves_icall_Mono_Runtime_GetNativeStackTrace (MonoException *exc);
1646 mono_exception_get_managed_backtrace (MonoException *exc);
1648 #endif /* __MONO_OBJECT_INTERNALS_H__ */