Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match CoreCLR behaviour on thread start failure #44124

Merged
merged 7 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/mono/mono/metadata/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,5 @@
<!-- marshal-ilgen.c:emit_invoke_call -->
<method signature="System.Void .ctor()" />
</type>

<!-- Used by binary formatter tests -->
<type fullname="System.Threading.ThreadStartException">
marek-safar marked this conversation as resolved.
Show resolved Hide resolved
<method name=".ctor" />
</type>
</assembly>
</linker>
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ internal void StartCallback()
}
}

// 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
Expand Down