Skip to content

Commit 279f0a2

Browse files
committed
avoid running finish_task inside of throw_internal
if throw_internal is running from the segv_handler, there might not be enough stack to run arbitrary functions this change, therefore, makes stack overflow in tasks more reliable
1 parent 4f063d8 commit 279f0a2

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/task.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,16 @@ static void NOINLINE NORETURN start_task()
238238
{
239239
// this runs the first time we switch to a task
240240
jl_task_t *t = jl_current_task;
241+
jl_value_t *res;
241242
throw_if_exception_set(t);
242-
jl_value_t *res = jl_apply(t->start, NULL, 0);
243+
JL_TRY {
244+
res = jl_apply(t->start, NULL, 0);
245+
}
246+
JL_CATCH {
247+
res = jl_exception_in_transit;
248+
t->exception = res;
249+
jl_gc_wb(t, res);
250+
}
243251
finish_task(t, res);
244252
abort();
245253
}
@@ -668,17 +676,11 @@ void NORETURN throw_internal(jl_value_t *e)
668676
jl_longjmp(jl_current_task->eh->eh_ctx, 1);
669677
}
670678
else {
671-
if (jl_current_task == jl_root_task) {
672-
jl_printf(JL_STDERR, "fatal: error thrown and no exception handler available.\n");
673-
jl_static_show(JL_STDERR, e);
674-
jl_printf(JL_STDERR, "\n");
675-
jlbacktrace();
676-
jl_exit(1);
677-
}
678-
jl_current_task->exception = e;
679-
jl_gc_wb(jl_current_task, e);
680-
finish_task(jl_current_task, e);
681-
assert(0);
679+
jl_printf(JL_STDERR, "fatal: error thrown and no exception handler available.\n");
680+
jl_static_show(JL_STDERR, e);
681+
jl_printf(JL_STDERR, "\n");
682+
jlbacktrace();
683+
jl_exit(1);
682684
}
683685
assert(0);
684686
}

0 commit comments

Comments
 (0)