Skip to content

Commit

Permalink
Fix access to m_pDynamicStaticsInfo (#97353)
Browse files Browse the repository at this point in the history
- Remove race condition where it is possible that an updated dynamic statics info pointer is published without ensuring that the data is also considered written.
- Use VolatileLoadWithoutBarrier at the read site (where locks are not taken) to ensure that there are no difficult to examine reads of this pointer.
  • Loading branch information
davidwrighton committed Jan 23, 2024
1 parent bf10f73 commit 85e9e7b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/vm/ceeload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ DWORD Module::AllocateDynamicEntry(MethodTable *pMT)
if (m_pDynamicStaticsInfo)
memcpy(pNewDynamicStaticsInfo, m_pDynamicStaticsInfo, sizeof(DynamicStaticsInfo) * m_maxDynamicEntries);

m_pDynamicStaticsInfo = pNewDynamicStaticsInfo;
VolatileStore(&m_pDynamicStaticsInfo, pNewDynamicStaticsInfo);
m_maxDynamicEntries = maxDynamicEntries;
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/ceeload.inl
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ inline MethodTable* Module::GetDynamicClassMT(DWORD dynamicClassID)
{
LIMITED_METHOD_CONTRACT;
_ASSERTE(m_cDynamicEntries > dynamicClassID);
return m_pDynamicStaticsInfo[dynamicClassID].pEnclosingMT;
return VolatileLoadWithoutBarrier(&m_pDynamicStaticsInfo)[dynamicClassID].pEnclosingMT;
}

#ifdef FEATURE_CODE_VERSIONING
Expand Down

0 comments on commit 85e9e7b

Please sign in to comment.