Rizin
unix-like reverse engineering framework and cli tools
signal.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2017-2020 polsha3 <polsha3@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_util.h>
5 
6 #include <signal.h>
7 #include <stddef.h>
8 
9 static struct {
10  const char *name;
11  int code;
12 } signals[] = {
13  { "SIGINT", SIGINT },
14  { "SIGILL", SIGILL },
15  { "SIGABRT", SIGABRT },
16  { "SIGFPE", SIGFPE },
17  { "SIGSEGV", SIGSEGV },
18  { "SIGTERM", SIGTERM },
19 #if __LINUX__
20  { "SIGSTKFLT", SIGSTKFLT },
21  { "SIGWINCH", SIGWINCH },
22  { "SIGIO", SIGIO },
23  { "SIGPWR", SIGPWR },
24  { "SIGPOLL", SIGPOLL },
25 #endif
26 #if !__WINDOWS__
27  { "SIGHUP", SIGHUP },
28  { "SIGQUIT", SIGQUIT },
29  { "SIGTRAP", SIGTRAP },
30  { "SIGBUS", SIGBUS },
31  { "SIGKILL", SIGKILL },
32  { "SIGUSR1", SIGUSR1 },
33  { "SIGUSR2", SIGUSR2 },
34  { "SIGPIPE", SIGPIPE },
35  { "SIGALRM", SIGALRM },
36  { "SIGCHLD", SIGCHLD },
37  { "SIGCONT", SIGCONT },
38  { "SIGSTOP", SIGSTOP },
39  { "SIGTSTP", SIGTSTP },
40  { "SIGTTIN", SIGTTIN },
41  { "SIGTTOU", SIGTTOU },
42  { "SIGURG", SIGURG },
43  { "SIGXCPU", SIGXCPU },
44  { "SIGXFSZ", SIGXFSZ },
45  { "SIGVTALRM", SIGVTALRM },
46  { "SIGPROF", SIGPROF },
47  { "SIGSYS", SIGSYS },
48 #endif
49  { NULL }
50 };
51 
52 RZ_API int rz_signal_from_string(const char *e) {
53  int i;
54  for (i = 1; signals[i].name; i++) {
55  const char *str = signals[i].name;
56  if (!strcmp(e, str)) {
57  return signals[i].code;
58  }
59  }
60  return atoi(e);
61 }
62 
63 RZ_API const char *rz_signal_to_string(int code) {
64  int i;
65  for (i = 1; signals[i].name; i++) {
66  if (signals[i].code == code) {
67  return signals[i].name;
68  }
69  }
70  return NULL;
71 }
72 
73 #if HAVE_PTHREAD
74 RZ_API void rz_signal_sigmask(int how, const sigset_t *newmask, sigset_t *oldmask) {
75  pthread_sigmask(how, newmask, oldmask);
76 }
77 #endif
#define e(frag)
lzma_index ** i
Definition: index.h:629
#define SIGKILL
#define RZ_API
#define NULL
Definition: cris-opc.c:27
int code
Definition: signal.c:11
RZ_API const char * rz_signal_to_string(int code)
Definition: signal.c:63
const char * name
Definition: signal.c:10
RZ_API int rz_signal_from_string(const char *e)
Definition: signal.c:52
static struct @333 signals[]
int sigset_t
Definition: sftypes.h:63
Definition: inftree9.h:24
#define SIGHUP
Definition: win.h:86
#define SIGWINCH
Definition: win.h:88