1 #ifndef __MONO_OBJECT_INTERNALS_H__
2 #define __MONO_OBJECT_INTERNALS_H__
4 #include <mono/metadata/object.h>
5 #include <mono/metadata/reflection.h>
6 #include <mono/io-layer/io-layer.h>
10 #define mono_assert(expr) G_STMT_START{ \
14 char *msg = g_strdup_printf ("file %s: line %d (%s): " \
15 "assertion failed: (%s)", __FILE__, __LINE__, \
16 __PRETTY_FUNCTION__, #expr); \
17 ex = mono_get_exception_execution_engine (msg); \
19 mono_raise_exception (ex); \
22 #define mono_assert_not_reached() G_STMT_START{ \
24 char *msg = g_strdup_printf ("file %s: line %d (%s): " \
25 "should not be reached", __FILE__, __LINE__, __PRETTY_FUNCTION__); \
26 ex = mono_get_exception_execution_engine (msg); \
28 mono_raise_exception (ex); \
31 #define mono_assert(expr) G_STMT_START{ \
35 char *msg = g_strdup_printf ("file %s: line %d: " \
36 "assertion failed: (%s)", __FILE__, __LINE__, \
38 ex = mono_get_exception_execution_engine (msg); \
40 mono_raise_exception (ex); \
43 #define mono_assert_not_reached() G_STMT_START{ \
45 char *msg = g_strdup_printf ("file %s: line %d): " \
46 "should not be reached", __FILE__, __LINE__); \
47 ex = mono_get_exception_execution_engine (msg); \
49 mono_raise_exception (ex); \
53 #define mono_assert(expr) g_assert(expr)
54 #define mono_assert_not_reached() g_assert_not_reached()
57 #define MONO_CHECK_ARG(arg, expr) G_STMT_START{ \
61 char *msg = g_strdup_printf ("assertion `%s' failed", \
63 if (arg) {} /* check if the name exists */ \
64 ex = mono_get_exception_argument (#arg, msg); \
66 mono_raise_exception (ex); \
69 #define MONO_CHECK_ARG_NULL(arg) G_STMT_START{ \
73 if (arg) {} /* check if the name exists */ \
74 ex = mono_get_exception_argument_null (#arg); \
75 mono_raise_exception (ex); \
79 /* 16 == default capacity */
80 #define mono_stringbuilder_capacity(sb) ((sb)->str ? ((sb)->str->length) : 16)
85 } MonoMarshalByRefObject;
87 /* This is a copy of System.AppDomain */
88 struct _MonoAppDomain {
89 MonoMarshalByRefObject mbr;
97 MonoString *cached_str;
109 } MonoArgumentHandle;
112 MonoMethodSignature *sig;
118 struct _MonoException {
120 MonoArray *trace_ips;
121 MonoObject *inner_ex;
123 MonoString *help_link;
124 MonoString *class_name;
125 MonoString *stack_trace;
126 MonoString *remote_stack_trace;
127 gint32 remote_stack_index;
134 } MonoSystemException;
137 MonoSystemException base;
138 MonoString *param_name;
139 } MonoArgumentException;
142 MonoSystemException base;
144 MonoString *type_name;
145 } MonoTypeLoadException;
149 MonoObject *async_state;
151 MonoObject *async_delegate;
153 MonoBoolean sync_completed;
154 MonoBoolean completed;
155 MonoBoolean endinvoke_called;
156 MonoObject *async_callback;
157 MonoObject *execution_context;
158 MonoObject *original_context;
162 MonoMarshalByRefObject object;
164 MonoBoolean disposed;
167 /* This is a copy of System.Runtime.Remoting.Messaging.CallType */
170 CallType_BeginInvoke = 1,
171 CallType_EndInvoke = 2,
175 struct _MonoReflectionType {
182 MonoReflectionType *class_to_proxy;
184 MonoObject *unwrapped_server;
185 gint32 target_domain_id;
186 MonoString *target_uri;
192 MonoRemoteClass *remote_class;
193 MonoBoolean custom_type_info;
194 } MonoTransparentProxy;
198 MonoReflectionMethod *method;
201 MonoArray *arg_types;
205 MonoAsyncResult *async_result;
212 gint32 native_offset;
213 MonoReflectionMethod *method;
214 MonoString *filename;
217 MonoString *internal_method_name;
222 int lock_thread_id; /* to be used as the pre-shifted thread id in thin locks */
224 MonoObject **culture_info;
225 MonoObject **ui_culture_info;
226 MonoBoolean threadpool_thread;
230 MonoException *abort_exc;
231 MonoObject *abort_state;
235 gpointer *static_data;
238 MonoAppContext *current_appcontext;
240 MonoObject *start_obj;
241 GSList *appdomain_refs;
242 MonoBoolean interruption_requested;
243 gpointer suspend_event;
244 gpointer suspended_event;
245 gpointer resume_event;
246 MonoObject *synch_lock;
247 guint8* serialized_culture_info;
248 guint32 serialized_culture_info_len;
249 guint8* serialized_ui_culture_info;
250 guint32 serialized_ui_culture_info_len;
251 MonoObject *execution_context;
253 * These fields are used to avoid having to increment corlib versions
254 * when a new field is added to the unmanaged MonoThread structure.
267 MonoReflectionType *type;
269 } MonoSerializationEntry;
273 MonoObject *additional;
274 } MonoStreamingContext;
278 MonoBoolean readOnly;
279 MonoString *AMDesignator;
280 MonoString *PMDesignator;
281 MonoString *DateSeparator;
282 MonoString *TimeSeparator;
283 MonoString *ShortDatePattern;
284 MonoString *LongDatePattern;
285 MonoString *ShortTimePattern;
286 MonoString *LongTimePattern;
287 MonoString *MonthDayPattern;
288 MonoString *YearMonthPattern;
289 MonoString *FullDateTimePattern;
290 MonoString *RFC1123Pattern;
291 MonoString *SortableDateTimePattern;
292 MonoString *UniversalSortableDateTimePattern;
293 guint32 FirstDayOfWeek;
294 MonoObject *Calendar;
295 guint32 CalendarWeekRule;
296 MonoArray *AbbreviatedDayNames;
298 MonoArray *MonthNames;
299 MonoArray *AbbreviatedMonthNames;
300 MonoArray *ShortDatePatterns;
301 MonoArray *LongDatePatterns;
302 MonoArray *ShortTimePatterns;
303 MonoArray *LongTimePatterns;
304 } MonoDateTimeFormatInfo;
309 MonoBoolean readOnly;
310 MonoString *decimalFormats;
311 MonoString *currencyFormats;
312 MonoString *percentFormats;
313 MonoString *digitPattern;
314 MonoString *zeroPattern;
315 gint32 currencyDecimalDigits;
316 MonoString *currencyDecimalSeparator;
317 MonoString *currencyGroupSeparator;
318 MonoArray *currencyGroupSizes;
319 gint32 currencyNegativePattern;
320 gint32 currencyPositivePattern;
321 MonoString *currencySymbol;
322 MonoString *naNSymbol;
323 MonoString *negativeInfinitySymbol;
324 MonoString *negativeSign;
325 guint32 numberDecimalDigits;
326 MonoString *numberDecimalSeparator;
327 MonoString *numberGroupSeparator;
328 MonoArray *numberGroupSizes;
329 gint32 numberNegativePattern;
330 gint32 percentDecimalDigits;
331 MonoString *percentDecimalSeparator;
332 MonoString *percentGroupSeparator;
333 MonoArray *percentGroupSizes;
334 gint32 percentNegativePattern;
335 gint32 percentPositivePattern;
336 MonoString *percentSymbol;
337 MonoString *perMilleSymbol;
338 MonoString *positiveInfinitySymbol;
339 MonoString *positiveSign;
340 } MonoNumberFormatInfo;
345 MonoString *icu_name;
346 gpointer ICU_collator;
351 MonoBoolean is_read_only;
354 gint32 specific_lcid;
355 gint32 datetime_index;
357 MonoBoolean use_user_override;
358 MonoNumberFormatInfo *number_format;
359 MonoDateTimeFormatInfo *datetime_format;
360 MonoObject *textinfo;
362 MonoString *displayname;
363 MonoString *englishname;
364 MonoString *nativename;
365 MonoString *iso3lang;
366 MonoString *iso2lang;
367 MonoString *icu_name;
368 MonoString *win3lang;
369 MonoCompareInfo *compareinfo;
370 const gint32 *calendar_data;
371 const void* text_info_data;
382 /* used to free a dynamic method */
383 typedef void (*MonoFreeMethodFunc) (MonoDomain *domain, MonoMethod *method);
385 /* Used to initialize the method pointers inside vtables */
386 typedef gboolean (*MonoInitVTableFunc) (MonoVTable *vtable);
388 /* remoting and async support */
391 mono_async_result_new (MonoDomain *domain, HANDLE handle,
392 MonoObject *state, gpointer data);
395 mono_wait_handle_new (MonoDomain *domain, HANDLE handle);
398 mono_message_init (MonoDomain *domain, MonoMethodMessage *this_obj,
399 MonoReflectionMethod *method, MonoArray *out_args);
402 mono_remoting_invoke (MonoObject *real_proxy, MonoMethodMessage *msg,
403 MonoObject **exc, MonoArray **out_args);
406 mono_message_invoke (MonoObject *target, MonoMethodMessage *msg,
407 MonoObject **exc, MonoArray **out_args);
410 mono_method_call_message_new (MonoMethod *method, gpointer *params, MonoMethod *invoke,
411 MonoDelegate **cb, MonoObject **state);
414 mono_method_return_message_restore (MonoMethod *method, gpointer *params, MonoArray *out_args);
417 mono_delegate_ctor (MonoObject *this_obj, MonoObject *target, gpointer addr);
420 mono_class_get_allocation_ftn (MonoVTable *vtable, gboolean for_box, gboolean *pass_size_in_words);
423 mono_runtime_free_method (MonoDomain *domain, MonoMethod *method);
425 /* runtime initialization functions */
426 typedef void (*MonoExceptionFunc) (MonoException *ex);
429 mono_install_handler (MonoExceptionFunc func);
432 mono_install_runtime_invoke (MonoInvokeFunc func);
435 mono_install_compile_method (MonoCompileFunc func);
438 mono_install_free_method (MonoFreeMethodFunc func);
441 mono_install_init_vtable (MonoInitVTableFunc func);
444 mono_type_initialization_init (void);
447 mono_thread_get_tls_key (void);
450 mono_thread_get_tls_offset (void);
453 mono_domain_get_tls_key (void);
456 mono_domain_get_tls_offset (void);
458 /* Reflection and Reflection.Emit support */
461 * The following structure must match the C# implementation in our corlib.
464 struct _MonoReflectionMethod {
468 MonoReflectionType *reftype;
471 typedef struct _MonoReflectionGenericMethod MonoReflectionGenericMethod;
472 struct _MonoReflectionGenericMethod {
473 MonoReflectionMethod method;
476 struct _MonoDelegate {
478 MonoObject *target_type;
480 MonoString *method_name;
482 gpointer delegate_trampoline;
483 MonoReflectionMethod *method_info;
486 typedef struct _MonoMulticastDelegate MonoMulticastDelegate;
487 struct _MonoMulticastDelegate {
488 MonoDelegate delegate;
489 MonoMulticastDelegate *prev;
492 struct _MonoReflectionField {
495 MonoClassField *field;
497 MonoReflectionType *type;
501 struct _MonoReflectionProperty {
504 MonoProperty *property;
507 struct _MonoReflectionEvent {
515 MonoReflectionType *ClassImpl;
516 MonoObject *DefaultValueImpl;
517 MonoObject *MemberImpl;
518 MonoString *NameImpl;
521 MonoObject *MarshalAsImpl;
522 } MonoReflectionParameter;
524 struct _MonoReflectionMethodBody {
529 MonoBoolean init_locals;
530 guint32 local_var_sig_token;
534 struct _MonoReflectionAssembly {
536 MonoAssembly *assembly;
537 MonoObject *resolve_event_holder;
539 MonoObject *evidence; /* Evidence */
540 MonoObject *minimum; /* PermissionSet - for SecurityAction.RequestMinimum */
541 MonoObject *optional; /* PermissionSet - for SecurityAction.RequestOptional */
542 MonoObject *refuse; /* PermissionSet - for SecurityAction.RequestRefuse */
543 MonoObject *granted; /* PermissionSet - for the resolved assembly granted permissions */
544 MonoObject *denied; /* PermissionSet - for the resolved assembly denied permissions */
546 MonoBoolean from_byte_array;
550 MonoReflectionType *utype;
556 MonoReflectionType *parent;
557 MonoReflectionType *ret;
564 MonoReflectionType *parent;
566 MonoReflectionMethod *get;
567 MonoReflectionMethod *set;
572 MonoReflectionType *declaring_type;
573 MonoReflectionType *reflected_type;
575 MonoReflectionMethod *add_method;
576 MonoReflectionMethod *remove_method;
577 MonoReflectionMethod *raise_method;
579 MonoArray *other_methods;
584 MonoString *name_space;
585 MonoReflectionType *etype;
586 MonoReflectionType *nested_in;
587 MonoReflectionAssembly *assembly;
589 MonoBoolean isprimitive;
595 } MonoReflectionILTokenInfo;
604 MonoArray *ex_handlers;
605 gint32 num_token_fixups;
606 MonoArray *token_fixups;
607 } MonoReflectionILGen;
614 } MonoILExceptionInfo;
617 MonoReflectionType *extype;
621 gint32 filter_offset;
622 } MonoILExceptionBlock;
626 MonoReflectionType *catch_type;
627 gint32 filter_offset;
631 gint32 handler_offset;
632 gint32 handler_length;
633 } MonoReflectionExceptionHandlingClause;
637 MonoReflectionType *local_type;
638 MonoBoolean is_pinned;
640 } MonoReflectionLocalVariableInfo;
644 * Must have the same layout as MonoReflectionLocalVariableInfo, since
645 * LocalBuilder inherits from it under net 2.0.
648 MonoReflectionType *type;
649 MonoBoolean is_pinned;
652 } MonoReflectionLocalBuilder;
661 MonoString *marshaltype;
662 MonoReflectionType *marshaltyperef;
664 MonoBoolean has_size;
665 } MonoReflectionMarshal;
672 MonoReflectionMarshal *marshal_info;
676 MonoObject *def_value;
677 } MonoReflectionParamBuilder;
682 MonoReflectionILGen *ilgen;
683 MonoArray *parameters;
691 MonoBoolean init_locals;
692 MonoArray *param_modreq;
693 MonoArray *param_modopt;
694 MonoArray *permissions;
695 } MonoReflectionCtorBuilder;
700 MonoReflectionType *rtype;
701 MonoArray *parameters;
707 MonoReflectionILGen *ilgen;
711 MonoReflectionMethod *override_method;
713 MonoString *dllentry;
718 MonoBoolean init_locals;
719 MonoGenericContainer *generic_container;
720 MonoArray *generic_params;
721 MonoArray *return_modreq;
722 MonoArray *return_modopt;
723 MonoArray *param_modreq;
724 MonoArray *param_modopt;
725 MonoArray *permissions;
726 } MonoReflectionMethodBuilder;
731 MonoReflectionType *parent;
732 MonoReflectionType *ret;
733 MonoArray *parameters;
737 } MonoReflectionArrayMethod;
742 MonoString *filename;
745 } MonoReflectionResource;
752 } MonoReflectionWin32Resource;
757 } MonoReflectionPermissionSet;
760 MonoReflectionAssembly assembly;
761 MonoDynamicAssembly *dynamic_assembly;
762 MonoReflectionMethod *entry_point;
767 MonoArray *resources;
768 MonoArray *public_key;
774 MonoBoolean delay_sign;
776 MonoArray *loaded_modules;
777 MonoArray *win32_resources;
779 MonoArray *permissions_minimum;
780 MonoArray *permissions_optional;
781 MonoArray *permissions_refused;
784 MonoBoolean corlib_internal;
785 } MonoReflectionAssemblyBuilder;
790 MonoReflectionType *type;
792 MonoObject *def_value;
795 MonoReflectionType *typeb;
798 MonoReflectionMarshal *marshal_info;
799 MonoClassField *handle;
802 } MonoReflectionFieldBuilder;
808 MonoReflectionType *type;
809 MonoArray *parameters;
811 MonoObject *def_value;
812 MonoReflectionMethodBuilder *set_method;
813 MonoReflectionMethodBuilder *get_method;
815 } MonoReflectionPropertyBuilder;
817 struct _MonoReflectionModule {
820 MonoReflectionAssembly *assembly;
823 MonoString *scopename;
824 MonoBoolean is_resource;
829 MonoReflectionModule module;
830 MonoDynamicImage *dynamic_image;
836 MonoReflectionAssemblyBuilder *assemblyb;
837 MonoArray *global_methods;
838 MonoArray *global_fields;
840 MonoArray *resources;
841 } MonoReflectionModuleBuilder;
844 MonoReflectionType type;
847 MonoReflectionType *parent;
848 MonoReflectionType *nesting_type;
849 MonoArray *interfaces;
853 MonoArray *properties;
861 MonoReflectionModuleBuilder *module;
864 MonoGenericContainer *generic_container;
865 MonoArray *generic_params;
866 MonoArray *permissions;
867 MonoReflectionType *created;
868 } MonoReflectionTypeBuilder;
871 MonoReflectionType type;
872 MonoReflectionTypeBuilder *tbuilder;
873 MonoReflectionMethodBuilder *mbuilder;
876 MonoReflectionType *base_type;
877 MonoArray *iface_constraints;
879 } MonoReflectionGenericParam;
881 typedef struct _MonoReflectionGenericClass MonoReflectionGenericClass;
882 struct _MonoReflectionGenericClass {
883 MonoReflectionType type;
884 MonoReflectionType *generic_type;
891 MonoString *codebase;
892 gint32 major, minor, build, revision;
893 MonoObject *cultureInfo;
897 MonoArray *publicKey;
899 guint32 versioncompat;
901 } MonoReflectionAssemblyName;
906 MonoReflectionType *type;
907 MonoReflectionTypeBuilder *typeb;
909 MonoReflectionMethodBuilder *add_method;
910 MonoReflectionMethodBuilder *remove_method;
911 MonoReflectionMethodBuilder *raise_method;
912 MonoArray *other_methods;
915 } MonoReflectionEventBuilder;
919 MonoReflectionMethod *ctor;
921 } MonoReflectionCustomAttr;
928 MonoString *entry_point;
929 MonoBoolean exact_spelling;
930 MonoBoolean preserve_sig;
931 MonoBoolean set_last_error;
932 MonoBoolean best_fit_mapping;
933 MonoBoolean throw_on_unmappable;
934 } MonoReflectionDllImportAttribute;
940 MonoBoolean set_last_error;
941 MonoBoolean best_fit_mapping;
942 MonoBoolean throw_on_unmappable;
943 } MonoReflectionUnmanagedFunctionPointerAttribute;
949 MonoReflectionType *rtype;
950 MonoArray *parameters;
953 MonoReflectionModule *module;
954 MonoBoolean skip_visibility;
955 MonoBoolean init_locals;
956 MonoReflectionILGen *ilgen;
959 } MonoReflectionDynamicMethod;
963 MonoReflectionModuleBuilder *module;
964 MonoArray *arguments;
966 MonoReflectionType *return_type;
968 guint32 unmanaged_call_conv;
969 } MonoReflectionSigHelper;
972 RESOURCE_LOCATION_EMBEDDED = 1,
973 RESOURCE_LOCATION_ANOTHER_ASSEMBLY = 2,
974 RESOURCE_LOCATION_IN_MANIFEST = 4
979 MonoReflectionAssembly *assembly;
980 MonoString *filename;
982 } MonoManifestResourceInfo;
984 /* Keep in sync with System.GenericParameterAttributes */
986 GENERIC_PARAMETER_ATTRIBUTE_NON_VARIANT = 0,
987 GENERIC_PARAMETER_ATTRIBUTE_COVARIANT = 1,
988 GENERIC_PARAMETER_ATTRIBUTE_CONTRAVARIANT = 2,
989 GENERIC_PARAMETER_ATTRIBUTE_VARIANCE_MASK = 3,
991 GENERIC_PARAMETER_ATTRIBUTE_NO_SPECIAL_CONSTRAINT = 0,
992 GENERIC_PARAMETER_ATTRIBUTE_REFERENCE_TYPE_CONSTRAINT = 4,
993 GENERIC_PARAMETER_ATTRIBUTE_VALUE_TYPE_CONSTRAINT = 8,
994 GENERIC_PARAMETER_ATTRIBUTE_CONSTRUCTOR_CONSTRAINT = 16,
995 GENERIC_PARAMETER_ATTRIBUTE_SPECIAL_CONSTRAINTS_MASK = 28
996 } GenericParameterAttributes;
998 void mono_image_create_pefile (MonoReflectionModuleBuilder *module, HANDLE file);
999 void mono_image_basic_init (MonoReflectionAssemblyBuilder *assembly);
1000 MonoReflectionModule * mono_image_load_module (MonoReflectionAssemblyBuilder *assembly, MonoString *file_name);
1001 guint32 mono_image_insert_string (MonoReflectionModuleBuilder *module, MonoString *str);
1002 guint32 mono_image_create_token (MonoDynamicImage *assembly, MonoObject *obj, gboolean create_methodspec);
1003 guint32 mono_image_create_method_token (MonoDynamicImage *assembly, MonoObject *obj, MonoArray *opt_param_types);
1004 void mono_image_module_basic_init (MonoReflectionModuleBuilder *module);
1006 void mono_reflection_setup_internal_class (MonoReflectionTypeBuilder *tb);
1008 void mono_reflection_create_internal_class (MonoReflectionTypeBuilder *tb);
1010 void mono_reflection_setup_generic_class (MonoReflectionTypeBuilder *tb);
1012 void mono_reflection_create_generic_class (MonoReflectionTypeBuilder *tb);
1014 MonoReflectionType* mono_reflection_create_runtime_class (MonoReflectionTypeBuilder *tb);
1016 void mono_reflection_create_dynamic_method (MonoReflectionDynamicMethod *m);
1018 void mono_reflection_initialize_generic_parameter (MonoReflectionGenericParam *gparam);
1021 mono_reflection_bind_generic_parameters (MonoReflectionType *type, int type_argc, MonoType **types);
1022 MonoReflectionMethod*
1023 mono_reflection_bind_generic_method_parameters (MonoReflectionMethod *method, MonoArray *types);
1025 mono_reflection_generic_class_initialize (MonoReflectionGenericClass *type, MonoArray *methods, MonoArray *ctors, MonoArray *fields, MonoArray *properties, MonoArray *events);
1026 MonoReflectionEvent *
1027 mono_reflection_event_builder_get_event_info (MonoReflectionTypeBuilder *tb, MonoReflectionEventBuilder *eb);
1029 MonoArray *mono_reflection_sighelper_get_signature_local (MonoReflectionSigHelper *sig);
1031 MonoArray *mono_reflection_sighelper_get_signature_field (MonoReflectionSigHelper *sig);
1033 MonoReflectionMarshal* mono_reflection_marshal_from_marshal_spec (MonoDomain *domain, MonoClass *klass, MonoMarshalSpec *spec);
1036 mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, MonoClass **handle_class);
1039 mono_reflection_call_is_assignable_to (MonoClass *klass, MonoClass *oklass);
1042 mono_image_build_metadata (MonoReflectionModuleBuilder *module);
1045 mono_get_constant_value_from_blob (MonoDomain* domain, MonoTypeEnum type, const char *blob, void *value);
1048 mono_release_type_locks (MonoThread *thread);
1051 mono_array_clone_in_domain (MonoDomain *domain, MonoArray *array);
1054 mono_array_full_copy (MonoArray *src, MonoArray *dest);
1057 mono_remote_class_vtable (MonoDomain *domain, MonoRemoteClass *remote_class, MonoRealProxy *real_proxy);
1059 MonoMethodSignature*
1060 mono_method_get_signature_full (MonoMethod *method, MonoImage *image, guint32 token, MonoGenericContext *context);
1063 mono_upgrade_remote_class (MonoDomain *domain, MonoObject *tproxy, MonoClass *klass);
1065 #endif /* __MONO_OBJECT_INTERNALS_H__ */