-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[clr-interp] Fix logic around interpreter stub startup where the CallStubHeader may not be generated due to a race #120952
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
[clr-interp] Fix logic around interpreter stub startup where the CallStubHeader may not be generated due to a race #120952
Conversation
davidwrighton
commented
Oct 21, 2025
- Instead of generating it at the end of DoPrestub, which does not reliably finish before other threads may attempt to use the CallStubHeader, do it on demand just when it is needed
- This reduces total memory allocation, and makes the logic correct by construction
- In addition the GetInterpThreadContextWithPossiblyMissingThread function did not correctly setup EH handling regions and such to accomodate for the possibility that it might need to allocate or do a GC transition, so I've added passing the transition context into it, and set it up to use a PrestubFrame to protect the argument registers
…StubHeader may not be generated due to a race - Instead of generating it at the end of DoPrestub, which does not reliably finish before other threads may attempt to use the CallStubHeader, do it on demand just when it is needed - This reduces total memory allocation, and makes the logic correct by construction - In addition the GetInterpThreadContextWithPossiblyMissingThread function did not correctly setup EH handling regions and such to accomodate for the possibility that it might need to allocate or do a GC transition, so I've added passing the transition context into it, and set it up to use a PrestubFrame to protect the argument registers
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
This PR fixes a race condition in the interpreter stub startup logic where the CallStubHeader might not be generated before other threads attempt to use it. The fix moves the CallStubHeader generation from DoPrestub (where it couldn't reliably complete before other threads needed it) to on-demand generation when actually needed.
- Removes early CallStubHeader generation from DoPrestub that could race
- Implements on-demand CallStubHeader generation in the interpreter stub path with proper synchronization
- Adds proper EH handling and GC transition support to GetInterpThreadContextWithPossiblyMissingThreadOrCallStub
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/coreclr/vm/virtualcallstub.cpp | Removes forward declaration now moved to header |
src/coreclr/vm/threads.cpp | Refactors and expands GetInterpThreadContextWithPossiblyMissingThread to handle on-demand CallStub generation with proper frame setup |
src/coreclr/vm/prestub.cpp | Removes premature CallStubHeader generation that could race |
src/coreclr/vm/precode.cpp | Fixes field access to use methodDesc instead of methodHnd |
src/coreclr/vm/interpexec.cpp | Simplifies CreateNativeToInterpreterCallStub early-exit logic and fixes field references |
src/coreclr/vm/exceptionhandling.h | Moves IsCallDescrWorkerInternalReturnAddress declaration to header for broader visibility |
src/coreclr/vm/exceptionhandling.cpp | Removes forward declaration now in header |
src/coreclr/vm/arm64/asmhelpers.asm | Updates assembly to call renamed function and check for missing CallStub |
src/coreclr/vm/arm64/asmhelpers.S | Updates assembly to call renamed function and check for missing CallStub |
src/coreclr/vm/amd64/asmhelpers.S | Updates assembly to call renamed function and check for missing CallStub |
src/coreclr/vm/amd64/AsmHelpers.asm | Updates assembly to call renamed function and check for missing CallStub |
src/coreclr/interpreter/interpreter.h | Defines INTERPRETER_COMPILER_INTERNAL to control field naming |
src/coreclr/interpreter/inc/interpretershared.h | Adds conditional compilation to expose methodDesc field outside compiler |
Tagging subscribers to this area: @mangod9 |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
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.
LGTM, thank you!
I hope there was a way to not to create the CallStub from the asm helper, but I don't see one. |