41 {
42
44 std::signal(SIGSEGV, SIG_DFL);
45 std::signal(SIGBUS, SIG_DFL);
46 std::signal(SIGFPE, SIG_DFL);
48 }};
49 {
50 std::signal(SIGSEGV, &handle_signal);
51 std::signal(SIGBUS, &handle_signal);
52 std::signal(SIGFPE, &handle_signal);
54 sig_handled = 0;
55 std::raise(SIGSEGV);
56 CHECK(sig_handled == 42 + SIGSEGV);
57 sig_handled = 0;
58 std::raise(SIGBUS);
59 CHECK(sig_handled == 42 + SIGBUS);
60 sig_handled = 0;
61 std::raise(SIGFPE);
62 CHECK(sig_handled == 42 + SIGFPE);
63 }
64 {
65 struct sigaction sa;
66 sa.sa_sigaction = &handle_signal_sigaction;
67 sigemptyset(&sa.sa_mask);
68 sa.sa_flags = SA_NODEFER | SA_SIGINFO;
69 sigaction(SIGSEGV, &sa, nullptr);
70 sigaction(SIGBUS, &sa, nullptr);
71 sigaction(SIGFPE, &sa, nullptr);
73 sig_handled = 0;
74 std::raise(SIGSEGV);
75 CHECK(sig_handled == 142 + SIGSEGV);
76 sig_handled = 0;
77 std::raise(SIGBUS);
78 CHECK(sig_handled == 142 + SIGBUS);
79 sig_handled = 0;
80 std::raise(SIGFPE);
81 CHECK(sig_handled == 142 + SIGFPE);
82 }
83}
void setup_signal_handler_impl()