[runtime] Protect mono_create_icall_signature with the corlib image lock.
authorRodrigo Kumpera <kumpera@gmail.com>
Tue, 26 Nov 2013 21:19:58 +0000 (16:19 -0500)
committerRodrigo Kumpera <kumpera@gmail.com>
Thu, 5 Dec 2013 19:11:55 +0000 (14:11 -0500)
mono/metadata/icall.c
mono/metadata/image.c

index 1112f988d94f4f1de45323b24dfa9f4a7cbfefc9..9ae6be8cdf46ef6f2e8cb5092ad6c7c35c5cb8f4 100644 (file)
@@ -8265,20 +8265,24 @@ type_from_typename (char *typename)
        return &klass->byval_arg;
 }
 
+/**
+ * LOCKING: Take the corlib image lock.
+ */
 MonoMethodSignature*
 mono_create_icall_signature (const char *sigstr)
 {
        gchar **parts;
        int i, len;
        gchar **tmp;
-       MonoMethodSignature *res;
+       MonoMethodSignature *res, *res2;
+       MonoImage *corlib = mono_defaults.corlib;
 
-       mono_loader_lock ();
-       res = g_hash_table_lookup (mono_defaults.corlib->helper_signatures, sigstr);
-       if (res) {
-               mono_loader_unlock ();
+       mono_image_lock (corlib);
+       res = g_hash_table_lookup (corlib->helper_signatures, sigstr);
+       mono_image_unlock (corlib);
+
+       if (res)
                return res;
-       }
 
        parts = g_strsplit (sigstr, " ", 256);
 
@@ -8289,7 +8293,7 @@ mono_create_icall_signature (const char *sigstr)
                tmp ++;
        }
 
-       res = mono_metadata_signature_alloc (mono_defaults.corlib, len - 1);
+       res = mono_metadata_signature_alloc (corlib, len - 1);
        res->pinvoke = 1;
 
 #ifdef HOST_WIN32
@@ -8307,9 +8311,13 @@ mono_create_icall_signature (const char *sigstr)
 
        g_strfreev (parts);
 
-       g_hash_table_insert (mono_defaults.corlib->helper_signatures, (gpointer)sigstr, res);
-
-       mono_loader_unlock ();
+       mono_image_lock (corlib);
+       res2 = g_hash_table_lookup (corlib->helper_signatures, sigstr);
+       if (res2)
+               res = res2; /*Value is allocated in the image pool*/
+       else
+               g_hash_table_insert (corlib->helper_signatures, (gpointer)sigstr, res);
+       mono_image_unlock (corlib);
 
        return res;
 }
index 7140a630bad2630e1e332dd5dd3b7c2e1ef089e6..5b097ea31d47e54f621d83cc39152fbb94ccabbf 100644 (file)
@@ -1653,9 +1653,7 @@ mono_image_close_except_pools (MonoImage *image)
        free_hash (image->pinvoke_scope_filenames);
 
        /* The ownership of signatures is not well defined */
-       //g_hash_table_foreach (image->memberref_signatures, free_mr_signatures, NULL);
        g_hash_table_destroy (image->memberref_signatures);
-       //g_hash_table_foreach (image->helper_signatures, free_mr_signatures, NULL);
        g_hash_table_destroy (image->helper_signatures);
        g_hash_table_destroy (image->method_signatures);