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

fix malloc-stack CI failure #49082

Merged
merged 1 commit into from
Mar 24, 2023
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
4 changes: 3 additions & 1 deletion src/gc-stacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ JL_DLLEXPORT void *jl_malloc_stack(size_t *bufsz, jl_task_t *owner) JL_NOTSAFEPO
ssize = LLT_ALIGN(ssize, jl_page_size);
}
if (stk == NULL) {
if (jl_atomic_load_relaxed(&num_stack_mappings) >= MAX_STACK_MAPPINGS)
if (jl_atomic_load_relaxed(&num_stack_mappings) >= MAX_STACK_MAPPINGS) {
// we accept that this can go over by as much as nthreads since it's not a CAS
errno = ENOMEM;
return NULL;
}
// TODO: allocate blocks of stacks? but need to mprotect individually anyways
stk = malloc_stack(ssize);
if (stk == MAP_FAILED)
Expand Down
2 changes: 1 addition & 1 deletion src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ static void allocate_segv_handler(void)
static void *alloc_sigstack(size_t *ssize)
{
void *stk = jl_malloc_stack(ssize, NULL);
if (stk == MAP_FAILED)
if (stk == NULL)
jl_errorf("fatal error allocating signal stack: mmap: %s", strerror(errno));
return stk;
}
Expand Down
18 changes: 11 additions & 7 deletions src/signals-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,15 @@ void jl_install_default_signal_handlers(void)

void jl_install_thread_signal_handler(jl_ptls_t ptls)
{
size_t ssize = sig_stack_size;
void *stk = jl_malloc_stack(&ssize, NULL);
collect_backtrace_fiber.uc_stack.ss_sp = (void*)stk;
collect_backtrace_fiber.uc_stack.ss_size = ssize;
jl_makecontext(&collect_backtrace_fiber, start_backtrace_fiber);
uv_mutex_init(&backtrace_lock);
have_backtrace_fiber = 1;
if (!have_backtrace_fiber) {
size_t ssize = sig_stack_size;
void *stk = jl_malloc_stack(&ssize, NULL);
if (stk == NULL)
jl_errorf("fatal error allocating signal stack: mmap: %s", strerror(errno));
collect_backtrace_fiber.uc_stack.ss_sp = (void*)stk;
collect_backtrace_fiber.uc_stack.ss_size = ssize;
jl_makecontext(&collect_backtrace_fiber, start_backtrace_fiber);
uv_mutex_init(&backtrace_lock);
have_backtrace_fiber = 1;
}
}
13 changes: 8 additions & 5 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -1552,12 +1552,15 @@ jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi)
#endif
if (jl_setjmp(ptls->copy_stack_ctx.uc_mcontext, 0))
start_task(); // sanitizer_finish_switch_fiber is part of start_task
return ct;
}
ssize = JL_STACK_SIZE;
char *stkbuf = jl_alloc_fiber(&ptls->base_ctx, &ssize, NULL);
ptls->stackbase = stkbuf + ssize;
ptls->stacksize = ssize;
else {
ssize = JL_STACK_SIZE;
char *stkbuf = jl_alloc_fiber(&ptls->base_ctx, &ssize, NULL);
if (stkbuf != NULL) {
ptls->stackbase = stkbuf + ssize;
ptls->stacksize = ssize;
}
}
#endif

if (jl_options.handle_signals == JL_OPTIONS_HANDLE_SIGNALS_ON)
Expand Down