blob: cb0125c02f2269a2c35199b2b698ac3527030733 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +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, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * 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>
Wichert Akkermanccef6372002-05-01 16:39:22 +00009 * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
10 * port by Greg Banks <gbanks@pocketpenguins.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +000011 *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000012 * All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035 */
36
37#include "defs.h"
Dmitry V. Levin6eee4e02014-12-11 19:25:02 +000038
Dmitry V. Levinc41808b2013-03-18 00:52:29 +000039#ifdef HAVE_ELF_H
40# include <elf.h>
41#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042
Dmitry V. Levin6eee4e02014-12-11 19:25:02 +000043#include "xlat/nt_descriptor_types.h"
44
Dmitry V. Levin7211dbc2015-02-28 12:20:21 +000045#include "regs.h"
Dmitry V. Levinfadf3792015-02-13 00:26:38 +000046#include "ptrace.h"
Dmitry V. Levin6eee4e02014-12-11 19:25:02 +000047#include "xlat/ptrace_cmds.h"
48#include "xlat/ptrace_setoptions_flags.h"
Dmitry V. Levin809ee3e2016-05-12 15:45:24 +000049#include "xlat/ptrace_peeksiginfo_flags.h"
Dmitry V. Levin6eee4e02014-12-11 19:25:02 +000050
Denys Vlasenko513e9c22012-03-21 14:39:22 +010051#define uoff(member) offsetof(struct user, member)
Dmitry V. Levinc6ce4fd2014-12-11 19:25:02 +000052#define XLAT_UOFF(member) { uoff(member), "offsetof(struct user, " #member ")" }
Denys Vlasenko513e9c22012-03-21 14:39:22 +010053
Dmitry V. Levin8c0ef942014-12-11 19:25:02 +000054static const struct xlat struct_user_offsets[] = {
Dmitry V. Levinfced7b02014-12-11 19:25:02 +000055#include "userent.h"
Dmitry V. Levin59452732014-02-05 02:20:51 +000056 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057};
58
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +000059static void
60print_user_offset_addr(const unsigned long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000061{
Roland McGrathd9f816f2004-09-04 03:39:20 +000062 const struct xlat *x;
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +000063
64 for (x = struct_user_offsets; x->str; ++x) {
65 if (x->val >= addr)
66 break;
67 }
68
69 if (!x->str) {
70 printaddr(addr);
71 } else if (x->val > addr) {
72 if (x == struct_user_offsets) {
73 printaddr(addr);
74 } else {
75 --x;
76 tprintf("%s + %lu",
77 x->str, addr - (unsigned long) x->val);
78 }
79 } else {
80 tprints(x->str);
81 }
82}
83
84SYS_FUNC(ptrace)
85{
Dmitry V. Levin73a8e972016-05-12 14:45:38 +000086 const unsigned long request = tcp->u_arg[0];
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +000087 const int pid = tcp->u_arg[1];
88 const unsigned long addr = tcp->u_arg[2];
89 const unsigned long data = tcp->u_arg[3];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000090
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000091 if (entering(tcp)) {
Dmitry V. Levin73a8e972016-05-12 14:45:38 +000092 /* request */
93 printxval64(ptrace_cmds, request, "PTRACE_???");
94
Dmitry V. Levin89ca4aa2016-05-12 15:03:58 +000095 if (request == PTRACE_TRACEME) {
96 /* pid, addr, and data are ignored. */
97 return RVAL_DECODED;
98 }
99
Dmitry V. Levin73a8e972016-05-12 14:45:38 +0000100 /* pid */
Dmitry V. Levin91bd1252016-05-12 15:10:41 +0000101 tprintf(", %d", pid);
Denys Vlasenkobe994972013-02-13 16:10:10 +0100102
Dmitry V. Levin73a8e972016-05-12 14:45:38 +0000103 /* addr */
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000104 switch (request) {
Dmitry V. Levin91bd1252016-05-12 15:10:41 +0000105 case PTRACE_ATTACH:
106 case PTRACE_INTERRUPT:
107 case PTRACE_KILL:
108 case PTRACE_LISTEN:
109 /* addr and data are ignored */
110 return RVAL_DECODED;
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000111 case PTRACE_PEEKUSER:
112 case PTRACE_POKEUSER:
Dmitry V. Levin91bd1252016-05-12 15:10:41 +0000113 tprints(", ");
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000114 print_user_offset_addr(addr);
115 break;
116 case PTRACE_GETREGSET:
117 case PTRACE_SETREGSET:
Dmitry V. Levin91bd1252016-05-12 15:10:41 +0000118 tprints(", ");
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000119 printxval(nt_descriptor_types, addr, "NT_???");
120 break;
Dmitry V. Levin3a5cd342016-05-12 15:38:35 +0000121 case PTRACE_GETSIGMASK:
122 case PTRACE_SETSIGMASK:
123 case PTRACE_SECCOMP_GET_FILTER:
124 tprintf(", %lu", addr);
125 break;
Dmitry V. Levin809ee3e2016-05-12 15:45:24 +0000126 case PTRACE_PEEKSIGINFO: {
127 tprints(", ");
128 struct {
129 uint64_t off;
130 uint32_t flags;
131 uint32_t nr;
132 } psi;
133 if (umove_or_printaddr(tcp, addr, &psi)) {
134 tprints(", ");
135 printaddr(data);
136 return RVAL_DECODED;
137 }
138 tprintf("{off=%" PRIu64 ", flags=", psi.off);
139 printflags(ptrace_peeksiginfo_flags, psi.flags,
140 "PTRACE_PEEKSIGINFO_???");
141 tprintf(", nr=%u}", psi.nr);
142 break;
143 }
Dmitry V. Levin5c720b02016-05-12 15:18:05 +0000144#if defined SPARC || defined SPARC64
145 case PTRACE_GETREGS:
146 case PTRACE_SETREGS:
147 case PTRACE_GETFPREGS:
148 case PTRACE_SETFPREGS:
149 tprints(", ");
150 printaddr(addr);
151 /* data is ignored */
152 return RVAL_DECODED;
153#endif
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000154 default:
Dmitry V. Levin91bd1252016-05-12 15:10:41 +0000155 tprints(", ");
Dmitry V. Levin14446eb2015-07-17 21:12:05 +0000156 printaddr(addr);
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000157 }
158
Dmitry V. Levin14446eb2015-07-17 21:12:05 +0000159 tprints(", ");
Denys Vlasenkobe994972013-02-13 16:10:10 +0100160
Dmitry V. Levin91bd1252016-05-12 15:10:41 +0000161 /* data */
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000162 switch (request) {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100163#ifndef IA64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164 case PTRACE_PEEKDATA:
165 case PTRACE_PEEKTEXT:
166 case PTRACE_PEEKUSER:
167 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100168#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000169 case PTRACE_CONT:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000170 case PTRACE_DETACH:
Dmitry V. Levincaa2bc32016-05-12 15:50:43 +0000171 case PTRACE_SYSCALL:
172#ifdef PTRACE_SINGLESTEP
173 case PTRACE_SINGLESTEP:
174#endif
175#ifdef PTRACE_SINGLEBLOCK
176 case PTRACE_SINGLEBLOCK:
177#endif
178#ifdef PTRACE_SYSEMU
179 case PTRACE_SYSEMU:
180#endif
181#ifdef PTRACE_SYSEMU_SINGLESTEP
182 case PTRACE_SYSEMU_SINGLESTEP:
183#endif
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000184 printsignal(data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185 break;
Dmitry V. Levin7c8e3302016-05-12 15:53:28 +0000186 case PTRACE_SEIZE:
Denys Vlasenkof535b542009-01-13 18:30:55 +0000187 case PTRACE_SETOPTIONS:
Dmitry V. Levin7c8e3302016-05-12 15:53:28 +0000188#ifdef PTRACE_OLDSETOPTIONS
189 case PTRACE_OLDSETOPTIONS:
190#endif
Dmitry V. Levin388aca62016-05-12 16:35:54 +0000191 printflags64(ptrace_setoptions_flags, data, "PTRACE_O_???");
Denys Vlasenkof535b542009-01-13 18:30:55 +0000192 break;
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000193 case PTRACE_SETSIGINFO:
194 printsiginfo_at(tcp, data);
Denys Vlasenkof535b542009-01-13 18:30:55 +0000195 break;
Denys Vlasenkobe994972013-02-13 16:10:10 +0100196 case PTRACE_SETREGSET:
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000197 tprint_iov(tcp, /*len:*/ 1, data, /*as string:*/ 0);
Denys Vlasenkobe994972013-02-13 16:10:10 +0100198 break;
Dmitry V. Levinfadf3792015-02-13 00:26:38 +0000199 case PTRACE_GETSIGINFO:
200 case PTRACE_GETREGSET:
201 /* Don't print anything, do it at syscall return. */
202 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203 default:
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000204 printaddr(data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205 break;
206 }
207 } else {
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000208 switch (request) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000209 case PTRACE_PEEKDATA:
210 case PTRACE_PEEKTEXT:
211 case PTRACE_PEEKUSER:
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100212#ifdef IA64
Roland McGrath1e868062007-11-19 22:11:45 +0000213 return RVAL_HEX;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100214#else
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000215 printnum_ptr(tcp, data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000216 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100217#endif
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000218 case PTRACE_GETSIGINFO:
219 printsiginfo_at(tcp, data);
Denys Vlasenkof535b542009-01-13 18:30:55 +0000220 break;
Denys Vlasenkobe994972013-02-13 16:10:10 +0100221 case PTRACE_GETREGSET:
Dmitry V. Levinccdc82a2016-04-01 00:28:33 +0000222 tprint_iov(tcp, /*len:*/ 1, data, /*as string:*/ 0);
Denys Vlasenkobe994972013-02-13 16:10:10 +0100223 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224 }
225 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226 return 0;
227}