Skip to content

Commit

Permalink
NativeAOT/x86: Implement ResolveVirtualFunction R2R helper (#99913)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipnavara authored Mar 18, 2024
1 parent 46cdeca commit 186c994
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,28 @@ protected override void EmitCode(NodeFactory factory, ref X86Emitter encoder, bo

case ReadyToRunHelperId.ResolveVirtualFunction:
{
encoder.EmitINT3();
MethodDesc targetMethod = (MethodDesc)Target;
if (targetMethod.OwningType.IsInterface)
{
encoder.EmitMOV(encoder.TargetRegister.Arg1, factory.InterfaceDispatchCell(targetMethod));
encoder.EmitJMP(factory.ExternSymbol("RhpResolveInterfaceMethod"));
}
else
{
if (relocsOnly)
break;

AddrMode loadFromThisPtr = new AddrMode(encoder.TargetRegister.Arg0, null, 0, 0, AddrModeSize.Int32);
encoder.EmitMOV(encoder.TargetRegister.Result, ref loadFromThisPtr);

Debug.Assert(!targetMethod.CanMethodBeInSealedVTable(factory));

int slot = VirtualMethodSlotHelper.GetVirtualMethodSlot(factory, targetMethod, targetMethod.OwningType);
Debug.Assert(slot != -1);
AddrMode loadFromSlot = new AddrMode(encoder.TargetRegister.Result, null, EETypeNode.GetVTableOffset(factory.Target.PointerSize) + (slot * factory.Target.PointerSize), 0, AddrModeSize.Int32);
encoder.EmitMOV(encoder.TargetRegister.Result, ref loadFromSlot);
encoder.EmitRET();
}
}
break;

Expand Down

0 comments on commit 186c994

Please sign in to comment.