Skip to content

Commit

Permalink
Merge pull request #26356 from JuliaLang/jn/bsd-kevent
Browse files Browse the repository at this point in the history
bsd: disable kevent
  • Loading branch information
StefanKarpinski authored Mar 7, 2018
2 parents b1b0149 + c5ba81f commit f3118ce
Showing 1 changed file with 16 additions and 29 deletions.
45 changes: 16 additions & 29 deletions src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#define HAVE_KEVENT
#elif defined(__FreeBSD__) // generic bsd
#define HAVE_ITIMER
#define HAVE_KEVENT
#else // generic linux
#define HAVE_TIMER
#endif
Expand Down Expand Up @@ -81,7 +80,7 @@ static inline __attribute__((unused)) uintptr_t jl_get_rsp_from_ctx(const void *
#endif
}

static void jl_call_in_ctx(jl_ptls_t ptls, void (*fptr)(void), void *_ctx)
static void jl_call_in_ctx(jl_ptls_t ptls, void (*fptr)(void), int sig, void *_ctx)
{
// Modifying the ucontext should work but there is concern that
// sigreturn oriented programming mitigation can work against us
Expand Down Expand Up @@ -154,17 +153,21 @@ static void jl_call_in_ctx(jl_ptls_t ptls, void (*fptr)(void), void *_ctx)
#else
#warning "julia: throw-in-context not supported on this platform"
// TODO Add support for PowerPC(64)?
sigset_t sset;
sigemptyset(&sset);
sigaddset(&sset, sig);
sigprocmask(SIG_UNBLOCK, &sset, NULL);
fptr();
#endif
}

static void jl_throw_in_ctx(jl_ptls_t ptls, jl_value_t *e, void *sigctx)
static void jl_throw_in_ctx(jl_ptls_t ptls, jl_value_t *e, int sig, void *sigctx)
{
if (!ptls->safe_restore)
ptls->bt_size = rec_backtrace_ctx(ptls->bt_data, JL_MAX_BT_SIZE,
jl_to_bt_context(sigctx));
ptls->exception_in_transit = e;
jl_call_in_ctx(ptls, &jl_rethrow, sigctx);
jl_call_in_ctx(ptls, &jl_rethrow, sig, sigctx);
}

static pthread_t signals_thread;
Expand Down Expand Up @@ -200,16 +203,6 @@ static void sigdie_handler(int sig, siginfo_t *info, void *context)
// fall-through return to re-execute faulting statement (but without the error handler)
}

static void jl_unblock_signal(int sig)
{
// Put in a separate function to save some stack space since
// sigset_t can be pretty big.
sigset_t sset;
sigemptyset(&sset);
sigaddset(&sset, sig);
sigprocmask(SIG_UNBLOCK, &sset, NULL);
}

#if defined(HAVE_MACH)
#include <signals-mach.c>
#else
Expand All @@ -233,7 +226,6 @@ static void segv_handler(int sig, siginfo_t *info, void *context)
assert(sig == SIGSEGV || sig == SIGBUS);

if (jl_addr_is_safepoint((uintptr_t)info->si_addr)) {
jl_unblock_signal(sig);
#ifdef JULIA_ENABLE_THREADING
jl_set_gc_and_wait();
// Do not raise sigint on worker thread
Expand All @@ -245,13 +237,12 @@ static void segv_handler(int sig, siginfo_t *info, void *context)
}
else if (jl_safepoint_consume_sigint()) {
jl_clear_force_sigint();
jl_throw_in_ctx(ptls, jl_interrupt_exception, context);
jl_throw_in_ctx(ptls, jl_interrupt_exception, sig, context);
}
return;
}
if (ptls->safe_restore || is_addr_on_stack(ptls, info->si_addr)) { // stack overflow, or restarting jl_
jl_unblock_signal(sig);
jl_throw_in_ctx(ptls, jl_stackovf_exception, context);
jl_throw_in_ctx(ptls, jl_stackovf_exception, sig, context);
}
else if (jl_is_on_sigstack(ptls, info->si_addr, context)) {
// This mainly happens when one of the finalizers during final cleanup
Expand All @@ -263,13 +254,11 @@ static void segv_handler(int sig, siginfo_t *info, void *context)
_exit(sig + 128);
}
else if (sig == SIGSEGV && info->si_code == SEGV_ACCERR) { // writing to read-only memory (e.g., mmap)
jl_unblock_signal(sig);
jl_throw_in_ctx(ptls, jl_readonlymemory_exception, context);
jl_throw_in_ctx(ptls, jl_readonlymemory_exception, sig, context);
}
else {
#ifdef SEGV_EXCEPTION
jl_unblock_signal(sig);
jl_throw_in_ctx(ptls, jl_segv_exception, context);
jl_throw_in_ctx(ptls, jl_segv_exception, sig, context);
#else
sigdie_handler(sig, info, context);
#endif
Expand Down Expand Up @@ -386,20 +375,18 @@ void usr2_handler(int sig, siginfo_t *info, void *ctx)
else
#endif
if (request == 2) {
jl_unblock_signal(sig);
int force = jl_check_force_sigint();
if (force || (!ptls->defer_signal && ptls->io_wait)) {
jl_safepoint_consume_sigint();
if (force)
jl_safe_printf("WARNING: Force throwing a SIGINT\n");
// Force a throw
jl_clear_force_sigint();
jl_throw_in_ctx(ptls, jl_interrupt_exception, ctx);
jl_throw_in_ctx(ptls, jl_interrupt_exception, sig, ctx);
}
}
else if (request == 3) {
jl_unblock_signal(sig);
jl_call_in_ctx(ptls, jl_exit_thread0_cb, ctx);
jl_call_in_ctx(ptls, jl_exit_thread0_cb, sig, ctx);
}
}

Expand Down Expand Up @@ -585,7 +572,7 @@ static void *signal_listener(void *arg)
errno = 0;
#ifdef HAVE_KEVENT
if (sigqueue != -1) {
int nevents = kevent(sigqueue, NULL, 0, &ev, 1, NULL);
int nevents = kevent(sigqueue, NULL, 0, &ev, 1, NULL);
if (nevents == -1) {
if (errno == EINTR)
continue;
Expand Down Expand Up @@ -622,6 +609,7 @@ static void *signal_listener(void *arg)
profile = (sig == SIGUSR1);
# endif
#endif

if (sig == SIGINT) {
if (jl_ignore_sigint()) {
continue;
Expand Down Expand Up @@ -733,8 +721,7 @@ static void fpe_handler(int sig, siginfo_t *info, void *context)
{
(void)info;
jl_ptls_t ptls = jl_get_ptls_states();
jl_unblock_signal(sig);
jl_throw_in_ctx(ptls, jl_diverror_exception, context);
jl_throw_in_ctx(ptls, jl_diverror_exception, sig, context);
}

static void sigint_handler(int sig)
Expand Down

2 comments on commit f3118ce

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.