Repository: dotnet/runtime
File: src/coreclr/vm/dynamicmethod.cpp (C++)

Code before:
        DECLARE_ARGHOLDER_ARRAY(args, 1);

        args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(ObjectFromHandle(m_managedResolver));

        CALL_MANAGED_METHOD_RETREF(dataArray, U1ARRAYREF, args);

        if (dataArray != NULL)
        {
            COR_ILMETHOD_SECT_EH* pEH = (COR_ILMETHOD_SECT_EH*)dataArray->GetDataPtr();

            COR_ILMETHOD_SECT_EH_CLAUSE_FAT ehClause;
            const COR_ILMETHOD_SECT_EH_CLAUSE_FAT* ehInfo;
            ehInfo = (COR_ILMETHOD_SECT_EH_CLAUSE_FAT*)pEH->EHClause(EHnumber, &ehClause);

            clause->Flags = (CORINFO_EH_CLAUSE_FLAGS)ehInfo->GetFlags();
            clause->TryOffset = ehInfo->GetTryOffset();
            clause->TryLength = ehInfo->GetTryLength();
            clause->HandlerOffset = ehInfo->GetHandlerOffset();
            clause->HandlerLength = ehInfo->GetHandlerLength();
            clause->ClassToken = ehInfo->GetClassToken();
            clause->FilterOffset = ehInfo->GetFilterOffset();
            return;
        }
    }

    // failed, get the info off the ilgenerator
    {
        PREPARE_SIMPLE_VIRTUAL_CALLSITE(METHOD__RESOLVER__GET_EH_INFO, ObjectFromHandle(m_managedResolver));

        DECLARE_ARGHOLDER_ARRAY(args, 3);

        args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(ObjectFromHandle(m_managedResolver));
        args[ARGNUM_1] = DWORD_TO_ARGHOLDER(EHnumber);
        args[ARGNUM_2] = PTR_TO_ARGHOLDER(clause);

        CALL_MANAGED_METHOD_NORET(args);
    }
}

#endif // !DACCESS_COMPILE

// Get the associated managed resolver. This method will be called during a GC so it should not throw, trigger a GC or cause the
// object in question to be validated.
OBJECTREF LCGMethodResolver::GetManagedResolver()
{
    LIMITED_METHOD_CONTRACT;
#ifdef DACCESS_COMPILE
    if (m_managedResolver == (OBJECTHANDLE)NULL)
        return NULL;
#endif // DACCESS_COMPILE
    return ObjectFromHandle(m_managedResolver);

Review comment (suggestion):
It looks like `CORINFO_EH_CLAUSE` is defined in `src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs`, can we do all this in managed also? Seems like the DynamicIL infrastructure might have a lot of this logic already available.

Code after:

    return SigPointer(pSig, cbSig);
} // LCGMethodResolver::ResolveSignatureForVarArg

//---------------------------------------------------------------------------------------
//
void LCGMethodResolver::GetEHInfo(unsigned EHnumber, CORINFO_EH_CLAUSE* clause)
{
    STANDARD_VM_CONTRACT;

    GCX_COOP();

    struct
    {
        OBJECTREF Resolver;
        U1ARRAYREF DataArray;
    } gc;
    gc.Resolver = ObjectFromHandle(m_managedResolver);
    gc.DataArray = NULL;

    GCPROTECT_BEGIN(gc);

    UnmanagedCallersOnlyCaller getEhInfo(METHOD__RESOLVER__GET_EH_INFO);
    getEhInfo.InvokeThrowing(&gc.Resolver, EHnumber, &gc.DataArray, clause);

    if (gc.DataArray != NULL)
    {
        // If we have raw EH info, we need to parse the clause manually.
        COR_ILMETHOD_SECT_EH* pEH = (COR_ILMETHOD_SECT_EH*)gc.DataArray->GetDataPtr();

        COR_ILMETHOD_SECT_EH_CLAUSE_FAT ehClause;
        const COR_ILMETHOD_SECT_EH_CLAUSE_FAT* ehInfo;
        ehInfo = (COR_ILMETHOD_SECT_EH_CLAUSE_FAT*)pEH->EHClause(EHnumber, &ehClause);

        clause->Flags = (CORINFO_EH_CLAUSE_FLAGS)ehInfo->GetFlags();
        clause->TryOffset = ehInfo->GetTryOffset();
        clause->TryLength = ehInfo->GetTryLength();
        clause->HandlerOffset = ehInfo->GetHandlerOffset();
        clause->HandlerLength = ehInfo->GetHandlerLength();
        clause->ClassToken = ehInfo->GetClassToken();
        clause->FilterOffset = ehInfo->GetFilterOffset();
    }

    GCPROTECT_END();
}

#endif // !DACCESS_COMPILE

// Get the associated managed resolver. This method will be called during a GC so it should not throw, trigger a GC or cause the
// object in question to be validated.
OBJECTREF LCGMethodResolver::GetManagedResolver()