Uh oh!
There was an error while loading. Please reload this page.
Add support in WASM for calling UnmanagedCallersOnly functions - #121359
Conversation
Tagging subscribers to this area: @mangod9 |
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for UnmanagedCallersOnly methods in the WASM interpreter environment. It implements a thunk lookup mechanism for reverse P/Invoke scenarios and refactors some existing code for better organization.
Key changes:
- Implements
GetUnmanagedCallersOnlyThunkfunction to look up thunks for methods with the UnmanagedCallersOnly attribute - Adds caching infrastructure for reverse thunks using hash-based lookup
- Refactors
ExecuteInterpretedMethodFromUnmanagedto consolidate interpreter method execution from unmanaged code - Enables UnmanagedCallersOnly support in
CreateDelegatefor WASM by removing the blanketE_NOTIMPLerror
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/wasm/helpers.cpp | Adds reverse thunk lookup infrastructure and GetUnmanagedCallersOnlyThunk implementation |
| src/coreclr/vm/wasm/callhelpers.hpp | Updates header guards and adds reverse thunk data structures |
| src/coreclr/vm/wasm/callhelpers.cpp | Adds reverse thunk map array definition with placeholder example |
| src/coreclr/vm/wasm/calldescrworkerwasm.cpp | Simplifies to use new ExecuteInterpretedMethodFromUnmanaged function |
| src/coreclr/vm/prestub.cpp | Refactors and renames function to ExecuteInterpretedMethodFromUnmanaged |
| src/coreclr/vm/precode_portable.hpp | Adds flags for tracking UnmanagedCallersOnly attribute |
| src/coreclr/vm/precode_portable.cpp | Implements HasUnmanagedCallersOnlyAttribute method with caching |
| src/coreclr/vm/method.cpp | Updates TryGetMultiCallableAddrOfCode to handle UnmanagedCallersOnly |
| src/coreclr/vm/interpexec.h | Adds forward declaration for ExecuteInterpretedMethodFromUnmanaged |
| src/coreclr/vm/corhost.cpp | Enables UnmanagedCallersOnly for WASM in CreateDelegate |
| src/coreclr/interpreter/compiler.cpp | Uses aggregate initialization instead of memset |
| src/coreclr/hosts/corerun/CMakeLists.txt | Conditionalizes WASM_BIGINT flag for browser-only scenarios |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
AaronRobinsonMSFT
commented
Nov 5, 2025
Converting this to draft. The approach in this PR doesn't permit linking against exports. I will need to modify it. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have the reversed generator part nearly ported, current output looks like https://gist.github.com/radekdoulik/049236003eca75bc34fed6ee727d89fc Take it just as a preview, didn't try to build the output yet. It also shouldn't have zero sized args arrays, etc. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Replace Win32 LONG with int32_t on new API.
Uh oh!
There was an error while loading. Please reload this page.
AaronRobinsonMSFT
commented
Nov 7, 2025
Thanks @radekdoulik. I had to tweak them a bit, but they were close. See 0bf48e9. Note that the hashing logic doesn't match what is in this PR. That means this will only work for exports and not through @pavelsavara Please checkout the above commit so you can see how to enable this for more. |
radekdoulik
commented
Nov 7, 2025
/ba-g unrelated timeouts |
Uh oh!
There was an error while loading. Please reload this page.
radekdoulik
commented
Nov 7, 2025
That's great, thank you. I will finish the generator changes. |
So now, we don't need those anymore runtime/src/coreclr/vm/corelib.h Lines 757 to 761 in 6e1e6b1 except they are keeping the IL from trimming. Because #101434 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Fixes#121006
This provides an entry point, similar to P/Invokes thunks, for generated reverse P/Invoke stubs. A commented out example of the generated code was provided.