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"
15 #include "mono/utils/mono-coop-mutex.h"
19 #define mono_assert(expr) G_STMT_START{ \
23 char *msg = g_strdup_printf ("file %s: line %d (%s): " \
24 "assertion failed: (%s)", __FILE__, __LINE__, \
25 __PRETTY_FUNCTION__, #expr); \
26 ex = mono_get_exception_execution_engine (msg); \
28 mono_raise_exception (ex); \
31 #define mono_assert_not_reached() G_STMT_START{ \
33 char *msg = g_strdup_printf ("file %s: line %d (%s): " \
34 "should not be reached", __FILE__, __LINE__, __PRETTY_FUNCTION__); \
35 ex = mono_get_exception_execution_engine (msg); \
37 mono_raise_exception (ex); \
40 #define mono_assert(expr) G_STMT_START{ \
44 char *msg = g_strdup_printf ("file %s: line %d: " \
45 "assertion failed: (%s)", __FILE__, __LINE__, \
47 ex = mono_get_exception_execution_engine (msg); \
49 mono_raise_exception (ex); \
52 #define mono_assert_not_reached() G_STMT_START{ \
54 char *msg = g_strdup_printf ("file %s: line %d): " \
55 "should not be reached", __FILE__, __LINE__); \
56 ex = mono_get_exception_execution_engine (msg); \
58 mono_raise_exception (ex); \
62 #define mono_assert(expr) g_assert(expr)
63 #define mono_assert_not_reached() g_assert_not_reached()
66 /* Use this as MONO_CHECK_ARG_NULL (arg,expr,) in functions returning void */
67 #define MONO_CHECK_ARG(arg, expr, retval) G_STMT_START{ \
68 if (G_UNLIKELY (!(expr))) \
71 char *msg = g_strdup_printf ("assertion `%s' failed", \
73 if (arg) {} /* check if the name exists */ \
74 ex = mono_get_exception_argument (#arg, msg); \
76 mono_set_pending_exception (ex); \
80 /* Use this as MONO_CHECK_ARG_NULL (arg,) in functions returning void */
81 #define MONO_CHECK_ARG_NULL(arg, retval) G_STMT_START{ \
82 if (G_UNLIKELY (arg == NULL)) \
85 if (arg) {} /* check if the name exists */ \
86 ex = mono_get_exception_argument_null (#arg); \
87 mono_set_pending_exception (ex); \
91 #define mono_string_builder_capacity(sb) sb->chunkOffset + sb->chunkChars->max_length
92 #define mono_string_builder_string_length(sb) sb->chunkOffset + sb->chunkLength
95 * Macros which cache the results of lookups locally.
96 * These should be used instead of the original versions, if the __GNUC__
97 * restriction is acceptable.
102 /* namespace and name should be a constant */
103 /* image must be mscorlib since other assemblies can be unloaded */
104 #define mono_class_from_name_cached(image,namespace,name) ({ \
105 static MonoClass *tmp_klass; \
107 g_assert (image == mono_defaults.corlib); \
108 tmp_klass = mono_class_from_name ((image), (namespace), (name)); \
109 g_assert (tmp_klass); \
112 /* name should be a compile-time constant */
113 #define mono_class_get_field_from_name_cached(klass,name) ({ \
114 static MonoClassField *tmp_field; \
116 tmp_field = mono_class_get_field_from_name ((klass), (name)); \
117 g_assert (tmp_field); \
120 /* eclass should be a run-time constant */
121 #define mono_array_class_get_cached(eclass,rank) ({ \
122 static MonoClass *tmp_klass; \
124 tmp_klass = mono_array_class_get ((eclass), (rank)); \
125 g_assert (tmp_klass); \
128 /* eclass should be a run-time constant */
129 #define mono_array_new_cached(domain, eclass, size) mono_array_new_specific (mono_class_vtable ((domain), mono_array_class_get_cached ((eclass), 1)), (size))
133 #define mono_class_from_name_cached(image,namespace,name) mono_class_from_name ((image), (namespace), (name))
134 #define mono_class_get_field_from_name_cached(klass,name) mono_class_get_field_from_name ((klass), (name))
135 #define mono_array_class_get_cached(eclass,rank) mono_array_class_get ((eclass), (rank))
136 #define mono_array_new_cached(domain, eclass, size) mono_array_new_specific (mono_class_vtable ((domain), mono_array_class_get_cached ((eclass), 1)), (size))
140 #ifdef MONO_BIG_ARRAYS
141 typedef uint64_t mono_array_size_t;
142 typedef int64_t mono_array_lower_bound_t;
143 #define MONO_ARRAY_MAX_INDEX G_MAXINT64
144 #define MONO_ARRAY_MAX_SIZE G_MAXUINT64
146 typedef uint32_t mono_array_size_t;
147 typedef int32_t mono_array_lower_bound_t;
148 #define MONO_ARRAY_MAX_INDEX ((int32_t) 0x7fffffff)
149 #define MONO_ARRAY_MAX_SIZE ((uint32_t) 0xffffffff)
153 mono_array_size_t length;
154 mono_array_lower_bound_t lower_bound;
159 /* bounds is NULL for szarrays */
160 MonoArrayBounds *bounds;
161 /* total number of elements of the array */
162 mono_array_size_t max_length;
163 /* we use double to ensure proper alignment on platforms that need it */
164 double vector [MONO_ZERO_LEN_ARRAY];
167 #define MONO_SIZEOF_MONO_ARRAY (sizeof (MonoArray) - MONO_ZERO_LEN_ARRAY * sizeof (double))
172 mono_unichar2 chars [MONO_ZERO_LEN_ARRAY];
175 #define mono_object_class(obj) (((MonoObject*)(obj))->vtable->klass)
176 #define mono_object_domain(obj) (((MonoObject*)(obj))->vtable->domain)
178 #define mono_string_chars_fast(s) ((mono_unichar2*)(s)->chars)
179 #define mono_string_length_fast(s) ((s)->length)
181 #define mono_array_length_fast(array) ((array)->max_length)
182 #define mono_array_addr_with_size_fast(array,size,index) ( ((char*)(array)->vector) + (size) * (index) )
184 #define mono_array_addr_fast(array,type,index) ((type*)(void*) mono_array_addr_with_size_fast (array, sizeof (type), index))
185 #define mono_array_get_fast(array,type,index) ( *(type*)mono_array_addr_fast ((array), type, (index)) )
186 #define mono_array_set_fast(array,type,index,value) \
188 type *__p = (type *) mono_array_addr_fast ((array), type, (index)); \
191 #define mono_array_setref_fast(array,index,value) \
193 void **__p = (void **) mono_array_addr_fast ((array), void*, (index)); \
194 mono_gc_wbarrier_set_arrayref ((array), __p, (MonoObject*)(value)); \
195 /* *__p = (value);*/ \
197 #define mono_array_memcpy_refs_fast(dest,destidx,src,srcidx,count) \
199 void **__p = (void **) mono_array_addr_fast ((dest), void*, (destidx)); \
200 void **__s = mono_array_addr_fast ((src), void*, (srcidx)); \
201 mono_gc_wbarrier_arrayref_copy (__p, __s, (count)); \
207 MonoObject *identity;
208 } MonoMarshalByRefObject;
210 /* This is a copy of System.AppDomain */
211 struct _MonoAppDomain {
212 MonoMarshalByRefObject mbr;
216 typedef struct _MonoStringBuilder MonoStringBuilder;
218 struct _MonoStringBuilder {
220 MonoArray *chunkChars;
221 MonoStringBuilder* chunkPrevious; // Link to the block logically before this block
222 int chunkLength; // The index in ChunkChars that represent the end of the block
223 int chunkOffset; // The logial offset (sum of all characters in previous blocks)
235 } MonoArgumentHandle;
238 MonoMethodSignature *sig;
244 struct _MonoException {
246 /* Stores the IPs and the generic sharing infos
247 (vtable/MRGCTX) of the frames. */
248 MonoArray *trace_ips;
249 MonoObject *inner_ex;
251 MonoString *help_link;
252 MonoString *class_name;
253 MonoString *stack_trace;
254 MonoString *remote_stack_trace;
255 gint32 remote_stack_index;
259 MonoObject *captured_traces;
260 MonoArray *native_trace_ips;
261 /* Dynamic methods referenced by the stack trace */
262 MonoObject *dynamic_methods;
267 } MonoSystemException;
270 MonoSystemException base;
271 MonoString *param_name;
272 } MonoArgumentException;
276 MonoObject *async_state;
278 MonoObject *async_delegate;
280 MonoObject *object_data;
281 MonoBoolean sync_completed;
282 MonoBoolean completed;
283 MonoBoolean endinvoke_called;
284 MonoObject *async_callback;
285 MonoObject *execution_context;
286 MonoObject *original_context;
291 MonoMarshalByRefObject object;
293 MonoBoolean disposed;
296 /* This is a copy of System.Runtime.Remoting.Messaging.CallType */
299 CallType_BeginInvoke = 1,
300 CallType_EndInvoke = 2,
304 /* This corresponds to System.Type */
305 struct _MonoReflectionType {
311 MonoReflectionType type;
312 MonoObject *type_info;
313 } MonoReflectionMonoType;
317 MonoReflectionType *class_to_proxy;
319 MonoObject *unwrapped_server;
320 gint32 target_domain_id;
321 MonoString *target_uri;
322 MonoObject *object_identity;
324 MonoObject *stub_data;
328 MonoMarshalByRefObject object;
330 GHashTable* itf_hash;
331 MonoObject *synchronization_context;
335 MonoRealProxy real_proxy;
336 MonoComObject *com_object;
338 } MonoComInteropProxy;
343 MonoRemoteClass *remote_class;
344 MonoBoolean custom_type_info;
345 } MonoTransparentProxy;
349 MonoReflectionMethod *method;
352 MonoArray *arg_types;
356 MonoAsyncResult *async_result;
360 /* Keep in sync with the System.MonoAsyncCall */
363 MonoMethodMessage *msg;
364 MonoMethod *cb_method;
365 MonoDelegate *cb_target;
374 gint32 native_offset;
375 gint64 method_address;
377 MonoReflectionMethod *method;
378 MonoString *filename;
381 MonoString *internal_method_name;
385 MONO_THREAD_FLAG_DONT_MANAGE = 1, // Don't wait for or abort this thread
386 MONO_THREAD_FLAG_NAME_SET = 2, // Thread name set from managed code
389 struct _MonoInternalThread {
391 volatile int lock_thread_id; /* to be used as the pre-shifted thread id in thin locks. Used for appdomain_ref push/pop */
393 MonoArray *cached_culture_info;
397 MonoException *abort_exc;
398 int abort_state_handle;
399 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 */
402 gpointer *static_data;
403 void *thread_info; /*This is MonoThreadInfo*, but to simplify dependencies, let's make it a void* here. */
404 MonoAppContext *current_appcontext;
405 MonoException *pending_exception;
406 MonoThread *root_domain_thread;
407 MonoObject *_serialized_principal;
408 int _serialized_principal_version;
409 gpointer appdomain_refs;
410 /* This is modified using atomic ops, so keep it a gint32 */
411 gint32 interruption_requested;
412 MonoCoopMutex *synch_cs;
413 MonoBoolean threadpool_thread;
414 MonoBoolean thread_interrupt_requested;
416 guint8 apartment_state;
417 gint32 critical_region_level;
420 MonoThreadManageCallback manage_callback;
421 gpointer interrupt_on_stop;
423 gpointer thread_pinning_ref;
425 * These fields are used to avoid having to increment corlib versions
426 * when a new field is added to this structure.
427 * Please synchronize any changes with InternalThread in Thread.cs, i.e. add the
436 struct _MonoInternalThread *internal_thread;
437 MonoObject *start_obj;
442 MonoObject *additional;
443 } MonoStreamingContext;
447 MonoBoolean readOnly;
448 MonoString *AMDesignator;
449 MonoString *PMDesignator;
450 MonoString *DateSeparator;
451 MonoString *TimeSeparator;
452 MonoString *ShortDatePattern;
453 MonoString *LongDatePattern;
454 MonoString *ShortTimePattern;
455 MonoString *LongTimePattern;
456 MonoString *MonthDayPattern;
457 MonoString *YearMonthPattern;
458 guint32 FirstDayOfWeek;
459 guint32 CalendarWeekRule;
460 MonoArray *AbbreviatedDayNames;
462 MonoArray *MonthNames;
463 MonoArray *GenitiveMonthNames;
464 MonoArray *AbbreviatedMonthNames;
465 MonoArray *GenitiveAbbreviatedMonthNames;
466 MonoArray *ShortDatePatterns;
467 MonoArray *LongDatePatterns;
468 MonoArray *ShortTimePatterns;
469 MonoArray *LongTimePatterns;
470 MonoArray *MonthDayPatterns;
471 MonoArray *YearMonthPatterns;
472 MonoArray *ShortestDayNames;
473 } MonoDateTimeFormatInfo;
478 MonoArray *numberGroupSizes;
479 MonoArray *currencyGroupSizes;
480 MonoArray *percentGroupSizes;
481 MonoString *positiveSign;
482 MonoString *negativeSign;
483 MonoString *numberDecimalSeparator;
484 MonoString *numberGroupSeparator;
485 MonoString *currencyGroupSeparator;
486 MonoString *currencyDecimalSeparator;
487 MonoString *currencySymbol;
488 MonoString *ansiCurrencySymbol; /* unused */
489 MonoString *naNSymbol;
490 MonoString *positiveInfinitySymbol;
491 MonoString *negativeInfinitySymbol;
492 MonoString *percentDecimalSeparator;
493 MonoString *percentGroupSeparator;
494 MonoString *percentSymbol;
495 MonoString *perMilleSymbol;
496 MonoString *nativeDigits; /* unused */
497 gint32 dataItem; /* unused */
498 guint32 numberDecimalDigits;
499 gint32 currencyDecimalDigits;
500 gint32 currencyPositivePattern;
501 gint32 currencyNegativePattern;
502 gint32 numberNegativePattern;
503 gint32 percentPositivePattern;
504 gint32 percentNegativePattern;
505 gint32 percentDecimalDigits;
506 } MonoNumberFormatInfo;
511 MonoString *icu_name;
512 gpointer ICU_collator;
517 MonoString *NativeName;
518 MonoArray *ShortDatePatterns;
519 MonoArray *YearMonthPatterns;
520 MonoArray *LongDatePatterns;
521 MonoString *MonthDayPattern;
524 MonoArray *AbbreviatedEraNames;
525 MonoArray *AbbreviatedEnglishEraNames;
527 MonoArray *AbbreviatedDayNames;
528 MonoArray *SuperShortDayNames;
529 MonoArray *MonthNames;
530 MonoArray *AbbreviatedMonthNames;
531 MonoArray *GenitiveMonthNames;
532 MonoArray *GenitiveAbbreviatedMonthNames;
537 MonoString *AMDesignator;
538 MonoString *PMDesignator;
539 MonoString *TimeSeparator;
540 MonoArray *LongTimePatterns;
541 MonoArray *ShortTimePatterns;
542 guint32 FirstDayOfWeek;
543 guint32 CalendarWeekRule;
548 MonoBoolean is_read_only;
551 gint32 datetime_index;
553 gint32 calendar_type;
554 MonoBoolean use_user_override;
555 MonoNumberFormatInfo *number_format;
556 MonoDateTimeFormatInfo *datetime_format;
557 MonoObject *textinfo;
559 MonoString *englishname;
560 MonoString *nativename;
561 MonoString *iso3lang;
562 MonoString *iso2lang;
563 MonoString *win3lang;
564 MonoString *territory;
565 MonoArray *native_calendar_names;
566 MonoCompareInfo *compareinfo;
567 const void* text_info_data;
573 MonoString *iso2name;
574 MonoString *iso3name;
575 MonoString *win3name;
576 MonoString *english_name;
577 MonoString *native_name;
578 MonoString *currency_symbol;
579 MonoString *iso_currency_symbol;
580 MonoString *currency_english_name;
581 MonoString *currency_native_name;
595 } MonoInterfaceTypeAttribute;
598 * Callbacks supplied by the runtime and called by the modules in metadata/
599 * This interface is easier to extend than adding a new function type +
600 * a new 'install' function for every callback.
603 gpointer (*create_ftnptr) (MonoDomain *domain, gpointer addr);
604 gpointer (*get_addr_from_ftnptr) (gpointer descr);
605 char* (*get_runtime_build_info) (void);
606 gpointer (*get_vtable_trampoline) (int slot_index);
607 gpointer (*get_imt_trampoline) (int imt_slot_index);
608 void (*set_cast_details) (MonoClass *from, MonoClass *to);
609 void (*debug_log) (int level, MonoString *category, MonoString *message);
610 gboolean (*debug_log_is_enabled) (void);
611 gboolean (*tls_key_supported) (MonoTlsKey key);
612 } MonoRuntimeCallbacks;
614 typedef gboolean (*MonoInternalStackWalk) (MonoStackFrameInfo *frame, MonoContext *ctx, gpointer data);
615 typedef gboolean (*MonoInternalExceptionFrameWalk) (MonoMethod *method, gpointer ip, size_t native_offset, gboolean managed, gpointer user_data);
618 void (*mono_walk_stack_with_ctx) (MonoInternalStackWalk func, MonoContext *ctx, MonoUnwindOptions options, void *user_data);
619 void (*mono_walk_stack_with_state) (MonoInternalStackWalk func, MonoThreadUnwindState *state, MonoUnwindOptions options, void *user_data);
620 void (*mono_raise_exception) (MonoException *ex);
621 void (*mono_raise_exception_with_ctx) (MonoException *ex, MonoContext *ctx);
622 gboolean (*mono_exception_walk_trace) (MonoException *ex, MonoInternalExceptionFrameWalk func, gpointer user_data);
623 gboolean (*mono_install_handler_block_guard) (MonoThreadUnwindState *unwind_state);
624 } MonoRuntimeExceptionHandlingCallbacks;
627 /* used to free a dynamic method */
628 typedef void (*MonoFreeMethodFunc) (MonoDomain *domain, MonoMethod *method);
630 /* Used to initialize the method pointers inside vtables */
631 typedef gboolean (*MonoInitVTableFunc) (MonoVTable *vtable);
633 MONO_COLD void mono_set_pending_exception (MonoException *exc);
635 /* remoting and async support */
638 mono_async_result_new (MonoDomain *domain, HANDLE handle,
639 MonoObject *state, gpointer data, MonoObject *object_data);
642 ves_icall_System_Runtime_Remoting_Messaging_AsyncResult_Invoke (MonoAsyncResult *ares);
645 mono_wait_handle_new (MonoDomain *domain, HANDLE handle);
648 mono_wait_handle_get_handle (MonoWaitHandle *handle);
651 mono_message_init (MonoDomain *domain, MonoMethodMessage *this_obj,
652 MonoReflectionMethod *method, MonoArray *out_args);
655 mono_message_invoke (MonoObject *target, MonoMethodMessage *msg,
656 MonoObject **exc, MonoArray **out_args);
659 mono_method_call_message_new (MonoMethod *method, gpointer *params, MonoMethod *invoke,
660 MonoDelegate **cb, MonoObject **state);
663 mono_method_return_message_restore (MonoMethod *method, gpointer *params, MonoArray *out_args);
666 mono_delegate_ctor_with_method (MonoObject *this_obj, MonoObject *target, gpointer addr, MonoMethod *method);
669 mono_delegate_ctor (MonoObject *this_obj, MonoObject *target, gpointer addr);
672 mono_class_get_allocation_ftn (MonoVTable *vtable, gboolean for_box, gboolean *pass_size_in_words);
675 mono_runtime_free_method (MonoDomain *domain, MonoMethod *method);
678 mono_install_runtime_invoke (MonoInvokeFunc func);
681 mono_install_compile_method (MonoCompileFunc func);
684 mono_install_free_method (MonoFreeMethodFunc func);
687 mono_install_callbacks (MonoRuntimeCallbacks *cbs);
689 MonoRuntimeCallbacks*
690 mono_get_runtime_callbacks (void);
693 mono_install_eh_callbacks (MonoRuntimeExceptionHandlingCallbacks *cbs);
695 MonoRuntimeExceptionHandlingCallbacks *
696 mono_get_eh_callbacks (void);
699 mono_raise_exception_with_context (MonoException *ex, MonoContext *ctx);
702 mono_type_initialization_init (void);
705 mono_type_initialization_cleanup (void);
708 mono_thread_kill (MonoInternalThread *thread, int signal);
711 mono_thread_get_tls_key (void);
714 mono_thread_get_tls_offset (void);
717 mono_domain_get_tls_key (void);
720 mono_domain_get_tls_offset (void);
722 /* Reflection and Reflection.Emit support */
725 * Handling System.Type objects:
727 * Fields defined as System.Type in managed code should be defined as MonoObject*
728 * in unmanaged structures, and the monotype_cast () function should be used for
729 * casting them to MonoReflectionType* to avoid crashes/security issues when
730 * encountering instances of user defined subclasses of System.Type.
733 #define IS_MONOTYPE(obj) (!(obj) || (((MonoObject*)(obj))->vtable->klass->image == mono_defaults.corlib && ((MonoReflectionType*)(obj))->type != NULL))
736 * Make sure the argument, which should be a System.Type is a System.MonoType object
737 * or equivalent, and not an instance of
738 * a user defined subclass of System.Type. This should be used in places were throwing
739 * an exception is safe.
741 #define CHECK_MONOTYPE(obj) do { \
742 if (!IS_MONOTYPE (obj)) \
743 mono_raise_exception (mono_get_exception_not_supported ("User defined subclasses of System.Type are not yet supported")); \
746 /* This should be used for accessing members of Type[] arrays */
747 #define mono_type_array_get(arr,index) monotype_cast (mono_array_get ((arr), gpointer, (index)))
750 * Cast an object to MonoReflectionType, making sure it is a System.MonoType or
753 static inline MonoReflectionType*
754 monotype_cast (MonoObject *obj)
756 g_assert (IS_MONOTYPE (obj));
758 return (MonoReflectionType*)obj;
762 * The following structure must match the C# implementation in our corlib.
765 struct _MonoReflectionMethod {
769 MonoReflectionType *reftype;
772 typedef struct _MonoReflectionGenericMethod MonoReflectionGenericMethod;
773 struct _MonoReflectionGenericMethod {
774 MonoReflectionMethod method;
777 struct _MonoDelegate {
779 /* The compiled code of the target method */
781 /* The invoke code */
782 gpointer invoke_impl;
785 gpointer delegate_trampoline;
788 * If non-NULL, this points to a memory location which stores the address of
789 * the compiled code of the method, or NULL if it is not yet compiled.
791 guint8 **method_code;
792 MonoReflectionMethod *method_info;
793 MonoReflectionMethod *original_method_info;
795 MonoBoolean method_is_virtual;
798 typedef struct _MonoMulticastDelegate MonoMulticastDelegate;
799 struct _MonoMulticastDelegate {
800 MonoDelegate delegate;
801 MonoArray *delegates;
804 struct _MonoReflectionField {
807 MonoClassField *field;
809 MonoReflectionType *type;
813 struct _MonoReflectionProperty {
816 MonoProperty *property;
819 /*This is System.EventInfo*/
820 struct _MonoReflectionEvent {
822 MonoObject *cached_add_event;
826 MonoReflectionEvent object;
829 } MonoReflectionMonoEvent;
833 MonoReflectionType *ClassImpl;
834 MonoObject *DefaultValueImpl;
835 MonoObject *MemberImpl;
836 MonoString *NameImpl;
839 MonoObject *MarshalAsImpl;
840 } MonoReflectionParameter;
842 struct _MonoReflectionMethodBody {
847 MonoBoolean init_locals;
848 guint32 local_var_sig_token;
852 struct _MonoReflectionAssembly {
854 MonoAssembly *assembly;
855 MonoObject *resolve_event_holder;
857 MonoObject *evidence; /* Evidence */
858 MonoObject *minimum; /* PermissionSet - for SecurityAction.RequestMinimum */
859 MonoObject *optional; /* PermissionSet - for SecurityAction.RequestOptional */
860 MonoObject *refuse; /* PermissionSet - for SecurityAction.RequestRefuse */
861 MonoObject *granted; /* PermissionSet - for the resolved assembly granted permissions */
862 MonoObject *denied; /* PermissionSet - for the resolved assembly denied permissions */
864 MonoBoolean from_byte_array;
869 MonoReflectionType *utype;
875 MonoReflectionType *parent;
876 MonoReflectionType *ret;
883 MonoReflectionType *parent;
884 MonoReflectionType *declaring_type;
886 MonoReflectionMethod *get;
887 MonoReflectionMethod *set;
892 MonoReflectionType *declaring_type;
893 MonoReflectionType *reflected_type;
895 MonoReflectionMethod *add_method;
896 MonoReflectionMethod *remove_method;
897 MonoReflectionMethod *raise_method;
899 MonoArray *other_methods;
904 MonoString *name_space;
905 MonoReflectionType *etype;
906 MonoReflectionType *nested_in;
907 MonoReflectionAssembly *assembly;
909 MonoBoolean isprimitive;
915 } MonoReflectionILTokenInfo;
924 MonoArray *ex_handlers;
925 gint32 num_token_fixups;
926 MonoArray *token_fixups;
927 } MonoReflectionILGen;
934 } MonoILExceptionInfo;
941 gint32 filter_offset;
942 } MonoILExceptionBlock;
946 MonoObject *catch_type;
947 gint32 filter_offset;
951 gint32 handler_offset;
952 gint32 handler_length;
953 } MonoReflectionExceptionHandlingClause;
957 MonoReflectionType *local_type;
958 MonoBoolean is_pinned;
960 } MonoReflectionLocalVariableInfo;
964 * Must have the same layout as MonoReflectionLocalVariableInfo, since
965 * LocalBuilder inherits from it under net 2.0.
969 MonoBoolean is_pinned;
972 } MonoReflectionLocalBuilder;
981 MonoString *marshaltype;
982 MonoObject *marshaltyperef;
984 MonoBoolean has_size;
985 } MonoReflectionMarshal;
992 MonoReflectionMarshal *marshal_info;
996 MonoObject *def_value;
997 } MonoReflectionParamBuilder;
1001 MonoMethod *mhandle;
1002 MonoReflectionILGen *ilgen;
1003 MonoArray *parameters;
1011 MonoBoolean init_locals;
1012 MonoArray *param_modreq;
1013 MonoArray *param_modopt;
1014 MonoArray *permissions;
1015 } MonoReflectionCtorBuilder;
1019 MonoMethod *mhandle;
1021 MonoArray *parameters;
1027 MonoReflectionILGen *ilgen;
1031 MonoArray *override_methods;
1033 MonoString *dllentry;
1035 guint32 extra_flags;
1038 MonoBoolean init_locals;
1039 MonoGenericContainer *generic_container;
1040 MonoArray *generic_params;
1041 MonoArray *return_modreq;
1042 MonoArray *return_modopt;
1043 MonoArray *param_modreq;
1044 MonoArray *param_modopt;
1045 MonoArray *permissions;
1046 } MonoReflectionMethodBuilder;
1050 MonoMethod *mhandle;
1051 MonoReflectionType *parent;
1052 MonoReflectionType *ret;
1053 MonoArray *parameters;
1057 } MonoReflectionArrayMethod;
1062 MonoString *filename;
1066 } MonoReflectionResource;
1072 MonoArray *res_data;
1073 } MonoReflectionWin32Resource;
1078 } MonoReflectionPermissionSet;
1081 MonoReflectionAssembly assembly;
1082 MonoDynamicAssembly *dynamic_assembly;
1083 MonoReflectionMethod *entry_point;
1088 MonoArray *resources;
1089 MonoArray *public_key;
1090 MonoString *version;
1091 MonoString *culture;
1095 MonoBoolean delay_sign;
1097 MonoArray *loaded_modules;
1098 MonoArray *win32_resources;
1100 MonoArray *permissions_minimum;
1101 MonoArray *permissions_optional;
1102 MonoArray *permissions_refused;
1105 MonoBoolean corlib_internal;
1106 MonoArray *type_forwarders;
1107 MonoArray *pktoken; /* as hexadecimal byte[] */
1108 } MonoReflectionAssemblyBuilder;
1115 MonoObject *def_value;
1118 MonoReflectionType *typeb;
1119 MonoArray *rva_data;
1121 MonoReflectionMarshal *marshal_info;
1122 MonoClassField *handle;
1125 } MonoReflectionFieldBuilder;
1132 MonoArray *parameters;
1134 MonoObject *def_value;
1135 MonoReflectionMethodBuilder *set_method;
1136 MonoReflectionMethodBuilder *get_method;
1138 MonoObject *type_builder;
1139 MonoArray *returnModReq;
1140 MonoArray *returnModOpt;
1141 MonoArray *paramModReq;
1142 MonoArray *paramModOpt;
1144 } MonoReflectionPropertyBuilder;
1146 struct _MonoReflectionModule {
1149 MonoReflectionAssembly *assembly;
1152 MonoString *scopename;
1153 MonoBoolean is_resource;
1158 MonoReflectionModule module;
1159 MonoDynamicImage *dynamic_image;
1165 MonoReflectionAssemblyBuilder *assemblyb;
1166 MonoArray *global_methods;
1167 MonoArray *global_fields;
1169 MonoArray *resources;
1170 } MonoReflectionModuleBuilder;
1173 MonoReflectionType type;
1177 MonoReflectionType *nesting_type;
1178 MonoArray *interfaces;
1182 MonoArray *properties;
1187 MonoArray *subtypes;
1190 MonoReflectionModuleBuilder *module;
1192 gint32 packing_size;
1193 MonoGenericContainer *generic_container;
1194 MonoArray *generic_params;
1195 MonoArray *permissions;
1196 MonoReflectionType *created;
1197 } MonoReflectionTypeBuilder;
1200 MonoReflectionType type;
1201 MonoReflectionType *element_type;
1203 } MonoReflectionArrayType;
1206 MonoReflectionType type;
1207 MonoReflectionType *element_type;
1208 } MonoReflectionDerivedType;
1211 MonoReflectionType type;
1212 MonoReflectionTypeBuilder *tbuilder;
1213 MonoReflectionMethodBuilder *mbuilder;
1216 MonoReflectionType *base_type;
1217 MonoArray *iface_constraints;
1220 } MonoReflectionGenericParam;
1222 typedef struct _MonoReflectionGenericClass MonoReflectionGenericClass;
1223 struct _MonoReflectionGenericClass {
1224 MonoReflectionType type;
1225 MonoReflectionType *generic_type; /*Can be either a MonoType or a TypeBuilder*/
1226 MonoArray *type_arguments;
1227 guint32 initialized;
1233 MonoString *codebase;
1234 gint32 major, minor, build, revision;
1235 MonoObject *cultureInfo;
1238 MonoObject *keypair;
1239 MonoArray *publicKey;
1240 MonoArray *keyToken;
1241 guint32 versioncompat;
1242 MonoObject *version;
1243 guint32 processor_architecture;
1244 } MonoReflectionAssemblyName;
1249 MonoReflectionType *type;
1250 MonoReflectionTypeBuilder *typeb;
1252 MonoReflectionMethodBuilder *add_method;
1253 MonoReflectionMethodBuilder *remove_method;
1254 MonoReflectionMethodBuilder *raise_method;
1255 MonoArray *other_methods;
1258 } MonoReflectionEventBuilder;
1262 MonoReflectionMethod *ctor;
1264 } MonoReflectionCustomAttr;
1268 MonoString *marshal_cookie;
1269 MonoString *marshal_type;
1270 MonoReflectionType *marshal_type_ref;
1271 MonoReflectionType *marshal_safe_array_user_defined_subtype;
1273 guint32 array_subtype;
1274 gint32 safe_array_subtype;
1276 gint32 IidParameterIndex;
1277 gint16 size_param_index;
1278 } MonoReflectionMarshalAsAttribute;
1284 MonoBoolean best_fit_mapping;
1285 MonoBoolean throw_on_unmappable;
1286 MonoBoolean set_last_error;
1287 } MonoReflectionUnmanagedFunctionPointerAttribute;
1292 } MonoReflectionGuidAttribute;
1296 MonoMethod *mhandle;
1298 MonoReflectionType *rtype;
1299 MonoArray *parameters;
1302 MonoReflectionModule *module;
1303 MonoBoolean skip_visibility;
1304 MonoBoolean init_locals;
1305 MonoReflectionILGen *ilgen;
1308 GSList *referenced_by;
1309 MonoReflectionType *owner;
1310 } MonoReflectionDynamicMethod;
1314 MonoReflectionModuleBuilder *module;
1315 MonoArray *arguments;
1317 MonoReflectionType *return_type;
1319 guint32 unmanaged_call_conv;
1322 } MonoReflectionSigHelper;
1326 MonoReflectionGenericClass *inst;
1327 MonoObject *fb; /*can be either a MonoField or a FieldBuilder*/
1328 } MonoReflectionFieldOnTypeBuilderInst;
1332 MonoReflectionGenericClass *inst;
1333 MonoObject *cb; /*can be either a MonoCMethod or ConstructorBuilder*/
1334 } MonoReflectionCtorOnTypeBuilderInst;
1338 MonoReflectionType *inst;
1339 MonoObject *mb; /*can be either a MonoMethod or MethodBuilder*/
1340 MonoArray *method_args;
1341 MonoReflectionMethodBuilder *generic_method_definition;
1342 } MonoReflectionMethodOnTypeBuilderInst;
1346 MonoBoolean visible;
1347 } MonoReflectionComVisibleAttribute;
1350 RESOURCE_LOCATION_EMBEDDED = 1,
1351 RESOURCE_LOCATION_ANOTHER_ASSEMBLY = 2,
1352 RESOURCE_LOCATION_IN_MANIFEST = 4
1357 MonoReflectionAssembly *assembly;
1358 MonoString *filename;
1360 } MonoManifestResourceInfo;
1362 /* A boxed IntPtr */
1368 /* Keep in sync with System.GenericParameterAttributes */
1370 GENERIC_PARAMETER_ATTRIBUTE_NON_VARIANT = 0,
1371 GENERIC_PARAMETER_ATTRIBUTE_COVARIANT = 1,
1372 GENERIC_PARAMETER_ATTRIBUTE_CONTRAVARIANT = 2,
1373 GENERIC_PARAMETER_ATTRIBUTE_VARIANCE_MASK = 3,
1375 GENERIC_PARAMETER_ATTRIBUTE_NO_SPECIAL_CONSTRAINT = 0,
1376 GENERIC_PARAMETER_ATTRIBUTE_REFERENCE_TYPE_CONSTRAINT = 4,
1377 GENERIC_PARAMETER_ATTRIBUTE_VALUE_TYPE_CONSTRAINT = 8,
1378 GENERIC_PARAMETER_ATTRIBUTE_CONSTRUCTOR_CONSTRAINT = 16,
1379 GENERIC_PARAMETER_ATTRIBUTE_SPECIAL_CONSTRAINTS_MASK = 28
1380 } GenericParameterAttributes;
1384 MonoClassField *field;
1388 void mono_image_create_pefile (MonoReflectionModuleBuilder *module, HANDLE file);
1389 void mono_image_basic_init (MonoReflectionAssemblyBuilder *assembly);
1390 MonoReflectionModule * mono_image_load_module_dynamic (MonoReflectionAssemblyBuilder *assembly, MonoString *file_name);
1391 guint32 mono_image_insert_string (MonoReflectionModuleBuilder *module, MonoString *str);
1392 guint32 mono_image_create_token (MonoDynamicImage *assembly, MonoObject *obj, gboolean create_methodspec, gboolean register_token);
1393 guint32 mono_image_create_method_token (MonoDynamicImage *assembly, MonoObject *obj, MonoArray *opt_param_types);
1394 void mono_image_module_basic_init (MonoReflectionModuleBuilder *module);
1395 void mono_image_register_token (MonoDynamicImage *assembly, guint32 token, MonoObject *obj);
1396 void mono_dynamic_image_free (MonoDynamicImage *image);
1397 void mono_dynamic_image_free_image (MonoDynamicImage *image);
1398 void mono_image_set_wrappers_type (MonoReflectionModuleBuilder *mb, MonoReflectionType *type);
1399 void mono_dynamic_image_release_gc_roots (MonoDynamicImage *image);
1401 void mono_reflection_setup_internal_class (MonoReflectionTypeBuilder *tb);
1403 void mono_reflection_create_internal_class (MonoReflectionTypeBuilder *tb);
1405 void mono_reflection_setup_generic_class (MonoReflectionTypeBuilder *tb);
1407 void mono_reflection_create_generic_class (MonoReflectionTypeBuilder *tb);
1409 MonoReflectionType* mono_reflection_create_runtime_class (MonoReflectionTypeBuilder *tb);
1411 void mono_reflection_get_dynamic_overrides (MonoClass *klass, MonoMethod ***overrides, int *num_overrides);
1413 void mono_reflection_create_dynamic_method (MonoReflectionDynamicMethod *m);
1414 void mono_reflection_destroy_dynamic_method (MonoReflectionDynamicMethod *mb);
1416 void mono_reflection_initialize_generic_parameter (MonoReflectionGenericParam *gparam);
1417 void mono_reflection_create_unmanaged_type (MonoReflectionType *type);
1418 void mono_reflection_register_with_runtime (MonoReflectionType *type);
1420 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);
1421 MonoMethodSignature * mono_reflection_lookup_signature (MonoImage *image, MonoMethod *method, guint32 token, MonoError *error);
1423 MonoArray* mono_param_get_objects_internal (MonoDomain *domain, MonoMethod *method, MonoClass *refclass);
1426 mono_class_bind_generic_parameters (MonoClass *klass, int type_argc, MonoType **types, gboolean is_dynamic);
1428 mono_reflection_bind_generic_parameters (MonoReflectionType *type, int type_argc, MonoType **types);
1429 MonoReflectionMethod*
1430 mono_reflection_bind_generic_method_parameters (MonoReflectionMethod *method, MonoArray *types);
1432 mono_reflection_generic_class_initialize (MonoReflectionGenericClass *type, MonoArray *fields);
1433 MonoReflectionEvent *
1434 mono_reflection_event_builder_get_event_info (MonoReflectionTypeBuilder *tb, MonoReflectionEventBuilder *eb);
1436 MonoArray *mono_reflection_sighelper_get_signature_local (MonoReflectionSigHelper *sig);
1438 MonoArray *mono_reflection_sighelper_get_signature_field (MonoReflectionSigHelper *sig);
1440 MonoReflectionMarshalAsAttribute* mono_reflection_marshal_as_attribute_from_marshal_spec (MonoDomain *domain, MonoClass *klass, MonoMarshalSpec *spec);
1443 mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context);
1446 mono_reflection_call_is_assignable_to (MonoClass *klass, MonoClass *oklass);
1449 mono_reflection_is_valid_dynamic_token (MonoDynamicImage *image, guint32 token);
1452 mono_reflection_resolve_custom_attribute_data (MonoReflectionMethod *method, MonoReflectionAssembly *assembly, gpointer data, guint32 data_length, MonoArray **ctor_args, MonoArray ** named_args);
1455 mono_reflection_type_get_handle (MonoReflectionType *ref);
1458 mono_reflection_free_dynamic_generic_class (MonoGenericClass *gclass);
1461 mono_image_build_metadata (MonoReflectionModuleBuilder *module);
1464 mono_get_constant_value_from_blob (MonoDomain* domain, MonoTypeEnum type, const char *blob, void *value);
1467 mono_release_type_locks (MonoInternalThread *thread);
1470 mono_string_to_utf8_mp (MonoMemPool *mp, MonoString *s, MonoError *error);
1473 mono_string_to_utf8_image (MonoImage *image, MonoString *s, MonoError *error);
1477 mono_array_clone_in_domain (MonoDomain *domain, MonoArray *array);
1480 mono_array_full_copy (MonoArray *src, MonoArray *dest);
1483 mono_array_calc_byte_len (MonoClass *klass, uintptr_t len, uintptr_t *res);
1485 #ifndef DISABLE_REMOTING
1487 mono_remoting_invoke (MonoObject *real_proxy, MonoMethodMessage *msg,
1488 MonoObject **exc, MonoArray **out_args);
1491 mono_remote_class_vtable (MonoDomain *domain, MonoRemoteClass *remote_class, MonoRealProxy *real_proxy);
1494 mono_upgrade_remote_class (MonoDomain *domain, MonoObject *tproxy, MonoClass *klass);
1498 mono_create_ftnptr (MonoDomain *domain, gpointer addr);
1501 mono_get_addr_from_ftnptr (gpointer descr);
1504 mono_nullable_init (guint8 *buf, MonoObject *value, MonoClass *klass);
1507 mono_nullable_box (guint8 *buf, MonoClass *klass);
1509 #ifdef MONO_SMALL_CONFIG
1510 #define MONO_IMT_SIZE 9
1512 #define MONO_IMT_SIZE 19
1517 gpointer target_code;
1520 typedef struct _MonoImtBuilderEntry {
1522 struct _MonoImtBuilderEntry *next;
1523 MonoImtItemValue value;
1525 guint8 has_target_code : 1;
1526 } MonoImtBuilderEntry;
1528 typedef struct _MonoIMTCheckItem MonoIMTCheckItem;
1530 struct _MonoIMTCheckItem {
1532 int check_target_idx;
1533 MonoImtItemValue value;
1535 guint8 *code_target;
1537 guint8 compare_done;
1539 guint8 short_branch;
1540 guint8 has_target_code;
1543 typedef gpointer (*MonoImtThunkBuilder) (MonoVTable *vtable, MonoDomain *domain,
1544 MonoIMTCheckItem **imt_entries, int count, gpointer fail_trunk);
1547 mono_install_imt_thunk_builder (MonoImtThunkBuilder func);
1550 mono_vtable_build_imt_slot (MonoVTable* vtable, int imt_slot);
1553 mono_method_get_imt_slot (MonoMethod *method);
1556 mono_method_add_generic_virtual_invocation (MonoDomain *domain, MonoVTable *vtable,
1557 gpointer *vtable_slot,
1558 MonoMethod *method, gpointer code);
1561 mono_method_alloc_generic_virtual_thunk (MonoDomain *domain, int size);
1564 MONO_UNHANDLED_POLICY_LEGACY,
1565 MONO_UNHANDLED_POLICY_CURRENT
1566 } MonoRuntimeUnhandledExceptionPolicy;
1568 MonoRuntimeUnhandledExceptionPolicy
1569 mono_runtime_unhandled_exception_policy_get (void);
1571 mono_runtime_unhandled_exception_policy_set (MonoRuntimeUnhandledExceptionPolicy policy);
1574 mono_class_try_get_vtable (MonoDomain *domain, MonoClass *klass);
1577 mono_runtime_class_init_full (MonoVTable *vtable, gboolean raise_exception);
1580 mono_method_clear_object (MonoDomain *domain, MonoMethod *method);
1583 mono_class_compute_gc_descriptor (MonoClass *klass);
1586 mono_class_compute_bitmap (MonoClass *klass, gsize *bitmap, int size, int offset, int *max_set, gboolean static_fields);
1589 mono_object_xdomain_representation (MonoObject *obj, MonoDomain *target_domain, MonoObject **exc);
1592 mono_class_is_reflection_method_or_constructor (MonoClass *klass);
1595 mono_get_object_from_blob (MonoDomain *domain, MonoType *type, const char *blob);
1598 mono_class_get_ref_info (MonoClass *klass);
1601 mono_class_set_ref_info (MonoClass *klass, gpointer obj);
1604 mono_class_free_ref_info (MonoClass *klass);
1607 mono_object_new_pinned (MonoDomain *domain, MonoClass *klass);
1610 mono_field_static_get_value_for_thread (MonoInternalThread *thread, MonoVTable *vt, MonoClassField *field, void *value);
1612 /* exported, used by the debugger */
1614 mono_vtable_get_static_field_data (MonoVTable *vt);
1617 mono_string_to_utf8_ignore (MonoString *s);
1620 mono_string_to_utf8_image_ignore (MonoImage *image, MonoString *s);
1623 mono_string_to_utf8_mp_ignore (MonoMemPool *mp, MonoString *s);
1626 mono_monitor_is_il_fastpath_wrapper (MonoMethod *method);
1629 mono_exception_get_native_backtrace (MonoException *exc);
1632 ves_icall_Mono_Runtime_GetNativeStackTrace (MonoException *exc);
1635 mono_exception_get_managed_backtrace (MonoException *exc);
1638 mono_copy_value (MonoType *type, void *dest, void *value, int deref_pointer);
1641 mono_error_raise_exception (MonoError *target_error);
1644 mono_error_set_pending_exception (MonoError *error);
1647 mono_glist_to_array (GList *list, MonoClass *eclass);
1649 #endif /* __MONO_OBJECT_INTERNALS_H__ */