Skip to content

Commit

Permalink
fix #9544. call jl_throw directly in JL_SIGATOMIC_END rather than ind…
Browse files Browse the repository at this point in the history
…irectly through raise
  • Loading branch information
vtjnash committed Jan 1, 2015
1 parent 88783ec commit 40c2225
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ class JuliaJITEventListener: public JITEventListener
StringRef sName;
#endif
#ifdef _OS_WINDOWS_
uint64_t SectionAddr;
uint64_t SectionSize;
uint64_t SectionAddr = 0;
uint64_t SectionSize = 0;
uint64_t SectionAddrCheck = 0; // assert that all of the Sections are at the same location
#endif

Expand Down
78 changes: 64 additions & 14 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,55 @@ static void jl_find_stack_bottom(void)
}

#ifdef _OS_WINDOWS_
void __cdecl fpe_handler(int arg, int num)
static char *strsignal(int sig)
{
(void)arg;
fpreset();
signal(SIGFPE, (void (__cdecl *)(int))fpe_handler);
switch(num) {
case _FPE_INVALID:
case _FPE_OVERFLOW:
case _FPE_UNDERFLOW:
default:
jl_errorf("Unexpected FPE Error 0x%X", num);
switch (sig) {
case SIGINT: return "SIGINT"; break;
case SIGILL: return "SIGILL"; break;
case SIGABRT_COMPAT: return "SIGABRT_COMPAT"; break;
case SIGFPE: return "SIGFPE"; break;
case SIGSEGV: return "SIGSEGV"; break;
case SIGTERM: return "SIGTERM"; break;
case SIGBREAK: return "SIGBREAK"; break;
case SIGABRT: return "SIGABRT"; break;
}
return "?";
}

void __cdecl crt_sig_handler(int sig, int num)
{
switch (sig) {
case SIGFPE:
fpreset();
signal(SIGFPE, (void (__cdecl *)(int))crt_sig_handler);
switch(num) {
case _FPE_INVALID:
case _FPE_OVERFLOW:
case _FPE_UNDERFLOW:
default:
jl_errorf("Unexpected FPE Error 0x%X", num);
break;
case _FPE_ZERODIVIDE:
jl_throw(jl_diverror_exception);
break;
}
break;
case _FPE_ZERODIVIDE:
jl_throw(jl_diverror_exception);
case SIGINT:
signal(SIGINT, (void (__cdecl *)(int))crt_sig_handler);
if (exit_on_sigint) jl_exit(0);
if (jl_defer_signal) {
jl_signal_pending = sig;
}
else {
jl_signal_pending = 0;
jl_throw(jl_interrupt_exception);
}
break;
default: // SIGSEGV, (SSIGTERM, IGILL)
ios_printf(ios_stderr,"\nsignal (%d): %s\n", sig, strsignal(sig));
bt_size = rec_backtrace(bt_data, MAX_BT_SIZE);
jlbacktrace();
raise(sig);
}
}
#else
Expand Down Expand Up @@ -260,7 +294,7 @@ static BOOL WINAPI sigint_handler(DWORD wsig) //This needs winapi types to guara
{
if (exit_on_sigint) jl_exit(0);
int sig;
//windows signals use different numbers from unix
//windows signals use different numbers from unix (raise)
switch(wsig) {
case CTRL_C_EVENT: sig = SIGINT; break;
//case CTRL_BREAK_EVENT: sig = SIGTERM; break;
Expand Down Expand Up @@ -1114,10 +1148,26 @@ void _julia_init(JL_IMAGE_SEARCH rel)
jl_exit(1);
}
#else // defined(_OS_WINDOWS_)
if (signal(SIGFPE, (void (__cdecl *)(int))fpe_handler) == SIG_ERR) {
if (signal(SIGFPE, (void (__cdecl *)(int))crt_sig_handler) == SIG_ERR) {
JL_PRINTF(JL_STDERR, "fatal error: Couldn't set SIGFPE\n");
jl_exit(1);
}
if (signal(SIGILL, (void (__cdecl *)(int))crt_sig_handler) == SIG_ERR) {
JL_PRINTF(JL_STDERR, "fatal error: Couldn't set SIGILL\n");
jl_exit(1);
}
if (signal(SIGINT, (void (__cdecl *)(int))crt_sig_handler) == SIG_ERR) {
JL_PRINTF(JL_STDERR, "fatal error: Couldn't set SIGINT\n");
jl_exit(1);
}
if (signal(SIGSEGV, (void (__cdecl *)(int))crt_sig_handler) == SIG_ERR) {
JL_PRINTF(JL_STDERR, "fatal error: Couldn't set SIGSEGV\n");
jl_exit(1);
}
if (signal(SIGTERM, (void (__cdecl *)(int))crt_sig_handler) == SIG_ERR) {
JL_PRINTF(JL_STDERR, "fatal error: Couldn't set SIGTERM\n");
jl_exit(1);
}
SetUnhandledExceptionFilter(exception_handler);
#endif

Expand Down
6 changes: 4 additions & 2 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1107,8 +1107,10 @@ DLLEXPORT extern volatile sig_atomic_t jl_defer_signal;
#define JL_SIGATOMIC_END() \
do { \
jl_defer_signal--; \
if (jl_defer_signal == 0 && jl_signal_pending != 0) \
raise(jl_signal_pending); \
if (jl_defer_signal == 0 && jl_signal_pending != 0) { \
jl_signal_pending = 0; \
jl_throw(jl_interrupt_exception); \
} \
} while(0)

DLLEXPORT void restore_signals(void);
Expand Down
3 changes: 3 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2020,3 +2020,6 @@ let x = [1,2,3]
@test ccall(:jl_new_bits, Any, (Any,Ptr{Void},), (Int,Int,Int), x) === (1,2,3)
@test (ccall(:jl_new_bits, Any, (Any,Ptr{Void},), (Int16,(Void,),Int8,(),Int,Void,Int), x)::Tuple)[[2,4,5,6,7]] === ((nothing,),(),2,nothing,3)
end

# sig 2 is SIGINT per the POSIX.1-1990 standard
@test_throws InterruptException ccall(:raise, Void, (Cint,), 2)

10 comments on commit 40c2225

@vtjnash
Copy link
Member Author

@vtjnash vtjnash commented on 40c2225 Jan 1, 2015

Choose a reason for hiding this comment

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

@tkelman
Copy link
Contributor

@tkelman tkelman commented on 40c2225 Jan 2, 2015

Choose a reason for hiding this comment

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

actually it might be this one since this was the first failure on appveyor https://ci.appveyor.com/project/StefanKarpinski/julia/build/1.0.1013/job/acm5hmdhiwwnnn7d

@vtjnash
Copy link
Member Author

@vtjnash vtjnash commented on 40c2225 Jan 2, 2015

Choose a reason for hiding this comment

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

perhaps just remove the test for win32? i'll be awhile before my (just started) win32 build is finished

@tkelman
Copy link
Contributor

@tkelman tkelman commented on 40c2225 Jan 2, 2015

Choose a reason for hiding this comment

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

I'm bisecting now, will let you know / open an issue when I have something conclusive.

@tkelman
Copy link
Contributor

@tkelman tkelman commented on 40c2225 Jan 2, 2015

Choose a reason for hiding this comment

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

yeppers, bisect consistent with appveyor

     * linalg/givens
     * core

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x6372ce03 -- jl_init_codegen at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_init_codegen at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_init_codegen at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_value_to_pointer at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_value_to_pointer at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_compile at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_trampoline at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_gf_invoke at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_f_invoke at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
anonymous at test.jl:83
do_test at test.jl:47
jl_apply_generic at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_interpret_toplevel_expr at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_interpret_toplevel_thunk_with at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_eval_with_compiler_p at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_parse_eval_all at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_load_ at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
runtests at C:\cygwin64\home\MPC_CAR\julia32\test\testdefs.jl:5
jl_apply_generic at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
vsnwprintf at C:\Windows\SysWOW64\ntdll.dll (unknown line)
jl_f_apply at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
anonymous at multi.jl:642
run_work_thunk at multi.jl:603
jl_apply_generic at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_f_apply at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
remotecall_fetch at multi.jl:691
jl_apply_generic at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
jl_f_apply at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
anonymous at task.jl:1614
jl_unprotect_stack at C:\cygwin64\home\MPC_CAR\julia32\usr\bin\libjulia.dll (unknown line)
unknown function (ip: 4202755)
unknown function (ip: 4202755)
Makefile:9: recipe for target 'all' failed
make[1]: *** [all] Error 1
Makefile:441: recipe for target 'testall1' failed
make: *** [testall1] Error 2

MPC_CAR@MPCCAR-Thinkpad ~/julia32
$ git bisect bad
40c222593f3df403133be7340dd0fc1d7f13ca63 is the first bad commit
commit 40c222593f3df403133be7340dd0fc1d7f13ca63
Author: Jameson Nash <vtjnash@gmail.com>
Date:   Thu Jan 1 14:25:49 2015 -0800

    fix #9544. call jl_throw directly in JL_SIGATOMIC_END rather than indirectly through raise

:040000 040000 2302d36106a9ced7a681135671a682e85381143a b00d820f214ab9c5d1b19f22541288b1f66e4359 M      src
:040000 040000 f5c49b05b461d8595b95147b28593717a1aba9d8 4ef87af5d5e31808be1cfd6377132c0f1a7390c2 M      test

@tkelman
Copy link
Contributor

@tkelman tkelman commented on 40c2225 Jan 2, 2015

Choose a reason for hiding this comment

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

gdb not telling me much

* core[New Thread 387144.0x5df5c]

gdb: unknown target exception 0xc0000008 at 0x774d12c7

Program received signal ?, Unknown signal.
0x0008d8d8 in ?? ()
(gdb) bt
#0  0x0008d8d8 in ?? ()

@vtjnash
Copy link
Member Author

@vtjnash vtjnash commented on 40c2225 Jan 2, 2015

Choose a reason for hiding this comment

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

this is strange...

the bigger question should actually be why this is only failing (correctly) on win32, and not all platforms.

corrected in 84464eb

@tkelman
Copy link
Contributor

@tkelman tkelman commented on 40c2225 Jan 2, 2015

Choose a reason for hiding this comment

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

to be squashed with 84464eb and 1f11824 when backported

@tkelman
Copy link
Contributor

@tkelman tkelman commented on 40c2225 Jan 3, 2015

Choose a reason for hiding this comment

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

I'm not sure whether it's still this commit, but we're getting what look like codegen segfaults intermittently on both Travis and AppVeyor.

@timholy
Copy link
Member

@timholy timholy commented on 40c2225 Jan 3, 2015

Choose a reason for hiding this comment

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

Cross-referencing #9570

Please sign in to comment.