- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
[interp] Reverse p/invoke #119133
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
[interp] Reverse p/invoke #119133
Conversation
b1b10b0    to
    8fcd3d1      
    Compare
  
    | I redid part of this from scratch to try and make it less messy and take into account @jkotas 's feedback. Still need to apply the optimization he suggested based on CORJIT_FLAG_PUBLISH_SECRET_PARAM. | 
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 implements reverse P/Invoke support in the CoreCLR interpreter by adding the GetStubContext intrinsic and ensuring proper hidden argument handling for interpreted code. The implementation allows the interpreter to capture and retrieve hidden arguments needed for reverse P/Invoke scenarios.
Key changes:
- Adds GetStubContext intrinsic support to the interpreter instruction set
- Implements thread-local storage for capturing hidden arguments during reverse P/Invoke transitions
- Modifies interpreter frame structure to store hidden arguments for later retrieval
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description | 
|---|---|
| src/coreclr/vm/prestub.cpp | Adds hidden argument capture logic to ExecuteInterpretedMethod | 
| src/coreclr/vm/interpexec.h | Extends InterpMethodContextFrame with hiddenArgument field | 
| src/coreclr/vm/interpexec.cpp | Implements INTOP_GETSTUBCONTEXT instruction handler | 
| src/coreclr/vm/dllimportcallback.h | Adds interpreter target support to UMEntryThunkData | 
| src/coreclr/vm/dllimportcallback.cpp | Implements thread-local storage for UMEntryThunkData | 
| src/coreclr/interpreter/intrinsics.cpp | Adds GetStubContext to named intrinsics mapping | 
| src/coreclr/interpreter/intops.def | Defines INTOP_GETSTUBCONTEXT instruction | 
| src/coreclr/interpreter/interpretershared.h | Adds hasHiddenArgument flag to InterpMethod | 
| src/coreclr/interpreter/compiler.cpp | Implements GetStubContext intrinsic compilation and adds hasHiddenArgument detection | 
…d reverse p/invoke stubs and ensure that the worker runs on every reverse p/invoke, so that the interpreter can recover the hidden argument and make it available via GetStubContext. Add INTOP_GETSTUBCONTEXT and always generate it for the GetStubContext intrinsic, even if other intrinsics are disabled Address PR feedback Revert most changes
Add missing ifdef
14de1a8    to
    2191010      
    Compare
  
    | GetInterpreterTarget had STANDARD_VM_CONTRACT which was causing spurious contract failures in JIT\SIMD\Vector3Interop_r\Vector3Interop_r. I've updated it to LIMITED_METHOD_CONTRACT since it's just a field getter. | 
… on demand instead of always having a field for it on InterpreterFrame
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.
Thank you!
Fixes baseservices\threading\regressions\115178 and probably others.