1 | #include "SignalTranslator.h" |
---|
2 | |
---|
3 | namespace UnitTest { |
---|
4 | |
---|
5 | sigjmp_buf* SignalTranslator::s_jumpTarget = 0; |
---|
6 | |
---|
7 | namespace { |
---|
8 | |
---|
9 | void SignalHandler ( int sig ) { |
---|
10 | siglongjmp ( *SignalTranslator::s_jumpTarget, sig ); |
---|
11 | } |
---|
12 | |
---|
13 | } |
---|
14 | |
---|
15 | |
---|
16 | SignalTranslator::SignalTranslator() { |
---|
17 | m_oldJumpTarget = s_jumpTarget; |
---|
18 | s_jumpTarget = &m_currentJumpTarget; |
---|
19 | |
---|
20 | struct sigaction action; |
---|
21 | action.sa_flags = 0; |
---|
22 | action.sa_handler = SignalHandler; |
---|
23 | sigemptyset ( &action.sa_mask ); |
---|
24 | |
---|
25 | sigaction ( SIGSEGV, &action, &m_old_SIGSEGV_action ); |
---|
26 | sigaction ( SIGFPE , &action, &m_old_SIGFPE_action ); |
---|
27 | sigaction ( SIGTRAP, &action, &m_old_SIGTRAP_action ); |
---|
28 | sigaction ( SIGBUS , &action, &m_old_SIGBUS_action ); |
---|
29 | sigaction ( SIGILL , &action, &m_old_SIGBUS_action ); |
---|
30 | } |
---|
31 | |
---|
32 | SignalTranslator::~SignalTranslator() { |
---|
33 | sigaction ( SIGILL , &m_old_SIGBUS_action , 0 ); |
---|
34 | sigaction ( SIGBUS , &m_old_SIGBUS_action , 0 ); |
---|
35 | sigaction ( SIGTRAP, &m_old_SIGTRAP_action, 0 ); |
---|
36 | sigaction ( SIGFPE , &m_old_SIGFPE_action , 0 ); |
---|
37 | sigaction ( SIGSEGV, &m_old_SIGSEGV_action, 0 ); |
---|
38 | |
---|
39 | s_jumpTarget = m_oldJumpTarget; |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | } |
---|