Repository: dotnet/runtime
File: src/coreclr/vm/callhelpers.h (C/C++)

Code before:
#define CALL_MANAGED_METHOD_RETREF(ret, reftype, args)  \
        PRECALL_PREP(args)                              \
        PERFORM_CALL                                    \
        ret = (reftype)ObjectToOBJECTREF((Object *)__retval);

#define ARGNUM_2 ARGNUM_N(2)
#define ARGNUM_3 ARGNUM_N(3)
#define ARGNUM_4 ARGNUM_N(4)
#define ARGNUM_5 ARGNUM_N(5)
#define ARGNUM_6 ARGNUM_N(6)
#define ARGNUM_7 ARGNUM_N(7)
#define ARGNUM_8 ARGNUM_N(8)


void CallDefaultConstructor(OBJECTREF ref);

//
// Helper types for calling managed methods marked with [UnmanagedCallersOnly]
// from native code.
//

// Helper class for calling managed methods marked with [UnmanagedCallersOnly].
// This provides a more efficient alternative to MethodDescCallSite for methods
// that use the reverse P/Invoke infrastructure.
// This class assumes the target method signature has a trailing argument for
// returning the exception (QCall::ObjectHandleOnStack). The C# signature should
// have that argument, but the templated class parameters should not include it.
//
// Example usage:
//   UnmanagedCallersOnlyCaller caller(BinderMethodID::MyMethod);
//   ...
//   caller.InvokeThrowing(arg1, arg2);
//
// The corresponding C# method would be declared as:
//   [UnmanagedCallersOnly]
//   public static void MyMethod(int arg1, object* arg2, Exception* pException);
//
class UnmanagedCallersOnlyCaller final
{
    MethodDesc* _pMD;
public:
    explicit UnmanagedCallersOnlyCaller(BinderMethodID id)
        : _pMD{}
    {
        CONTRACTL
        {
            THROWS;
            GC_TRIGGERS;
            MODE_COOPERATIVE;
        }
        CONTRACTL_END;

Review comment (suggestion):
This should be updated to match the latest (the exception is no longer returned via `ObjectHandleOnStack`).

Code after:
#define CALL_MANAGED_METHOD_RETREF(ret, reftype, args)  \
        PRECALL_PREP(args)                              \
        PERFORM_CALL                                    \
        ret = (reftype)ObjectToOBJECTREF((Object *)__retval);

#define ARGNUM_2 ARGNUM_N(2)
#define ARGNUM_3 ARGNUM_N(3)
#define ARGNUM_4 ARGNUM_N(4)
#define ARGNUM_5 ARGNUM_N(5)
#define ARGNUM_6 ARGNUM_N(6)
#define ARGNUM_7 ARGNUM_N(7)
#define ARGNUM_8 ARGNUM_N(8)


void CallDefaultConstructor(OBJECTREF ref);

//
// Helper types for calling managed methods marked with [UnmanagedCallersOnly]
// from native code.
//

// Helper class for calling managed methods marked with [UnmanagedCallersOnly].
// This provides a more efficient alternative to MethodDescCallSite for methods
// using the reverse P/Invoke infrastructure.
// This class assumes the target method signature has a trailing argument for
// returning the exception (that is, Exception* in C#).
//
// Example usage:
//   UnmanagedCallersOnlyCaller caller(BinderMethodID::MyMethod);
//   ...
//   caller.InvokeThrowing(arg1, arg2);
//
// The corresponding C# method would be declared as:
//   [UnmanagedCallersOnly]
//   public static void MyMethod(int arg1, object* arg2, Exception* pException);
//
class UnmanagedCallersOnlyCaller final
{
    MethodDesc* _pMD;
public:
    explicit UnmanagedCallersOnlyCaller(BinderMethodID id)
        : _pMD{}
    {
        CONTRACTL
        {
            THROWS;
            GC_TRIGGERS;
            MODE_COOPERATIVE;
        }
        CONTRACTL_END;