Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
18b5fe6
Fix AsyncVoidMethodBuilder race condition around SynchronizationConte…
github-actions[bot] Mar 13, 2024
f09cd44
Always keep global symbols on ApplePlatforms (#99650)
github-actions[bot] Mar 13, 2024
c0a2606
Delete Decrypt_Pkcs1_ErrorsForInvalidPadding
github-actions[bot] Mar 13, 2024
c412efb
Rename MSBuild property MicrosoftNativeQuicMsQuicVersion -> Microsoft…
carlossanlop Mar 14, 2024
e373424
Fixing SignedXml.CheckSignature for enveloped signature with `#xpoint…
bartonjs Mar 14, 2024
50c3c86
[release/8.0-staging] disable optimizations for PopCount (#99832)
github-actions[bot] Mar 15, 2024
ff80834
[release/8.0-staging] Handle NativeOverlapped* coming from both the W…
github-actions[bot] Mar 16, 2024
cf1182c
Fix exporting certificate keys on macOS 14.4.
github-actions[bot] Mar 19, 2024
c27b203
[release/8.0] Upgrade zlib to 1.3.1 (#99473)
carlossanlop Mar 20, 2024
250354b
Fix failing CertificateValidationRemoteServer.ConnectWithRevocation_W…
rzikm Mar 20, 2024
afb3fca
[mono] Stop exporting ICU symbols from Mono (#99449)
matouskozak Mar 20, 2024
99c7022
[release/8.0-staging] Fix AV in HttpTelemetry.WriteEvent (#99607)
github-actions[bot] Mar 21, 2024
155a4ab
Merge branch 'release/8.0-staging' into merge/release/8.0-to-release/…
carlossanlop Mar 25, 2024
b7f0477
[Http/2] Fix handling of effectively empty DATA frame (#99502) (#99677)
ManickaP Mar 26, 2024
3f774aa
[release/8.0-staging] [HttpStress] [SslStress] Workaround image bug i…
github-actions[bot] Mar 27, 2024
ab416e9
Support building against clang 18 (#100258)
omajid Mar 27, 2024
f36dd88
[release/8.0][browser] WebSocket works differently depending on if we…
ilonatommy Mar 28, 2024
ba9df1e
[release/8.0-staging] Call the Copy Constructor for stack arguments i…
AaronRobinsonMSFT Mar 30, 2024
3ea18f2
[release/8.0] Don't unset ALPN list pointer during ALPN selection cal…
github-actions[bot] Apr 2, 2024
9de64a2
Backport of #99843 (#99844)
thaystg Apr 2, 2024
7d45915
[release/8.0-staging] Ensure that Sse3.MoveAndDuplicate correctly tra…
tannergooding Apr 4, 2024
7ae2d00
Fix allocation of empty array in the frozen heap for collectible type…
jkotas Apr 4, 2024
479defb
Use clang --version to get Apple toolset version (#100199)
github-actions[bot] Apr 4, 2024
d49f6cf
Azure Linux 3.0 deps package (#100684)
github-actions[bot] Apr 5, 2024
2b94204
Fix Http2 deadlock (#100086)
github-actions[bot] Apr 9, 2024
0de7023
[release/8.0-staging] Update CI builds to not use VS Previews (#100622)
github-actions[bot] Apr 10, 2024
4be29ad
Update dependencies from https://github.com/dotnet/hotreload-utils bu…
dotnet-maestro[bot] Apr 12, 2024
cca20d0
[release/8.0-staging] Update dependencies from dotnet/runtime-assets …
dotnet-maestro[bot] Apr 12, 2024
4814719
Merge pull request #99585 from dotnet-maestro-bot/merge/release/8.0-t…
ericstj Apr 12, 2024
f37eb48
Update dependencies from https://github.com/dotnet/source-build-exter…
dotnet-maestro[bot] Apr 12, 2024
0a26d20
Update dependencies from https://github.com/dotnet/xharness build 202…
dotnet-maestro[bot] Apr 12, 2024
24e52a0
[release/8.0-staging] Update dependencies from dotnet/source-build-re…
dotnet-maestro[bot] Apr 12, 2024
b1b775e
[release/8.0-staging] Update dependencies from dotnet/source-build-ex…
dotnet-maestro[bot] Apr 12, 2024
be4864f
Update dependencies from https://github.com/dotnet/runtime-assets bui…
dotnet-maestro[bot] Apr 12, 2024
78cde87
Update dependencies from https://github.com/dotnet/arcade build 20240…
dotnet-maestro[bot] Apr 12, 2024
9b82dcc
Fix native leak in CryptoNative_GetX509nameInfo
github-actions[bot] Apr 12, 2024
7fa8815
[release/8.0-staging] Update dependencies from dotnet/emsdk (#99696)
dotnet-maestro[bot] Apr 12, 2024
f9feb68
Try to find seqpoints directly from jitinfo if it's not find on get_d…
github-actions[bot] Apr 13, 2024
af764fd
[release/8.0][browser] fix emscripten out/err overrides (#100818)
pavelsavara Apr 15, 2024
cd27afe
[mono][eventpipe] Fix firing dynamic method wrappers crash (#99712)
github-actions[bot] Apr 15, 2024
f0f42cc
Update Alpine versions for `release/8.0-staging` (#99849)
richlander Apr 15, 2024
6f29267
[release/8.0-staging] Guard against -1 Returned from sysconf for the …
github-actions[bot] Apr 15, 2024
a494d22
[Release/8.0] Remove preventing EH at shutdown (#100836)
janvorli Apr 15, 2024
3c5a0af
Add workload metadata (#100649)
joeloff Apr 15, 2024
2d7642d
System.Diagnostics.DiagnosticSource (#99583)
carlossanlop Apr 15, 2024
88be910
Always zero-init if object contains pointers (#100265) (#100426)
VSadov Apr 15, 2024
aa7c7ff
[release/8.0-staging] JIT: Fixed incorrect reversed condition for GT …
github-actions[bot] Apr 15, 2024
befe7ad
Merge branch 'release/8.0' into release/8.0-staging
directhex Apr 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[release/8.0-staging] Call the Copy Constructor for stack arguments i…
…n C++/CLI on x86 (#100221)

* Call the Copy Constructor for stack arguments in C++/CLI on Windows-x86 (#100050)

* Add repro test case

* Directly load the argument address using ldarga to avoid making a copy

* Reimplement the "Copy Constructor Cookie" logic in a more modern and maintainable style to get the test passing again

* Narrow support to Windows only

---------

Co-authored-by: Jeremy Koritzinsky <[email protected]>
  • Loading branch information
AaronRobinsonMSFT and jkoritzinsky authored Mar 30, 2024
commit ba9df1e9210fd3e2d5631637eb9c70630ccc346c
69 changes: 69 additions & 0 deletions src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,75 @@ public IntPtr AddRef()
}
} // class CleanupWorkListElement

internal unsafe struct CopyConstructorCookie
{
private void* m_source;

private nuint m_destinationOffset;

public delegate*<void*, void*, void> m_copyConstructor;

public delegate*<void*, void> m_destructor;

public CopyConstructorCookie* m_next;

[StackTraceHidden]
public void ExecuteCopy(void* destinationBase)
{
if (m_copyConstructor != null)
{
m_copyConstructor((byte*)destinationBase + m_destinationOffset, m_source);
}

if (m_destructor != null)
{
m_destructor(m_source);
}
}
}

internal unsafe struct CopyConstructorChain
{
public void* m_realTarget;
public CopyConstructorCookie* m_head;

public void Add(CopyConstructorCookie* cookie)
{
cookie->m_next = m_head;
m_head = cookie;
}

[ThreadStatic]
private static CopyConstructorChain s_copyConstructorChain;

public void Install(void* realTarget)
{
m_realTarget = realTarget;
s_copyConstructorChain = this;
}

[StackTraceHidden]
private void ExecuteCopies(void* destinationBase)
{
for (CopyConstructorCookie* current = m_head; current != null; current = current->m_next)
{
current->ExecuteCopy(destinationBase);
}
}

[UnmanagedCallersOnly]
[StackTraceHidden]
public static void* ExecuteCurrentCopiesAndGetTarget(void* destinationBase)
{
void* target = s_copyConstructorChain.m_realTarget;
s_copyConstructorChain.ExecuteCopies(destinationBase);
// Reset this instance to ensure we don't accidentally execute the copies again.
// All of the pointers point to the stack, so we don't need to free any memory.
s_copyConstructorChain = default;
return target;
}
}

internal static class StubHelpers
{
[MethodImpl(MethodImplOptions.InternalCall)]
Expand Down
15 changes: 15 additions & 0 deletions src/coreclr/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,21 @@ DEFINE_METHOD(HANDLE_MARSHALER, CONVERT_SAFEHANDLE_TO_NATIVE,ConvertSaf
DEFINE_METHOD(HANDLE_MARSHALER, THROW_SAFEHANDLE_FIELD_CHANGED, ThrowSafeHandleFieldChanged, SM_RetVoid)
DEFINE_METHOD(HANDLE_MARSHALER, THROW_CRITICALHANDLE_FIELD_CHANGED, ThrowCriticalHandleFieldChanged, SM_RetVoid)

#ifdef TARGET_WINDOWS
#ifdef TARGET_X86
DEFINE_CLASS(COPY_CONSTRUCTOR_CHAIN, StubHelpers, CopyConstructorChain)
DEFINE_METHOD(COPY_CONSTRUCTOR_CHAIN, EXECUTE_CURRENT_COPIES_AND_GET_TARGET, ExecuteCurrentCopiesAndGetTarget, SM_PtrVoid_RetPtrVoid)
DEFINE_METHOD(COPY_CONSTRUCTOR_CHAIN, INSTALL, Install, IM_PtrVoid_RetVoid)
DEFINE_METHOD(COPY_CONSTRUCTOR_CHAIN, ADD, Add, IM_PtrCopyConstructorCookie_RetVoid)

DEFINE_CLASS(COPY_CONSTRUCTOR_COOKIE, StubHelpers, CopyConstructorCookie)
DEFINE_FIELD(COPY_CONSTRUCTOR_COOKIE, SOURCE, m_source)
DEFINE_FIELD(COPY_CONSTRUCTOR_COOKIE, DESTINATION_OFFSET, m_destinationOffset)
DEFINE_FIELD(COPY_CONSTRUCTOR_COOKIE, COPY_CONSTRUCTOR, m_copyConstructor)
DEFINE_FIELD(COPY_CONSTRUCTOR_COOKIE, DESTRUCTOR, m_destructor)
#endif // TARGET_X86
#endif // TARGET_WINDOWS

DEFINE_CLASS(NATIVEVARIANT, StubHelpers, NativeVariant)
DEFINE_CLASS(NATIVEDECIMAL, StubHelpers, NativeDecimal)

Expand Down
56 changes: 56 additions & 0 deletions src/coreclr/vm/dllimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,10 @@ NDirectStubLinker::NDirectStubLinker(
m_pcsSetup->EmitSTLOC(m_dwTargetInterfacePointerLocalNum);
}
#endif // FEATURE_COMINTEROP

#if defined(TARGET_X86) && defined(TARGET_WINDOWS)
m_dwCopyCtorChainLocalNum = (DWORD)-1;
#endif // defined(TARGET_X86) && defined(TARGET_WINDOWS)
}

void NDirectStubLinker::SetCallingConvention(CorInfoCallConvExtension unmngCallConv, BOOL fIsVarArg)
Expand Down Expand Up @@ -1835,6 +1839,23 @@ DWORD NDirectStubLinker::GetReturnValueLocalNum()
return m_dwRetValLocalNum;
}

#if defined(TARGET_X86) && defined(TARGET_WINDOWS)
DWORD NDirectStubLinker::GetCopyCtorChainLocalNum()
{
STANDARD_VM_CONTRACT;

if (m_dwCopyCtorChainLocalNum == (DWORD)-1)
{
// The local is created and initialized lazily when first asked.
m_dwCopyCtorChainLocalNum = NewLocal(CoreLibBinder::GetClass(CLASS__COPY_CONSTRUCTOR_CHAIN));
m_pcsSetup->EmitLDLOCA(m_dwCopyCtorChainLocalNum);
m_pcsSetup->EmitINITOBJ(m_pcsSetup->GetToken(CoreLibBinder::GetClass(CLASS__COPY_CONSTRUCTOR_CHAIN)));
}

return m_dwCopyCtorChainLocalNum;
}
#endif // defined(TARGET_X86) && defined(TARGET_WINDOWS)

BOOL NDirectStubLinker::IsCleanupNeeded()
{
LIMITED_METHOD_CONTRACT;
Expand Down Expand Up @@ -2064,6 +2085,10 @@ void NDirectStubLinker::End(DWORD dwStubFlags)
}
}

#if defined(TARGET_X86) && defined(TARGET_WINDOWS)
EXTERN_C void STDCALL CopyConstructorCallStub(void);
#endif // defined(TARGET_X86) && defined(TARGET_WINDOWS)

void NDirectStubLinker::DoNDirect(ILCodeStream *pcsEmit, DWORD dwStubFlags, MethodDesc * pStubMD)
{
STANDARD_VM_CONTRACT;
Expand Down Expand Up @@ -2150,6 +2175,21 @@ void NDirectStubLinker::DoNDirect(ILCodeStream *pcsEmit, DWORD dwStubFlags, Meth
}
}

#if defined(TARGET_X86) && defined(TARGET_WINDOWS)
if (m_dwCopyCtorChainLocalNum != (DWORD)-1)
{
// If we have a copy constructor chain local, we need to call the copy constructor stub
// to ensure that the chain is called correctly.
// Let's install the stub chain here and redirect the call to the stub.
DWORD targetLoc = NewLocal(ELEMENT_TYPE_I);
pcsEmit->EmitSTLOC(targetLoc);
pcsEmit->EmitLDLOCA(m_dwCopyCtorChainLocalNum);
pcsEmit->EmitLDLOC(targetLoc);
pcsEmit->EmitCALL(METHOD__COPY_CONSTRUCTOR_CHAIN__INSTALL, 2, 0);
pcsEmit->EmitLDC((DWORD_PTR)&CopyConstructorCallStub);
}
#endif // defined(TARGET_X86) && defined(TARGET_WINDOWS)

// For managed-to-native calls, the rest of the work is done by the JIT. It will
// erect InlinedCallFrame, flip GC mode, and use the specified calling convention
// to call the target. For native-to-managed calls, this is an ordinary managed
Expand Down Expand Up @@ -6078,5 +6118,21 @@ PCODE GetILStubForCalli(VASigCookie *pVASigCookie, MethodDesc *pMD)
RETURN pVASigCookie->pNDirectILStub;
}

#if defined(TARGET_X86) && defined(TARGET_WINDOWS)
// Copy constructor support for C++/CLI
EXTERN_C void* STDCALL CallCopyConstructorsWorker(void* esp)
{
STATIC_CONTRACT_THROWS;
STATIC_CONTRACT_GC_TRIGGERS;
STATIC_CONTRACT_MODE_PREEMPTIVE; // we've already switched to preemptive

using ExecuteCallback = void*(STDMETHODCALLTYPE*)(void*);

MethodDesc* pMD = CoreLibBinder::GetMethod(METHOD__COPY_CONSTRUCTOR_CHAIN__EXECUTE_CURRENT_COPIES_AND_GET_TARGET);
ExecuteCallback pExecute = (ExecuteCallback)pMD->GetMultiCallableAddrOfCode();

return pExecute(esp);
}
#endif // defined(TARGET_X86) && defined(TARGET_WINDOWS)

#endif // #ifndef DACCESS_COMPILE
7 changes: 7 additions & 0 deletions src/coreclr/vm/dllimport.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ class NDirectStubLinker : public ILStubLinker
DWORD GetCleanupWorkListLocalNum();
DWORD GetThreadLocalNum();
DWORD GetReturnValueLocalNum();
#if defined(TARGET_X86) && defined(TARGET_WINDOWS)
DWORD GetCopyCtorChainLocalNum();
#endif // defined(TARGET_X86) && defined(TARGET_WINDOWS)
void SetCleanupNeeded();
void SetExceptionCleanupNeeded();
BOOL IsCleanupWorkListSetup();
Expand Down Expand Up @@ -553,6 +556,10 @@ class NDirectStubLinker : public ILStubLinker
DWORD m_dwTargetEntryPointLocalNum;
#endif // FEATURE_COMINTEROP

#if defined(TARGET_X86) && defined(TARGET_WINDOWS)
DWORD m_dwCopyCtorChainLocalNum;
#endif // defined(TARGET_X86) && defined(TARGET_WINDOWS)

BOOL m_fHasCleanupCode;
BOOL m_fHasExceptionCleanupCode;
BOOL m_fCleanupWorkListIsSetup;
Expand Down
24 changes: 24 additions & 0 deletions src/coreclr/vm/i386/asmhelpers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ EXTERN _NDirectImportWorker@4:PROC

EXTERN _VarargPInvokeStubWorker@12:PROC
EXTERN _GenericPInvokeCalliStubWorker@12:PROC
EXTERN _CallCopyConstructorsWorker@4:PROC

EXTERN _PreStubWorker@8:PROC
EXTERN _TheUMEntryPrestubWorker@4:PROC
Expand Down Expand Up @@ -1062,6 +1063,29 @@ GoCallCalliWorker:

_GenericPInvokeCalliHelper@0 endp

;==========================================================================
; This is small stub whose purpose is to record current stack pointer and
; call CallCopyConstructorsWorker to invoke copy constructors and destructors
; as appropriate. This stub operates on arguments already pushed to the
; stack by JITted IL stub and must not create a new frame, i.e. it must tail
; call to the target for it to see the arguments that copy ctors have been
; called on.
;
_CopyConstructorCallStub@0 proc public
; there may be an argument in ecx - save it
push ecx

; push pointer to arguments
lea edx, [esp + 8]
push edx

call _CallCopyConstructorsWorker@4

; restore ecx and tail call to the target
pop ecx
jmp eax
_CopyConstructorCallStub@0 endp

ifdef FEATURE_COMINTEROP

;==========================================================================
Expand Down
36 changes: 36 additions & 0 deletions src/coreclr/vm/ilmarshalers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3459,6 +3459,38 @@ MarshalerOverrideStatus ILBlittableValueClassWithCopyCtorMarshaler::ArgumentOver
#ifdef TARGET_X86
pslIL->SetStubTargetArgType(&locDesc); // native type is the value type
pslILDispatch->EmitLDLOC(dwNewValueTypeLocal); // we load the local directly

#if defined(TARGET_WINDOWS)
// Record this argument's stack slot in the copy constructor chain so we can correctly invoke the copy constructor.
DWORD ctorCookie = pslIL->NewLocal(CoreLibBinder::GetClass(CLASS__COPY_CONSTRUCTOR_COOKIE));
pslIL->EmitLDLOCA(ctorCookie);
pslIL->EmitINITOBJ(pslIL->GetToken(CoreLibBinder::GetClass(CLASS__COPY_CONSTRUCTOR_COOKIE)));
pslIL->EmitLDLOCA(ctorCookie);
pslIL->EmitLDLOCA(dwNewValueTypeLocal);
pslIL->EmitSTFLD(pslIL->GetToken(CoreLibBinder::GetField(FIELD__COPY_CONSTRUCTOR_COOKIE__SOURCE)));
pslIL->EmitLDLOCA(ctorCookie);
pslIL->EmitLDC(nativeStackOffset);
pslIL->EmitSTFLD(pslIL->GetToken(CoreLibBinder::GetField(FIELD__COPY_CONSTRUCTOR_COOKIE__DESTINATION_OFFSET)));

if (pargs->mm.m_pCopyCtor)
{
pslIL->EmitLDLOCA(ctorCookie);
pslIL->EmitLDFTN(pslIL->GetToken(pargs->mm.m_pCopyCtor));
pslIL->EmitSTFLD(pslIL->GetToken(CoreLibBinder::GetField(FIELD__COPY_CONSTRUCTOR_COOKIE__COPY_CONSTRUCTOR)));
}

if (pargs->mm.m_pDtor)
{
pslIL->EmitLDLOCA(ctorCookie);
pslIL->EmitLDFTN(pslIL->GetToken(pargs->mm.m_pDtor));
pslIL->EmitSTFLD(pslIL->GetToken(CoreLibBinder::GetField(FIELD__COPY_CONSTRUCTOR_COOKIE__DESTRUCTOR)));
}

pslIL->EmitLDLOCA(psl->GetCopyCtorChainLocalNum());
pslIL->EmitLDLOCA(ctorCookie);
pslIL->EmitCALL(METHOD__COPY_CONSTRUCTOR_CHAIN__ADD, 2, 0);
#endif // defined(TARGET_WINDOWS)

#else
pslIL->SetStubTargetArgType(ELEMENT_TYPE_I); // native type is a pointer
EmitLoadNativeLocalAddrForByRefDispatch(pslILDispatch, dwNewValueTypeLocal);
Expand All @@ -3477,9 +3509,13 @@ MarshalerOverrideStatus ILBlittableValueClassWithCopyCtorMarshaler::ArgumentOver

DWORD dwNewValueTypeLocal;
dwNewValueTypeLocal = pslIL->NewLocal(locDesc);
#ifdef TARGET_WINDOWS
pslILDispatch->EmitLDARGA(argidx);
#else // !TARGET_WINDOWS
pslILDispatch->EmitLDARG(argidx);
pslILDispatch->EmitSTLOC(dwNewValueTypeLocal);
pslILDispatch->EmitLDLOCA(dwNewValueTypeLocal);
#endif // TARGET_WINDOWS
#else
LocalDesc locDesc(pargs->mm.m_pMT);
locDesc.MakeCopyConstructedPointer();
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/vm/metasig.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,13 @@ DEFINE_METASIG_T(SM(RefCleanupWorkListElement_RetVoid, r(C(CLEANUP_WORK_LIST_ELE
DEFINE_METASIG_T(SM(RefCleanupWorkListElement_SafeHandle_RetIntPtr, r(C(CLEANUP_WORK_LIST_ELEMENT)) C(SAFE_HANDLE), I))
DEFINE_METASIG_T(SM(RefCleanupWorkListElement_Obj_RetVoid, r(C(CLEANUP_WORK_LIST_ELEMENT)) j, v))

DEFINE_METASIG(SM(PtrVoid_RetPtrVoid, P(v), P(v)))
DEFINE_METASIG(IM(PtrVoid_RetVoid, P(v), v))
#if defined(TARGET_X86) && defined(TARGET_WINDOWS)
DEFINE_METASIG_T(IM(PtrCopyConstructorCookie_RetVoid, P(g(COPY_CONSTRUCTOR_COOKIE)), v))
#endif // defined(TARGET_X86) && defined(TARGET_WINDOWS)


#ifdef FEATURE_ICASTABLE
DEFINE_METASIG_T(SM(ICastable_RtType_RefException_RetBool, C(ICASTABLE) C(CLASS) r(C(EXCEPTION)), F))
DEFINE_METASIG_T(SM(ICastable_RtType_RetRtType, C(ICASTABLE) C(CLASS), C(CLASS)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,62 @@ static int Main()
object testInstance = Activator.CreateInstance(testType);
MethodInfo testMethod = testType.GetMethod("PInvokeNumCopies");

// On x86, we have an additional copy on every P/Invoke from the "native" parameter to the actual location on the stack.
int platformExtra = 0;
if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
{
platformExtra = 1;
}

// PInvoke will copy twice. Once from argument to parameter, and once from the managed to native parameter.
Assert.Equal(2, (int)testMethod.Invoke(testInstance, null));
Assert.Equal(2 + platformExtra, (int)testMethod.Invoke(testInstance, null));

testMethod = testType.GetMethod("ReversePInvokeNumCopies");

// Reverse PInvoke will copy 3 times. Two are from the same paths as the PInvoke,
// and the third is from the reverse P/Invoke call.
Assert.Equal(3, (int)testMethod.Invoke(testInstance, null));
Assert.Equal(3 + platformExtra, (int)testMethod.Invoke(testInstance, null));

testMethod = testType.GetMethod("PInvokeNumCopiesDerivedType");

// PInvoke will copy twice. Once from argument to parameter, and once from the managed to native parameter.
Assert.Equal(2, (int)testMethod.Invoke(testInstance, null));
Assert.Equal(2 + platformExtra, (int)testMethod.Invoke(testInstance, null));

testMethod = testType.GetMethod("ReversePInvokeNumCopiesDerivedType");

// Reverse PInvoke will copy 3 times. Two are from the same paths as the PInvoke,
// and the third is from the reverse P/Invoke call.
Assert.Equal(3, (int)testMethod.Invoke(testInstance, null));
Assert.Equal(3 + platformExtra, (int)testMethod.Invoke(testInstance, null));
}
catch (Exception ex)
{
Console.WriteLine(ex);
return 101;
}

try
{
CopyConstructorsInArgumentStackSlots();
}
catch (Exception ex)
{
Console.WriteLine(ex);
return 101;
}

return 100;
}

public static void CopyConstructorsInArgumentStackSlots()
{
Assembly ijwNativeDll = Assembly.Load("IjwCopyConstructorMarshaler");
Type testType = ijwNativeDll.GetType("TestClass");
object testInstance = Activator.CreateInstance(testType);
MethodInfo testMethod = testType.GetMethod("ExposedThisCopyConstructorScenario");

Assert.Equal(0, (int)testMethod.Invoke(testInstance, null));
}

[DllImport("kernel32.dll")]
static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, int dwFlags);

Expand Down
Loading