2023-11-21 13:26:32 +00:00
|
|
|
/* radare - LGPL - Copyright 2017-2023 - polsha3 */
|
2020-04-07 12:07:40 +00:00
|
|
|
|
2017-02-02 13:33:52 +00:00
|
|
|
#include <r_util.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
const char *name;
|
|
|
|
int code;
|
|
|
|
} signals[] = {
|
|
|
|
{ "SIGINT", SIGINT },
|
|
|
|
{ "SIGILL", SIGILL },
|
|
|
|
{ "SIGABRT", SIGABRT },
|
|
|
|
{ "SIGFPE", SIGFPE },
|
2017-02-03 00:31:29 +00:00
|
|
|
{ "SIGSEGV", SIGSEGV },
|
|
|
|
{ "SIGTERM", SIGTERM },
|
2021-07-17 10:55:41 +00:00
|
|
|
#if __linux__
|
2017-02-03 00:31:29 +00:00
|
|
|
{ "SIGWINCH", SIGWINCH },
|
|
|
|
{ "SIGIO", SIGIO },
|
|
|
|
{ "SIGPWR", SIGPWR },
|
|
|
|
{ "SIGPOLL", SIGPOLL },
|
|
|
|
#endif
|
2022-12-10 18:23:37 +00:00
|
|
|
#if !R2__WINDOWS__
|
2017-02-03 00:31:29 +00:00
|
|
|
{ "SIGHUP", SIGHUP },
|
|
|
|
{ "SIGQUIT", SIGQUIT },
|
|
|
|
{ "SIGTRAP", SIGTRAP },
|
|
|
|
{ "SIGBUS", SIGBUS },
|
2017-02-02 13:33:52 +00:00
|
|
|
{ "SIGKILL", SIGKILL },
|
|
|
|
{ "SIGUSR1", SIGUSR1 },
|
|
|
|
{ "SIGUSR2", SIGUSR2 },
|
|
|
|
{ "SIGPIPE", SIGPIPE },
|
|
|
|
{ "SIGALRM", SIGALRM },
|
|
|
|
{ "SIGCHLD", SIGCHLD },
|
|
|
|
{ "SIGCONT", SIGCONT },
|
|
|
|
{ "SIGSTOP", SIGSTOP },
|
|
|
|
{ "SIGTSTP", SIGTSTP },
|
|
|
|
{ "SIGTTIN", SIGTTIN },
|
|
|
|
{ "SIGTTOU", SIGTTOU },
|
|
|
|
{ "SIGURG", SIGURG },
|
|
|
|
{ "SIGXCPU", SIGXCPU },
|
|
|
|
{ "SIGXFSZ", SIGXFSZ },
|
|
|
|
{ "SIGVTALRM", SIGVTALRM },
|
|
|
|
{ "SIGPROF", SIGPROF },
|
|
|
|
{ "SIGSYS", SIGSYS },
|
2017-02-03 00:31:29 +00:00
|
|
|
#endif
|
2017-02-02 13:33:52 +00:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2021-06-10 14:13:38 +00:00
|
|
|
R_API int r_signal_from_string(const char *e) {
|
2017-02-02 13:33:52 +00:00
|
|
|
int i;
|
|
|
|
for (i = 1; signals[i].name; i++) {
|
|
|
|
const char *str = signals[i].name;
|
|
|
|
if (!strcmp (e, str)) {
|
|
|
|
return signals[i].code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return atoi (e);
|
|
|
|
}
|
|
|
|
|
2022-10-24 18:59:18 +00:00
|
|
|
R_API const char* r_signal_tostring(int code) {
|
2017-02-02 13:33:52 +00:00
|
|
|
int i;
|
|
|
|
for (i = 1; signals[i].name; i++) {
|
|
|
|
if (signals[i].code == code) {
|
|
|
|
return signals[i].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-11 18:35:45 +00:00
|
|
|
|
2022-12-10 18:25:57 +00:00
|
|
|
#if R2__UNIX__
|
2018-07-11 18:35:45 +00:00
|
|
|
R_API void r_signal_sigmask(int how, const sigset_t *newmask, sigset_t *oldmask) {
|
2021-06-10 11:52:29 +00:00
|
|
|
#if HAVE_PTHREAD
|
2018-07-11 18:35:45 +00:00
|
|
|
pthread_sigmask (how, newmask, oldmask);
|
2021-06-10 11:52:29 +00:00
|
|
|
#endif
|
2018-07-11 18:35:45 +00:00
|
|
|
}
|
2019-03-15 04:55:08 +00:00
|
|
|
#endif
|
2021-07-17 10:55:41 +00:00
|
|
|
|
|
|
|
R_API const char *r_signal_to_human(int signum) {
|
2022-12-10 18:25:57 +00:00
|
|
|
#if R2__UNIX__
|
2021-07-17 10:55:41 +00:00
|
|
|
switch (signum) {
|
|
|
|
case SIGALRM: return "Alarm Clock";
|
|
|
|
case SIGBUS: return "Bus Error";
|
|
|
|
case SIGCHLD: return "Child";
|
|
|
|
case SIGCONT: return "Continue Execution";
|
|
|
|
#ifdef SIGEMT
|
|
|
|
case SIGEMT: return "Hardware Error";
|
|
|
|
#endif
|
|
|
|
case SIGFPE: return "Floating Point Exception";
|
|
|
|
case SIGHUP: return "Hangup";
|
|
|
|
case SIGILL: return "Illegal instruction";
|
|
|
|
case SIGABRT: return "Abort";
|
|
|
|
case SIGKILL: return "Killed";
|
|
|
|
case SIGPROF: return "Profiling Timer Expired";
|
|
|
|
#if __linux__
|
|
|
|
case SIGPWR: return "Power Failure";
|
|
|
|
case SIGPOLL: return "Pollable Event (Same as SIGIO)";
|
|
|
|
// case SIGIO: return "IO ready";
|
|
|
|
#endif
|
|
|
|
case SIGQUIT: return "Quit";
|
|
|
|
case SIGSEGV: return "Segmentation fault";
|
|
|
|
case SIGSTOP: return "Stopped";
|
|
|
|
case SIGSYS: return "Bad system call";
|
|
|
|
case SIGTERM: return "Terminated";
|
|
|
|
case SIGTSTP: return "Stopped";
|
|
|
|
case SIGPIPE: return "Broken pipe";
|
|
|
|
case SIGTTIN: return "Stopped";
|
|
|
|
case SIGTTOU: return "Stopped";
|
|
|
|
case SIGURG: return "Urgent";
|
|
|
|
case SIGUSR1: return "User Defined Signal 1";
|
|
|
|
case SIGUSR2: return "User Defined Signal 2";
|
|
|
|
case SIGVTALRM: return "Virtual Timer Expired";
|
|
|
|
case SIGWINCH: return "Window Changed Size";
|
|
|
|
case SIGXCPU: return "CPU time limit exceeded";
|
|
|
|
case SIGXFSZ: return "File size limit exceeded";
|
|
|
|
default: return "unhandled";
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
return "unhandled";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|