Skip to content

Commit ee542b6

Browse files
authored
Remove unused JL_HAVE_SIGALTSTACK code (#54568)
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?
1 parent dfb2fd9 commit ee542b6

File tree

3 files changed

+3
-99
lines changed

3 files changed

+3
-99
lines changed

src/julia_threads.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ JL_DLLEXPORT int8_t jl_threadpoolid(int16_t tid) JL_NOTSAFEPOINT;
3131
// JL_HAVE_ASM && JL_HAVE_UNW_CONTEXT -- libunwind-based
3232
// JL_HAVE_UNW_CONTEXT -- libunwind-based
3333
// JL_HAVE_UCONTEXT -- posix standard API, requires syscall for resume
34-
// JL_HAVE_SIGALTSTACK -- requires several syscall for start, setjmp for resume
3534

3635
#ifdef _OS_WINDOWS_
3736
#define JL_HAVE_UCONTEXT
@@ -53,8 +52,7 @@ typedef struct {
5352
} jl_stack_context_t;
5453
#if !defined(JL_HAVE_UCONTEXT) && \
5554
!defined(JL_HAVE_ASM) && \
56-
!defined(JL_HAVE_UNW_CONTEXT) && \
57-
!defined(JL_HAVE_SIGALTSTACK)
55+
!defined(JL_HAVE_UNW_CONTEXT)
5856
#if (defined(_CPU_X86_64_) || defined(_CPU_X86_) || defined(_CPU_AARCH64_) || \
5957
defined(_CPU_ARM_) || defined(_CPU_PPC64_))
6058
#define JL_HAVE_ASM
@@ -70,7 +68,7 @@ typedef struct {
7068
#endif
7169
#endif
7270

73-
#if (!defined(JL_HAVE_UNW_CONTEXT) && defined(JL_HAVE_ASM)) || defined(JL_HAVE_SIGALTSTACK)
71+
#if !defined(JL_HAVE_UNW_CONTEXT) && defined(JL_HAVE_ASM)
7472
typedef jl_stack_context_t _jl_ucontext_t;
7573
#endif
7674
#pragma GCC visibility push(default)

src/stackwalk.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,8 +1151,6 @@ static void jl_rec_backtrace(jl_task_t *t) JL_NOTSAFEPOINT
11511151
#pragma message("jl_rec_backtrace not defined for ASM/SETJMP on unknown system")
11521152
(void)c;
11531153
#endif
1154-
#elif defined(JL_HAVE_SIGALTSTACK)
1155-
#pragma message("jl_rec_backtrace not defined for SIGALTSTACK")
11561154
#else
11571155
#pragma message("jl_rec_backtrace not defined for unknown task system")
11581156
#endif

src/task.c

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ JL_NO_ASAN static void restore_stack2(jl_task_t *t, jl_ptls_t ptls, jl_task_t *l
272272
return;
273273
if (r != 0 || returns != 1)
274274
abort();
275-
#elif defined(JL_HAVE_ASM) || defined(JL_HAVE_SIGALTSTACK) || defined(_OS_WINDOWS_)
275+
#elif defined(JL_HAVE_ASM) || defined(_OS_WINDOWS_)
276276
if (jl_setjmp(lastt->ctx.copy_ctx.uc_mcontext, 0))
277277
return;
278278
#else
@@ -1510,98 +1510,6 @@ JL_NO_ASAN static void jl_start_fiber_set(jl_ucontext_t *t)
15101510
}
15111511
#endif
15121512

1513-
#if defined(JL_HAVE_SIGALTSTACK)
1514-
#if defined(_COMPILER_TSAN_ENABLED_)
1515-
#error TSAN support not currently implemented for this tasking model
1516-
#endif
1517-
1518-
static void start_basefiber(int sig)
1519-
{
1520-
jl_ptls_t ptls = jl_current_task->ptls;
1521-
if (jl_setjmp(ptls->base_ctx.uc_mcontext, 0))
1522-
start_task(); // sanitizer_finish_switch_fiber is part of start_task
1523-
}
1524-
static char *jl_alloc_fiber(_jl_ucontext_t *t, size_t *ssize, jl_task_t *owner)
1525-
{
1526-
stack_t uc_stack, osigstk;
1527-
struct sigaction sa, osa;
1528-
sigset_t set, oset;
1529-
void *stk = jl_malloc_stack(ssize, owner);
1530-
if (stk == NULL)
1531-
return NULL;
1532-
// setup
1533-
jl_ptls_t ptls = jl_current_task->ptls;
1534-
_jl_ucontext_t base_ctx;
1535-
memcpy(&base_ctx, &ptls->base_ctx, sizeof(base_ctx));
1536-
sigfillset(&set);
1537-
if (pthread_sigmask(SIG_BLOCK, &set, &oset) != 0) {
1538-
jl_free_stack(stk, *ssize);
1539-
jl_error("pthread_sigmask failed");
1540-
}
1541-
uc_stack.ss_sp = stk;
1542-
uc_stack.ss_size = *ssize;
1543-
uc_stack.ss_flags = 0;
1544-
if (sigaltstack(&uc_stack, &osigstk) != 0) {
1545-
jl_free_stack(stk, *ssize);
1546-
jl_error("sigaltstack failed");
1547-
}
1548-
memset(&sa, 0, sizeof(sa));
1549-
sigemptyset(&sa.sa_mask);
1550-
sa.sa_handler = start_basefiber;
1551-
sa.sa_flags = SA_ONSTACK;
1552-
if (sigaction(SIGUSR2, &sa, &osa) != 0) {
1553-
jl_free_stack(stk, *ssize);
1554-
jl_error("sigaction failed");
1555-
}
1556-
// emit signal
1557-
pthread_kill(pthread_self(), SIGUSR2); // initializes jl_basectx
1558-
sigdelset(&set, SIGUSR2);
1559-
sigsuspend(&set);
1560-
// cleanup
1561-
if (sigaction(SIGUSR2, &osa, NULL) != 0) {
1562-
jl_free_stack(stk, *ssize);
1563-
jl_error("sigaction failed");
1564-
}
1565-
if (osigstk.ss_size < MINSTKSZ && (osigstk.ss_flags | SS_DISABLE))
1566-
osigstk.ss_size = MINSTKSZ;
1567-
if (sigaltstack(&osigstk, NULL) != 0) {
1568-
jl_free_stack(stk, *ssize);
1569-
jl_error("sigaltstack failed");
1570-
}
1571-
if (pthread_sigmask(SIG_SETMASK, &oset, NULL) != 0) {
1572-
jl_free_stack(stk, *ssize);
1573-
jl_error("pthread_sigmask failed");
1574-
}
1575-
if (&ptls->base_ctx != t) {
1576-
memcpy(&t, &ptls->base_ctx, sizeof(base_ctx));
1577-
memcpy(&ptls->base_ctx, &base_ctx, sizeof(base_ctx)); // restore COPY_STACKS context
1578-
}
1579-
return (char*)stk;
1580-
}
1581-
static void jl_start_fiber_set(jl_ucontext_t *t) {
1582-
jl_longjmp(t->ctx.uc_mcontext, 1); // (doesn't return)
1583-
}
1584-
static void jl_start_fiber_swap(jl_ucontext_t *lastt, jl_ucontext_t *t)
1585-
{
1586-
assert(lastt);
1587-
if (lastt && jl_setjmp(lastt->ctx.uc_mcontext, 0))
1588-
return;
1589-
tsan_switch_to_ctx(t);
1590-
jl_start_fiber_set(t);
1591-
}
1592-
static void jl_swap_fiber(jl_ucontext_t *lastt, jl_ucontext_t *t)
1593-
{
1594-
if (jl_setjmp(lastt->ctx.uc_mcontext, 0))
1595-
return;
1596-
tsan_switch_to_ctx(t);
1597-
jl_start_fiber_set(t); // doesn't return
1598-
}
1599-
static void jl_set_fiber(jl_ucontext_t *t)
1600-
{
1601-
jl_longjmp(t->ctx.uc_mcontext, 1);
1602-
}
1603-
#endif
1604-
16051513
// Initialize a root task using the given stack.
16061514
jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi)
16071515
{

0 commit comments

Comments
 (0)