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 | fadf379 | 2015-02-13 00:26:38 +0000 | [diff] [blame] | 45 | #include "ptrace.h" |
Dmitry V. Levin | 6eee4e0 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 46 | #include "xlat/ptrace_cmds.h" |
| 47 | #include "xlat/ptrace_setoptions_flags.h" |
| 48 | |
Dmitry V. Levin | 5503dd2 | 2015-02-13 02:12:14 +0000 | [diff] [blame] | 49 | #include "regs.h" |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 50 | |
Denys Vlasenko | 513e9c2 | 2012-03-21 14:39:22 +0100 | [diff] [blame] | 51 | #define uoff(member) offsetof(struct user, member) |
Dmitry V. Levin | c6ce4fd | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 52 | #define XLAT_UOFF(member) { uoff(member), "offsetof(struct user, " #member ")" } |
Denys Vlasenko | 513e9c2 | 2012-03-21 14:39:22 +0100 | [diff] [blame] | 53 | |
Dmitry V. Levin | 8c0ef94 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 54 | static const struct xlat struct_user_offsets[] = { |
Dmitry V. Levin | fced7b0 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 55 | #include "userent.h" |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 56 | XLAT_END |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | int |
Denys Vlasenko | c7e8371 | 2009-02-24 12:59:47 +0000 | [diff] [blame] | 60 | sys_ptrace(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 61 | { |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 62 | const struct xlat *x; |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 63 | unsigned long addr; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 64 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 65 | if (entering(tcp)) { |
Denys Vlasenko | b7a6dae | 2012-03-20 16:48:35 +0100 | [diff] [blame] | 66 | printxval(ptrace_cmds, tcp->u_arg[0], "PTRACE_???"); |
Roland McGrath | bf621d4 | 2003-01-14 09:46:21 +0000 | [diff] [blame] | 67 | tprintf(", %lu, ", tcp->u_arg[1]); |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 68 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 69 | addr = tcp->u_arg[2]; |
| 70 | if (tcp->u_arg[0] == PTRACE_PEEKUSER |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 71 | || tcp->u_arg[0] == PTRACE_POKEUSER |
| 72 | ) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 73 | for (x = struct_user_offsets; x->str; x++) { |
| 74 | if (x->val >= addr) |
| 75 | break; |
| 76 | } |
| 77 | if (!x->str) |
| 78 | tprintf("%#lx, ", addr); |
| 79 | else if (x->val > addr && x != struct_user_offsets) { |
| 80 | x--; |
| 81 | tprintf("%s + %ld, ", x->str, addr - x->val); |
| 82 | } |
| 83 | else |
| 84 | tprintf("%s, ", x->str); |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 85 | } else |
Dmitry V. Levin | c41808b | 2013-03-18 00:52:29 +0000 | [diff] [blame] | 86 | if (tcp->u_arg[0] == PTRACE_GETREGSET |
| 87 | || tcp->u_arg[0] == PTRACE_SETREGSET |
| 88 | ) { |
| 89 | printxval(nt_descriptor_types, tcp->u_arg[2], "NT_???"); |
| 90 | tprints(", "); |
| 91 | } else |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 92 | tprintf("%#lx, ", addr); |
| 93 | |
| 94 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 95 | switch (tcp->u_arg[0]) { |
Denys Vlasenko | 3e3490a | 2012-03-17 01:27:37 +0100 | [diff] [blame] | 96 | #ifndef IA64 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 97 | case PTRACE_PEEKDATA: |
| 98 | case PTRACE_PEEKTEXT: |
| 99 | case PTRACE_PEEKUSER: |
| 100 | break; |
Denys Vlasenko | 3e3490a | 2012-03-17 01:27:37 +0100 | [diff] [blame] | 101 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 102 | case PTRACE_CONT: |
| 103 | case PTRACE_SINGLESTEP: |
| 104 | case PTRACE_SYSCALL: |
| 105 | case PTRACE_DETACH: |
| 106 | printsignal(tcp->u_arg[3]); |
| 107 | break; |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 108 | case PTRACE_SETOPTIONS: |
| 109 | printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???"); |
| 110 | break; |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 111 | case PTRACE_SETSIGINFO: { |
Denys Vlasenko | d4d3ede | 2013-02-13 16:31:32 +0100 | [diff] [blame] | 112 | printsiginfo_at(tcp, tcp->u_arg[3]); |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 113 | break; |
| 114 | } |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 115 | case PTRACE_SETREGSET: |
| 116 | tprint_iov(tcp, /*len:*/ 1, tcp->u_arg[3], /*as string:*/ 0); |
| 117 | break; |
Dmitry V. Levin | fadf379 | 2015-02-13 00:26:38 +0000 | [diff] [blame] | 118 | case PTRACE_GETSIGINFO: |
| 119 | case PTRACE_GETREGSET: |
| 120 | /* Don't print anything, do it at syscall return. */ |
| 121 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 122 | default: |
| 123 | tprintf("%#lx", tcp->u_arg[3]); |
| 124 | break; |
| 125 | } |
| 126 | } else { |
| 127 | switch (tcp->u_arg[0]) { |
| 128 | case PTRACE_PEEKDATA: |
| 129 | case PTRACE_PEEKTEXT: |
| 130 | case PTRACE_PEEKUSER: |
Denys Vlasenko | 3e3490a | 2012-03-17 01:27:37 +0100 | [diff] [blame] | 131 | #ifdef IA64 |
Roland McGrath | 1e86806 | 2007-11-19 22:11:45 +0000 | [diff] [blame] | 132 | return RVAL_HEX; |
Denys Vlasenko | 3e3490a | 2012-03-17 01:27:37 +0100 | [diff] [blame] | 133 | #else |
Dmitry V. Levin | 1c603a9 | 2015-02-17 22:03:17 +0000 | [diff] [blame] | 134 | printnum_long(tcp, tcp->u_arg[3], "%#lx"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 135 | break; |
Denys Vlasenko | 3e3490a | 2012-03-17 01:27:37 +0100 | [diff] [blame] | 136 | #endif |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 137 | case PTRACE_GETSIGINFO: { |
Denys Vlasenko | d4d3ede | 2013-02-13 16:31:32 +0100 | [diff] [blame] | 138 | printsiginfo_at(tcp, tcp->u_arg[3]); |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 139 | break; |
| 140 | } |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 141 | case PTRACE_GETREGSET: |
| 142 | tprint_iov(tcp, /*len:*/ 1, tcp->u_arg[3], /*as string:*/ 0); |
| 143 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 144 | } |
| 145 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 146 | return 0; |
| 147 | } |