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 * SPDX-License-Identifier: LGPL-2.1-or-later
18 #include DEF_MPERS_TYPE(siginfo_t)
21 #include <linux/audit.h>
25 #include "nr_prefix.c"
27 #include "print_fields.h"
30 # include "printsiginfo.h"
33 #define XLAT_MACROS_ONLY
34 /* For xlat/audit_arch.h */
35 # include "xlat/elf_em.h"
36 #undef XLAT_MACROS_ONLY
38 #include "xlat/audit_arch.h"
39 #include "xlat/sigbus_codes.h"
40 #include "xlat/sigchld_codes.h"
41 #include "xlat/sigfpe_codes.h"
42 #include "xlat/sigill_codes.h"
43 #include "xlat/siginfo_codes.h"
44 #include "xlat/sigpoll_codes.h"
45 #include "xlat/sigprof_codes.h"
46 #include "xlat/sigsegv_codes.h"
47 #include "xlat/sigsys_codes.h"
48 #include "xlat/sigtrap_codes.h"
51 # include "xlat/sigemt_codes.h"
55 # define SI_FROMUSER(sip) ((sip)->si_code <= 0)
59 printsigsource(const siginfo_t *sip)
61 tprintf(", si_pid=%u, si_uid=%u",
62 (unsigned int) sip->si_pid,
63 (unsigned int) sip->si_uid);
67 printsigval(const siginfo_t *sip)
69 tprintf(", si_value={int=%d, ptr=", sip->si_int);
70 printaddr(ptr_to_kulong(sip->si_ptr));
75 print_si_code(int si_signo, unsigned int si_code)
77 const char *code = xlookup(siginfo_codes, si_code);
82 code = xlookup(sigtrap_codes, si_code);
85 code = xlookup(sigchld_codes, si_code);
88 code = xlookup(sigpoll_codes, si_code);
91 code = xlookup(sigprof_codes, si_code);
94 code = xlookup(sigill_codes, si_code);
98 code = xlookup(sigemt_codes, si_code);
102 code = xlookup(sigfpe_codes, si_code);
105 code = xlookup(sigsegv_codes, si_code);
108 code = xlookup(sigbus_codes, si_code);
111 code = xlookup(sigsys_codes, si_code);
116 print_xlat_ex(si_code, code, XLAT_STYLE_DEFAULT);
120 print_si_info(const siginfo_t *sip)
123 PRINT_FIELD_ERR_U(", ", *sip, si_errno);
125 if (SI_FROMUSER(sip)) {
126 switch (sip->si_code) {
133 #if defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
135 tprintf(", si_timerid=%#x, si_overrun=%d",
136 sip->si_timerid, sip->si_overrun);
147 switch (sip->si_signo) {
150 tprints(", si_status=");
151 if (sip->si_code == CLD_EXITED)
152 tprintf("%d", sip->si_status);
154 printsignal(sip->si_status);
155 tprintf(", si_utime=%llu, si_stime=%llu",
156 zero_extend_signed_to_ull(sip->si_utime),
157 zero_extend_signed_to_ull(sip->si_stime));
159 case SIGILL: case SIGFPE:
160 case SIGSEGV: case SIGBUS:
161 tprints(", si_addr=");
162 printaddr(ptr_to_kulong(sip->si_addr));
165 switch (sip->si_code) {
166 case POLL_IN: case POLL_OUT: case POLL_MSG:
167 tprintf(", si_band=%ld",
168 (long) sip->si_band);
172 #ifdef HAVE_SIGINFO_T_SI_SYSCALL
175 * Note that we can safely use the personlity set in
176 * current_personality here (and don't have to guess it
177 * based on X32_SYSCALL_BIT and si_arch, for example):
178 * - The signal is delivered as a result of seccomp
179 * filtering to the process executing forbidden
181 * - We have set the personality for the tracee during
182 * the syscall entering.
183 * - The current_personality is reliably switched in
184 * the next_event routine, it is set to the
185 * personality of the last call made (the one that
186 * triggered the signal delivery).
187 * - Looks like there are no other cases where SIGSYS
188 * is delivered from the kernel so far.
190 const char *scname = syscall_name(shuffle_scno(
191 (unsigned) sip->si_syscall));
193 tprints(", si_call_addr=");
194 printaddr(ptr_to_kulong(sip->si_call_addr));
195 tprints(", si_syscall=");
198 nr_prefix(sip->si_syscall), scname);
200 tprintf("%u", (unsigned) sip->si_syscall);
201 tprints(", si_arch=");
202 printxval(audit_arch, sip->si_arch, "AUDIT_ARCH_???");
207 if (sip->si_pid || sip->si_uid)
219 printsiginfo(const siginfo_t *sip)
221 if (sip->si_signo == 0) {
225 tprints("{si_signo=");
226 printsignal(sip->si_signo);
228 tprints(", si_code=");
229 print_si_code(sip->si_signo, sip->si_code);
232 if (sip->si_code != SI_NOINFO)
239 MPERS_PRINTER_DECL(void, printsiginfo_at,
240 struct tcb *const tcp, const kernel_ulong_t addr)
244 if (!umove_or_printaddr(tcp, addr, &si))
249 print_siginfo_t(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
251 printsiginfo((const siginfo_t *) elem_buf);
255 MPERS_PRINTER_DECL(void, print_siginfo_array, struct tcb *const tcp,
256 const kernel_ulong_t addr, const kernel_ulong_t len)
260 print_array(tcp, addr, len, &si, sizeof(si),
261 tfetch_mem, print_siginfo_t, 0);