[cominterop] Attach to runtime from IUnknown and IDispatch methods (mono/mono#18175)
authorAleksey Kliger (λgeek) <alklig@microsoft.com>
Fri, 13 Dec 2019 20:32:06 +0000 (15:32 -0500)
committerGitHub <noreply@github.com>
Fri, 13 Dec 2019 20:32:06 +0000 (15:32 -0500)
commit69ff23de6205705d9119db853a0578339bdb90d4
treedcfddc46bc57a33afacb17ecf3e68dae1fbf3d89
parente649693127645386f863e31513a11b2531a9bc08
[cominterop] Attach to runtime from IUnknown and IDispatch methods (mono/mono#18175)

* [cominterop][test] Calling QueryInterface from an unattached thread asserts

If we pass a managed COM object to native code and the native code calls one of
the IUnknown methods, we assert because the thread is not attached but we want
to enter GC Unsafe mode.

* [cominterop] Attach to runtime from IUnkown and IDispatch methods

If the COM objects for a managed object is passed to a thread that hasn't
interacted with Mono before, we need to attach before doing GC thread state
transitions.

Addresses https://github.com/mono/mono/issues/18137

* [test] Call managed method through COM wrapper from unattached thread

This works, but I don't think we had a test previously.  Call a managed method
via a COM interface from a thread that is not attached to the runtime, to
ensure that it is attached.

Commit migrated from https://github.com/mono/mono/commit/d0f27ce4feb07bdcf7958272e6e943eb2a2f0f7b
src/mono/mono/metadata/cominterop.c
src/mono/mono/tests/cominterop.cs
src/mono/mono/tests/libtest.c