Skip to content

Commit

Permalink
Remove unused JL_HAVE_SIGALTSTACK code (JuliaLang#54568)
Browse files Browse the repository at this point in the history
Nothing is ever activating this, and it probably hasn't been tested in a
while.

As far as I can tell, this code path was added by @vtjnash in
082d7d2

I have no particular beef with this code other than "it complicates the
thread / task logic, so dealing with this requires understanding one
more moving part, removing it makes it simpler". If it is decided that
this code should rather be kept, "just in case" (which, though), that's
equally fine by me. Thought perhaps a comment could be added explaining
the motivation for keeping it even thought it is currently always
disabled?
  • Loading branch information
fingolfin authored Jun 12, 2024
1 parent dfb2fd9 commit ee542b6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 99 deletions.
6 changes: 2 additions & 4 deletions src/julia_threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ JL_DLLEXPORT int8_t jl_threadpoolid(int16_t tid) JL_NOTSAFEPOINT;
// JL_HAVE_ASM && JL_HAVE_UNW_CONTEXT -- libunwind-based
// JL_HAVE_UNW_CONTEXT -- libunwind-based
// JL_HAVE_UCONTEXT -- posix standard API, requires syscall for resume
// JL_HAVE_SIGALTSTACK -- requires several syscall for start, setjmp for resume

#ifdef _OS_WINDOWS_
#define JL_HAVE_UCONTEXT
Expand All @@ -53,8 +52,7 @@ typedef struct {
} jl_stack_context_t;
#if !defined(JL_HAVE_UCONTEXT) && \
!defined(JL_HAVE_ASM) && \
!defined(JL_HAVE_UNW_CONTEXT) && \
!defined(JL_HAVE_SIGALTSTACK)
!defined(JL_HAVE_UNW_CONTEXT)
#if (defined(_CPU_X86_64_) || defined(_CPU_X86_) || defined(_CPU_AARCH64_) || \
defined(_CPU_ARM_) || defined(_CPU_PPC64_))
#define JL_HAVE_ASM
Expand All @@ -70,7 +68,7 @@ typedef struct {
#endif
#endif

#if (!defined(JL_HAVE_UNW_CONTEXT) && defined(JL_HAVE_ASM)) || defined(JL_HAVE_SIGALTSTACK)
#if !defined(JL_HAVE_UNW_CONTEXT) && defined(JL_HAVE_ASM)
typedef jl_stack_context_t _jl_ucontext_t;
#endif
#pragma GCC visibility push(default)
Expand Down
2 changes: 0 additions & 2 deletions src/stackwalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,6 @@ static void jl_rec_backtrace(jl_task_t *t) JL_NOTSAFEPOINT
#pragma message("jl_rec_backtrace not defined for ASM/SETJMP on unknown system")
(void)c;
#endif
#elif defined(JL_HAVE_SIGALTSTACK)
#pragma message("jl_rec_backtrace not defined for SIGALTSTACK")
#else
#pragma message("jl_rec_backtrace not defined for unknown task system")
#endif
Expand Down
94 changes: 1 addition & 93 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ JL_NO_ASAN static void restore_stack2(jl_task_t *t, jl_ptls_t ptls, jl_task_t *l
return;
if (r != 0 || returns != 1)
abort();
#elif defined(JL_HAVE_ASM) || defined(JL_HAVE_SIGALTSTACK) || defined(_OS_WINDOWS_)
#elif defined(JL_HAVE_ASM) || defined(_OS_WINDOWS_)
if (jl_setjmp(lastt->ctx.copy_ctx.uc_mcontext, 0))
return;
#else
Expand Down Expand Up @@ -1510,98 +1510,6 @@ JL_NO_ASAN static void jl_start_fiber_set(jl_ucontext_t *t)
}
#endif

#if defined(JL_HAVE_SIGALTSTACK)
#if defined(_COMPILER_TSAN_ENABLED_)
#error TSAN support not currently implemented for this tasking model
#endif

static void start_basefiber(int sig)
{
jl_ptls_t ptls = jl_current_task->ptls;
if (jl_setjmp(ptls->base_ctx.uc_mcontext, 0))
start_task(); // sanitizer_finish_switch_fiber is part of start_task
}
static char *jl_alloc_fiber(_jl_ucontext_t *t, size_t *ssize, jl_task_t *owner)
{
stack_t uc_stack, osigstk;
struct sigaction sa, osa;
sigset_t set, oset;
void *stk = jl_malloc_stack(ssize, owner);
if (stk == NULL)
return NULL;
// setup
jl_ptls_t ptls = jl_current_task->ptls;
_jl_ucontext_t base_ctx;
memcpy(&base_ctx, &ptls->base_ctx, sizeof(base_ctx));
sigfillset(&set);
if (pthread_sigmask(SIG_BLOCK, &set, &oset) != 0) {
jl_free_stack(stk, *ssize);
jl_error("pthread_sigmask failed");
}
uc_stack.ss_sp = stk;
uc_stack.ss_size = *ssize;
uc_stack.ss_flags = 0;
if (sigaltstack(&uc_stack, &osigstk) != 0) {
jl_free_stack(stk, *ssize);
jl_error("sigaltstack failed");
}
memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_handler = start_basefiber;
sa.sa_flags = SA_ONSTACK;
if (sigaction(SIGUSR2, &sa, &osa) != 0) {
jl_free_stack(stk, *ssize);
jl_error("sigaction failed");
}
// emit signal
pthread_kill(pthread_self(), SIGUSR2); // initializes jl_basectx
sigdelset(&set, SIGUSR2);
sigsuspend(&set);
// cleanup
if (sigaction(SIGUSR2, &osa, NULL) != 0) {
jl_free_stack(stk, *ssize);
jl_error("sigaction failed");
}
if (osigstk.ss_size < MINSTKSZ && (osigstk.ss_flags | SS_DISABLE))
osigstk.ss_size = MINSTKSZ;
if (sigaltstack(&osigstk, NULL) != 0) {
jl_free_stack(stk, *ssize);
jl_error("sigaltstack failed");
}
if (pthread_sigmask(SIG_SETMASK, &oset, NULL) != 0) {
jl_free_stack(stk, *ssize);
jl_error("pthread_sigmask failed");
}
if (&ptls->base_ctx != t) {
memcpy(&t, &ptls->base_ctx, sizeof(base_ctx));
memcpy(&ptls->base_ctx, &base_ctx, sizeof(base_ctx)); // restore COPY_STACKS context
}
return (char*)stk;
}
static void jl_start_fiber_set(jl_ucontext_t *t) {
jl_longjmp(t->ctx.uc_mcontext, 1); // (doesn't return)
}
static void jl_start_fiber_swap(jl_ucontext_t *lastt, jl_ucontext_t *t)
{
assert(lastt);
if (lastt && jl_setjmp(lastt->ctx.uc_mcontext, 0))
return;
tsan_switch_to_ctx(t);
jl_start_fiber_set(t);
}
static void jl_swap_fiber(jl_ucontext_t *lastt, jl_ucontext_t *t)
{
if (jl_setjmp(lastt->ctx.uc_mcontext, 0))
return;
tsan_switch_to_ctx(t);
jl_start_fiber_set(t); // doesn't return
}
static void jl_set_fiber(jl_ucontext_t *t)
{
jl_longjmp(t->ctx.uc_mcontext, 1);
}
#endif

// Initialize a root task using the given stack.
jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi)
{
Expand Down

0 comments on commit ee542b6

Please sign in to comment.