Skip to content

Commit

Permalink
Fix notsafepoint marking on jl_sigint_safepoint (JuliaLang#37172)
Browse files Browse the repository at this point in the history
Despite (or as stated in) the name, it is a safepoint.
A GC on another thread will always run no matter what kind of safepoint get triggered.
  • Loading branch information
yuyichao authored Aug 24, 2020
1 parent a60b328 commit 7695e37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ static jl_ast_context_t *jl_ast_ctx_enter(void) JL_GLOBALLY_ROOTED JL_NOTSAFEPOI
return ctx;
}

static void jl_ast_ctx_leave(jl_ast_context_t *ctx) JL_NOTSAFEPOINT
static void jl_ast_ctx_leave(jl_ast_context_t *ctx)
{
JL_SIGATOMIC_END();
if (--ctx->ref)
Expand Down Expand Up @@ -850,8 +850,10 @@ jl_value_t *jl_call_scm_on_ast(const char *funcname, jl_value_t *expr, jl_module
value_t arg = julia_to_scm(fl_ctx, expr);
value_t e = fl_applyn(fl_ctx, 1, symbol_value(symbol(fl_ctx, funcname)), arg);
jl_value_t *result = scm_to_julia(fl_ctx, e, inmodule);
JL_GC_PUSH1(&result);
JL_AST_PRESERVE_POP(ctx, old_roots);
jl_ast_ctx_leave(ctx);
JL_GC_POP();
return result;
}

Expand All @@ -865,8 +867,10 @@ jl_value_t *jl_call_scm_on_ast_and_loc(const char *funcname, jl_value_t *expr, j
value_t e = fl_applyn(fl_ctx, 3, symbol_value(symbol(fl_ctx, funcname)), arg,
symbol(fl_ctx, file), fixnum(line));
jl_value_t *result = scm_to_julia(fl_ctx, e, inmodule);
JL_GC_PUSH1(&result);
JL_AST_PRESERVE_POP(ctx, old_roots);
jl_ast_ctx_leave(ctx);
JL_GC_POP();
return result;
}

Expand Down
10 changes: 5 additions & 5 deletions src/julia_threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ extern "C" {
JL_DLLEXPORT void (jl_cpu_pause)(void);
JL_DLLEXPORT void (jl_cpu_wake)(void);

#ifdef __clang_analyzer__
// Note that the sigint safepoint can also trigger GC, albeit less likely
void jl_gc_safepoint_(jl_ptls_t tls);
void jl_sigint_safepoint(jl_ptls_t tls);
#else
// gc safepoint and gc states
// This triggers a SegFault when we are in GC
// Assign it to a variable to make sure the compiler emit the load
Expand All @@ -284,11 +289,6 @@ JL_DLLEXPORT void (jl_cpu_wake)(void);
jl_signal_fence(); \
(void)safepoint_load; \
} while (0)
#ifdef __clang_analyzer__
// This is a sigint safepoint, not a GC safepoint (which
// JL_NOTSAFEPOINT refers to)
void jl_sigint_safepoint(jl_ptls_t tls) JL_NOTSAFEPOINT;
#else
#define jl_sigint_safepoint(ptls) do { \
jl_signal_fence(); \
size_t safepoint_load = ptls->safepoint[-1]; \
Expand Down

0 comments on commit 7695e37

Please sign in to comment.