Fix read ordering bug between buckets pointer and counter (#26997) (#27009)
authorFadi Hanna <fadim@microsoft.com>
Thu, 3 Oct 2019 19:08:01 +0000 (12:08 -0700)
committerGitHub <noreply@github.com>
Thu, 3 Oct 2019 19:08:01 +0000 (12:08 -0700)
* Fix read ordering bug between buckets pointer and counter

Use VolaiteLoad to read counter

src/vm/ngenhash.inl

index cc1f139..de16e38 100644 (file)
@@ -1263,8 +1263,11 @@ DPTR(VALUE) NgenHashTable<NGEN_HASH_ARGS>::FindVolatileEntryByHash(NgenHashValue
     // Since there is at least one entry there must be at least one bucket.
     _ASSERTE(m_cWarmBuckets > 0);
 
+    // Compute which bucket the entry belongs in based on the hash.
+    DWORD dwBucket = iHash % VolatileLoad(&m_cWarmBuckets);
+
     // Point at the first entry in the bucket chain which would contain any entries with the given hash code.
-    PTR_VolatileEntry pEntry = (GetWarmBuckets())[iHash % m_cWarmBuckets];
+    PTR_VolatileEntry pEntry = (GetWarmBuckets())[dwBucket];
 
     // Walk the bucket chain one entry at a time.
     while (pEntry)