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 * Copyright (c) 2015-2018 The strace developers.
11 * All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include DEF_MPERS_TYPE(siginfo_t)
41 #include <linux/audit.h>
45 #include "nr_prefix.c"
48 #include "printsiginfo.h"
51 #include "xlat/audit_arch.h"
52 #include "xlat/sigbus_codes.h"
53 #include "xlat/sigchld_codes.h"
54 #include "xlat/sigfpe_codes.h"
55 #include "xlat/sigill_codes.h"
56 #include "xlat/siginfo_codes.h"
57 #include "xlat/sigpoll_codes.h"
58 #include "xlat/sigprof_codes.h"
59 #include "xlat/sigsegv_codes.h"
60 #include "xlat/sigsys_codes.h"
61 #include "xlat/sigtrap_codes.h"
64 # include "xlat/sigemt_codes.h"
68 # define SI_FROMUSER(sip) ((sip)->si_code <= 0)
72 printsigsource(const siginfo_t *sip)
74 tprintf(", si_pid=%u, si_uid=%u",
75 (unsigned int) sip->si_pid,
76 (unsigned int) sip->si_uid);
80 printsigval(const siginfo_t *sip)
82 tprintf(", si_value={int=%d, ptr=", sip->si_int);
83 printaddr(ptr_to_kulong(sip->si_ptr));
88 print_si_code(int si_signo, unsigned int si_code)
90 const char *code = xlookup(siginfo_codes, si_code);
95 code = xlookup(sigtrap_codes, si_code);
98 code = xlookup(sigchld_codes, si_code);
101 code = xlookup(sigpoll_codes, si_code);
104 code = xlookup(sigprof_codes, si_code);
107 code = xlookup(sigill_codes, si_code);
111 code = xlookup(sigemt_codes, si_code);
115 code = xlookup(sigfpe_codes, si_code);
118 code = xlookup(sigsegv_codes, si_code);
121 code = xlookup(sigbus_codes, si_code);
124 code = xlookup(sigsys_codes, si_code);
129 print_xlat_ex(si_code, code, XLAT_STYLE_DEFAULT);
133 print_si_info(const siginfo_t *sip)
136 tprints(", si_errno=");
137 if ((unsigned) sip->si_errno < nerrnos
138 && errnoent[sip->si_errno])
139 tprints(errnoent[sip->si_errno]);
141 tprintf("%d", sip->si_errno);
144 if (SI_FROMUSER(sip)) {
145 switch (sip->si_code) {
152 #if defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
154 tprintf(", si_timerid=%#x, si_overrun=%d",
155 sip->si_timerid, sip->si_overrun);
166 switch (sip->si_signo) {
169 tprints(", si_status=");
170 if (sip->si_code == CLD_EXITED)
171 tprintf("%d", sip->si_status);
173 printsignal(sip->si_status);
174 tprintf(", si_utime=%llu, si_stime=%llu",
175 zero_extend_signed_to_ull(sip->si_utime),
176 zero_extend_signed_to_ull(sip->si_stime));
178 case SIGILL: case SIGFPE:
179 case SIGSEGV: case SIGBUS:
180 tprints(", si_addr=");
181 printaddr(ptr_to_kulong(sip->si_addr));
184 switch (sip->si_code) {
185 case POLL_IN: case POLL_OUT: case POLL_MSG:
186 tprintf(", si_band=%ld",
187 (long) sip->si_band);
191 #ifdef HAVE_SIGINFO_T_SI_SYSCALL
194 * Note that we can safely use the personlity set in
195 * current_personality here (and don't have to guess it
196 * based on X32_SYSCALL_BIT and si_arch, for example):
197 * - The signal is delivered as a result of seccomp
198 * filtering to the process executing forbidden
200 * - We have set the personality for the tracee during
201 * the syscall entering.
202 * - The current_personality is reliably switched in
203 * the next_event routine, it is set to the
204 * personality of the last call made (the one that
205 * triggered the signal delivery).
206 * - Looks like there are no other cases where SIGSYS
207 * is delivered from the kernel so far.
209 const char *scname = syscall_name(shuffle_scno(
210 (unsigned) sip->si_syscall));
212 tprints(", si_call_addr=");
213 printaddr(ptr_to_kulong(sip->si_call_addr));
214 tprints(", si_syscall=");
217 nr_prefix(sip->si_syscall), scname);
219 tprintf("%u", (unsigned) sip->si_syscall);
220 tprints(", si_arch=");
221 printxval(audit_arch, sip->si_arch, "AUDIT_ARCH_???");
226 if (sip->si_pid || sip->si_uid)
238 printsiginfo(const siginfo_t *sip)
240 if (sip->si_signo == 0) {
244 tprints("{si_signo=");
245 printsignal(sip->si_signo);
247 tprints(", si_code=");
248 print_si_code(sip->si_signo, sip->si_code);
251 if (sip->si_code != SI_NOINFO)
258 MPERS_PRINTER_DECL(void, printsiginfo_at,
259 struct tcb *const tcp, const kernel_ulong_t addr)
263 if (!umove_or_printaddr(tcp, addr, &si))
268 print_siginfo_t(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
270 printsiginfo((const siginfo_t *) elem_buf);
274 MPERS_PRINTER_DECL(void, print_siginfo_array, struct tcb *const tcp,
275 const kernel_ulong_t addr, const kernel_ulong_t len)
279 print_array(tcp, addr, len, &si, sizeof(si),
280 umoven_or_printaddr, print_siginfo_t, 0);