-
Notifications
You must be signed in to change notification settings - Fork 11
/
signal.c
74 lines (58 loc) · 1.47 KB
/
signal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* These header files need to be included before asm/siginfo.h such that
* pid_t, timer_t, and clock_t are defined. */
#include <stdlib.h>
#include <unistd.h>
#include <syscall.h>
#include <asm/siginfo.h>
#define __have_siginfo_t 1
#define __have_sigval_t 1
#define __have_sigevent_t 1
#include <signal.h>
#include <string.h>
#include "signal.h"
#include "util.h"
struct local_sigsys {
void *ip;
int nr;
unsigned int arch;
};
int signum_fd = -1;
void log_sigsys_handler(int nr, siginfo_t *info, void *void_context)
{
struct local_sigsys sigsys;
memcpy(&sigsys, &info->_sifields, sizeof(sigsys));
int written = 0;
if (signum_fd != -1)
written = write(signum_fd, &sigsys.nr, sizeof(sigsys.nr));
(void) void_context;
(void) nr;
(void) written;
/*
* We trapped on a syscall that should have killed the process.
* This should never ever return, but we're paranoid.
*/
for (;;)
syscall(__NR_exit_group, 1);
}
int install_sigsys_handler()
{
int ret = 0;
struct sigaction act;
sigset_t mask;
memset(&act, 0, sizeof(act));
act.sa_sigaction = &log_sigsys_handler;
act.sa_flags = SA_SIGINFO;
sigemptyset(&mask);
sigaddset(&mask, SIGSYS);
ret = sigaction(SIGSYS, &act, NULL);
if (ret < 0)
return ret;
ret = sigprocmask(SIG_UNBLOCK, &mask, NULL);
if (ret < 0)
return ret;
return 0;
}