Skip to content

Commit 58637d0

Browse files
alexanderkyteluhenry
authored andcommitted
[runtime] Gracefully handle crashes before mono-state dependencies initialized (mono#8842)
1 parent c22f532 commit 58637d0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mono/metadata/threads.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,6 +3638,10 @@ collect_threads (MonoInternalThread **thread_array, int max_threads)
36383638
{
36393639
CollectThreadsUserData ud;
36403640

3641+
mono_memory_barrier ();
3642+
if (!threads)
3643+
return 0;
3644+
36413645
memset (&ud, 0, sizeof (ud));
36423646
/* This array contains refs, but its on the stack, so its ok */
36433647
ud.threads = thread_array;
@@ -5618,6 +5622,9 @@ mono_threads_summarize (MonoContext *ctx, gchar **out)
56185622
MonoInternalThread *thread_array [128];
56195623
int nthreads = collect_threads (thread_array, 128);
56205624

5625+
if (nthreads == 0)
5626+
MOSTLY_ASYNC_SAFE_PRINTF("No managed threads detected, error occured before thread init\n");
5627+
56215628
sigset_t sigset, old_sigset;
56225629
sigemptyset(&sigset);
56235630
sigaddset(&sigset, SIGTERM);

0 commit comments

Comments
 (0)