From d03342b33ecca8d5462048bbf32e5bb45f496e5a Mon Sep 17 00:00:00 2001 From: Evgeny Pavlov Date: Thu, 16 Mar 2017 07:30:37 +0300 Subject: [PATCH] [x86/Linux] Fix NativeCallableTest (dotnet/coreclr#10060) * [x86/Linux] Fix NativeCallableTest * Move m_cbActualArgSize adjustment outside if statement * [x86/Linux] Adjust m_cbActualArgSize in case pStubMD == NULL * [x86/Linux] Move m_cbActualArgSize calculation to #else part of '#ifdef _TARGET_X86_' * [x86/Linux] Remove redundant computations, add comments for m_cbActualArgSize meaning Commit migrated from https://github.com/dotnet/coreclr/commit/6f3aa999a842cfa4bf83415e88ea7fb1650ab5bf --- src/coreclr/src/vm/dllimportcallback.cpp | 16 ++++++++++------ src/coreclr/src/vm/dllimportcallback.h | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/coreclr/src/vm/dllimportcallback.cpp b/src/coreclr/src/vm/dllimportcallback.cpp index fb96875..b72bc16 100644 --- a/src/coreclr/src/vm/dllimportcallback.cpp +++ b/src/coreclr/src/vm/dllimportcallback.cpp @@ -1375,15 +1375,9 @@ VOID UMThunkMarshInfo::RunTimeInit() } } - // - // m_cbActualArgSize gets the number of arg bytes for the NATIVE signature - // - m_cbActualArgSize = - (pStubMD != NULL) ? pStubMD->AsDynamicMethodDesc()->GetNativeStackArgSize() : pMD->SizeOfArgStack(); #if defined(_TARGET_X86_) MetaSig sig(pMD); - ArgIterator argit(&sig); int numRegistersUsed = 0; // @@ -1407,11 +1401,14 @@ VOID UMThunkMarshInfo::RunTimeInit() m_cbStackArgSize += StackElemSize(cbSize); } } + m_cbActualArgSize = (pStubMD != NULL) ? pStubMD->AsDynamicMethodDesc()->GetNativeStackArgSize() : offs; + PInvokeStaticSigInfo sigInfo; if (pMD != NULL) new (&sigInfo) PInvokeStaticSigInfo(pMD); else new (&sigInfo) PInvokeStaticSigInfo(GetSignature(), GetModule()); + if (sigInfo.GetCallConv() == pmCallConvCdecl) { // caller pop @@ -1422,6 +1419,13 @@ VOID UMThunkMarshInfo::RunTimeInit() // callee pop m_cbRetPop = static_cast(m_cbActualArgSize); } +#else // _TARGET_X86_ + // + // m_cbActualArgSize gets the number of arg bytes for the NATIVE signature + // + m_cbActualArgSize = + (pStubMD != NULL) ? pStubMD->AsDynamicMethodDesc()->GetNativeStackArgSize() : pMD->SizeOfArgStack(); + #endif // _TARGET_X86_ #endif // _TARGET_X86_ && !FEATURE_STUBS_AS_IL diff --git a/src/coreclr/src/vm/dllimportcallback.h b/src/coreclr/src/vm/dllimportcallback.h index b50b917..af2a0b1 100644 --- a/src/coreclr/src/vm/dllimportcallback.h +++ b/src/coreclr/src/vm/dllimportcallback.h @@ -220,6 +220,7 @@ private: // On x86, NULL for no-marshal signatures // On non-x86, the managed entrypoint for no-delegate no-marshal signatures UINT32 m_cbActualArgSize; // caches m_pSig.SizeOfFrameArgumentArray() + // On x86/Linux we have to augment with numRegistersUsed * STACK_ELEM_SIZE #if defined(_TARGET_X86_) UINT16 m_cbRetPop; // stack bytes popped by callee (for UpdateRegDisplay) #if defined(FEATURE_STUBS_AS_IL) -- 2.7.4