Implement support for copy constructors when marshalling in IJW (#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)
commit4bca72836811aa1b82389c50dc4f2bcae222bdc0
tree6852f8c74ddd435a7ebc59867b00ca310a5c0c06
parentaccc6eb0f0f669494bee0788884b5a10101f1243
Implement support for copy constructors when marshalling in IJW (#22805)

Fixes #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.
12 files changed:
src/dlls/mscorrc/mscorrc.rc
src/dlls/mscorrc/resource.h
src/vm/dllimport.cpp
src/vm/ilmarshalers.cpp
src/vm/ilmarshalers.h
src/vm/mlinfo.cpp
src/vm/mtypes.h
tests/src/Interop/CMakeLists.txt
tests/src/Interop/IJW/CopyConstructorMarshaler/CMakeLists.txt [new file with mode: 0644]
tests/src/Interop/IJW/CopyConstructorMarshaler/CopyConstructorMarshaler.cs [new file with mode: 0644]
tests/src/Interop/IJW/CopyConstructorMarshaler/CopyConstructorMarshaler.csproj [new file with mode: 0644]
tests/src/Interop/IJW/CopyConstructorMarshaler/IjwCopyConstructorMarshaler.cpp [new file with mode: 0644]