From db340c61c6a56fa6c24cda7a630e9af2e24a1b3f Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 6 Jan 2021 20:49:40 -0800 Subject: [PATCH] Port .NET 5 fix for reverse P/Invoke marshalling of structs. --- src/vm/dllimport.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/dllimport.cpp b/src/vm/dllimport.cpp index eed690454d30..84e9003f0123 100644 --- a/src/vm/dllimport.cpp +++ b/src/vm/dllimport.cpp @@ -3836,10 +3836,10 @@ static void CreateNDirectStubWorker(StubState* pss, // For functions with value type class, managed and unmanaged calling convention differ fMarshalReturnValueFirst = HasRetBuffArgUnmanagedFixup(&msig); #elif defined(_TARGET_ARM_) - fMarshalReturnValueFirst = HasRetBuffArg(&msig); + fMarshalReturnValueFirst = (isInstanceMethod && isReturnTypeValueType) && HasRetBuffArg(&msig); #else // On Windows-X86, the native signature might need a return buffer when the managed doesn't (specifically when the native signature is a member function). - fMarshalReturnValueFirst = HasRetBuffArg(&msig) || (isInstanceMethod && isReturnTypeValueType); + fMarshalReturnValueFirst = (!SF_IsReverseStub(dwStubFlags) && HasRetBuffArg(&msig)) || (isInstanceMethod && isReturnTypeValueType); #endif // UNIX_X86_ABI #elif defined(_TARGET_AMD64_) || defined (_TARGET_ARM64_) fMarshalReturnValueFirst = isInstanceMethod && isReturnTypeValueType;