Skip to content

Conversation

davidwrighton
Copy link
Member

  • 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
@Copilot Copilot AI review requested due to automatic review settings October 21, 2025 21:17
Copy link
Contributor

@Copilot Copilot AI left a 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

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@janvorli
Copy link
Member

I hope there was a way to not to create the CallStub from the asm helper, but I don't see one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants