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, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Linux for s390 port by D.J. Barrow
8 * <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com>
9 * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
10 * port by Greg Banks <gbanks@pocketpenguins.com>
11 * Copyright (c) 1999-2018 The strace developers.
13 * All rights reserved.
15 * SPDX-License-Identifier: LGPL-2.1-or-later
25 #include "ptrace_syscall_info.h"
28 #include "xlat/nt_descriptor_types.h"
29 #include "xlat/ptrace_cmds.h"
30 #include "xlat/ptrace_setoptions_flags.h"
31 #include "xlat/ptrace_peeksiginfo_flags.h"
33 #define uoff(member) offsetof(struct user, member)
34 #define XLAT_UOFF(member) { uoff(member), "offsetof(struct user, " #member ")" }
36 static const struct xlat struct_user_offsets[] = {
42 print_user_offset_addr(const kernel_ulong_t addr)
47 for (x = struct_user_offsets; x->str; ++x) {
52 if (!x->str || (x == struct_user_offsets && x->val > addr))
54 if (no_str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
56 if (no_str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
59 if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
64 tprintf("%s + %" PRI_klu,
65 x->str, addr - (kernel_ulong_t) x->val);
70 if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
76 const kernel_ulong_t request = tcp->u_arg[0];
77 const int pid = tcp->u_arg[1];
78 const kernel_ulong_t addr = tcp->u_arg[2];
79 const kernel_ulong_t data = tcp->u_arg[3];
83 printxval64(ptrace_cmds, request, "PTRACE_???");
85 if (request == PTRACE_TRACEME) {
86 /* pid, addr, and data are ignored. */
96 case PTRACE_INTERRUPT:
99 /* addr and data are ignored */
101 case PTRACE_PEEKUSER:
102 case PTRACE_POKEUSER:
104 print_user_offset_addr(addr);
106 case PTRACE_GETREGSET:
107 case PTRACE_SETREGSET:
109 printxval(nt_descriptor_types, addr, "NT_???");
111 case PTRACE_GETSIGMASK:
112 case PTRACE_SETSIGMASK:
113 case PTRACE_SECCOMP_GET_FILTER:
114 case PTRACE_SECCOMP_GET_METADATA:
115 case PTRACE_GET_SYSCALL_INFO:
116 tprintf(", %" PRI_klu, addr);
118 case PTRACE_PEEKSIGINFO: {
125 if (umove_or_printaddr(tcp, addr, &psi)) {
130 tprintf("{off=%" PRIu64 ", flags=", psi.off);
131 printflags(ptrace_peeksiginfo_flags, psi.flags,
132 "PTRACE_PEEKSIGINFO_???");
133 tprintf(", nr=%u}", psi.nr);
141 # if defined IA64 || defined SPARC || defined SPARC64
144 case PTRACE_PEEKDATA:
145 case PTRACE_PEEKTEXT:
146 case PTRACE_PEEKUSER:
147 /* data is ignored */
148 return RVAL_DECODED | RVAL_HEX;
150 # if defined SPARC || defined SPARC64
153 case PTRACE_GETFPREGS:
154 case PTRACE_SETFPREGS:
155 /* data is ignored */
157 # endif /* SPARC || SPARC64 */
159 # endif /* IA64 || SPARC || SPARC64 */
168 #ifdef PTRACE_SINGLESTEP
169 case PTRACE_SINGLESTEP:
171 #ifdef PTRACE_SINGLEBLOCK
172 case PTRACE_SINGLEBLOCK:
177 #ifdef PTRACE_SYSEMU_SINGLESTEP
178 case PTRACE_SYSEMU_SINGLESTEP:
183 case PTRACE_SETOPTIONS:
184 #ifdef PTRACE_OLDSETOPTIONS
185 case PTRACE_OLDSETOPTIONS:
187 printflags64(ptrace_setoptions_flags, data, "PTRACE_O_???");
189 case PTRACE_SETSIGINFO:
190 printsiginfo_at(tcp, data);
192 case PTRACE_SETSIGMASK:
193 print_sigset_addr_len(tcp, data, addr);
195 case PTRACE_SETREGSET:
196 tprint_iov(tcp, /*len:*/ 1, data, IOV_DECODE_ADDR);
198 case PTRACE_SECCOMP_GET_METADATA:
201 if (addr < sizeof(filter_off) ||
202 umove(tcp, data, &filter_off)) {
207 tprintf("{filter_off=%" PRIu64, filter_off);
214 case PTRACE_PEEKDATA:
215 case PTRACE_PEEKTEXT:
216 case PTRACE_PEEKUSER:
218 case PTRACE_GETEVENTMSG:
219 case PTRACE_GETREGSET:
220 case PTRACE_GETSIGINFO:
221 case PTRACE_GETSIGMASK:
222 case PTRACE_PEEKSIGINFO:
223 case PTRACE_SECCOMP_GET_FILTER:
224 case PTRACE_GET_SYSCALL_INFO:
226 /* print data on exiting syscall */
229 ATTRIBUTE_FALLTHROUGH;
239 case PTRACE_PEEKDATA:
240 case PTRACE_PEEKTEXT:
241 case PTRACE_PEEKUSER:
242 printnum_ptr(tcp, data);
245 case PTRACE_GETEVENTMSG:
246 printnum_ulong(tcp, data);
248 case PTRACE_GETREGSET:
249 tprint_iov(tcp, /*len:*/ 1, data, IOV_DECODE_ADDR);
251 case PTRACE_GETSIGINFO:
252 printsiginfo_at(tcp, data);
254 case PTRACE_GETSIGMASK:
255 print_sigset_addr_len(tcp, data, addr);
257 case PTRACE_PEEKSIGINFO:
258 print_siginfo_array(tcp, data, tcp->u_rval);
260 case PTRACE_SECCOMP_GET_FILTER:
261 print_seccomp_fprog(tcp, data, tcp->u_rval);
263 case PTRACE_SECCOMP_GET_METADATA: {
264 const size_t offset = sizeof(uint64_t);
266 size_t ret_size = MIN((kernel_ulong_t) tcp->u_rval,
267 offset + sizeof(flags));
269 if (syserror(tcp) || ret_size <= offset) {
274 if (umoven(tcp, data + offset, ret_size - offset,
281 printflags64(seccomp_filter_flags, flags,
282 "SECCOMP_FILTER_FLAG_???");
284 if ((kernel_ulong_t) tcp->u_rval > ret_size)
290 case PTRACE_GET_SYSCALL_INFO:
291 print_ptrace_syscall_info(tcp, data, addr);