Skip to content

Implement interpreter PInvoke Calli - #119356

Merged
janvorli merged 6 commits into
dotnet:mainfrom
janvorli:implement-pinvoke-calli-support
Sep 8, 2025
Merged

Implement interpreter PInvoke Calli#119356
janvorli merged 6 commits into
dotnet:mainfrom
janvorli:implement-pinvoke-calli-support

Conversation

@janvorli

Copy link
Copy Markdown
Member

The Calli implementation was missing support for the case when the targer is a pinvoke. That resulted in errors due to incorrect GC mode. This change fixes that.

@janvorlijanvorli added this to the 11.0.0 milestone Sep 4, 2025
@janvorlijanvorli self-assigned this Sep 4, 2025
CopilotAI review requested due to automatic review settings September 4, 2025 17:39

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 missing PInvoke support for the interpreter's Calli (indirect call) functionality in the CoreCLR runtime. The implementation ensures proper GC mode handling when calling native functions through function pointers.

Key changes:

  • Added a new InvokePInvokeCalliStub function that handles PInvoke calls with proper GC mode transitions
  • Extended the Calli opcode to include PInvoke detection information
  • Refactored Calli emission code to centralize the logic and include calling convention analysis

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
src/coreclr/vm/wasm/helpers.cppAdded stub implementation of InvokePInvokeCalliStub for WASM platform
src/coreclr/vm/interpexec.cppImplemented InvokePInvokeCalliStub with proper GC transitions and updated Calli execution logic
src/coreclr/interpreter/intops.defExtended Calli opcodes to include an additional parameter for PInvoke detection
src/coreclr/interpreter/compiler.hAdded declaration for new EmitCalli helper method
src/coreclr/interpreter/compiler.cppImplemented EmitCalli method and refactored call emission to use it

Comment threadsrc/coreclr/interpreter/compiler.cpp Outdated
Comment threadsrc/coreclr/vm/interpexec.cpp Outdated
Comment threadsrc/coreclr/vm/interpexec.cpp
Comment threadsrc/coreclr/vm/interpexec.cpp Outdated
The Calli implementation was missing support for the case when the
targer is a pinvoke. That resulted in errors due to incorrect GC mode.
This change fixes that.
Comment threadsrc/coreclr/interpreter/compiler.cpp Outdated
Comment threadsrc/coreclr/vm/interpexec.cpp Outdated
* Disable calli with marshalled pinvokes
* Refactor the target invocation methods
Comment threadsrc/coreclr/vm/interpexec.cpp Outdated
Comment threadsrc/coreclr/vm/interpexec.cpp Outdated
Comment threadsrc/coreclr/vm/wasm/helpers.cpp Outdated
Comment threadsrc/coreclr/interpreter/compiler.cpp Outdated
@janvorli
janvorli merged commit a216015 into dotnet:mainSep 8, 2025
98 checks passed
@janvorli
janvorli deleted the implement-pinvoke-calli-support branch September 8, 2025 21:23
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Oct 9, 2025
@pavelsavara

Copy link
Copy Markdown
Member

I can see this again #123008

I'm runningSystem.Runtime.Tests in Release mode.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@janvorli@pavelsavara@jkotas