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 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. The name of the author may not be used to endorse or promote products
24 * derived from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 #include "xlat/nt_descriptor_types.h"
48 #include "xlat/ptrace_cmds.h"
49 #include "xlat/ptrace_setoptions_flags.h"
50 #include "xlat/ptrace_peeksiginfo_flags.h"
52 #define uoff(member) offsetof(struct user, member)
53 #define XLAT_UOFF(member) { uoff(member), "offsetof(struct user, " #member ")" }
55 static const struct xlat struct_user_offsets[] = {
61 print_user_offset_addr(const kernel_ulong_t addr)
65 for (x = struct_user_offsets; x->str; ++x) {
72 } else if (x->val > addr) {
73 if (x == struct_user_offsets) {
77 tprintf("%s + %" PRI_klu,
78 x->str, addr - (kernel_ulong_t) x->val);
87 const kernel_ulong_t request = tcp->u_arg[0];
88 const int pid = tcp->u_arg[1];
89 const kernel_ulong_t addr = tcp->u_arg[2];
90 const kernel_ulong_t data = tcp->u_arg[3];
94 printxval64(ptrace_cmds, request, "PTRACE_???");
96 if (request == PTRACE_TRACEME) {
97 /* pid, addr, and data are ignored. */
102 tprintf(", %d", pid);
107 case PTRACE_INTERRUPT:
110 /* addr and data are ignored */
112 case PTRACE_PEEKUSER:
113 case PTRACE_POKEUSER:
115 print_user_offset_addr(addr);
117 case PTRACE_GETREGSET:
118 case PTRACE_SETREGSET:
120 printxval(nt_descriptor_types, addr, "NT_???");
122 case PTRACE_GETSIGMASK:
123 case PTRACE_SETSIGMASK:
124 case PTRACE_SECCOMP_GET_FILTER:
125 case PTRACE_SECCOMP_GET_METADATA:
126 tprintf(", %" PRI_klu, addr);
128 case PTRACE_PEEKSIGINFO: {
135 if (umove_or_printaddr(tcp, addr, &psi)) {
140 tprintf("{off=%" PRIu64 ", flags=", psi.off);
141 printflags(ptrace_peeksiginfo_flags, psi.flags,
142 "PTRACE_PEEKSIGINFO_???");
143 tprintf(", nr=%u}", psi.nr);
151 # if defined IA64 || defined SPARC || defined SPARC64
154 case PTRACE_PEEKDATA:
155 case PTRACE_PEEKTEXT:
156 case PTRACE_PEEKUSER:
157 /* data is ignored */
158 return RVAL_DECODED | RVAL_HEX;
160 # if defined SPARC || defined SPARC64
163 case PTRACE_GETFPREGS:
164 case PTRACE_SETFPREGS:
165 /* data is ignored */
167 # endif /* SPARC || SPARC64 */
169 # endif /* IA64 || SPARC || SPARC64 */
178 #ifdef PTRACE_SINGLESTEP
179 case PTRACE_SINGLESTEP:
181 #ifdef PTRACE_SINGLEBLOCK
182 case PTRACE_SINGLEBLOCK:
187 #ifdef PTRACE_SYSEMU_SINGLESTEP
188 case PTRACE_SYSEMU_SINGLESTEP:
193 case PTRACE_SETOPTIONS:
194 #ifdef PTRACE_OLDSETOPTIONS
195 case PTRACE_OLDSETOPTIONS:
197 printflags64(ptrace_setoptions_flags, data, "PTRACE_O_???");
199 case PTRACE_SETSIGINFO:
200 printsiginfo_at(tcp, data);
202 case PTRACE_SETSIGMASK:
203 print_sigset_addr_len(tcp, data, addr);
205 case PTRACE_SETREGSET:
206 tprint_iov(tcp, /*len:*/ 1, data, IOV_DECODE_ADDR);
208 case PTRACE_SECCOMP_GET_METADATA:
211 if (addr < sizeof(filter_off) ||
212 umove(tcp, data, &filter_off)) {
217 tprintf("{filter_off=%" PRIu64, filter_off);
224 case PTRACE_PEEKDATA:
225 case PTRACE_PEEKTEXT:
226 case PTRACE_PEEKUSER:
228 case PTRACE_GETEVENTMSG:
229 case PTRACE_GETREGSET:
230 case PTRACE_GETSIGINFO:
231 case PTRACE_GETSIGMASK:
232 case PTRACE_PEEKSIGINFO:
233 case PTRACE_SECCOMP_GET_FILTER:
235 /* print data on exiting syscall */
238 ATTRIBUTE_FALLTHROUGH;
248 case PTRACE_PEEKDATA:
249 case PTRACE_PEEKTEXT:
250 case PTRACE_PEEKUSER:
251 printnum_ptr(tcp, data);
254 case PTRACE_GETEVENTMSG:
255 printnum_ulong(tcp, data);
257 case PTRACE_GETREGSET:
258 tprint_iov(tcp, /*len:*/ 1, data, IOV_DECODE_ADDR);
260 case PTRACE_GETSIGINFO:
261 printsiginfo_at(tcp, data);
263 case PTRACE_GETSIGMASK:
264 print_sigset_addr_len(tcp, data, addr);
266 case PTRACE_PEEKSIGINFO:
267 print_siginfo_array(tcp, data, tcp->u_rval);
269 case PTRACE_SECCOMP_GET_FILTER:
270 print_seccomp_fprog(tcp, data, tcp->u_rval);
272 case PTRACE_SECCOMP_GET_METADATA: {
273 const size_t offset = sizeof(uint64_t);
275 size_t ret_size = MIN((kernel_ulong_t) tcp->u_rval,
276 offset + sizeof(flags));
278 if (syserror(tcp) || ret_size <= offset) {
283 if (umoven(tcp, data + offset, ret_size - offset,
290 printflags64(seccomp_filter_flags, flags,
291 "SECCOMP_FILTER_FLAG_???");
293 if ((kernel_ulong_t) tcp->u_rval > ret_size)