Skip to content

Commit

Permalink
Fix marshaling/interop code emitting ldloc 65535 instruction when cal…
Browse files Browse the repository at this point in the history
…ling method on a COM interface. This happened due to unitialized local variable (gc_safe_transition_builder.coop_cominterop_fnptr) getting loaded when "need_gc_safe" is false. This caused the JIT to throw an InvalidOperationException (case UUM-62035).
  • Loading branch information
TautvydasZilys committed Mar 21, 2024
1 parent c869ed8 commit 103c7b0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mono/metadata/marshal-ilgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,12 @@ emit_native_wrapper_ilgen (MonoImage *image, MonoMethodBuilder *mb, MonoMethodSi
mono_mb_emit_calli (mb, csig);
} else if (MONO_CLASS_IS_IMPORT (mb->method->klass)) {
#ifndef DISABLE_COM
mono_mb_emit_ldloc (mb, gc_safe_transition_builder.coop_cominterop_fnptr);
if (need_gc_safe) {
mono_mb_emit_ldloc (mb, gc_safe_transition_builder.coop_cominterop_fnptr);
} else {
mono_mb_emit_cominterop_get_function_pointer (mb, &piinfo->method);
}

if (piinfo->piflags & PINVOKE_ATTRIBUTE_SUPPORTS_LAST_ERROR) {
mono_mb_emit_byte (mb, MONO_CUSTOM_PREFIX);
mono_mb_emit_byte (mb, CEE_MONO_SAVE_LAST_ERROR);
Expand Down

0 comments on commit 103c7b0

Please sign in to comment.