[wasm] Fix reflection invoke of R2R-compiled methods#129808
Closed
AndyAyersMS wants to merge 1 commit into
Closed
Conversation
CallDescrWorkerInternal only dispatched to interpreted targets: for an R2R method GetInterpreterCode() stays null after the prestub, so it ran the interpreter with a null target, executed nothing, and left the return buffer aliasing the arguments. Dispatch through InvokeManagedMethod (the interpreter-to-R2R thunk) when there is no interpreter code, as ExecuteInterpretedMethodWithArgs_PortableEntryPoint_Complex already does. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli, @kg |
Member
Author
|
@davidwrighton PTAL |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the WASM CallDescrWorkerInternal (reflection/dynamic invoke) dispatch so that methods without interpreter bytecode (e.g., R2R/native Wasm methods) are invoked via InvokeManagedMethod rather than attempting ExecuteInterpretedMethodWithArgs with a null target, which could leave the return buffer in an invalid/aliased state.
Changes:
- Add an R2R-aware dispatch path: if
GetInterpreterCode()remains null afterDoPrestub, invoke viaInvokeManagedMethod. - Preserve the existing interpreter invocation path when interpreter code is available.
Comment on lines
+43
to
+49
| // The target has no interpreter code because it is R2R (native Wasm) compiled. | ||
| // Dispatch to the native entry point via the interpreter-to-R2R thunk, mirroring | ||
| // ExecuteInterpretedMethodWithArgs_PortableEntryPoint_Complex. Calling the | ||
| // interpreter with a NULL target would not execute the method and would leave the | ||
| // return buffer aliasing the incoming arguments. | ||
| ManagedMethodParam param = { pMethod, args, (int8_t*)retBuff, (PCODE)NULL, NULL }; | ||
| InvokeManagedMethod(¶m); |
Member
Author
|
This is redundant with #129766. |
This was referenced Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On wasm,
CallDescrWorkerInternal(the reflection / dynamic-invoke path) onlydispatched to interpreted targets. For an R2R (native wasm) compiled method,
GetInterpreterCode()stays null even afterDoPrestub, so it calledExecuteInterpretedMethodWithArgswith a null target: the method never executedand the return buffer was left aliasing the incoming arguments. As a result,
reflection
Invokeof any value-returning R2R method returned the first argument(or first struct field) instead of the real return value.
Dispatch through
InvokeManagedMethod(the interpreter-to-R2R thunk) when there isno interpreter code, mirroring
ExecuteInterpretedMethodWithArgs_PortableEntryPoint_Complex.Fixes
InterlockedTest.TestCompareExchangeUnextended(which invokes the target viareflection) and, more broadly, all value-returning reflection invocations of R2R
methods on wasm. Validated against a standalone repro and the JIT_r test group.