Add minimal COM support into WinAOT BCL profile and Windows Mono runtime.
authorlateralusX <lateralusx.github@gmail.com>
Mon, 29 Apr 2019 08:17:45 +0000 (10:17 +0200)
committerMarek Safar <marek.safar@gmail.com>
Tue, 30 Apr 2019 10:14:57 +0000 (12:14 +0200)
Technologies like SharpDX uses a minimal set of COM support from runtime
and System.Runtime.InteropServices.Marshal:

AddRef
Release
QueryInterface

All these are low level wrappers around methods in IUknown interface and
doesn't need any of the additional runtime COM support enabled to work.

Technologies like CoreRT includes these methods in their full AOT
profile, meaning that SharpDX can run on CoreRT on Windows platforms. Mono's
WinAOT profile and runtime currently don't, making it impossible  to use
SharpDX.

This PR adds the needed methods into WinAOT profile and also make
sure corresponding icalls always gets included on Windows build Mono runtime.

Commit migrated from https://github.com/mono/mono/commit/81ce33f6b6a2cc70ac3f9dd91073e747b5739611

src/mono/mono/metadata/cominterop.c
src/mono/mono/metadata/icall-def.h

index 5078bce..6517840 100644 (file)
@@ -53,7 +53,7 @@
 static void
 mono_System_ComObject_ReleaseInterfaces (MonoComObjectHandle obj);
 
-#ifndef DISABLE_COM
+#if !defined (DISABLE_COM) || defined (HOST_WIN32)
 
 static int
 mono_IUnknown_QueryInterface (MonoIUnknown *pUnk, gconstpointer riid, gpointer* ppv)
@@ -3623,6 +3623,29 @@ mono_marshal_free_ccw (MonoObject* object)
        return FALSE;
 }
 
+#ifdef HOST_WIN32
+
+int
+ves_icall_System_Runtime_InteropServices_Marshal_AddRefInternal (MonoIUnknown *pUnk)
+{
+       return mono_IUnknown_AddRef (pUnk);
+}
+
+int
+ves_icall_System_Runtime_InteropServices_Marshal_ReleaseInternal (MonoIUnknown *pUnk)
+{
+       g_assert (pUnk);
+       return mono_IUnknown_Release (pUnk);
+}
+
+int
+ves_icall_System_Runtime_InteropServices_Marshal_QueryInterfaceInternal (MonoIUnknown *pUnk, gconstpointer riid, gpointer* ppv)
+{
+       return mono_IUnknown_QueryInterface (pUnk, riid, ppv);
+}
+
+#else /* HOST_WIN32 */
+
 int
 ves_icall_System_Runtime_InteropServices_Marshal_AddRefInternal (MonoIUnknown *pUnk)
 {
@@ -3637,6 +3660,7 @@ ves_icall_System_Runtime_InteropServices_Marshal_ReleaseInternal (MonoIUnknown *
        return 0;
 }
 
+
 int
 ves_icall_System_Runtime_InteropServices_Marshal_QueryInterfaceInternal (MonoIUnknown *pUnk, gconstpointer riid, gpointer* ppv)
 {
@@ -3644,6 +3668,7 @@ ves_icall_System_Runtime_InteropServices_Marshal_QueryInterfaceInternal (MonoIUn
        return 0;
 }
 
+#endif /* HOST_WIN32 */
 #endif /* DISABLE_COM */
 
 MonoStringHandle
index 93d6876..c9f93b0 100644 (file)
@@ -825,7 +825,7 @@ HANDLES(GCH_4, "GetTarget", ves_icall_System_GCHandle_GetTarget, MonoObject, 1,
 HANDLES(GCH_5, "GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle, guint32, 3, (MonoObject, guint32, gint32))
 #endif
 
-#ifndef DISABLE_COM
+#if !defined(DISABLE_COM) || defined (HOST_WIN32)
 ICALL_TYPE(MARSHAL, "System.Runtime.InteropServices.Marshal", MARSHAL_1)
 NOHANDLES(ICALL(MARSHAL_1, "AddRefInternal", ves_icall_System_Runtime_InteropServices_Marshal_AddRefInternal))
 #else
@@ -880,13 +880,15 @@ HANDLES(MARSHAL_20, "PtrToStructureInternal", ves_icall_System_Runtime_InteropSe
 HANDLES(MARSHAL_20, "PtrToStructure(intptr,System.Type)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type, MonoObject, 2, (gconstpointer, MonoReflectionType))
 HANDLES(MARSHAL_21, "PtrToStructure(intptr,object)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure, void, 2, (gconstpointer, MonoObject))
 #endif
-#ifndef DISABLE_COM
+#if !defined (DISABLE_COM) || defined (HOST_WIN32)
 NOHANDLES(ICALL(MARSHAL_22, "QueryInterfaceInternal", ves_icall_System_Runtime_InteropServices_Marshal_QueryInterfaceInternal))
 #endif
 HANDLES(MARSHAL_43, "ReAllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_ReAllocCoTaskMem, gpointer, 2, (gpointer, int))
 HANDLES(MARSHAL_23, "ReAllocHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_ReAllocHGlobal, gpointer, 2, (gpointer, gsize))
 #ifndef DISABLE_COM
 HANDLES(MARSHAL_49, "ReleaseComObjectInternal", ves_icall_System_Runtime_InteropServices_Marshal_ReleaseComObjectInternal, gint32, 1, (MonoObject))
+#endif
+#if !defined (DISABLE_COM) || defined (HOST_WIN32)
 NOHANDLES(ICALL(MARSHAL_29, "ReleaseInternal", ves_icall_System_Runtime_InteropServices_Marshal_ReleaseInternal))
 #endif
 HANDLES(MARSHAL_30, "SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf, guint32, 1, (MonoReflectionType))