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

Parse MethodDescs to obtain function ptrs on .NET Core 3.0+ #25

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

0x0ade
Copy link
Member

@0x0ade 0x0ade commented May 22, 2022

This PR introduces MethodDesc parsing for .NET Core 3.0+, which can be opt out of by setting the environment variable MONOMOD_RUNTIMEDETOUR_NETCORE30PLUS_OLDFTNPTR to 1.

Quoting myself from the MonoMod Discord server:

I see it as either "keep up with runtime internals by parsing methoddescs" or "keep up with runtime internals on a per platform basis by trying to understand what the JIT emits"
in the past, the runtime was a black box and "fixing" RuntimeMethodHandle.GetFunctionPointer might've been less effort than trying to understand methoddescs
but nowadays precode walking is stable enough on framework, coreclr is open source, yet another platform is on the horizon, and it feels like there are more combinations of stubs and platforms than there are variations of method descriptors to grab pointers from

Reducing the dependency on precode walking should also theoretically help with getting new platforms up and running faster, such as ARM. My current focus is fixing an edge case interaction between RuntimeDetour and coreclr's backpatcher though, discovered by tModLoader modders, where RuntimeDetour's precode walker misinterprets the location of the method desc in the method table as the location of the code and zeroes it out, shortly before the runtime dies on a backpatch attempt.

Copy link
Contributor

@nike4613 nike4613 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me. I would maybe ask for actual field names for the various offsets, as the offsets for DisableInlining have, to make updating them in the case of changes easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants