| 1 |
#if defined(__ANDROID__) |
| 2 |
#include <signal.h> |
| 3 |
|
| 4 |
#define SIGMAX 64 |
| 5 |
|
| 6 |
static void (*wrapped_signal_handlers[SIGMAX]) (int, siginfo_t *, void *); |
| 7 |
|
| 8 |
static void signal_handler(int signum, siginfo_t* siginfo, void* sigcontext) |
| 9 |
{ |
| 10 |
if (wrapped_signal_handlers[signum]) |
| 11 |
wrapped_signal_handlers[signum](signum, siginfo, sigcontext); |
| 12 |
} |
| 13 |
|
| 14 |
extern int __real_sigaction(int signum, const struct sigaction *action, struct sigaction *old_action); |
| 15 |
__attribute__((used)) int __wrap_sigaction(int signum, const struct sigaction *action, struct sigaction *old_action) |
| 16 |
{ |
| 17 |
struct sigaction wrapper_action_data; |
| 18 |
struct sigaction* wrapper_action = NULL; |
| 19 |
|
| 20 |
if (signum >= SIGMAX) |
| 21 |
return __real_sigaction(signum, action, old_action); |
| 22 |
|
| 23 |
// patch sig action with our thumb compiled dispatcher |
| 24 |
if (action) |
| 25 |
{ |
| 26 |
wrapper_action = &wrapper_action_data; |
| 27 |
memcpy(wrapper_action, action, sizeof(*action)); |
| 28 |
wrapper_action->sa_sigaction = signal_handler; |
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
// install handler (abort on error) |
| 33 |
if (__real_sigaction(signum, wrapper_action, old_action) == -1) |
| 34 |
return -1; |
| 35 |
|
| 36 |
// hide any previously installed wrapper |
| 37 |
if (old_action && old_action->sa_sigaction == signal_handler) |
| 38 |
old_action->sa_sigaction = wrapped_signal_handlers[signum]; |
| 39 |
|
| 40 |
// add action to dispatch table |
| 41 |
if (action) |
| 42 |
wrapped_signal_handlers[signum] = action->sa_sigaction; |
| 43 |
|
| 44 |
return 0; |
| 45 |
} |
| 46 |
|
| 47 |
#undef SIGMAX |
| 48 |
#endif /* __ANDROID__ */ |