Skip to content

JIT: Unify InlinedCallFrame secret stub arg handling #100662

Closed
@jakobbotsch

Description

@jakobbotsch

For some IL stubs with pinvokes in them the runtime passes a non-standard argument that the JIT must save in a known place. Currently this mechanism is different between 32 bit and 64 bit platforms. On 32 bit platforms the argument is stored by the JIT in the local stack frame at a known place:

// Given a methodDesc representing an ILStub for a pinvoke call,
// this method will return the MethodDesc for the actual interop
// method if the current InlinedCallFrame is inactive.
PTR_MethodDesc GetActualInteropMethodDesc()
{
#if defined(TARGET_X86) || defined(TARGET_ARM)
// Important: This code relies on the way JIT lays out frames. Keep it in sync
// with code:Compiler.lvaAssignFrameOffsets.
//
// | ... |
// +--------------------+
// | lvaStubArgumentVar | <= filled with EAX in prolog |
// +--------------------+ |
// | | |
// | InlinedCallFrame | |
// | | <= m_pCrawl.pFrame | to lower addresses
// +--------------------+ V
// | ... |
//
// Extract the actual MethodDesc to report from the InlinedCallFrame.
TADDR addr = dac_cast<TADDR>(this) + sizeof(InlinedCallFrame);
return PTR_MethodDesc(*PTR_TADDR(addr));
#elif defined(HOST_64BIT)
// On 64bit, the actual interop MethodDesc is saved off in a field off the InlinedCrawlFrame
// which is populated by the JIT. Refer to JIT_InitPInvokeFrame for details.
return PTR_MethodDesc(m_StubSecretArg);
#else
_ASSERTE(!"NYI - Interop method reporting for this architecture!");
return NULL;
#endif // defined(TARGET_X86) || defined(TARGET_ARM)
}

On 64-bit platforms the argument is instead passed to the CORINFO_HELP_INIT_PINVOKE_FRAME helper call.

We can unify these mechanisms in the way suggested by @jkotas here, by storing it directly inside the InlinedFrame that the JIT already has special knowledge of. It will save us some special casing within the JIT and avoid the unnecessary store on 64-bit in many cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions