Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 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 Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 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> |
Wichert Akkerman | ccef637 | 2002-05-01 16:39:22 +0000 | [diff] [blame] | 9 | * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH |
| 10 | * port by Greg Banks <gbanks@pocketpenguins.com> |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 11 | * |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 12 | * 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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 35 | */ |
| 36 | |
| 37 | #include "defs.h" |
Dmitry V. Levin | 6eee4e0 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 38 | |
Dmitry V. Levin | c41808b | 2013-03-18 00:52:29 +0000 | [diff] [blame] | 39 | #ifdef HAVE_ELF_H |
| 40 | # include <elf.h> |
| 41 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 42 | |
Dmitry V. Levin | 6eee4e0 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 43 | #include "xlat/nt_descriptor_types.h" |
| 44 | |
Dmitry V. Levin | 7211dbc | 2015-02-28 12:20:21 +0000 | [diff] [blame] | 45 | #include "regs.h" |
Dmitry V. Levin | fadf379 | 2015-02-13 00:26:38 +0000 | [diff] [blame] | 46 | #include "ptrace.h" |
Dmitry V. Levin | 6eee4e0 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 47 | #include "xlat/ptrace_cmds.h" |
| 48 | #include "xlat/ptrace_setoptions_flags.h" |
| 49 | |
Denys Vlasenko | 513e9c2 | 2012-03-21 14:39:22 +0100 | [diff] [blame] | 50 | #define uoff(member) offsetof(struct user, member) |
Dmitry V. Levin | c6ce4fd | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 51 | #define XLAT_UOFF(member) { uoff(member), "offsetof(struct user, " #member ")" } |
Denys Vlasenko | 513e9c2 | 2012-03-21 14:39:22 +0100 | [diff] [blame] | 52 | |
Dmitry V. Levin | 8c0ef94 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 53 | static const struct xlat struct_user_offsets[] = { |
Dmitry V. Levin | fced7b0 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 54 | #include "userent.h" |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 55 | XLAT_END |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 58 | static void |
| 59 | print_user_offset_addr(const unsigned long addr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 60 | { |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 61 | const struct xlat *x; |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 62 | |
| 63 | for (x = struct_user_offsets; x->str; ++x) { |
| 64 | if (x->val >= addr) |
| 65 | break; |
| 66 | } |
| 67 | |
| 68 | if (!x->str) { |
| 69 | printaddr(addr); |
| 70 | } else if (x->val > addr) { |
| 71 | if (x == struct_user_offsets) { |
| 72 | printaddr(addr); |
| 73 | } else { |
| 74 | --x; |
| 75 | tprintf("%s + %lu", |
| 76 | x->str, addr - (unsigned long) x->val); |
| 77 | } |
| 78 | } else { |
| 79 | tprints(x->str); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | SYS_FUNC(ptrace) |
| 84 | { |
Dmitry V. Levin | 73a8e97 | 2016-05-12 14:45:38 +0000 | [diff] [blame] | 85 | const unsigned long request = tcp->u_arg[0]; |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 86 | const int pid = tcp->u_arg[1]; |
| 87 | const unsigned long addr = tcp->u_arg[2]; |
| 88 | const unsigned long data = tcp->u_arg[3]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 89 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 90 | if (entering(tcp)) { |
Dmitry V. Levin | 73a8e97 | 2016-05-12 14:45:38 +0000 | [diff] [blame] | 91 | /* request */ |
| 92 | printxval64(ptrace_cmds, request, "PTRACE_???"); |
| 93 | |
Dmitry V. Levin | 89ca4aa | 2016-05-12 15:03:58 +0000 | [diff] [blame^] | 94 | if (request == PTRACE_TRACEME) { |
| 95 | /* pid, addr, and data are ignored. */ |
| 96 | return RVAL_DECODED; |
| 97 | } |
| 98 | |
Dmitry V. Levin | 73a8e97 | 2016-05-12 14:45:38 +0000 | [diff] [blame] | 99 | /* pid */ |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 100 | tprintf(", %d, ", pid); |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 101 | |
Dmitry V. Levin | 73a8e97 | 2016-05-12 14:45:38 +0000 | [diff] [blame] | 102 | /* addr */ |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 103 | switch (request) { |
| 104 | case PTRACE_PEEKUSER: |
| 105 | case PTRACE_POKEUSER: |
| 106 | print_user_offset_addr(addr); |
| 107 | break; |
| 108 | case PTRACE_GETREGSET: |
| 109 | case PTRACE_SETREGSET: |
| 110 | printxval(nt_descriptor_types, addr, "NT_???"); |
| 111 | break; |
| 112 | default: |
Dmitry V. Levin | 14446eb | 2015-07-17 21:12:05 +0000 | [diff] [blame] | 113 | printaddr(addr); |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Dmitry V. Levin | 14446eb | 2015-07-17 21:12:05 +0000 | [diff] [blame] | 116 | tprints(", "); |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 117 | |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 118 | switch (request) { |
Denys Vlasenko | 3e3490a | 2012-03-17 01:27:37 +0100 | [diff] [blame] | 119 | #ifndef IA64 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 120 | case PTRACE_PEEKDATA: |
| 121 | case PTRACE_PEEKTEXT: |
| 122 | case PTRACE_PEEKUSER: |
| 123 | break; |
Denys Vlasenko | 3e3490a | 2012-03-17 01:27:37 +0100 | [diff] [blame] | 124 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 125 | case PTRACE_CONT: |
| 126 | case PTRACE_SINGLESTEP: |
| 127 | case PTRACE_SYSCALL: |
| 128 | case PTRACE_DETACH: |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 129 | printsignal(data); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 130 | break; |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 131 | case PTRACE_SETOPTIONS: |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 132 | printflags(ptrace_setoptions_flags, data, "PTRACE_O_???"); |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 133 | break; |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 134 | case PTRACE_SETSIGINFO: |
| 135 | printsiginfo_at(tcp, data); |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 136 | break; |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 137 | case PTRACE_SETREGSET: |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 138 | tprint_iov(tcp, /*len:*/ 1, data, /*as string:*/ 0); |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 139 | break; |
Dmitry V. Levin | fadf379 | 2015-02-13 00:26:38 +0000 | [diff] [blame] | 140 | case PTRACE_GETSIGINFO: |
| 141 | case PTRACE_GETREGSET: |
| 142 | /* Don't print anything, do it at syscall return. */ |
| 143 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 144 | default: |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 145 | printaddr(data); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 146 | break; |
| 147 | } |
| 148 | } else { |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 149 | switch (request) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 150 | case PTRACE_PEEKDATA: |
| 151 | case PTRACE_PEEKTEXT: |
| 152 | case PTRACE_PEEKUSER: |
Denys Vlasenko | 3e3490a | 2012-03-17 01:27:37 +0100 | [diff] [blame] | 153 | #ifdef IA64 |
Roland McGrath | 1e86806 | 2007-11-19 22:11:45 +0000 | [diff] [blame] | 154 | return RVAL_HEX; |
Denys Vlasenko | 3e3490a | 2012-03-17 01:27:37 +0100 | [diff] [blame] | 155 | #else |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 156 | printnum_ptr(tcp, data); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 157 | break; |
Denys Vlasenko | 3e3490a | 2012-03-17 01:27:37 +0100 | [diff] [blame] | 158 | #endif |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 159 | case PTRACE_GETSIGINFO: |
| 160 | printsiginfo_at(tcp, data); |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 161 | break; |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 162 | case PTRACE_GETREGSET: |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 163 | tprint_iov(tcp, /*len:*/ 1, data, /*as string:*/ 0); |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 164 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 165 | } |
| 166 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 167 | return 0; |
| 168 | } |