blob: 78508df31abdb7b5adb2e16056d428686a9ca5e2 [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com>
5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 2001 John Hughes <john@Calva.COM>
7 * Copyright (c) 2013 Denys Vlasenko <vda.linux@googlemail.com>
8 * Copyright (c) 2011-2015 Dmitry V. Levin <ldv@altlinux.org>
9 * Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
Dmitry V. Levin537c9642015-03-27 23:28:15 +000035#include "defs.h"
36
Elvira Khabirovaa0b62492015-08-04 02:16:40 +030037#include DEF_MPERS_TYPE(siginfo_t)
38
Dmitry V. Levin0e946ab2015-07-17 23:56:54 +000039#include <signal.h>
Mike Frysingerd2eaf672015-08-18 03:24:59 -040040#include <linux/audit.h>
Dmitry V. Levin0e946ab2015-07-17 23:56:54 +000041
Elvira Khabirovaa0b62492015-08-04 02:16:40 +030042#include MPERS_DEFS
43
44#ifndef IN_MPERS
Dmitry V. Levin0e946ab2015-07-17 23:56:54 +000045#include "printsiginfo.h"
Elvira Khabirovaa0b62492015-08-04 02:16:40 +030046#endif
Dmitry V. Levin0e946ab2015-07-17 23:56:54 +000047
Mike Frysingerd2eaf672015-08-18 03:24:59 -040048#include "xlat/audit_arch.h"
Dmitry V. Levin537c9642015-03-27 23:28:15 +000049#include "xlat/sigbus_codes.h"
50#include "xlat/sigchld_codes.h"
51#include "xlat/sigfpe_codes.h"
52#include "xlat/sigill_codes.h"
53#include "xlat/siginfo_codes.h"
54#include "xlat/sigpoll_codes.h"
55#include "xlat/sigprof_codes.h"
56#include "xlat/sigsegv_codes.h"
57#include "xlat/sigsys_codes.h"
58#include "xlat/sigtrap_codes.h"
59
60#ifdef SIGEMT
61# include "xlat/sigemt_codes.h"
62#endif
63
64#ifndef SI_FROMUSER
65# define SI_FROMUSER(sip) ((sip)->si_code <= 0)
66#endif
67
68static void
69printsigsource(const siginfo_t *sip)
70{
Elvira Khabirova3595f4a2015-08-21 20:46:35 +030071 tprintf(", si_pid=%u, si_uid=%u",
72 (unsigned int) sip->si_pid,
73 (unsigned int) sip->si_uid);
Dmitry V. Levin537c9642015-03-27 23:28:15 +000074}
75
76static void
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +000077printsigval(const siginfo_t *sip)
Dmitry V. Levin537c9642015-03-27 23:28:15 +000078{
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +000079 tprintf(", si_value={int=%d, ptr=%#lx}",
80 sip->si_int, (unsigned long) sip->si_ptr);
Dmitry V. Levin537c9642015-03-27 23:28:15 +000081}
82
83static void
Dmitry V. Levin9134aab2016-05-14 21:46:05 +000084print_si_code(int si_signo, unsigned int si_code)
Dmitry V. Levin537c9642015-03-27 23:28:15 +000085{
86 const char *code = xlookup(siginfo_codes, si_code);
87
88 if (!code) {
89 switch (si_signo) {
90 case SIGTRAP:
91 code = xlookup(sigtrap_codes, si_code);
92 break;
93 case SIGCHLD:
94 code = xlookup(sigchld_codes, si_code);
95 break;
96 case SIGPOLL:
97 code = xlookup(sigpoll_codes, si_code);
98 break;
99 case SIGPROF:
100 code = xlookup(sigprof_codes, si_code);
101 break;
102 case SIGILL:
103 code = xlookup(sigill_codes, si_code);
104 break;
105#ifdef SIGEMT
106 case SIGEMT:
107 code = xlookup(sigemt_codes, si_code);
108 break;
109#endif
110 case SIGFPE:
111 code = xlookup(sigfpe_codes, si_code);
112 break;
113 case SIGSEGV:
114 code = xlookup(sigsegv_codes, si_code);
115 break;
116 case SIGBUS:
117 code = xlookup(sigbus_codes, si_code);
118 break;
119 case SIGSYS:
120 code = xlookup(sigsys_codes, si_code);
121 break;
122 }
123 }
124
125 if (code)
126 tprints(code);
127 else
128 tprintf("%#x", si_code);
129}
130
131static void
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000132print_si_info(const siginfo_t *sip)
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000133{
134 if (sip->si_errno) {
135 tprints(", si_errno=");
136 if ((unsigned) sip->si_errno < nerrnos
137 && errnoent[sip->si_errno])
138 tprints(errnoent[sip->si_errno]);
139 else
140 tprintf("%d", sip->si_errno);
141 }
142
143 if (SI_FROMUSER(sip)) {
144 switch (sip->si_code) {
145 case SI_USER:
146 printsigsource(sip);
147 break;
148 case SI_TKILL:
149 printsigsource(sip);
150 break;
151#if defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
152 case SI_TIMER:
153 tprintf(", si_timerid=%#x, si_overrun=%d",
154 sip->si_timerid, sip->si_overrun);
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000155 printsigval(sip);
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000156 break;
157#endif
158 default:
159 printsigsource(sip);
160 if (sip->si_ptr)
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000161 printsigval(sip);
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000162 break;
163 }
164 } else {
165 switch (sip->si_signo) {
166 case SIGCHLD:
167 printsigsource(sip);
168 tprints(", si_status=");
169 if (sip->si_code == CLD_EXITED)
170 tprintf("%d", sip->si_status);
171 else
172 printsignal(sip->si_status);
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000173 tprintf(", si_utime=%llu, si_stime=%llu",
174 (unsigned long long) sip->si_utime,
175 (unsigned long long) sip->si_stime);
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000176 break;
177 case SIGILL: case SIGFPE:
178 case SIGSEGV: case SIGBUS:
179 tprintf(", si_addr=%#lx",
180 (unsigned long) sip->si_addr);
181 break;
182 case SIGPOLL:
183 switch (sip->si_code) {
184 case POLL_IN: case POLL_OUT: case POLL_MSG:
185 tprintf(", si_band=%ld",
186 (long) sip->si_band);
187 break;
188 }
189 break;
190#ifdef HAVE_SIGINFO_T_SI_SYSCALL
191 case SIGSYS:
Mike Frysingerd2eaf672015-08-18 03:24:59 -0400192 tprintf(", si_call_addr=%#lx, si_syscall=__NR_%s, si_arch=",
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000193 (unsigned long) sip->si_call_addr,
Dmitry V. Levin49955942016-05-12 14:27:49 +0000194 syscall_name((unsigned) sip->si_syscall));
Mike Frysingerd2eaf672015-08-18 03:24:59 -0400195 printxval(audit_arch, sip->si_arch, "AUDIT_ARCH_???");
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000196 break;
197#endif
198 default:
199 if (sip->si_pid || sip->si_uid)
200 printsigsource(sip);
201 if (sip->si_ptr)
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000202 printsigval(sip);
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000203 }
204 }
205}
206
Elvira Khabirovaa0b62492015-08-04 02:16:40 +0300207#ifdef IN_MPERS
208static
209#endif
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000210void
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000211printsiginfo(const siginfo_t *sip)
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000212{
213 if (sip->si_signo == 0) {
214 tprints("{}");
215 return;
216 }
217 tprints("{si_signo=");
218 printsignal(sip->si_signo);
219
220 tprints(", si_code=");
221 print_si_code(sip->si_signo, sip->si_code);
222
223#ifdef SI_NOINFO
224 if (sip->si_code != SI_NOINFO)
225#endif
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000226 print_si_info(sip);
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000227
228 tprints("}");
229}
230
Elvira Khabirovaa0b62492015-08-04 02:16:40 +0300231MPERS_PRINTER_DECL(void, printsiginfo_at)(struct tcb *tcp, long addr)
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000232{
233 siginfo_t si;
Dmitry V. Levina528eb52015-07-17 21:58:18 +0000234
235 if (!umove_or_printaddr(tcp, addr, &si))
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000236 printsiginfo(&si);
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000237}
Dmitry V. Levin76b4c332016-05-13 02:33:33 +0000238
239static bool
240print_siginfo_t(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
241{
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000242 printsiginfo((const siginfo_t *) elem_buf);
Dmitry V. Levin76b4c332016-05-13 02:33:33 +0000243 return true;
244}
245
246MPERS_PRINTER_DECL(void, print_siginfo_array)(struct tcb *tcp, unsigned long addr, unsigned long len)
247{
248 siginfo_t si;
249
250 print_array(tcp, addr, len, &si, sizeof(si),
251 umoven_or_printaddr, print_siginfo_t, 0);
252}