[TSan] Unlock fastpath when checking domains_to_finalize (#5598)
authorArmin Hasitzka <cherusker@users.noreply.github.com>
Wed, 20 Sep 2017 19:51:18 +0000 (21:51 +0200)
committermonojenkins <jo.shields+jenkins@xamarin.com>
Wed, 20 Sep 2017 19:51:18 +0000 (21:51 +0200)
[TSan] Unlock fastpath when checking domains_to_finalize

I understand that the affected line is a fastpath which seems absolutely fine to me as it is properly checked later. It is, however, rightfully, detected as a data race by Clang's ThreadSanitizer. I would, therefore, suggest using `UnlockedReadPointer ()` to mark this race as known + accepted.

mono/metadata/gc.c
mono/utils/unlocked.h

index 3c78b6153c23f4d56966de04b7c5dba586f11911..3e0fcb0953e83f67c14eaf27afae8c3a4ddaf978 100644 (file)
@@ -44,6 +44,7 @@
 #include <mono/utils/mono-coop-semaphore.h>
 #include <mono/utils/hazard-pointer.h>
 #include <mono/utils/w32api.h>
+#include <mono/utils/unlocked.h>
 
 #ifndef HOST_WIN32
 #include <pthread.h>
@@ -780,7 +781,7 @@ finalize_domain_objects (void)
        DomainFinalizationReq *req = NULL;
        MonoDomain *domain;
 
-       if (domains_to_finalize) {
+       if (UnlockedReadPointer ((gpointer)&domains_to_finalize)) {
                mono_finalizer_lock ();
                if (domains_to_finalize) {
                        req = (DomainFinalizationReq *)domains_to_finalize->data;
index dedcc4e73cf066ad777e8bc0510f978b65c619a4..406b686cfeb850c2e064353c12ca696342f335cb 100644 (file)
@@ -122,4 +122,11 @@ UnlockedReadBool (gboolean *src)
        return *src;
 }
 
+MONO_UNLOCKED_ATTRS
+gpointer
+UnlockedReadPointer (volatile gpointer *src)
+{
+       return *src;
+}
+
 #endif /* _UNLOCKED_H_ */