[release/9.0-staging] Add acquire barrier to populate bit reading #119967
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #117523 to release/9.0-staging
/cc @AaronRobinsonMSFT
Fixes #119947
Customer Impact
See confirmation the fix addressed the issue in .NET 10 and the OP is requesting backport to .NET 9 - #119947. The original issue can be found at #112565.
The setting of the
PInvokeMethodDesc::kPInvokePopulatedbit is done via an interlocked operation. This bit is used to indicate if thePInvokeMethodDeschas been populated with the needed information to load the P/Invoke. The reading of this bit however was missing an acquire barrier and thus setting of fields between the check and set weren't being observed correctly.Regression
It isn't obvious when this was likely introduced, but it is likely been in the code base for many years. It was likely uncovered by refactors of PInvoke code paths.
Testing
This was checked in .NET 10 and the external user has been running without observing a crash for several weeks.
Risk
Low. This has been running in .NET 10 preview for several weeks and an external user has been running with these bits without observing the issue.