From 796776c2c340947fd092ccb9ddab579c41c0fd77 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 6 May 2019 13:45:52 -0700 Subject: [PATCH] Handle E_NOTIMPL return from CoInitializeEx. (#24387) * Handle E_NOTIMPL return from CoInitializeEx. * Remove unneeded STA attributes. --- src/dlls/mscorrc/mscorrc.rc | 1 + src/dlls/mscorrc/resource.h | 2 ++ src/vm/threads.cpp | 4 ++++ tests/src/JIT/Methodical/eh/deadcode/loopstrswitchgoto.cs | 2 +- tests/src/JIT/Methodical/eh/finallyexec/switchincatch.cs | 1 - tests/src/JIT/Methodical/eh/interactions/gcincatch.cs | 1 - tests/src/JIT/Methodical/eh/interactions/strswitchfinal.cs | 2 +- tests/src/JIT/Methodical/eh/interactions/switchinfinally.cs | 1 - tests/src/JIT/Methodical/eh/regress/asurt/122239/outermostFinally.cs | 2 +- tests/src/JIT/Regression/VS-ia64-JIT/M00/b111192/strswitch2.cs | 1 - .../src/JIT/Regression/VS-ia64-JIT/M00/b98431/ConsoleApplication2.il | 1 - tests/src/JIT/Regression/VS-ia64-JIT/M00/b99403/cbyte7a.il | 1 - .../generics/Variance/Regressions/dev10_468712/dev10_468712.il | 1 - tests/src/Loader/classloader/regressions/91888/pumpFromCctor.cs | 2 -- .../RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.cs | 1 - .../threading/interlocked/compareexchange/compareexchangefloat.cs | 1 - .../threading/interlocked/compareexchange/compareexchangeintptr.cs | 1 - .../threading/interlocked/compareexchange/compareexchangeobject.cs | 1 - .../src/baseservices/threading/interlocked/exchange/exchangefloat.cs | 1 - .../src/baseservices/threading/interlocked/exchange/exchangeobject.cs | 1 - 20 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/dlls/mscorrc/mscorrc.rc b/src/dlls/mscorrc/mscorrc.rc index 3576b48..f11d48a 100644 --- a/src/dlls/mscorrc/mscorrc.rc +++ b/src/dlls/mscorrc/mscorrc.rc @@ -496,6 +496,7 @@ BEGIN STRINGTABLE DISCARDABLE BEGIN CEE_E_CVTRES_NOT_FOUND "Could not execute CVTRES.EXE." + IDS_EE_THREAD_APARTMENT_NOT_SUPPORTED "The system does not support the %1 thread apartment." IDS_EE_NDIRECT_UNSUPPORTED_SIG "Method's type signature is not PInvoke compatible." IDS_EE_COM_UNSUPPORTED_SIG "Method's type signature is not Interop compatible." IDS_EE_COM_UNSUPPORTED_TYPE "The method returned a COM Variant type that is not Interop compatible." diff --git a/src/dlls/mscorrc/resource.h b/src/dlls/mscorrc/resource.h index 01982d3..3d92d42 100644 --- a/src/dlls/mscorrc/resource.h +++ b/src/dlls/mscorrc/resource.h @@ -723,3 +723,5 @@ #define IDS_EE_BADMARSHAL_COPYCTORRESTRICTION 0x2647 #define IDS_EE_BADMARSHAL_WINRT_COPYCTOR 0x2648 #define IDS_EE_BADMARSHAL_DELEGATE_TLB_INTERFACE 0x2649 +#define IDS_EE_THREAD_APARTMENT_NOT_SUPPORTED 0x264A + \ No newline at end of file diff --git a/src/vm/threads.cpp b/src/vm/threads.cpp index 73d452c..06be462 100644 --- a/src/vm/threads.cpp +++ b/src/vm/threads.cpp @@ -5092,6 +5092,10 @@ Thread::ApartmentState Thread::SetApartment(ApartmentState state, BOOL fFireMDAO { COMPlusThrowOM(); } + else if (hr == E_NOTIMPL) + { + COMPlusThrow(kPlatformNotSupportedException, IDS_EE_THREAD_APARTMENT_NOT_SUPPORTED, (state == AS_InSTA) ? W("STA") : W("MTA")); + } else { _ASSERTE(!"Unexpected HRESULT returned from CoInitializeEx!"); diff --git a/tests/src/JIT/Methodical/eh/deadcode/loopstrswitchgoto.cs b/tests/src/JIT/Methodical/eh/deadcode/loopstrswitchgoto.cs index 8c46521..4002b08 100644 --- a/tests/src/JIT/Methodical/eh/deadcode/loopstrswitchgoto.cs +++ b/tests/src/JIT/Methodical/eh/deadcode/loopstrswitchgoto.cs @@ -25,7 +25,7 @@ namespace strswitch s_testLog = new TestUtil.TestLog(expectedOut); } - [STAThread] + private static int Main(string[] args) { string[] s = { "one", "two", "three", "four", "five", "six" }; diff --git a/tests/src/JIT/Methodical/eh/finallyexec/switchincatch.cs b/tests/src/JIT/Methodical/eh/finallyexec/switchincatch.cs index fff8a5e..f355396 100644 --- a/tests/src/JIT/Methodical/eh/finallyexec/switchincatch.cs +++ b/tests/src/JIT/Methodical/eh/finallyexec/switchincatch.cs @@ -41,7 +41,6 @@ namespace strswitch /// /// The main entry point for the application. /// - [STAThread] static int Main(string[] args) { string[] s = { "one", "two", "three", "four", "five", "six" }; diff --git a/tests/src/JIT/Methodical/eh/interactions/gcincatch.cs b/tests/src/JIT/Methodical/eh/interactions/gcincatch.cs index 6f1d5a0..e3594b4 100644 --- a/tests/src/JIT/Methodical/eh/interactions/gcincatch.cs +++ b/tests/src/JIT/Methodical/eh/interactions/gcincatch.cs @@ -41,7 +41,6 @@ namespace test2 /// /// The main entry point for the application. /// - [STAThread] public static int Main(String[] args) { int[] ar = new int[] { 1, 2, 3, 4, 5 }; diff --git a/tests/src/JIT/Methodical/eh/interactions/strswitchfinal.cs b/tests/src/JIT/Methodical/eh/interactions/strswitchfinal.cs index a65594f..cc7b14f 100644 --- a/tests/src/JIT/Methodical/eh/interactions/strswitchfinal.cs +++ b/tests/src/JIT/Methodical/eh/interactions/strswitchfinal.cs @@ -54,7 +54,7 @@ namespace strswitch s_testLog = new TestUtil.TestLog(expectedOut); } - [STAThread] + private static int Main(string[] args) { string[] s = { "one", "two", "three", "four", "five", "six" }; diff --git a/tests/src/JIT/Methodical/eh/interactions/switchinfinally.cs b/tests/src/JIT/Methodical/eh/interactions/switchinfinally.cs index 388ee9b..547e889 100644 --- a/tests/src/JIT/Methodical/eh/interactions/switchinfinally.cs +++ b/tests/src/JIT/Methodical/eh/interactions/switchinfinally.cs @@ -86,7 +86,6 @@ namespace test3 /// /// The main entry point for the application. /// - [STAThread] static int Main(string[] args) { //Start recording diff --git a/tests/src/JIT/Methodical/eh/regress/asurt/122239/outermostFinally.cs b/tests/src/JIT/Methodical/eh/regress/asurt/122239/outermostFinally.cs index 2e78a25..dc5a137 100644 --- a/tests/src/JIT/Methodical/eh/regress/asurt/122239/outermostFinally.cs +++ b/tests/src/JIT/Methodical/eh/regress/asurt/122239/outermostFinally.cs @@ -26,7 +26,7 @@ namespace test // Create and initialize test log object testLog = new TestUtil.TestLog(expectedOut); } - [STAThread] + static int Main(string[] args) { int[] array = { 1, 2, 3, 4, 5, 6 }; diff --git a/tests/src/JIT/Regression/VS-ia64-JIT/M00/b111192/strswitch2.cs b/tests/src/JIT/Regression/VS-ia64-JIT/M00/b111192/strswitch2.cs index 8cc671a..085cd78 100644 --- a/tests/src/JIT/Regression/VS-ia64-JIT/M00/b111192/strswitch2.cs +++ b/tests/src/JIT/Regression/VS-ia64-JIT/M00/b111192/strswitch2.cs @@ -8,7 +8,6 @@ namespace strswitch { internal class Class1 { - [STAThread] private static int Main(string[] args) { string[] s = { "one", "two", "three", "four", "five", "six" }; diff --git a/tests/src/JIT/Regression/VS-ia64-JIT/M00/b98431/ConsoleApplication2.il b/tests/src/JIT/Regression/VS-ia64-JIT/M00/b98431/ConsoleApplication2.il index 441f334..9d0de90 100644 --- a/tests/src/JIT/Regression/VS-ia64-JIT/M00/b98431/ConsoleApplication2.il +++ b/tests/src/JIT/Regression/VS-ia64-JIT/M00/b98431/ConsoleApplication2.il @@ -47,7 +47,6 @@ .method public static int32 Main() cil managed { .entrypoint - .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 2 .locals init (bool V_0, int16 V_1, diff --git a/tests/src/JIT/Regression/VS-ia64-JIT/M00/b99403/cbyte7a.il b/tests/src/JIT/Regression/VS-ia64-JIT/M00/b99403/cbyte7a.il index e4ada33..2d3b95f 100644 --- a/tests/src/JIT/Regression/VS-ia64-JIT/M00/b99403/cbyte7a.il +++ b/tests/src/JIT/Regression/VS-ia64-JIT/M00/b99403/cbyte7a.il @@ -47,7 +47,6 @@ .method public static int32 Main() cil managed { .entrypoint - .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 2 .locals init (bool V_0, uint8 V_1) diff --git a/tests/src/Loader/classloader/generics/Variance/Regressions/dev10_468712/dev10_468712.il b/tests/src/Loader/classloader/generics/Variance/Regressions/dev10_468712/dev10_468712.il index 122c600..b96f8f0 100644 --- a/tests/src/Loader/classloader/generics/Variance/Regressions/dev10_468712/dev10_468712.il +++ b/tests/src/Loader/classloader/generics/Variance/Regressions/dev10_468712/dev10_468712.il @@ -76,7 +76,6 @@ .method public static int32 Main() cil managed { .entrypoint - .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 1 .locals init ([0] class ConsoleApplicationVB.ICovariant`1 y) IL_0000: nop diff --git a/tests/src/Loader/classloader/regressions/91888/pumpFromCctor.cs b/tests/src/Loader/classloader/regressions/91888/pumpFromCctor.cs index 3039771..f1b7f85 100644 --- a/tests/src/Loader/classloader/regressions/91888/pumpFromCctor.cs +++ b/tests/src/Loader/classloader/regressions/91888/pumpFromCctor.cs @@ -41,8 +41,6 @@ class Test // post-finalization work to be done. const int maxIterations = 10; - // STA - [STAThread] static int Main() { MyFinalizeObject mfo; diff --git a/tests/src/baseservices/compilerservices/RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.cs b/tests/src/baseservices/compilerservices/RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.cs index 58cee3c..40b92b7 100644 --- a/tests/src/baseservices/compilerservices/RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.cs +++ b/tests/src/baseservices/compilerservices/RuntimeHelpers/ExecuteCodeWithGuaranteedCleanup.cs @@ -40,7 +40,6 @@ namespace GCD /// /// The main entry point for the application. /// - [STAThread] static int Main(string[] args) { GCD gcd = new GCD(); diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangefloat.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangefloat.cs index 9ffe170..a7ce330 100644 --- a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangefloat.cs +++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangefloat.cs @@ -15,7 +15,6 @@ namespace Exchange /// /// The main entry point for the application. /// - [STAThread] static int Main(string[] args) { int loops = 100; diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeintptr.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeintptr.cs index 9010b3e..572435c 100644 --- a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeintptr.cs +++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeintptr.cs @@ -16,7 +16,6 @@ namespace Exchange /// /// The main entry point for the application. /// - [STAThread] static int Main(string[] args) { int rValue = 0; diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeobject.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeobject.cs index f135e15..c645513 100644 --- a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeobject.cs +++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangeobject.cs @@ -16,7 +16,6 @@ namespace Exchange /// /// The main entry point for the application. /// - [STAThread] static int Main(string[] args) { int rValue = 0; diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchangefloat.cs b/tests/src/baseservices/threading/interlocked/exchange/exchangefloat.cs index 0811db9..34bc335 100644 --- a/tests/src/baseservices/threading/interlocked/exchange/exchangefloat.cs +++ b/tests/src/baseservices/threading/interlocked/exchange/exchangefloat.cs @@ -15,7 +15,6 @@ namespace Exchange /// /// The main entry point for the application. /// - [STAThread] static int Main(string[] args) { int rValue = 0; diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchangeobject.cs b/tests/src/baseservices/threading/interlocked/exchange/exchangeobject.cs index 09fa32a..76da18a 100644 --- a/tests/src/baseservices/threading/interlocked/exchange/exchangeobject.cs +++ b/tests/src/baseservices/threading/interlocked/exchange/exchangeobject.cs @@ -15,7 +15,6 @@ namespace InteropTests /// /// The main entry point for the application. /// - [STAThread] static int Main(string[] args) { int rValue = 0; -- 2.7.4