Skip to content
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

Handle InlineSig in MethodRewriter #25

Open
Miista opened this issue Jan 24, 2024 · 3 comments
Open

Handle InlineSig in MethodRewriter #25

Miista opened this issue Jan 24, 2024 · 3 comments
Assignees
Labels
bug Something isn't working priority: medium The issue has medium priority
Milestone

Comments

@Miista
Copy link
Owner

Miista commented Jan 24, 2024

Please refer to tonerdo/pose#30

This has low priority until we have investigated the impact on not being able to handle the instruction.

@Miista Miista added bug Something isn't working priority: low The issue has low priority labels Jan 24, 2024
@Miista Miista added priority: medium The issue has medium priority and removed priority: low The issue has low priority labels Jan 31, 2024
@Miista
Copy link
Owner Author

Miista commented Jan 31, 2024

I'm changing this to medium priority since we are seeing the issue on .NET 6 as noted in #9

@Miista
Copy link
Owner Author

Miista commented Feb 10, 2024

@Miista
Copy link
Owner Author

Miista commented Jun 5, 2024

The following is a minimal working example:

var dateTimeShim = Shim.Replace(() => DateTime.Now).With(() => new DateTime(2004, 1, 1));
PoseContext.Isolate(
    () =>
    {
        Console.WriteLine(DateTime.UtcNow);
    }, dateTimeShim);

Invoking the above code results in System.NotSupportedException: InlineSig due to the opcode not being supported.

Adding support

It seems we can add support by:

  1. Add a case in the switch in method MethodRewriter.Rewrite
  2. Emit calli instruction

Update MethodRewriter.Rewrite

case OperandType.InlineSig:
    EmitILForInlineSig(ilGenerator, instruction);
    break;

Emit instruction

private void EmitILForInlineSig(ILGenerator ilGenerator, Instruction instruction)
{
    ilGenerator.EmitCalli(OpCodes.Calli, CallingConvention.StdCall, typeof(void), new Type[]{typeof(ulong)});
}

These two changes makes it so there's no longer an exception when running the code. In fact, the code now prints the expected result. Please see below.

05-06-2024 06:53:46

Concerns

I am not certain this covers all uses of InlineSig. I cannot know if the opcode will ever take on a different form which makes this translation incorrect.

For now, the assumption is that the InlineSig opcode always:

  • Returns void
  • Takes a pointer to an unsigned ulong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: medium The issue has medium priority
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant