Implement support for copy constructors when marshalling in IJW (dotnet/coreclr#22805)
authorJeremy Koritzinsky <jkoritzinsky@gmail.com>
Tue, 19 Mar 2019 23:22:47 +0000 (16:22 -0700)
committerGitHub <noreply@github.com>
Tue, 19 Mar 2019 23:22:47 +0000 (16:22 -0700)
commita58c41d7a65af180a5a8af4e8d1df1504c1ce7ed
treed4e5708fdbfc1ae9dc02e18e5d78cff4f067b9a0
parentca70f58c407648b69c4c484efe87927f989f9ebb
Implement support for copy constructors when marshalling in IJW (dotnet/coreclr#22805)

Fixes dotnet/coreclr#22219.

I decided to try simplifying the code when bringing this feature over from .NET Framework. The .NETFX x86 implementation of this marshaler adds a lot of extra code-paths, and intercepts the calling stub to enable it to exactly replicate the behavior of what would be the native code by copy-constructing an object in-place where it goes on the stack for the native call.

Instead of adding all of that extra goo, I decided to keep the implementation much more similar to the non-x86 implementation from .NETFX. Instead of intercepting the call and adding bookkeeping helper stubs, the marshaler just copies to a local in the IL stub, just like non-x86. When calling the native function, it just loads the local onto the IL stack and calls the native function as a normal function. There is a difference there, but I cannot think of a way that the difference is observable to the user.

The non-x86 implementation is identical to the .NETFX implementation.

Commit migrated from https://github.com/dotnet/coreclr/commit/4bca72836811aa1b82389c50dc4f2bcae222bdc0
12 files changed:
src/coreclr/src/dlls/mscorrc/mscorrc.rc
src/coreclr/src/dlls/mscorrc/resource.h
src/coreclr/src/vm/dllimport.cpp
src/coreclr/src/vm/ilmarshalers.cpp
src/coreclr/src/vm/ilmarshalers.h
src/coreclr/src/vm/mlinfo.cpp
src/coreclr/src/vm/mtypes.h
src/coreclr/tests/src/Interop/CMakeLists.txt
src/coreclr/tests/src/Interop/IJW/CopyConstructorMarshaler/CMakeLists.txt [new file with mode: 0644]
src/coreclr/tests/src/Interop/IJW/CopyConstructorMarshaler/CopyConstructorMarshaler.cs [new file with mode: 0644]
src/coreclr/tests/src/Interop/IJW/CopyConstructorMarshaler/CopyConstructorMarshaler.csproj [new file with mode: 0644]
src/coreclr/tests/src/Interop/IJW/CopyConstructorMarshaler/IjwCopyConstructorMarshaler.cpp [new file with mode: 0644]