From 2b75360b858cf7bb8f6d560282396fc147767c25 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Tue, 18 May 2021 13:58:09 -0700 Subject: [PATCH 1/2] COM related work and native host name changes --- docs/workflow/trimming/feature-switches.md | 4 +- .../src/ILLink/ILLink.Substitutions.xml | 4 +- .../InteropServices/ComponentActivator.cs | 2 +- .../InteropServices/InMemoryAssemblyLoader.cs | 2 +- src/coreclr/vm/corelib.h | 35 ++++++++++-- .../ComWrappersTestsBuiltInComDisabled.csproj | 17 ++++++ ...Instance.Marshalling.BuiltInComDisabled.cs | 53 +++++++++++++++++++ ...eMarshallingTestsBuiltInComDisabled.csproj | 33 ++++++++++++ 8 files changed, 140 insertions(+), 10 deletions(-) create mode 100644 src/tests/Interop/COM/ComWrappers/API/ComWrappersTestsBuiltInComDisabled.csproj create mode 100644 src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.BuiltInComDisabled.cs create mode 100644 src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceMarshallingTestsBuiltInComDisabled.csproj diff --git a/docs/workflow/trimming/feature-switches.md b/docs/workflow/trimming/feature-switches.md index e780f9bbd388e..a6823ca890cb3 100644 --- a/docs/workflow/trimming/feature-switches.md +++ b/docs/workflow/trimming/feature-switches.md @@ -21,8 +21,8 @@ configurations but their defaults might vary as any SDK can set the defaults dif | CustomResourceTypesSupport | System.Resources.ResourceManager.AllowCustomResourceTypes | Use of custom resource types is disabled when set to false. ResourceManager code paths that use reflection for custom types can be trimmed. | | EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization | System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization | BinaryFormatter serialization support is trimmed when set to false. | | BuiltInComInteropSupport | System.Runtime.InteropServices.BuiltInComInterop.IsSupported | Built-in COM support is trimmed when set to false. | -| EnableCPlusPlusCLIHostActivation | Internal.Runtime.InteropServices.InMemoryAssemblyLoader.IsSupported | C++/CLI host activation code is disabled when set to false and related functionality can be trimmed. | -| _EnableCallingManagedFunctionFromNativeHosting | Internal.Runtime.InteropServices.ComponentActivator.IsSupported | Getting a managed function from native hosting is disabled when set to false and related functionality can be trimmed. | +| EnableCPlusPlusCLIHostActivation | System.Runtime.InteropServices.CPlusPlusCLIHostActivation.IsSupported | C++/CLI host activation code is disabled when set to false and related functionality can be trimmed. | +| _EnableCallingManagedFunctionFromNativeHosting | System.Runtime.InteropServices.CallingManagedFunctionFromNativeHosting.IsSupported | Getting a managed function from native hosting is disabled when set to false and related functionality can be trimmed. | Any feature-switch which defines property can be set in csproj file or on the command line as any other MSBuild property. Those without predefined property name diff --git a/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml b/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml index ec19ddf8d340e..3bf6b0d86a91e 100644 --- a/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml +++ b/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml @@ -3,10 +3,10 @@ - + - + diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs index 205de7a9b3576..29c7873f7b019 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs @@ -23,7 +23,7 @@ public static class ComponentActivator private static bool IsSupported { get; } = InitializeIsSupported(); - private static bool InitializeIsSupported() => AppContext.TryGetSwitch("Internal.Runtime.InteropServices.ComponentActivator.IsSupported", out bool isSupported) ? isSupported : true; + private static bool InitializeIsSupported() => AppContext.TryGetSwitch("System.Runtime.InteropServices.CallingManagedFunctionFromNativeHosting.IsSupported", out bool isSupported) ? isSupported : true; public delegate int ComponentEntryPoint(IntPtr args, int sizeBytes); diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs index cf6dc6adc3102..b4f22cabbe10f 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs @@ -14,7 +14,7 @@ public static class InMemoryAssemblyLoader { private static bool IsSupported { get; } = InitializeIsSupported(); - private static bool InitializeIsSupported() => AppContext.TryGetSwitch("Internal.Runtime.InteropServices.InMemoryAssemblyLoader.IsSupported", out bool isSupported) ? isSupported : true; + private static bool InitializeIsSupported() => AppContext.TryGetSwitch("System.Runtime.InteropServices.CPlusPlusCLIHostActivation.IsSupported", out bool isSupported) ? isSupported : true; /// /// Loads into an isolated AssemblyLoadContext an assembly that has already been loaded into memory by the OS loader as a native module. diff --git a/src/coreclr/vm/corelib.h b/src/coreclr/vm/corelib.h index f9e0de124108b..aff8c750f7e3d 100644 --- a/src/coreclr/vm/corelib.h +++ b/src/coreclr/vm/corelib.h @@ -68,6 +68,19 @@ #define DEFINE_FIELD_U(stringName, unmanagedContainingType, unmanagedOffset) #endif +// +// BEGIN_ILLINK_FEATURE_SWITCH and END_ILLINK_FEATURE_SWITCH allow IL linker to guard types behind a feature switch +// Current support is only around class scope and not for standalone members of classes +// +#ifndef BEGIN_ILLINK_FEATURE_SWITCH +#define BEGIN_ILLINK_FEATURE_SWITCH(featureName, featureValue, featureDefault) +#endif + +#ifndef END_ILLINK_FEATURE_SWITCH +#define END_ILLINK_FEATURE_SWITCH() +#endif + + // NOTE: Make this window really wide if you want to read the table... DEFINE_CLASS(ACTIVATOR, System, Activator) @@ -176,6 +189,7 @@ DEFINE_METHOD(CLASS, GET_PROPERTY_INFO, GetPropertyInfo, DEFINE_METHOD(CLASS, FORWARD_CALL_TO_INVOKE, ForwardCallToInvokeMember, IM_Str_BindingFlags_Obj_ArrObj_ArrBool_ArrInt_ArrType_Type_RetObj) #endif // FEATURE_COMINTEROP +BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsSupported, true, true) #ifdef FEATURE_COMINTEROP DEFINE_CLASS(BSTR_WRAPPER, Interop, BStrWrapper) DEFINE_CLASS(CURRENCY_WRAPPER, Interop, CurrencyWrapper) @@ -184,7 +198,9 @@ DEFINE_CLASS(ERROR_WRAPPER, Interop, ErrorWrapper) DEFINE_CLASS(UNKNOWN_WRAPPER, Interop, UnknownWrapper) DEFINE_CLASS(VARIANT_WRAPPER, Interop, VariantWrapper) #endif // FEATURE_COMINTEROP +END_ILLINK_FEATURE_SWITCH() +BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsSupported, true, true) #ifdef FEATURE_COMINTEROP DEFINE_CLASS_U(System, __ComObject, ComObject) DEFINE_FIELD_U(m_ObjectToDataMap, ComObject, m_ObjectToDataMap) @@ -201,6 +217,7 @@ DEFINE_METHOD(LICENSE_INTEROP_PROXY, GETCURRENTCONTEXTINFO, GetCurrentContextI DEFINE_METHOD(LICENSE_INTEROP_PROXY, SAVEKEYINCURRENTCONTEXT, SaveKeyInCurrentContext, IM_IntPtr_RetVoid) #endif // FEATURE_COMINTEROP +END_ILLINK_FEATURE_SWITCH() DEFINE_CLASS_U(Interop, CriticalHandle, CriticalHandle) DEFINE_FIELD_U(handle, CriticalHandle, m_handle) @@ -285,9 +302,11 @@ DEFINE_METHOD(CURRENCY, DECIMAL_CTOR, .ctor, DEFINE_CLASS(DATE_TIME, System, DateTime) DEFINE_METHOD(DATE_TIME, LONG_CTOR, .ctor, IM_Long_RetVoid) +BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsSupported, true, true) #ifdef FEATURE_COMINTEROP DEFINE_CLASS(DATE_TIME_OFFSET, System, DateTimeOffset) #endif // FEATURE_COMINTEROP +END_ILLINK_FEATURE_SWITCH() DEFINE_CLASS(DECIMAL, System, Decimal) DEFINE_METHOD(DECIMAL, CURRENCY_CTOR, .ctor, IM_Currency_RetVoid) @@ -402,6 +421,7 @@ DEFINE_METHOD(FIELD_INFO, GET_VALUE, GetValue, DEFINE_CLASS(GUID, System, Guid) +BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsSupported, true, true) #ifdef FEATURE_COMINTEROP DEFINE_CLASS(VARIANT, System, Variant) DEFINE_METHOD(VARIANT, CONVERT_OBJECT_TO_VARIANT,MarshalHelperConvertObjectToVariant,SM_Obj_RefVariant_RetVoid) @@ -413,6 +433,7 @@ DEFINE_FIELD_U(_objref, VariantData, m_objref) DEFINE_FIELD_U(_data, VariantData, m_data) DEFINE_FIELD_U(_flags, VariantData, m_flags) #endif // FEATURE_COMINTEROP +END_ILLINK_FEATURE_SWITCH() DEFINE_CLASS(IASYNCRESULT, System, IAsyncResult) @@ -431,11 +452,13 @@ DEFINE_CLASS(DYNAMICINTERFACECASTABLEHELPERS, Interop, DynamicInterfaceCasta DEFINE_METHOD(DYNAMICINTERFACECASTABLEHELPERS, IS_INTERFACE_IMPLEMENTED, IsInterfaceImplemented, SM_IDynamicInterfaceCastable_RuntimeType_Bool_RetBool) DEFINE_METHOD(DYNAMICINTERFACECASTABLEHELPERS, GET_INTERFACE_IMPLEMENTATION, GetInterfaceImplementation, SM_IDynamicInterfaceCastable_RuntimeType_RetRtType) +BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsSupported, true, true) #ifdef FEATURE_COMINTEROP DEFINE_CLASS(ICUSTOM_QUERYINTERFACE, Interop, ICustomQueryInterface) DEFINE_METHOD(ICUSTOM_QUERYINTERFACE, GET_INTERFACE, GetInterface, IM_RefGuid_OutIntPtr_RetCustomQueryInterfaceResult) DEFINE_CLASS(CUSTOMQUERYINTERFACERESULT, Interop, CustomQueryInterfaceResult) #endif //FEATURE_COMINTEROP +END_ILLINK_FEATURE_SWITCH() #ifdef FEATURE_COMWRAPPERS DEFINE_CLASS(COMWRAPPERS, Interop, ComWrappers) @@ -467,11 +490,11 @@ DEFINE_METHOD(IREFLECT, GET_FIELDS, GetFields, DEFINE_METHOD(IREFLECT, GET_METHODS, GetMethods, IM_BindingFlags_RetArrMethodInfo) DEFINE_METHOD(IREFLECT, INVOKE_MEMBER, InvokeMember, IM_Str_BindingFlags_Binder_Obj_ArrObj_ArrParameterModifier_CultureInfo_ArrStr_RetObj) - +BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsSupported, true, true) #ifdef FEATURE_COMINTEROP DEFINE_CLASS(LCID_CONVERSION_TYPE, Interop, LCIDConversionAttribute) #endif // FEATURE_COMINTEROP - +END_ILLINK_FEATURE_SWITCH() DEFINE_CLASS(MARSHAL, Interop, Marshal) #ifdef FEATURE_COMINTEROP @@ -618,10 +641,11 @@ DEFINE_METHOD(SINGLE, GET_HASH_CODE, GetHashCode, IM_RetI DEFINE_CLASS(__CANON, System, __Canon) - +BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsSupported, true, true) #ifdef FEATURE_COMINTEROP DEFINE_CLASS(OLE_AUT_BINDER, System, OleAutBinder) #endif // FEATURE_COMINTEROP +END_ILLINK_FEATURE_SWITCH() DEFINE_CLASS(MONITOR, Threading, Monitor) DEFINE_METHOD(MONITOR, ENTER, Enter, SM_Obj_RetVoid) @@ -1060,6 +1084,7 @@ DEFINE_METHOD(ANSIBSTRMARSHALER, CONVERT_TO_NATIVE, ConvertToNative, DEFINE_METHOD(ANSIBSTRMARSHALER, CONVERT_TO_MANAGED, ConvertToManaged, SM_IntPtr_RetStr) DEFINE_METHOD(ANSIBSTRMARSHALER, CLEAR_NATIVE, ClearNative, SM_IntPtr_RetVoid) +BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsSupported, true, true) #ifdef FEATURE_COMINTEROP DEFINE_CLASS(OBJECTMARSHALER, StubHelpers, ObjectMarshaler) DEFINE_METHOD(OBJECTMARSHALER, CONVERT_TO_NATIVE, ConvertToNative, SM_ObjIntPtr_RetVoid) @@ -1080,6 +1105,7 @@ DEFINE_METHOD(MNGD_SAFE_ARRAY_MARSHALER, CONVERT_SPACE_TO_MANAGED, ConvertSpa DEFINE_METHOD(MNGD_SAFE_ARRAY_MARSHALER, CONVERT_CONTENTS_TO_MANAGED, ConvertContentsToManaged, SM_IntPtr_RefObj_IntPtr_RetVoid) DEFINE_METHOD(MNGD_SAFE_ARRAY_MARSHALER, CLEAR_NATIVE, ClearNative, SM_IntPtr_RefObj_IntPtr_RetVoid) #endif // FEATURE_COMINTEROP +END_ILLINK_FEATURE_SWITCH() DEFINE_CLASS(DATEMARSHALER, StubHelpers, DateMarshaler) DEFINE_METHOD(DATEMARSHALER, CONVERT_TO_NATIVE, ConvertToNative, SM_DateTime_RetDbl) @@ -1274,9 +1300,10 @@ DEFINE_FIELD_U(_generationInfo2, GCMemoryInfoData, generationInfo2) DEFINE_FIELD_U(_generationInfo3, GCMemoryInfoData, generationInfo3) DEFINE_FIELD_U(_generationInfo4, GCMemoryInfoData, generationInfo4) - #undef DEFINE_CLASS #undef DEFINE_METHOD #undef DEFINE_FIELD #undef DEFINE_CLASS_U #undef DEFINE_FIELD_U +#undef BEGIN_ILLINK_FEATURE_SWITCH +#undef END_ILLINK_FEATURE_SWITCH diff --git a/src/tests/Interop/COM/ComWrappers/API/ComWrappersTestsBuiltInComDisabled.csproj b/src/tests/Interop/COM/ComWrappers/API/ComWrappersTestsBuiltInComDisabled.csproj new file mode 100644 index 0000000000000..a51b1eb40779f --- /dev/null +++ b/src/tests/Interop/COM/ComWrappers/API/ComWrappersTestsBuiltInComDisabled.csproj @@ -0,0 +1,17 @@ + + + Exe + true + + + + + + + + + + + + + diff --git a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.BuiltInComDisabled.cs b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.BuiltInComDisabled.cs new file mode 100644 index 0000000000000..e7ec466ee1170 --- /dev/null +++ b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.BuiltInComDisabled.cs @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace ComWrappersTests.GlobalInstance +{ + using System; + + using ComWrappersTests.Common; + using TestLibrary; + + partial class Program + { + private static void ValidateNotRegisteredForTrackerSupport() + { + Console.WriteLine($"Running {nameof(ValidateNotRegisteredForTrackerSupport)}..."); + + int hr = MockReferenceTrackerRuntime.Trigger_NotifyEndOfReferenceTrackingOnThread(); + Assert.AreNotEqual(GlobalComWrappers.ReleaseObjectsCallAck, hr); + } + + static int Main(string[] doNotUse) + { + try + { + // The first test registers a global ComWrappers instance for marshalling + // Subsequents tests assume the global instance has already been registered. + ValidateRegisterForMarshalling(); + + ValidateMarshalAPIs(validateUseRegistered: true); + + ValidatePInvokes(validateUseRegistered: true); + + // This calls ValidateNativeServerActivation which calls Marshal.GetTypeFromCLSID that is not supported + // ValidateComActivation(validateUseRegistered: true); + + ValidateNotRegisteredForTrackerSupport(); + + // Register a global ComWrappers instance for tracker support + ValidateRegisterForTrackerSupport(); + + ValidateNotifyEndOfReferenceTrackingOnThread(); + } + catch (Exception e) + { + Console.WriteLine($"Test Failure: {e}"); + return 101; + } + + return 100; + } + } +} + diff --git a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceMarshallingTestsBuiltInComDisabled.csproj b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceMarshallingTestsBuiltInComDisabled.csproj new file mode 100644 index 0000000000000..53f67c8dccc80 --- /dev/null +++ b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceMarshallingTestsBuiltInComDisabled.csproj @@ -0,0 +1,33 @@ + + + Exe + App.manifest + true + true + true + + + + + + + + + + + + + false + Content + Always + + + + + PreserveNewest + + + + + + From fd15540541a867d4edb1872f6f773afba1fb53f6 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 19 May 2021 17:47:13 -0700 Subject: [PATCH 2/2] FB --- docs/workflow/trimming/feature-switches.md | 4 +- .../src/ILLink/ILLink.Substitutions.xml | 4 +- .../InteropServices/ComponentActivator.cs | 2 +- .../InteropServices/InMemoryAssemblyLoader.cs | 2 +- src/coreclr/vm/corelib.h | 12 ++--- ...Instance.Marshalling.BuiltInComDisabled.cs | 53 ------------------- .../GlobalInstance.Marshalling.cs | 27 ++++++++-- ...eMarshallingTestsBuiltInComDisabled.csproj | 2 +- 8 files changed, 34 insertions(+), 72 deletions(-) delete mode 100644 src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.BuiltInComDisabled.cs diff --git a/docs/workflow/trimming/feature-switches.md b/docs/workflow/trimming/feature-switches.md index a6823ca890cb3..ea884b411b0e0 100644 --- a/docs/workflow/trimming/feature-switches.md +++ b/docs/workflow/trimming/feature-switches.md @@ -21,8 +21,8 @@ configurations but their defaults might vary as any SDK can set the defaults dif | CustomResourceTypesSupport | System.Resources.ResourceManager.AllowCustomResourceTypes | Use of custom resource types is disabled when set to false. ResourceManager code paths that use reflection for custom types can be trimmed. | | EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization | System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization | BinaryFormatter serialization support is trimmed when set to false. | | BuiltInComInteropSupport | System.Runtime.InteropServices.BuiltInComInterop.IsSupported | Built-in COM support is trimmed when set to false. | -| EnableCPlusPlusCLIHostActivation | System.Runtime.InteropServices.CPlusPlusCLIHostActivation.IsSupported | C++/CLI host activation code is disabled when set to false and related functionality can be trimmed. | -| _EnableCallingManagedFunctionFromNativeHosting | System.Runtime.InteropServices.CallingManagedFunctionFromNativeHosting.IsSupported | Getting a managed function from native hosting is disabled when set to false and related functionality can be trimmed. | +| EnableCppCLIHostActivation | System.Runtime.InteropServices.EnableCppCLIHostActivation | C++/CLI host activation code is disabled when set to false and related functionality can be trimmed. | +| _EnableConsumingManagedCodeFromNativeHosting | System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting | Getting a managed function from native hosting is disabled when set to false and related functionality can be trimmed. | Any feature-switch which defines property can be set in csproj file or on the command line as any other MSBuild property. Those without predefined property name diff --git a/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml b/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml index 3bf6b0d86a91e..e7d1dd3482d8e 100644 --- a/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml +++ b/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml @@ -3,10 +3,10 @@ - + - + diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs index 29c7873f7b019..e276025cfd37b 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs @@ -23,7 +23,7 @@ public static class ComponentActivator private static bool IsSupported { get; } = InitializeIsSupported(); - private static bool InitializeIsSupported() => AppContext.TryGetSwitch("System.Runtime.InteropServices.CallingManagedFunctionFromNativeHosting.IsSupported", out bool isSupported) ? isSupported : true; + private static bool InitializeIsSupported() => AppContext.TryGetSwitch("System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting", out bool isSupported) ? isSupported : true; public delegate int ComponentEntryPoint(IntPtr args, int sizeBytes); diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs index b4f22cabbe10f..311ce31bdc95a 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs @@ -14,7 +14,7 @@ public static class InMemoryAssemblyLoader { private static bool IsSupported { get; } = InitializeIsSupported(); - private static bool InitializeIsSupported() => AppContext.TryGetSwitch("System.Runtime.InteropServices.CPlusPlusCLIHostActivation.IsSupported", out bool isSupported) ? isSupported : true; + private static bool InitializeIsSupported() => AppContext.TryGetSwitch("System.Runtime.InteropServices.EnableCppCLIHostActivation", out bool isSupported) ? isSupported : true; /// /// Loads into an isolated AssemblyLoadContext an assembly that has already been loaded into memory by the OS loader as a native module. diff --git a/src/coreclr/vm/corelib.h b/src/coreclr/vm/corelib.h index aff8c750f7e3d..5fe53b824e83a 100644 --- a/src/coreclr/vm/corelib.h +++ b/src/coreclr/vm/corelib.h @@ -69,8 +69,10 @@ #endif // -// BEGIN_ILLINK_FEATURE_SWITCH and END_ILLINK_FEATURE_SWITCH allow IL linker to guard types behind a feature switch -// Current support is only around class scope and not for standalone members of classes +// BEGIN_ILLINK_FEATURE_SWITCH and END_ILLINK_FEATURE_SWITCH allow IL linker to guard types behind a feature switch. +// Current support is only around class scope and not for standalone members of classes. +// See usage in this file itself and on the link (the assembly name for feature switch in this file will be System.Private.CoreLib), +// https://github.com/dotnet/designs/blob/main/accepted/2020/feature-switch.md#generate-the-right-input-for-the-linker-in-sdk // #ifndef BEGIN_ILLINK_FEATURE_SWITCH #define BEGIN_ILLINK_FEATURE_SWITCH(featureName, featureValue, featureDefault) @@ -302,12 +304,6 @@ DEFINE_METHOD(CURRENCY, DECIMAL_CTOR, .ctor, DEFINE_CLASS(DATE_TIME, System, DateTime) DEFINE_METHOD(DATE_TIME, LONG_CTOR, .ctor, IM_Long_RetVoid) -BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsSupported, true, true) -#ifdef FEATURE_COMINTEROP -DEFINE_CLASS(DATE_TIME_OFFSET, System, DateTimeOffset) -#endif // FEATURE_COMINTEROP -END_ILLINK_FEATURE_SWITCH() - DEFINE_CLASS(DECIMAL, System, Decimal) DEFINE_METHOD(DECIMAL, CURRENCY_CTOR, .ctor, IM_Currency_RetVoid) diff --git a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.BuiltInComDisabled.cs b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.BuiltInComDisabled.cs deleted file mode 100644 index e7ec466ee1170..0000000000000 --- a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.BuiltInComDisabled.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace ComWrappersTests.GlobalInstance -{ - using System; - - using ComWrappersTests.Common; - using TestLibrary; - - partial class Program - { - private static void ValidateNotRegisteredForTrackerSupport() - { - Console.WriteLine($"Running {nameof(ValidateNotRegisteredForTrackerSupport)}..."); - - int hr = MockReferenceTrackerRuntime.Trigger_NotifyEndOfReferenceTrackingOnThread(); - Assert.AreNotEqual(GlobalComWrappers.ReleaseObjectsCallAck, hr); - } - - static int Main(string[] doNotUse) - { - try - { - // The first test registers a global ComWrappers instance for marshalling - // Subsequents tests assume the global instance has already been registered. - ValidateRegisterForMarshalling(); - - ValidateMarshalAPIs(validateUseRegistered: true); - - ValidatePInvokes(validateUseRegistered: true); - - // This calls ValidateNativeServerActivation which calls Marshal.GetTypeFromCLSID that is not supported - // ValidateComActivation(validateUseRegistered: true); - - ValidateNotRegisteredForTrackerSupport(); - - // Register a global ComWrappers instance for tracker support - ValidateRegisterForTrackerSupport(); - - ValidateNotifyEndOfReferenceTrackingOnThread(); - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - - return 100; - } - } -} - diff --git a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.cs b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.cs index 7a03a67a05100..d01d79f153db4 100644 --- a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.cs +++ b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.cs @@ -22,18 +22,37 @@ static int Main(string[] doNotUse) { try { + bool builtInComDisabled=false; + var comConfig = AppContext.GetData("System.Runtime.InteropServices.BuiltInComInterop.IsSupported"); + if(comConfig != null && !bool.Parse(comConfig.ToString())) + { + builtInComDisabled=true; + } + Console.WriteLine($"Built-in COM Disabled?: {builtInComDisabled}"); + + // The first test registers a global ComWrappers instance for marshalling // Subsequents tests assume the global instance has already been registered. ValidateRegisterForMarshalling(); ValidateMarshalAPIs(validateUseRegistered: true); - ValidateMarshalAPIs(validateUseRegistered: false); + if(!builtInComDisabled) + { + ValidateMarshalAPIs(validateUseRegistered: false); + } ValidatePInvokes(validateUseRegistered: true); - ValidatePInvokes(validateUseRegistered: false); + if(!builtInComDisabled) + { + ValidatePInvokes(validateUseRegistered: false); + } - ValidateComActivation(validateUseRegistered: true); - ValidateComActivation(validateUseRegistered: false); + if(!builtInComDisabled) + { + // This calls ValidateNativeServerActivation which calls Marshal.GetTypeFromCLSID that is not supported + ValidateComActivation(validateUseRegistered: true); + ValidateComActivation(validateUseRegistered: false); + } ValidateNotRegisteredForTrackerSupport(); diff --git a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceMarshallingTestsBuiltInComDisabled.csproj b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceMarshallingTestsBuiltInComDisabled.csproj index 53f67c8dccc80..11622e1c77524 100644 --- a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceMarshallingTestsBuiltInComDisabled.csproj +++ b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceMarshallingTestsBuiltInComDisabled.csproj @@ -8,7 +8,7 @@ - +