blob: 5a5ae9cd19e32f1543b2ff69ded69636b242e76f [file] [log] [blame]
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -07001/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
Ben Chanfc420602014-04-01 14:00:36 -07006/* These header files need to be included before asm/siginfo.h such that
7 * pid_t, timer_t, and clock_t are defined. */
8#include <stdlib.h>
9#include <unistd.h>
10
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070011#include <asm/siginfo.h>
12#define __have_siginfo_t 1
13#define __have_sigval_t 1
14#define __have_sigevent_t 1
15
16#include <signal.h>
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070017#include <string.h>
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070018
Jorge Lucangeli Obesa21c8fc2015-07-15 16:22:34 -070019#include "signal_handler.h"
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070020
21#include "util.h"
22
23struct local_sigsys {
24 void *ip;
25 int nr;
26 unsigned int arch;
27};
28
29void log_sigsys_handler(int nr, siginfo_t *info, void *void_context)
30{
31 struct local_sigsys sigsys;
32 const char *syscall_name;
33 memcpy(&sigsys, &info->_sifields, sizeof(sigsys));
34 syscall_name = lookup_syscall_name(sigsys.nr);
35
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070036 (void) void_context;
37
Jeff Vander Stoep00c57912016-02-03 15:48:06 -080038 if (syscall_name)
39 die("blocked syscall: %s", syscall_name);
40 else
41 die("blocked syscall: %d", nr);
42
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070043 /*
44 * We trapped on a syscall that should have killed the process.
45 * This should never ever return, but we're paranoid.
46 */
47 for (;;)
48 _exit(1);
49}
50
51int install_sigsys_handler()
52{
53 int ret = 0;
54 struct sigaction act;
55 sigset_t mask;
56
57 memset(&act, 0, sizeof(act));
58 act.sa_sigaction = &log_sigsys_handler;
59 act.sa_flags = SA_SIGINFO;
60
61 sigemptyset(&mask);
62 sigaddset(&mask, SIGSYS);
63
64 ret = sigaction(SIGSYS, &act, NULL);
65 if (ret < 0)
66 return ret;
67
68 ret = sigprocmask(SIG_UNBLOCK, &mask, NULL);
69 if (ret < 0)
70 return ret;
71
72 return 0;
73}