Fix initialization of t_MostRecentUMEntryThunkData in reverse pinvokes #126579
Open
BrzVlad wants to merge 4 commits intodotnet:mainfrom
Open
Fix initialization of t_MostRecentUMEntryThunkData in reverse pinvokes #126579BrzVlad wants to merge 4 commits intodotnet:mainfrom
BrzVlad wants to merge 4 commits intodotnet:mainfrom
Conversation
Interpreter doesn't have cominterop support
After recent change, `TheUMEntryPrestubWorker` returns the interpreter precode rather than the prestub (which was setting this variable in the fast path). The interpreter needs to access the hidden argument from this TLS variable.
targetIsPrecode was misleading because, in interpreter case, it was false but the target was pointing to interpreter precode, and not the prestub.
Contributor
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes reverse P/Invoke behavior when targeting the interpreter by ensuring t_MostRecentUMEntryThunkData is populated even when the call path can directly jump to the interpreter precode (skipping the second prestub pass that previously performed the TLS write).
Changes:
- Update
TheUMEntryPrestubWorkerto sett_MostRecentUMEntryThunkDatawhen the prestub cannot be skipped (interpreter path), including a rename fromtargetIsPrecode→canSkipPreStubfor clarity. - Remove interpreter-specific TLS plumbing from COM call prestub code, which is now dead/unnecessary.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/coreclr/vm/dllimportcallback.cpp |
Ensures reverse P/Invoke interpreter path initializes the TLS thunk-data used as the hidden argument. |
src/coreclr/vm/comcallablewrapper.cpp |
Removes unused interpreter-specific TLS handling from COM prestub flow. |
jkoritzinsky
reviewed
Apr 6, 2026
This was referenced Apr 7, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In reverse pinvokes, the interpreter receives the
UMEntryThunkDatain this TLS variable as a hidden argument. The way this is implemented is that reverse pinvokes always go through the prestub which checks whether the target is interpreter, in which case it writes this TLS variable. This means that first call was going through the prestub twice, first to initialize the thunk data and secondly to set this argument (TheUMEntryPrestubWorkerwas returning itself so it gets called again).Following 60f1dc1, we obtain the entryPoint so we end up calling the interpreter precode directly. The problem is that we failed to set the TLS variable, which is what this PR is doing.
This also does minor cleanup by removing dead interpreter code from COM sources and renaming
targetIsPrecodetocanSkipPreStub, because the first name was misleading (it was false whenentryPointwas pointing to interpreter precode).