1 /* radare - LGPL - Copyright 2017-2020 - polsha3 */
2 
3 #include <r_util.h>
4 
5 #include <signal.h>
6 #include <stddef.h>
7 
8 static struct {
9 	const char *name;
10 	int code;
11 } signals[] = {
12 	{ "SIGINT", SIGINT },
13 	{ "SIGILL", SIGILL },
14 	{ "SIGABRT", SIGABRT },
15 	{ "SIGFPE", SIGFPE },
16 	{ "SIGSEGV", SIGSEGV },
17 	{ "SIGTERM", SIGTERM },
18 #if __LINUX__
19 	{ "SIGSTKFLT", SIGSTKFLT },
20 	{ "SIGWINCH", SIGWINCH },
21 	{ "SIGIO", SIGIO },
22 	{ "SIGPWR", SIGPWR },
23 	{ "SIGPOLL", SIGPOLL },
24 #endif
25 #if !__WINDOWS__
26 	{ "SIGHUP", SIGHUP },
27 	{ "SIGQUIT", SIGQUIT },
28 	{ "SIGTRAP", SIGTRAP },
29 	{ "SIGBUS", SIGBUS },
30 	{ "SIGKILL", SIGKILL },
31 	{ "SIGUSR1", SIGUSR1 },
32 	{ "SIGUSR2", SIGUSR2 },
33 	{ "SIGPIPE", SIGPIPE },
34 	{ "SIGALRM", SIGALRM },
35 	{ "SIGCHLD", SIGCHLD },
36 	{ "SIGCONT", SIGCONT },
37 	{ "SIGSTOP", SIGSTOP },
38 	{ "SIGTSTP", SIGTSTP },
39 	{ "SIGTTIN", SIGTTIN },
40 	{ "SIGTTOU", SIGTTOU },
41 	{ "SIGURG", SIGURG },
42 	{ "SIGXCPU", SIGXCPU },
43 	{ "SIGXFSZ", SIGXFSZ },
44 	{ "SIGVTALRM", SIGVTALRM },
45 	{ "SIGPROF", SIGPROF },
46 	{ "SIGSYS", SIGSYS },
47 #endif
48 	{ NULL }
49 };
50 
r_signal_from_string(const char * e)51 R_API int r_signal_from_string (const char *e) {
52 	int i;
53 	for (i = 1; signals[i].name; i++) {
54 		const char *str = signals[i].name;
55 		if (!strcmp (e, str)) {
56 			return signals[i].code;
57 		}
58 	}
59 	return atoi (e);
60 }
61 
r_signal_to_string(int code)62 R_API const char* r_signal_to_string (int code) {
63 	int i;
64 	for (i = 1; signals[i].name; i++) {
65 		if (signals[i].code == code) {
66 			return signals[i].name;
67 		}
68 	}
69 	return NULL;
70 }
71 
72 #if HAVE_PTHREAD
r_signal_sigmask(int how,const sigset_t * newmask,sigset_t * oldmask)73 R_API void r_signal_sigmask(int how, const sigset_t *newmask, sigset_t *oldmask) {
74 	pthread_sigmask (how, newmask, oldmask);
75 }
76 #endif
77