Investigation: IJW HRException with 17+ by-ref parameters on x64#127169
Closed
Investigation: IJW HRException with 17+ by-ref parameters on x64#127169
Conversation
Copilot
AI
changed the title
[WIP] Fix HRException crash on managed function with 17+ parameters
Investigation: IJW HRException with 17+ by-ref parameters on x64
Apr 20, 2026
Contributor
|
Tagging subscribers to this area: @agocke |
Member
|
Superseded by #127182 |
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.
Note
This content was generated by GitHub Copilot.
Calling a C++/CLI managed static with 17+
const T¶meters from native code throwsHRExceptionon .NET 9/10 (worked on .NET 8). Reproduction requires Windows + MSVC + IJW, which is not available in this environment, so no code change is being proposed — this PR is an investigation report with a pointer to the likely regression.Description
cfa0cc5b0282, "Inject IJW Copy Constructor calls in the JIT instead of in the IL stubs"), which re-enabled GS (buffer security) checks on Reverse P/Invoke IL stubs.Compiler::gsCopyIntoShadowinsrc/coreclr/jit/gschecks.cpp. There is aTARGET_X86 && FEATURE_IJWbranch that, foropts.IsReversePInvoke(), inserts the shadow copy afterCORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER(i.e. after the GC transition). The fall-through path used on x64 inserts the copy at the start offgFirstBB— before the transition:lvIsPtr = 1) and emits a shadow copy per param. The "17" threshold is probably where cumulative frame / stack-arg load first surfaces a latent ordering bug against the P/Invoke-enter helper. This is unverified.ijwhoststart_runtime_thunk_stubandTheUMEntryPrestubprologues — both preserve the caller's stack-arg region across register/XMM save+restore andTAILJMP_RAX. Alignment and shadow-space math check out for >16 args.patch_vtable_entries/FixupVTables/UMEntryThunk— no arg-count-dependent code paths.src/tests/Interop/IJW/**) do not cover managed static vtfixup entries with ≥17 by-ref parameters, which is consistent with the regression slipping through.Suggested next steps (for a reviewer with a Windows box)
DOTNET_JitDump=IL_STUB*/DOTNET_JitDisasm=IL_STUB*and confirm whether shadow copies for the 18 params are emitted beforeJIT_REVERSE_PINVOKE_ENTER.TARGET_X86 && FEATURE_IJWbranch ingsCopyIntoShadow(and the matching branch ingsParamsToShadows) to fire for allopts.IsReversePInvoke()targets.src/tests/Interop/IJW/covering a C++/CLI static exposed via vtfixup with ≥17const T¶meters.cc @AaronRobinsonMSFT @jkoritzinsky.