-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add support in WASM for calling UnmanagedCallersOnly functions
#121359
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
Conversation
|
Tagging subscribers to this area: @mangod9 |
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 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 |
|
Converting this to draft. The approach in this PR doesn't permit linking against exports. I will need to modify it. |
|
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. |
Replace Win32 LONG with int32_t on new API.
jkotas
left a comment
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.
Thanks
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. |
|
/ba-g unrelated timeouts |
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 |
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.