[mono] Add support for UnmanagedCallersOnlyAttribute (#38728)
authorAleksey Kliger (λgeek) <alklig@microsoft.com>
Fri, 10 Jul 2020 00:37:36 +0000 (20:37 -0400)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2020 00:37:36 +0000 (20:37 -0400)
commit1e3c959b087bc7cc7d10e360211150b3db050454
tree6f1f10e27d178e2b03e6bd6c0709d1bba21ac6ff
parent838fcffb0f7a2f4467449c4612de433dc269af24
[mono] Add support for UnmanagedCallersOnlyAttribute (#38728)

* [marshal] Add mono_method_has_unmanaged_callers_only_attribute

* [marshal] Allow calls to mono_marshal_get_managed_wrapped without a delegate class

   In that case, create a wrapper based on the signature of the method itself.

* [aot] Allow decode_method_ref to decode NATIVE_TO_MANAGED wrappers without a delegate class

   Bump the AOT file format

* [interp] ldftn will return a native-to-managed wrapper to UnmanagedCallersOnly methods

* aot: emit byte when we don't expect a class

* jit: create wrapper creation for ldftn in method-to-ir

   Do it at IR generation of the caller, not every time the ldftn is executed

* jit: don't create a jump trampoline for ldftn of a native-to-managed wrapper

   The wrapper might be called from a thread that's not attached to the runtime, and the jump trampoline will look at TLS vars that are not initialized

* interp: transform LDFTN into LDC of a create_method_pointer for UnmanagedCallersOnly method

* marshal: throw invalid program exception for instance and generic methods

* Emit IPE throw instead of aborting JIT or interp compilation for bad UnmanagedCallersOnly methods

   Instead of throwing while JITing (or transforming), throw when the LDFTN is executed.

* disallow delegate constructor calls on UnmanagedCallersOnly methods

* throw IPE if UnmanagedCallersOnly method has non-blittable args

* disallow DllImport and UnmanagedCallersOnly together

   throw NotSupportedException

Co-authored-by: Ryan Lucia <ryan@luciaonline.net>
src/mono/mono/metadata/class-internals.h
src/mono/mono/metadata/jit-icall-reg.h
src/mono/mono/metadata/marshal.c
src/mono/mono/mini/aot-compiler.c
src/mono/mono/mini/aot-runtime.c
src/mono/mono/mini/aot-runtime.h
src/mono/mono/mini/interp/transform.c
src/mono/mono/mini/jit-icalls.c
src/mono/mono/mini/jit-icalls.h
src/mono/mono/mini/method-to-ir.c
src/mono/mono/mini/mini-runtime.c