diff --git a/configure.py b/configure.py index 7f8bb514..645fa269 100644 --- a/configure.py +++ b/configure.py @@ -1961,7 +1961,7 @@ config.libs = [ Object(Matching, "MSL_Common/qsort.c", extra_cflags=["-Cpp_exceptions on"]), Object(Matching, "MSL_Common/rand.c"), Object(NonMatching, "MSL_Common/scanf.c"), - Object(NonMatching, "MSL_Common/signal.c"), + Object(Matching, "MSL_Common/signal.c", extra_cflags=["-Cpp_exceptions on"]), Object(NonMatching, "MSL_Common/string.c"), Object(Matching, "MSL_Common/float.c"), Object(NonMatching, "MSL_Common/strtold.c"), diff --git a/libs/MSL/include/signal.h b/libs/MSL/include/signal.h index 8d05fc6c..1dddb2bd 100644 --- a/libs/MSL/include/signal.h +++ b/libs/MSL/include/signal.h @@ -5,6 +5,19 @@ extern "C" { #endif +#define SIGNAL_ACTION_DEFAULT ((__signal_func_ptr)0) +#define SIGNAL_ACTION_IGNORE ((__signal_func_ptr)1) + +#define SIGNAL_ABORT 1 +#define SIGNAL_UNK2 2 +#define SIGNAL_UNK3 3 +#define SIGNAL_UNK4 4 +#define SIGNAL_UNK5 5 +#define SIGNAL_UNK6 6 +#define SIGNAL_UNK7 7 + +typedef void (*__signal_func_ptr)(int); + int raise(int signal); #ifdef __cplusplus diff --git a/libs/MSL/src/MSL_Common/signal.c b/libs/MSL/src/MSL_Common/signal.c new file mode 100644 index 00000000..652c8fc5 --- /dev/null +++ b/libs/MSL/src/MSL_Common/signal.c @@ -0,0 +1,30 @@ +#include + +int exit(int); + +__signal_func_ptr signal_funcs[8]; + +int raise(int sig) { + __signal_func_ptr signal_func; + + if (sig < SIGNAL_ABORT || sig > SIGNAL_UNK7) { + return -1; + } + + signal_func = signal_funcs[sig - 1]; + + if (signal_func != SIGNAL_ACTION_IGNORE) { + signal_funcs[sig - 1] = SIGNAL_ACTION_DEFAULT; + } + + if (signal_func == SIGNAL_ACTION_IGNORE || (signal_func == SIGNAL_ACTION_DEFAULT && sig == SIGNAL_ABORT)) { + return 0; + } + + if (signal_func == SIGNAL_ACTION_DEFAULT) { + exit(0); + } + + (*signal_func)(sig); + return 0; +}