New tests.
[mono.git] / mono / metadata / metadata-internals.h
index 9b9c75353048709addb615c625ab9d862779050e..9fa06f0446ca323c5198aec79510381af9866f3d 100644 (file)
 #include "mono/utils/monobitset.h"
 #include "mono/utils/mono-property-hash.h"
 #include "mono/utils/mono-value-hash.h"
+#include <mono/utils/mono-error.h>
+
+struct _MonoType {
+       union {
+               MonoClass *klass; /* for VALUETYPE and CLASS */
+               MonoType *type;   /* for PTR */
+               MonoArrayType *array; /* for ARRAY */
+               MonoMethodSignature *method;
+               MonoGenericParam *generic_param; /* for VAR and MVAR */
+               MonoGenericClass *generic_class; /* for GENERICINST */
+       } data;
+       unsigned int attrs    : 16; /* param attributes or field flags */
+       MonoTypeEnum type     : 8;
+       unsigned int num_mods : 6;  /* max 64 modifiers follow at the end */
+       unsigned int byref    : 1;
+       unsigned int pinned   : 1;  /* valid when included in a local var signature */
+       MonoCustomMod modifiers [MONO_ZERO_LEN_ARRAY]; /* this may grow */
+};
+
+#define MONO_SIZEOF_TYPE (offsetof (struct _MonoType, modifiers))
 
 #define MONO_SECMAN_FLAG_INIT(x)               (x & 0x2)
 #define MONO_SECMAN_FLAG_GET_VALUE(x)          (x & 0x1)
 #define MONO_SECMAN_FLAG_SET_VALUE(x,y)                do { x = ((y) ? 0x3 : 0x2); } while (0)
 
+#define MONO_PUBLIC_KEY_TOKEN_LENGTH   17
+
+struct _MonoAssemblyName {
+       const char *name;
+       const char *culture;
+       const char *hash_value;
+       const mono_byte* public_key;
+       // string of 16 hex chars + 1 NULL
+       mono_byte public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
+       uint32_t hash_alg;
+       uint32_t hash_len;
+       uint32_t flags;
+       uint16_t major, minor, build, revision;
+};
+
+struct MonoTypeNameParse {
+       char *name_space;
+       char *name;
+       MonoAssemblyName assembly;
+       GList *modifiers; /* 0 -> byref, -1 -> pointer, > 0 -> array rank */
+       GPtrArray *type_arguments;
+       GList *nested;
+};
+
 struct _MonoAssembly {
        /* 
         * The number of appdomains which have this assembly loaded plus the number of 
@@ -85,7 +129,7 @@ struct _MonoImage {
        guint8 raw_buffer_used    : 1;
        guint8 raw_data_allocated : 1;
 
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
        /* Module was loaded using LoadLibrary. */
        guint8 is_module_handle : 1;
 
@@ -108,6 +152,9 @@ struct _MonoImage {
        guint8 idx_string_wide : 1;
        guint8 idx_guid_wide : 1;
        guint8 idx_blob_wide : 1;
+
+       /* Whenever this image is considered as platform code for the CoreCLR security model */
+       guint8 core_clr_platform_code : 1;
                            
        char *name;
        const char *assembly_name;
@@ -116,7 +163,7 @@ struct _MonoImage {
        gint16 md_version_major, md_version_minor;
        char *guid;
        void *image_info;
-       MonoMemPool         *mempool;
+       MonoMemPool         *mempool; /*protected by the image lock*/
 
        char                *raw_metadata;
                            
@@ -155,11 +202,11 @@ struct _MonoImage {
        /*
         * Indexed by method tokens and typedef tokens.
         */
-       MonoValueHashTable *method_cache;
+       GHashTable *method_cache; /*protected by the image lock*/
        MonoInternalHashTable class_cache;
 
        /* Indexed by memberref + methodspec tokens */
-       GHashTable *methodref_cache;
+       GHashTable *methodref_cache; /*protected by the image lock*/
 
        /*
         * Indexed by fielddef and memberref tokens
@@ -178,7 +225,7 @@ struct _MonoImage {
        /*
         * Indexes namespaces to hash tables that map class name to typedef token.
         */
-       GHashTable *name_cache;
+       GHashTable *name_cache;  /*protected by the image lock*/
 
        /*
         * Indexed by MonoClass
@@ -186,6 +233,10 @@ struct _MonoImage {
        GHashTable *array_cache;
        GHashTable *ptr_cache;
 
+       GHashTable *szarray_cache;
+       /* This has a separate lock to improve scalability */
+       CRITICAL_SECTION szarray_cache_lock;
+
        /*
         * indexed by MonoMethodSignature 
         */
@@ -203,14 +254,15 @@ struct _MonoImage {
         * indexed by MonoMethod pointers 
         */
        GHashTable *runtime_invoke_direct_cache;
+       GHashTable *runtime_invoke_vcall_cache;
        GHashTable *managed_wrapper_cache;
        GHashTable *native_wrapper_cache;
+       GHashTable *native_wrapper_aot_cache;
        GHashTable *remoting_invoke_cache;
        GHashTable *synchronized_cache;
        GHashTable *unbox_wrapper_cache;
        GHashTable *cominterop_invoke_cache;
-       GHashTable *cominterop_wrapper_cache;
-       GHashTable *static_rgctx_invoke_cache; /* LOCKING: marshal lock */
+       GHashTable *cominterop_wrapper_cache; /* LOCKING: marshal lock */
        GHashTable *thunk_invoke_cache;
 
        /*
@@ -224,11 +276,6 @@ struct _MonoImage {
        GHashTable *proxy_isinst_cache;
        GHashTable *rgctx_template_hash; /* LOCKING: templates lock */
 
-       /*
-        * indexed by token and MonoGenericContext pointer
-        */
-       GHashTable *generic_class_cache;
-
        /* Contains rarely used fields of runtime structures belonging to this image */
        MonoPropertyHash *property_hash;
 
@@ -245,8 +292,43 @@ struct _MonoImage {
 
        /* interfaces IDs from this image */
        MonoBitSet *interface_bitset;
+
+       /* when the image is being closed, this is abused as a list of
+          malloc'ed regions to be freed. */
+       GSList *reflection_info_unregister_classes;
+
+       /* List of image sets containing this image */
+       GSList *image_sets;
+
+       /*
+        * No other runtime locks must be taken while holding this lock.
+        * It's meant to be used only to mutate and query structures part of this image.
+        */
+       CRITICAL_SECTION    lock;
 };
 
+/*
+ * Generic instances depend on many images, and they need to be deleted if one
+ * of the images they depend on is unloaded. For example,
+ * List<Foo> depends on both List's image and Foo's image.
+ * A MonoImageSet is the owner of all generic instances depending on the same set of
+ * images.
+ */
+typedef struct {
+       int nimages;
+       MonoImage **images;
+
+       GHashTable *gclass_cache, *ginst_cache, *gmethod_cache, *gsignature_cache;
+
+       CRITICAL_SECTION    lock;
+
+       /*
+        * Memory for generic instances owned by this image set should be allocated from
+        * this mempool, using the mono_image_set_alloc family of functions.
+        */
+       MonoMemPool         *mempool;
+} MonoImageSet;
+
 enum {
        MONO_SECTION_TEXT,
        MONO_SECTION_RSRC,
@@ -277,6 +359,7 @@ struct _MonoDynamicAssembly {
        guint32 strong_name_size;
        guint8 run;
        guint8 save;
+       MonoDomain *domain;
 };
 
 struct _MonoDynamicImage {
@@ -299,6 +382,7 @@ struct _MonoDynamicImage {
        GHashTable *typespec;
        GHashTable *typeref;
        GHashTable *handleref;
+       MonoGHashTable *handleref_managed;
        MonoGHashTable *tokens;
        GHashTable *blob_cache;
        GHashTable *standalonesig_cache;
@@ -328,6 +412,7 @@ struct _MonoDynamicImage {
        MonoDynamicStream tstream;
        MonoDynamicStream guid;
        MonoDynamicTable tables [MONO_TABLE_NUM];
+       MonoClass *wrappers_type; /*wrappers are bound to this type instead of <Module>*/
 };
 
 /* Contains information about assembly binding */
@@ -347,9 +432,14 @@ typedef struct _MonoAssemblyBindingInfo {
 } MonoAssemblyBindingInfo;
 
 struct _MonoMethodHeader {
-       guint32      code_size;
        const unsigned char  *code;
-       guint16      max_stack;
+#ifdef MONO_SMALL_CONFIG
+       guint16      code_size;
+#else
+       guint32      code_size;
+#endif
+       guint16      max_stack   : 15;
+       unsigned int is_transient: 1; /* mono_metadata_free_mh () will actually free this header */
        unsigned int num_clauses : 15;
        /* if num_locals != 0, then the following apply: */
        unsigned int init_locals : 1;
@@ -358,6 +448,35 @@ struct _MonoMethodHeader {
        MonoType    *locals [MONO_ZERO_LEN_ARRAY];
 };
 
+typedef struct {
+       guint32      code_size;
+       gboolean     has_clauses;
+} MonoMethodHeaderSummary;
+
+#define MONO_SIZEOF_METHOD_HEADER (sizeof (struct _MonoMethodHeader) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
+
+struct _MonoMethodSignature {
+       MonoType     *ret;
+#ifdef MONO_SMALL_CONFIG
+       guint8        param_count;
+       gint8         sentinelpos;
+       unsigned int  generic_param_count : 5;
+#else
+       guint16       param_count;
+       gint16        sentinelpos;
+       unsigned int  generic_param_count : 16;
+#endif
+       unsigned int  call_convention     : 6;
+       unsigned int  hasthis             : 1;
+       unsigned int  explicit_this       : 1;
+       unsigned int  pinvoke             : 1;
+       unsigned int  is_inflated         : 1;
+       unsigned int  has_type_parameters : 1;
+       MonoType     *params [MONO_ZERO_LEN_ARRAY];
+};
+
+#define MONO_SIZEOF_METHOD_SIGNATURE (sizeof (struct _MonoMethodSignature) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
+
 /* for use with allocated memory blocks (assumes alignment is to 8 bytes) */
 guint mono_aligned_addr_hash (gconstpointer ptr) MONO_INTERNAL;
 
@@ -373,12 +492,47 @@ mono_image_alloc0 (MonoImage *image, guint size) MONO_INTERNAL;
 char*
 mono_image_strdup (MonoImage *image, const char *s) MONO_INTERNAL;
 
+GList*
+g_list_prepend_image (MonoImage *image, GList *list, gpointer data) MONO_INTERNAL;
+
+GSList*
+g_slist_append_image (MonoImage *image, GSList *list, gpointer data) MONO_INTERNAL;
+
+void
+mono_image_lock (MonoImage *image) MONO_INTERNAL;
+
+void
+mono_image_unlock (MonoImage *image) MONO_INTERNAL;
+
+gpointer
+mono_image_property_lookup (MonoImage *image, gpointer subject, guint32 property) MONO_INTERNAL;
+
+void
+mono_image_property_insert (MonoImage *image, gpointer subject, guint32 property, gpointer value) MONO_INTERNAL;
+
+void
+mono_image_property_remove (MonoImage *image, gpointer subject) MONO_INTERNAL;
+
+gboolean
+mono_image_close_except_pools (MonoImage *image) MONO_INTERNAL;
+
+void
+mono_image_close_finish (MonoImage *image) MONO_INTERNAL;
+
+typedef void  (*MonoImageUnloadFunc) (MonoImage *image, gpointer user_data);
+
+void
+mono_install_image_unload_hook (MonoImageUnloadFunc func, gpointer user_data) MONO_INTERNAL;
+
 MonoType*
 mono_metadata_get_shared_type (MonoType *type) MONO_INTERNAL;
 
-void
+GSList*
 mono_metadata_clean_for_image (MonoImage *image) MONO_INTERNAL;
 
+void
+mono_metadata_clean_generic_classes_for_image (MonoImage *image) MONO_INTERNAL;
+
 void
 mono_metadata_cleanup (void);
 
@@ -390,6 +544,7 @@ mono_metadata_interfaces_from_typedef_full  (MonoImage             *image,
                                                                                         guint32                table_index,
                                                                                         MonoClass           ***interfaces,
                                                                                         guint                 *count,
+                                                                                        gboolean               heap_alloc_result,
                                                                                         MonoGenericContext    *context) MONO_INTERNAL;
 
 MonoArrayType *
@@ -423,7 +578,11 @@ mono_metadata_parse_mh_full                 (MonoImage             *image,
                                             MonoGenericContainer  *container,
                                             const char            *ptr);
 
-int* mono_metadata_get_param_attrs          (MonoImage *m, int def);
+gboolean
+mono_method_get_header_summary (MonoMethod *method, MonoMethodHeaderSummary *summary) MONO_INTERNAL;
+
+int* mono_metadata_get_param_attrs          (MonoImage *m, int def, int param_count) MONO_INTERNAL;
+gboolean mono_metadata_method_has_param_attrs (MonoImage *m, int def) MONO_INTERNAL;
 
 guint
 mono_metadata_generic_context_hash          (const MonoGenericContext *context) MONO_INTERNAL;
@@ -448,18 +607,22 @@ mono_metadata_lookup_generic_class          (MonoClass               *gclass,
                                             MonoGenericInst       *inst,
                                             gboolean               is_dynamic) MONO_INTERNAL;
 
-MonoGenericInst *
-mono_metadata_inflate_generic_inst          (MonoGenericInst       *ginst,
-                                            MonoGenericContext    *context) MONO_INTERNAL;
+MonoGenericInst * mono_metadata_inflate_generic_inst  (MonoGenericInst *ginst, MonoGenericContext *context, MonoError *error) MONO_INTERNAL;
 
 void mono_dynamic_stream_reset  (MonoDynamicStream* stream) MONO_INTERNAL;
 void mono_assembly_addref       (MonoAssembly *assembly) MONO_INTERNAL;
 void mono_assembly_load_friends (MonoAssembly* ass) MONO_INTERNAL;
 gboolean mono_assembly_has_skip_verification (MonoAssembly* ass) MONO_INTERNAL;
 
+gboolean mono_assembly_close_except_image_pools (MonoAssembly *assembly) MONO_INTERNAL;
+void mono_assembly_close_finish (MonoAssembly *assembly) MONO_INTERNAL;
+
+
 gboolean mono_public_tokens_are_equal (const unsigned char *pubt1, const unsigned char *pubt2) MONO_INTERNAL;
 
 void mono_config_parse_publisher_policy (const char *filename, MonoAssemblyBindingInfo *binding_info) MONO_INTERNAL;
+void mono_config_parse_assembly_bindings (const char *filename, int major, int minor, void *user_data,
+                                         void (*infocb)(MonoAssemblyBindingInfo *info, void *user_data)) MONO_INTERNAL;
 
 gboolean
 mono_assembly_name_parse_full               (const char           *name,
@@ -473,8 +636,9 @@ guint32 mono_metadata_get_generic_param_row (MonoImage *image, guint32 token, gu
 void mono_unload_interface_ids (MonoBitSet *bitset) MONO_INTERNAL;
 
 
-MonoType *mono_metadata_type_dup (MonoMemPool *mp, const MonoType *original) MONO_INTERNAL;
-MonoMethodSignature  *mono_metadata_signature_dup_full (MonoMemPool *mp,MonoMethodSignature *sig) MONO_INTERNAL;
+MonoType *mono_metadata_type_dup (MonoImage *image, const MonoType *original) MONO_INTERNAL;
+MonoMethodSignature  *mono_metadata_signature_dup_full (MonoImage *image,MonoMethodSignature *sig) MONO_INTERNAL;
+MonoMethodSignature  *mono_metadata_signature_dup_mempool (MonoMemPool *mp, MonoMethodSignature *sig) MONO_INTERNAL;
 
 MonoGenericInst *
 mono_get_shared_generic_inst (MonoGenericContainer *container) MONO_INTERNAL;
@@ -482,17 +646,19 @@ mono_get_shared_generic_inst (MonoGenericContainer *container) MONO_INTERNAL;
 int
 mono_type_stack_size_internal (MonoType *t, int *align, gboolean allow_open) MONO_INTERNAL;
 
+void            mono_type_get_desc (GString *res, MonoType *type, mono_bool include_namespace);
+
 gboolean
 mono_metadata_type_equal_full (MonoType *t1, MonoType *t2, gboolean signature_only) MONO_INTERNAL;
 
 MonoMarshalSpec *
-mono_metadata_parse_marshal_spec_with_mempool (MonoMemPool *mp, const char *ptr) MONO_INTERNAL;
+mono_metadata_parse_marshal_spec_full (MonoImage *image, const char *ptr) MONO_INTERNAL;
 
 guint         mono_metadata_generic_inst_hash (gconstpointer data) MONO_INTERNAL;
 gboolean       mono_metadata_generic_inst_equal (gconstpointer ka, gconstpointer kb) MONO_INTERNAL;
 
 void
-mono_metadata_field_info_with_mempool (MonoMemPool *mp, 
+mono_metadata_field_info_with_mempool (
                                          MonoImage *meta, 
                                      guint32       table_index,
                                      guint32      *offset,
@@ -508,5 +674,22 @@ mono_metadata_get_corresponding_event_from_generic_type_definition (MonoEvent *e
 MonoProperty*
 mono_metadata_get_corresponding_property_from_generic_type_definition (MonoProperty *property) MONO_INTERNAL;
 
+guint32
+mono_metadata_signature_size (MonoMethodSignature *sig) MONO_INTERNAL;
+
+guint mono_metadata_str_hash (gconstpointer v1) MONO_INTERNAL;
+
+gboolean mono_image_load_pe_data (MonoImage *image) MONO_INTERNAL;
+
+gboolean mono_image_load_cli_data (MonoImage *image) MONO_INTERNAL;
+
+void mono_image_load_names (MonoImage *image) MONO_INTERNAL;
+
+MonoImage *mono_image_open_raw (const char *fname, MonoImageOpenStatus *status) MONO_INTERNAL;
+
+MonoException *mono_get_exception_field_access_msg (const char *msg) MONO_INTERNAL;
+
+MonoException *mono_get_exception_method_access_msg (const char *msg) MONO_INTERNAL;
+
 #endif /* __MONO_METADATA_INTERNALS_H__ */