Skip to content

[Wasm RyuJIT] Codegen for reverse pinvoke/unmanagedcallersonly#127751

Open
kg wants to merge 3 commits intodotnet:mainfrom
kg:wasm-rpinvoke-1
Open

[Wasm RyuJIT] Codegen for reverse pinvoke/unmanagedcallersonly#127751
kg wants to merge 3 commits intodotnet:mainfrom
kg:wasm-rpinvoke-1

Conversation

@kg
Copy link
Copy Markdown
Member

@kg kg commented May 4, 2026

Sufficient to compile

    [MethodImpl(MethodImplOptions.NoInlining)]
    static void * getUco () {
        return (delegate* unmanaged[Cdecl]<int>)&uco;
    }

    [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
    static int uco () {
        return 42;
    }

Copilot AI review requested due to automatic review settings May 4, 2026 13:49
@kg kg added arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labels May 4, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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 updates the WASM RyuJIT prolog to support methods where the WASM shadow stack pointer is not passed as an explicit argument (reverse P/Invoke / UnmanagedCallersOnly entrypoints), allowing the sample in the PR description to compile.

Changes:

  • Introduces a WASM global index constant intended to represent the stack pointer global.
  • Updates CodeGen::genAllocLclFrame to initialize the SP local from a global when the SP “arg” is not actually a parameter (RPI case).
  • Keeps the existing SP-as-first-arg path for normal managed calling convention.

Comment thread src/coreclr/jit/codegenwasm.cpp
Comment thread src/coreclr/jit/codegenwasm.cpp Outdated
@kg kg marked this pull request as ready for review May 4, 2026 21:17
Copilot AI review requested due to automatic review settings May 4, 2026 21:17
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/jit/codegenwasm.cpp
@kg
Copy link
Copy Markdown
Member Author

kg commented May 5, 2026

PTAL @dotnet/jit-contrib

Copy link
Copy Markdown
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

I think we may run into some trouble when lvaWasmSpArg does not represent an arg.

In particular compMapILargNum and compMap2ILvarNum are not prepared to handle this case.

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

Labels

arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants