-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add acquire barrier to populate bit reading #117523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add acquire barrier to populate bit reading #117523
Conversation
The setting of the NDirectMethodDesc::kNDirectPopulated bit is done via an interlocked operation. This bit is used to indicate if the NDirectMethodDesc has 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds an acquire barrier to the IsPopulated
check so that any writes performed before setting the kNDirectPopulated
bit are correctly observed by readers.
- Updated
IsPopulated
to useVolatileLoad
when readingm_wFlags
Tagging subscribers to this area: @dotnet/interop-contrib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must have been an absolute pain to debug and find. LGTM!
Definitely not for this change, but should we have something similar for |
/backport to release/9.0-staging |
Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/17923699227 |
The setting of the
NDirectMethodDesc::kNDirectPopulated
bit is done via an interlocked operation. This bit is used to indicate if theNDirectMethodDesc
has 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.Fixes #112565
This should be considered to backport to .NET 9.0.