2009-07-30 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / metadata / metadata-internals.h
index 929cd0847cc9e3af0c2eaea49301aaef5f18bbeb..e27ffc770a1a527888ae2215d7dc4d2c3d9ea6ce 100644 (file)
 #include "mono/utils/mono-compiler.h"
 #include "mono/utils/mono-dl.h"
 #include "mono/utils/monobitset.h"
+#include "mono/utils/mono-property-hash.h"
+#include "mono/utils/mono-value-hash.h"
+
+#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)
 
 struct _MonoAssembly {
        /* 
@@ -23,9 +29,9 @@ struct _MonoAssembly {
        int ref_count; /* use atomic operations only */
        char *basedir;
        MonoAssemblyName aname;
-       MonoDl *aot_module;
        MonoImage *image;
-       GSList *friend_assembly_names;
+       GSList *friend_assembly_names; /* Computed by mono_assembly_load_friends () */
+       guint8 friend_assembly_names_inited;
        guint8 in_gac;
        guint8 dynamic;
        guint8 corlib_internal;
@@ -35,6 +41,7 @@ struct _MonoAssembly {
        guint32 aptc:2;         /* Has the [AllowPartiallyTrustedCallers] attributes */
        guint32 fulltrust:2;    /* Has FullTrust permission */
        guint32 unmanaged:2;    /* Has SecurityPermissionFlag.UnmanagedCode permission */
+       guint32 skipverification:2;     /* Has SecurityPermissionFlag.SkipVerification permission */
 };
 
 typedef struct {
@@ -72,11 +79,20 @@ struct _MonoImage {
         * this image between calls of mono_image_open () and mono_image_close ().
         */
        int   ref_count;
+       void *raw_data_handle;
        char *raw_data;
        guint32 raw_data_len;
        guint8 raw_buffer_used    : 1;
        guint8 raw_data_allocated : 1;
 
+#ifdef PLATFORM_WIN32
+       /* Module was loaded using LoadLibrary. */
+       guint8 is_module_handle : 1;
+
+       /* Module entry point is _CorDllMain. */
+       guint8 has_entry_point : 1;
+#endif
+
        /* Whenever this is a dynamically emitted module */
        guint8 dynamic : 1;
 
@@ -92,6 +108,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;
@@ -100,7 +119,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;
                            
@@ -129,6 +148,8 @@ struct _MonoImage {
 
        MonoImage **files;
 
+       gpointer aot_module;
+
        /*
         * The Assembly this image was loaded from.
         */
@@ -137,8 +158,12 @@ struct _MonoImage {
        /*
         * Indexed by method tokens and typedef tokens.
         */
-       GHashTable *method_cache;
+       MonoValueHashTable *method_cache; /*protected by the image lock*/
        MonoInternalHashTable class_cache;
+
+       /* Indexed by memberref + methodspec tokens */
+       GHashTable *methodref_cache; /*protected by the image lock*/
+
        /*
         * Indexed by fielddef and memberref tokens
         */
@@ -156,7 +181,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
@@ -164,6 +189,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 
         */
@@ -181,39 +210,36 @@ 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 *cominterop_wrapper_cache; /* LOCKING: marshal lock */
+       GHashTable *thunk_invoke_cache;
 
        /*
         * indexed by MonoClass pointers
         */
        GHashTable *ldfld_wrapper_cache;
        GHashTable *ldflda_wrapper_cache;
-       GHashTable *ldfld_remote_wrapper_cache;
        GHashTable *stfld_wrapper_cache;
-       GHashTable *stfld_remote_wrapper_cache;
        GHashTable *isinst_cache;
        GHashTable *castclass_cache;
        GHashTable *proxy_isinst_cache;
        GHashTable *rgctx_template_hash; /* LOCKING: templates lock */
-       /* Maps from uninstantiated generic classes to GSList's of
-        * instantiated open generic classes whose container class is the key
-        * class.
-        *
-        * LOCKING: templates lock
-        */
-       GHashTable *generic_class_open_instances_hash;
 
        /*
         * indexed by token and MonoGenericContext pointer
         */
        GHashTable *generic_class_cache;
 
+       /* Contains rarely used fields of runtime structures belonging to this image */
+       MonoPropertyHash *property_hash;
+
        void *reflection_info;
 
        /*
@@ -227,6 +253,12 @@ struct _MonoImage {
 
        /* interfaces IDs from this image */
        MonoBitSet *interface_bitset;
+
+       /*
+        * 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;
 };
 
 enum {
@@ -283,12 +315,15 @@ struct _MonoDynamicImage {
        GHashTable *handleref;
        MonoGHashTable *tokens;
        GHashTable *blob_cache;
+       GHashTable *standalonesig_cache;
        GList *array_methods;
        GPtrArray *gen_params;
        MonoGHashTable *token_fixups;
        GHashTable *method_to_table_idx;
        GHashTable *field_to_table_idx;
        GHashTable *method_aux_hash;
+       MonoGHashTable *generic_def_objects;
+       MonoGHashTable *methodspec;
        gboolean run;
        gboolean save;
        gboolean initial_image;
@@ -307,6 +342,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 */
@@ -343,6 +379,40 @@ guint mono_aligned_addr_hash (gconstpointer ptr) MONO_INTERNAL;
 void
 mono_image_check_for_module_cctor (MonoImage *image) MONO_INTERNAL;
 
+gpointer
+mono_image_alloc  (MonoImage *image, guint size) MONO_INTERNAL;
+
+gpointer
+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;
+
+
+MonoType*
+mono_metadata_get_shared_type (MonoType *type) MONO_INTERNAL;
+
 void
 mono_metadata_clean_for_image (MonoImage *image) MONO_INTERNAL;
 
@@ -421,7 +491,10 @@ mono_metadata_inflate_generic_inst          (MonoGenericInst       *ginst,
 
 void mono_dynamic_stream_reset  (MonoDynamicStream* stream) MONO_INTERNAL;
 void mono_assembly_addref       (MonoAssembly *assembly) MONO_INTERNAL;
-void mono_assembly_load_friends (MonoAssembly* ass);
+void mono_assembly_load_friends (MonoAssembly* ass) MONO_INTERNAL;
+gboolean mono_assembly_has_skip_verification (MonoAssembly* ass) 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;
 
@@ -437,7 +510,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;
+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;
@@ -448,6 +523,39 @@ mono_type_stack_size_internal (MonoType *t, int *align, gboolean allow_open) MON
 gboolean
 mono_metadata_type_equal_full (MonoType *t1, MonoType *t2, gboolean signature_only) MONO_INTERNAL;
 
+MonoMarshalSpec *
+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 (
+                                         MonoImage *meta, 
+                                     guint32       table_index,
+                                     guint32      *offset,
+                                     guint32      *rva,
+                                     MonoMarshalSpec **marshal_spec);
+
+MonoClassField*
+mono_metadata_get_corresponding_field_from_generic_type_definition (MonoClassField *field) MONO_INTERNAL;
+
+MonoEvent*
+mono_metadata_get_corresponding_event_from_generic_type_definition (MonoEvent *event) MONO_INTERNAL;
+
+MonoProperty*
+mono_metadata_get_corresponding_property_from_generic_type_definition (MonoProperty *property) MONO_INTERNAL;
+
+guint32
+mono_metadata_signature_size (MonoMethodSignature *sig) 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;
 
 #endif /* __MONO_METADATA_INTERNALS_H__ */