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

Code before:
{
    WRAPPER_NO_CONTRACT;
    _ASSERTE(!IsGenericMethodDefinition());
    return GetMethodEntryPoint();
}

PCODE MethodDesc::GetSingleCallableAddrOfCodeForUnmanagedCallersOnly()
{
    CONTRACTL
    {
        THROWS;
        GC_NOTRIGGER;
        MODE_ANY;
    }
    CONTRACTL_END;

#ifdef FEATURE_PORTABLE_ENTRYPOINTS
    PCODE entryPoint = GetPortableEntryPoint();
    if (!PortableEntryPoint::ToPortableEntryPoint(entryPoint)->EnsureUnmanagedCallersOnlyAttribute())
        COMPlusThrow(kInvalidOperationException);
    return (PCODE)PortableEntryPoint::GetActualCode(entryPoint);

#else // !FEATURE_PORTABLE_ENTRYPOINTS
    // HasUnmanagedCallersOnlyAttribute() must be true for this API.
    // We only validate this on non portable entrypoints because HasUnmanagedCallersOnlyAttribute()
    // is an unnecessary cost, even in non-Release builds, on portable entrypoint platforms.
    _ASSERTE(HasUnmanagedCallersOnlyAttribute());
    return GetSingleCallableAddrOfCode();

#endif // FEATURE_PORTABLE_ENTRYPOINTS
}

//*******************************************************************************
PCODE MethodDesc::GetSingleCallableAddrOfVirtualizedCode(OBJECTREF *orThis, TypeHandle staticTH)
{
    WRAPPER_NO_CONTRACT;
    PRECONDITION(IsVtableMethod());

    MethodTable *pObjMT = (*orThis)->GetMethodTable();

    if (HasMethodInstantiation())
    {
        CheckRestore();
        MethodDesc *pResultMD = ResolveGenericVirtualMethod(orThis);

        // If we're remoting this call we can't call directly on the returned
        // method desc, we need to go through a stub that guarantees we end up
        // in the remoting handler. The stub we use below is normally just for
        // non-virtual calls on virtual methods (that have the same problem
        // where we could end up bypassing the remoting system), but it serves
        // our purpose here (basically pushes our correctly instantiated,

Review comment (suggestion):
```suggestion
```
We validate this for portable entrypoints too now

Code after:
{
    WRAPPER_NO_CONTRACT;
    _ASSERTE(!IsGenericMethodDefinition());
    return GetMethodEntryPoint();
}

PCODE MethodDesc::GetSingleCallableAddrOfCodeForUnmanagedCallersOnly()
{
    CONTRACTL
    {
        THROWS;
        GC_NOTRIGGER;
        MODE_ANY;
        PRECONDITION(HasUnmanagedCallersOnlyAttribute());
    }
    CONTRACTL_END;

    PCODE entryPoint;

#ifdef FEATURE_PORTABLE_ENTRYPOINTS
    entryPoint = GetPortableEntryPoint();
    (void)PortableEntryPoint::ToPortableEntryPoint(entryPoint)->EnsureCodeForUnmanagedCallersOnly();
    entryPoint = (PCODE)PortableEntryPoint::GetActualCode(entryPoint);
#else // !FEATURE_PORTABLE_ENTRYPOINTS
    entryPoint = GetSingleCallableAddrOfCode();
#endif // FEATURE_PORTABLE_ENTRYPOINTS

    return entryPoint;
}

//*******************************************************************************
PCODE MethodDesc::GetSingleCallableAddrOfVirtualizedCode(OBJECTREF *orThis, TypeHandle staticTH)
{
    WRAPPER_NO_CONTRACT;
    PRECONDITION(IsVtableMethod());

    MethodTable *pObjMT = (*orThis)->GetMethodTable();

    if (HasMethodInstantiation())
    {
        CheckRestore();
        MethodDesc *pResultMD = ResolveGenericVirtualMethod(orThis);

        // If we're remoting this call we can't call directly on the returned
        // method desc, we need to go through a stub that guarantees we end up
        // in the remoting handler. The stub we use below is normally just for
        // non-virtual calls on virtual methods (that have the same problem
        // where we could end up bypassing the remoting system), but it serves
        // our purpose here (basically pushes our correctly instantiated,
        // resolved method desc on the stack and calls the remoting code).