| |
| |
| |
| |
| |
| |
|
|
| #define _GNU_SOURCE |
| #include <stdbool.h> |
| #include <stddef.h> |
| #include <signal.h> |
|
|
| #include "emscripten_internal.h" |
|
|
| extern struct sigaction __sig_actions[_NSIG]; |
|
|
| bool __sig_is_blocked(int sig); |
|
|
| |
| |
|
|
| void action_abort(int sig) { |
| abort(); |
| } |
|
|
| void action_terminate(int sig) { |
| |
| _emscripten_runtime_keepalive_clear(); |
| |
| _Exit(128 + sig); |
| } |
|
|
| static sighandler_t default_actions[_NSIG] = { |
| [SIGABRT] = action_abort, |
| [SIGALRM] = action_terminate, |
| [SIGBUS] = action_abort, |
| [SIGFPE] = action_abort, |
| [SIGHUP] = action_terminate, |
| [SIGILL] = action_abort, |
| [SIGINT] = action_terminate, |
| [SIGKILL] = action_terminate, |
| [SIGPIPE] = action_terminate, |
| [SIGQUIT] = action_abort, |
| [SIGSEGV] = action_abort, |
| [SIGTERM] = action_terminate, |
| [SIGUSR1] = action_terminate, |
| [SIGUSR2] = action_terminate, |
| [SIGPOLL] = action_terminate, |
| [SIGPROF] = action_terminate, |
| [SIGSYS] = action_abort, |
| [SIGTRAP] = action_abort, |
| [SIGVTALRM] = action_terminate, |
| [SIGXCPU] = action_abort, |
| [SIGXFSZ] = action_abort, |
| }; |
|
|
| int raise(int sig) { |
| if (__sig_is_blocked(sig)) { |
| sigaddset(&__sig_pending, sig); |
| return 0; |
| } |
| if (__sig_actions[sig].sa_flags & SA_SIGINFO) { |
| siginfo_t t = {0}; |
| __sig_actions[sig].sa_sigaction(sig, &t, NULL); |
| } else { |
| sighandler_t handler = __sig_actions[sig].sa_handler; |
| if (handler == SIG_DFL) { |
| handler = default_actions[sig]; |
| if (handler) { |
| handler(sig); |
| } |
| } else if (handler != SIG_IGN) { |
| |
| |
| |
| __call_sighandler(handler, sig); |
| } |
| } |
| return 0; |
| } |
|
|