From: Marek Safar Date: Fri, 6 Nov 2020 22:28:06 +0000 (+0100) Subject: Match CoreCLR behaviour on thread start failure (#44124) X-Git-Tag: submit/tizen/20210909.063632~4726 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c15cb701ab14448294b38c6e3e78083271ea4fb9;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Match CoreCLR behaviour on thread start failure (#44124) Co-authored-by: Aleksey Kliger (λgeek) --- diff --git a/src/mono/mono/metadata/threads.c b/src/mono/mono/metadata/threads.c index 5be659c..30d2b07 100644 --- a/src/mono/mono/metadata/threads.c +++ b/src/mono/mono/metadata/threads.c @@ -1321,6 +1321,29 @@ start_wrapper (gpointer data) g_assert_not_reached (); } +static void +throw_thread_start_exception (guint32 error_code, MonoError *error) +{ + ERROR_DECL (method_error); + + MONO_STATIC_POINTER_INIT (MonoMethod, throw) + + throw = mono_class_get_method_from_name_checked (mono_defaults.thread_class, "ThrowThreadStartException", 1, 0, method_error); + mono_error_assert_ok (method_error); + + MONO_STATIC_POINTER_INIT_END (MonoMethod, throw) + g_assert (throw); + + char *msg = g_strdup_printf ("0x%x", error_code); + MonoException *ex = mono_get_exception_execution_engine (msg); + g_free (msg); + + gpointer args [1]; + args [0] = ex; + + mono_runtime_invoke_checked (throw, NULL, args, error); +} + /* * create_thread: * @@ -1403,7 +1426,12 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, MonoObject *sta mono_threads_lock (); mono_g_hash_table_remove (threads_starting_up, thread); mono_threads_unlock (); + +#ifdef ENABLE_NETCORE + throw_thread_start_exception (mono_w32error_get_last(), error); +#else mono_error_set_execution_engine (error, "Couldn't create thread. Error 0x%x", mono_w32error_get_last()); +#endif /* ref is not going to be decremented in start_wrapper_internal */ mono_atomic_dec_i32 (&start_info->ref); ret = FALSE; diff --git a/src/mono/netcore/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.xml b/src/mono/netcore/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.xml index 31c5d35..0732f1f 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.xml +++ b/src/mono/netcore/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.xml @@ -692,10 +692,5 @@ - - - - - diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs index 3783134..0cc8310 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs @@ -289,7 +289,11 @@ namespace System.Threading } } + // Called from the runtime + internal static void ThrowThreadStartException(Exception ex) => throw new ThreadStartException(ex); + [DynamicDependency(nameof(StartCallback))] + [DynamicDependency(nameof(ThrowThreadStartException))] [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern void StartInternal(Thread runtime_thread); #endif