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 | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
| 18 | * documentation and/or other materials provided with the distribution. |
| 19 | * 3. The name of the author may not be used to endorse or promote products |
| 20 | * derived from this software without specific prior written permission. |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 25 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 32 | */ |
| 33 | |
| 34 | #include "defs.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 35 | #include <sys/user.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | #include <sys/param.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 37 | |
Wichert Akkerman | 15dea97 | 1999-10-06 13:06:34 +0000 | [diff] [blame] | 38 | #ifdef HAVE_SYS_REG_H |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 39 | # include <sys/reg.h> |
| 40 | # ifndef PTRACE_PEEKUSR |
| 41 | # define PTRACE_PEEKUSR PTRACE_PEEKUSER |
| 42 | # endif |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 43 | #elif defined(HAVE_LINUX_PTRACE_H) |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 44 | # undef PTRACE_SYSCALL |
Roland McGrath | ce9f074 | 2004-03-01 21:29:22 +0000 | [diff] [blame] | 45 | # ifdef HAVE_STRUCT_IA64_FPREG |
| 46 | # define ia64_fpreg XXX_ia64_fpreg |
| 47 | # endif |
| 48 | # ifdef HAVE_STRUCT_PT_ALL_USER_REGS |
| 49 | # define pt_all_user_regs XXX_pt_all_user_regs |
| 50 | # endif |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 51 | # include <linux/ptrace.h> |
Roland McGrath | ce9f074 | 2004-03-01 21:29:22 +0000 | [diff] [blame] | 52 | # undef ia64_fpreg |
| 53 | # undef pt_all_user_regs |
Wichert Akkerman | 15dea97 | 1999-10-06 13:06:34 +0000 | [diff] [blame] | 54 | #endif |
| 55 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 56 | #if defined(SPARC64) |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 57 | # undef PTRACE_GETREGS |
| 58 | # define PTRACE_GETREGS PTRACE_GETREGS64 |
| 59 | # undef PTRACE_SETREGS |
| 60 | # define PTRACE_SETREGS PTRACE_SETREGS64 |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 61 | #endif |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 62 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 63 | #if defined(IA64) |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 64 | # include <asm/ptrace_offsets.h> |
| 65 | # include <asm/rse.h> |
| 66 | #endif |
| 67 | |
Steve McIntyre | d8d3bd3 | 2012-10-24 17:58:16 +0100 | [diff] [blame] | 68 | #if defined(AARCH64) |
| 69 | # include <asm/ptrace.h> |
| 70 | # include <sys/uio.h> |
| 71 | # include <elf.h> |
| 72 | #endif |
| 73 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 74 | #ifndef ERESTARTSYS |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 75 | # define ERESTARTSYS 512 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 76 | #endif |
Denys Vlasenko | 3da9693 | 2012-03-17 03:17:15 +0100 | [diff] [blame] | 77 | #ifndef ERESTARTNOINTR |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 78 | # define ERESTARTNOINTR 513 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 79 | #endif |
Denys Vlasenko | 3da9693 | 2012-03-17 03:17:15 +0100 | [diff] [blame] | 80 | #ifndef ERESTARTNOHAND |
| 81 | # define ERESTARTNOHAND 514 /* restart if no handler */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 82 | #endif |
Denys Vlasenko | 3da9693 | 2012-03-17 03:17:15 +0100 | [diff] [blame] | 83 | #ifndef ERESTART_RESTARTBLOCK |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 84 | # define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */ |
Roland McGrath | 9c555e7 | 2003-07-09 09:47:59 +0000 | [diff] [blame] | 85 | #endif |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 86 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 87 | #ifndef NSIG |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 88 | # warning: NSIG is not defined, using 32 |
| 89 | # define NSIG 32 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 90 | #endif |
| 91 | #ifdef ARM |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 92 | /* Ugh. Is this really correct? ARM has no RT signals?! */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 93 | # undef NSIG |
| 94 | # define NSIG 32 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 95 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 96 | |
| 97 | #include "syscall.h" |
| 98 | |
| 99 | /* Define these shorthand notations to simplify the syscallent files. */ |
Roland McGrath | 2fe7b13 | 2005-07-05 03:25:35 +0000 | [diff] [blame] | 100 | #define TD TRACE_DESC |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 101 | #define TF TRACE_FILE |
| 102 | #define TI TRACE_IPC |
| 103 | #define TN TRACE_NETWORK |
| 104 | #define TP TRACE_PROCESS |
| 105 | #define TS TRACE_SIGNAL |
Namhyung Kim | 9679296 | 2012-10-24 11:41:57 +0900 | [diff] [blame] | 106 | #define TM TRACE_MEMORY |
Dmitry V. Levin | 50a218d | 2011-01-18 17:36:20 +0000 | [diff] [blame] | 107 | #define NF SYSCALL_NEVER_FAILS |
Denys Vlasenko | ac1ce77 | 2011-08-23 13:24:17 +0200 | [diff] [blame] | 108 | #define MA MAX_ARGS |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 109 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 110 | static const struct sysent sysent0[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 111 | #include "syscallent.h" |
| 112 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 113 | |
| 114 | #if SUPPORTED_PERSONALITIES >= 2 |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 115 | static const struct sysent sysent1[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 116 | # include "syscallent1.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 117 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 118 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 119 | |
| 120 | #if SUPPORTED_PERSONALITIES >= 3 |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 121 | static const struct sysent sysent2[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 122 | # include "syscallent2.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 123 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 124 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 125 | |
| 126 | /* Now undef them since short defines cause wicked namespace pollution. */ |
Roland McGrath | 2fe7b13 | 2005-07-05 03:25:35 +0000 | [diff] [blame] | 127 | #undef TD |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 128 | #undef TF |
| 129 | #undef TI |
| 130 | #undef TN |
| 131 | #undef TP |
| 132 | #undef TS |
Namhyung Kim | 9679296 | 2012-10-24 11:41:57 +0900 | [diff] [blame] | 133 | #undef TM |
Dmitry V. Levin | 50a218d | 2011-01-18 17:36:20 +0000 | [diff] [blame] | 134 | #undef NF |
Denys Vlasenko | ac1ce77 | 2011-08-23 13:24:17 +0200 | [diff] [blame] | 135 | #undef MA |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 136 | |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 137 | /* |
| 138 | * `ioctlent.h' may be generated from `ioctlent.raw' by the auxiliary |
| 139 | * program `ioctlsort', such that the list is sorted by the `code' field. |
| 140 | * This has the side-effect of resolving the _IO.. macros into |
| 141 | * plain integers, eliminating the need to include here everything |
| 142 | * in "/usr/include". |
| 143 | */ |
| 144 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 145 | static const char *const errnoent0[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 146 | #include "errnoent.h" |
| 147 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 148 | static const char *const signalent0[] = { |
| 149 | #include "signalent.h" |
| 150 | }; |
| 151 | static const struct ioctlent ioctlent0[] = { |
| 152 | #include "ioctlent.h" |
| 153 | }; |
| 154 | enum { nsyscalls0 = ARRAY_SIZE(sysent0) }; |
| 155 | enum { nerrnos0 = ARRAY_SIZE(errnoent0) }; |
| 156 | enum { nsignals0 = ARRAY_SIZE(signalent0) }; |
| 157 | enum { nioctlents0 = ARRAY_SIZE(ioctlent0) }; |
| 158 | int qual_flags0[MAX_QUALS]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 159 | |
| 160 | #if SUPPORTED_PERSONALITIES >= 2 |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 161 | static const char *const errnoent1[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 162 | # include "errnoent1.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 163 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 164 | static const char *const signalent1[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 165 | # include "signalent1.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 166 | }; |
| 167 | static const struct ioctlent ioctlent1[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 168 | # include "ioctlent1.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 169 | }; |
| 170 | enum { nsyscalls1 = ARRAY_SIZE(sysent1) }; |
| 171 | enum { nerrnos1 = ARRAY_SIZE(errnoent1) }; |
| 172 | enum { nsignals1 = ARRAY_SIZE(signalent1) }; |
| 173 | enum { nioctlents1 = ARRAY_SIZE(ioctlent1) }; |
| 174 | int qual_flags1[MAX_QUALS]; |
| 175 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 176 | |
| 177 | #if SUPPORTED_PERSONALITIES >= 3 |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 178 | static const char *const errnoent2[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 179 | # include "errnoent2.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 180 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 181 | static const char *const signalent2[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 182 | # include "signalent2.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 183 | }; |
| 184 | static const struct ioctlent ioctlent2[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 185 | # include "ioctlent2.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 186 | }; |
| 187 | enum { nsyscalls2 = ARRAY_SIZE(sysent2) }; |
| 188 | enum { nerrnos2 = ARRAY_SIZE(errnoent2) }; |
| 189 | enum { nsignals2 = ARRAY_SIZE(signalent2) }; |
| 190 | enum { nioctlents2 = ARRAY_SIZE(ioctlent2) }; |
| 191 | int qual_flags2[MAX_QUALS]; |
| 192 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 193 | |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 194 | const struct sysent *sysent = sysent0; |
| 195 | const char *const *errnoent = errnoent0; |
| 196 | const char *const *signalent = signalent0; |
| 197 | const struct ioctlent *ioctlent = ioctlent0; |
| 198 | unsigned nsyscalls = nsyscalls0; |
| 199 | unsigned nerrnos = nerrnos0; |
| 200 | unsigned nsignals = nsignals0; |
| 201 | unsigned nioctlents = nioctlents0; |
| 202 | int *qual_flags = qual_flags0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 203 | |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 204 | #if SUPPORTED_PERSONALITIES > 1 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 205 | int current_personality; |
| 206 | |
Roland McGrath | 4b2dcca | 2006-01-12 10:18:53 +0000 | [diff] [blame] | 207 | const int personality_wordsize[SUPPORTED_PERSONALITIES] = { |
| 208 | PERSONALITY0_WORDSIZE, |
Roland McGrath | 4b2dcca | 2006-01-12 10:18:53 +0000 | [diff] [blame] | 209 | PERSONALITY1_WORDSIZE, |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 210 | # if SUPPORTED_PERSONALITIES > 2 |
Roland McGrath | 4b2dcca | 2006-01-12 10:18:53 +0000 | [diff] [blame] | 211 | PERSONALITY2_WORDSIZE, |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 212 | # endif |
Denys Vlasenko | 5c774b2 | 2011-08-20 01:50:09 +0200 | [diff] [blame] | 213 | }; |
Roland McGrath | 4b2dcca | 2006-01-12 10:18:53 +0000 | [diff] [blame] | 214 | |
Denys Vlasenko | 5c774b2 | 2011-08-20 01:50:09 +0200 | [diff] [blame] | 215 | void |
Dmitry V. Levin | 3abe8b2 | 2006-12-20 22:37:21 +0000 | [diff] [blame] | 216 | set_personality(int personality) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 217 | { |
| 218 | switch (personality) { |
| 219 | case 0: |
| 220 | errnoent = errnoent0; |
| 221 | nerrnos = nerrnos0; |
| 222 | sysent = sysent0; |
| 223 | nsyscalls = nsyscalls0; |
| 224 | ioctlent = ioctlent0; |
| 225 | nioctlents = nioctlents0; |
| 226 | signalent = signalent0; |
| 227 | nsignals = nsignals0; |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 228 | qual_flags = qual_flags0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 229 | break; |
| 230 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 231 | case 1: |
| 232 | errnoent = errnoent1; |
| 233 | nerrnos = nerrnos1; |
| 234 | sysent = sysent1; |
| 235 | nsyscalls = nsyscalls1; |
| 236 | ioctlent = ioctlent1; |
| 237 | nioctlents = nioctlents1; |
| 238 | signalent = signalent1; |
| 239 | nsignals = nsignals1; |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 240 | qual_flags = qual_flags1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 241 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 242 | |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 243 | # if SUPPORTED_PERSONALITIES >= 3 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 244 | case 2: |
| 245 | errnoent = errnoent2; |
| 246 | nerrnos = nerrnos2; |
| 247 | sysent = sysent2; |
| 248 | nsyscalls = nsyscalls2; |
| 249 | ioctlent = ioctlent2; |
| 250 | nioctlents = nioctlents2; |
| 251 | signalent = signalent2; |
| 252 | nsignals = nsignals2; |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 253 | qual_flags = qual_flags2; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 254 | break; |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 255 | # endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | current_personality = personality; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 261 | static void |
| 262 | update_personality(struct tcb *tcp, int personality) |
| 263 | { |
| 264 | if (personality == current_personality) |
| 265 | return; |
| 266 | set_personality(personality); |
| 267 | |
| 268 | if (personality == tcp->currpers) |
| 269 | return; |
| 270 | tcp->currpers = personality; |
| 271 | |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 272 | # if defined(POWERPC64) |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 273 | if (!qflag) { |
| 274 | static const char *const names[] = {"64 bit", "32 bit"}; |
| 275 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 276 | tcp->pid, names[personality]); |
| 277 | } |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 278 | # elif defined(X86_64) |
| 279 | if (!qflag) { |
| 280 | static const char *const names[] = {"64 bit", "32 bit", "x32"}; |
| 281 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 282 | tcp->pid, names[personality]); |
| 283 | } |
H.J. Lu | 085e428 | 2012-04-17 11:05:04 -0700 | [diff] [blame] | 284 | # elif defined(X32) |
| 285 | if (!qflag) { |
| 286 | static const char *const names[] = {"x32", "32 bit"}; |
| 287 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 288 | tcp->pid, names[personality]); |
| 289 | } |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 290 | # elif defined(AARCH64) |
| 291 | if (!qflag) { |
| 292 | static const char *const names[] = {"32-bit ARM", "AArch64"}; |
| 293 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 294 | tcp->pid, names[personality]); |
| 295 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 296 | # endif |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 297 | } |
| 298 | #endif |
Roland McGrath | e10e62a | 2004-09-04 04:20:43 +0000 | [diff] [blame] | 299 | |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 300 | static int qual_syscall(), qual_signal(), qual_fault(), qual_desc(); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 301 | |
Roland McGrath | e10e62a | 2004-09-04 04:20:43 +0000 | [diff] [blame] | 302 | static const struct qual_options { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 303 | int bitflag; |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 304 | const char *option_name; |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 305 | int (*qualify)(const char *, int, int); |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 306 | const char *argument_name; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 307 | } qual_options[] = { |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 308 | { QUAL_TRACE, "trace", qual_syscall, "system call" }, |
| 309 | { QUAL_TRACE, "t", qual_syscall, "system call" }, |
| 310 | { QUAL_ABBREV, "abbrev", qual_syscall, "system call" }, |
| 311 | { QUAL_ABBREV, "a", qual_syscall, "system call" }, |
| 312 | { QUAL_VERBOSE, "verbose", qual_syscall, "system call" }, |
| 313 | { QUAL_VERBOSE, "v", qual_syscall, "system call" }, |
| 314 | { QUAL_RAW, "raw", qual_syscall, "system call" }, |
| 315 | { QUAL_RAW, "x", qual_syscall, "system call" }, |
| 316 | { QUAL_SIGNAL, "signal", qual_signal, "signal" }, |
| 317 | { QUAL_SIGNAL, "signals", qual_signal, "signal" }, |
| 318 | { QUAL_SIGNAL, "s", qual_signal, "signal" }, |
| 319 | { QUAL_FAULT, "fault", qual_fault, "fault" }, |
| 320 | { QUAL_FAULT, "faults", qual_fault, "fault" }, |
| 321 | { QUAL_FAULT, "m", qual_fault, "fault" }, |
| 322 | { QUAL_READ, "read", qual_desc, "descriptor" }, |
| 323 | { QUAL_READ, "reads", qual_desc, "descriptor" }, |
| 324 | { QUAL_READ, "r", qual_desc, "descriptor" }, |
| 325 | { QUAL_WRITE, "write", qual_desc, "descriptor" }, |
| 326 | { QUAL_WRITE, "writes", qual_desc, "descriptor" }, |
| 327 | { QUAL_WRITE, "w", qual_desc, "descriptor" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 328 | { 0, NULL, NULL, NULL }, |
| 329 | }; |
| 330 | |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 331 | static void |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 332 | qualify_one(int n, int bitflag, int not, int pers) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 333 | { |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 334 | if (pers == 0 || pers < 0) { |
| 335 | if (not) |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 336 | qual_flags0[n] &= ~bitflag; |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 337 | else |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 338 | qual_flags0[n] |= bitflag; |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | #if SUPPORTED_PERSONALITIES >= 2 |
| 342 | if (pers == 1 || pers < 0) { |
| 343 | if (not) |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 344 | qual_flags1[n] &= ~bitflag; |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 345 | else |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 346 | qual_flags1[n] |= bitflag; |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 347 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 348 | #endif |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 349 | |
| 350 | #if SUPPORTED_PERSONALITIES >= 3 |
| 351 | if (pers == 2 || pers < 0) { |
| 352 | if (not) |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 353 | qual_flags2[n] &= ~bitflag; |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 354 | else |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 355 | qual_flags2[n] |= bitflag; |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 356 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 357 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | static int |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 361 | qual_syscall(const char *s, int bitflag, int not) |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 362 | { |
| 363 | int i; |
Roland McGrath | fe6b352 | 2005-02-02 04:40:11 +0000 | [diff] [blame] | 364 | int rc = -1; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 365 | |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 366 | if (*s >= '0' && *s <= '9') { |
Dmitry V. Levin | ccee169 | 2012-03-25 21:49:48 +0000 | [diff] [blame] | 367 | int i = string_to_uint(s); |
Dmitry V. Levin | c18c703 | 2007-08-22 21:43:30 +0000 | [diff] [blame] | 368 | if (i < 0 || i >= MAX_QUALS) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 369 | return -1; |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 370 | qualify_one(i, bitflag, not, -1); |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 371 | return 0; |
Roland McGrath | 48a035f | 2006-01-12 09:45:56 +0000 | [diff] [blame] | 372 | } |
Dmitry V. Levin | c18c703 | 2007-08-22 21:43:30 +0000 | [diff] [blame] | 373 | for (i = 0; i < nsyscalls0; i++) |
Dmitry V. Levin | 4372cc9 | 2012-03-26 14:14:50 +0000 | [diff] [blame] | 374 | if (sysent0[i].sys_name && |
| 375 | strcmp(s, sysent0[i].sys_name) == 0) { |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 376 | qualify_one(i, bitflag, not, 0); |
Roland McGrath | fe6b352 | 2005-02-02 04:40:11 +0000 | [diff] [blame] | 377 | rc = 0; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 378 | } |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 379 | |
| 380 | #if SUPPORTED_PERSONALITIES >= 2 |
Dmitry V. Levin | c18c703 | 2007-08-22 21:43:30 +0000 | [diff] [blame] | 381 | for (i = 0; i < nsyscalls1; i++) |
Dmitry V. Levin | 4372cc9 | 2012-03-26 14:14:50 +0000 | [diff] [blame] | 382 | if (sysent1[i].sys_name && |
| 383 | strcmp(s, sysent1[i].sys_name) == 0) { |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 384 | qualify_one(i, bitflag, not, 1); |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 385 | rc = 0; |
| 386 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 387 | #endif |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 388 | |
| 389 | #if SUPPORTED_PERSONALITIES >= 3 |
Dmitry V. Levin | c18c703 | 2007-08-22 21:43:30 +0000 | [diff] [blame] | 390 | for (i = 0; i < nsyscalls2; i++) |
Dmitry V. Levin | 4372cc9 | 2012-03-26 14:14:50 +0000 | [diff] [blame] | 391 | if (sysent2[i].sys_name && |
| 392 | strcmp(s, sysent2[i].sys_name) == 0) { |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 393 | qualify_one(i, bitflag, not, 2); |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 394 | rc = 0; |
| 395 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 396 | #endif |
Dmitry V. Levin | c18c703 | 2007-08-22 21:43:30 +0000 | [diff] [blame] | 397 | |
Roland McGrath | fe6b352 | 2005-02-02 04:40:11 +0000 | [diff] [blame] | 398 | return rc; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | static int |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 402 | qual_signal(const char *s, int bitflag, int not) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 403 | { |
| 404 | int i; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 405 | |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 406 | if (*s >= '0' && *s <= '9') { |
Dmitry V. Levin | ccee169 | 2012-03-25 21:49:48 +0000 | [diff] [blame] | 407 | int signo = string_to_uint(s); |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 408 | if (signo < 0 || signo >= MAX_QUALS) |
| 409 | return -1; |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 410 | qualify_one(signo, bitflag, not, -1); |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 411 | return 0; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 412 | } |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 413 | if (strncasecmp(s, "SIG", 3) == 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 414 | s += 3; |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 415 | for (i = 0; i <= NSIG; i++) { |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 416 | if (strcasecmp(s, signame(i) + 3) == 0) { |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 417 | qualify_one(i, bitflag, not, -1); |
Roland McGrath | 76421df | 2005-02-02 03:51:18 +0000 | [diff] [blame] | 418 | return 0; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 419 | } |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 420 | } |
Roland McGrath | 76421df | 2005-02-02 03:51:18 +0000 | [diff] [blame] | 421 | return -1; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | static int |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 425 | qual_fault(const char *s, int bitflag, int not) |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 426 | { |
| 427 | return -1; |
| 428 | } |
| 429 | |
| 430 | static int |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 431 | qual_desc(const char *s, int bitflag, int not) |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 432 | { |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 433 | if (*s >= '0' && *s <= '9') { |
Dmitry V. Levin | ccee169 | 2012-03-25 21:49:48 +0000 | [diff] [blame] | 434 | int desc = string_to_uint(s); |
Roland McGrath | fe6b352 | 2005-02-02 04:40:11 +0000 | [diff] [blame] | 435 | if (desc < 0 || desc >= MAX_QUALS) |
| 436 | return -1; |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 437 | qualify_one(desc, bitflag, not, -1); |
Roland McGrath | 2b61902 | 2003-04-10 18:58:20 +0000 | [diff] [blame] | 438 | return 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 439 | } |
| 440 | return -1; |
| 441 | } |
| 442 | |
| 443 | static int |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 444 | lookup_class(const char *s) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 445 | { |
| 446 | if (strcmp(s, "file") == 0) |
| 447 | return TRACE_FILE; |
| 448 | if (strcmp(s, "ipc") == 0) |
| 449 | return TRACE_IPC; |
| 450 | if (strcmp(s, "network") == 0) |
| 451 | return TRACE_NETWORK; |
| 452 | if (strcmp(s, "process") == 0) |
| 453 | return TRACE_PROCESS; |
| 454 | if (strcmp(s, "signal") == 0) |
| 455 | return TRACE_SIGNAL; |
Roland McGrath | 2fe7b13 | 2005-07-05 03:25:35 +0000 | [diff] [blame] | 456 | if (strcmp(s, "desc") == 0) |
| 457 | return TRACE_DESC; |
Namhyung Kim | 9679296 | 2012-10-24 11:41:57 +0900 | [diff] [blame] | 458 | if (strcmp(s, "memory") == 0) |
| 459 | return TRACE_MEMORY; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 460 | return -1; |
| 461 | } |
| 462 | |
| 463 | void |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 464 | qualify(const char *s) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 465 | { |
Roland McGrath | e10e62a | 2004-09-04 04:20:43 +0000 | [diff] [blame] | 466 | const struct qual_options *opt; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 467 | int not; |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 468 | char *copy; |
| 469 | const char *p; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 470 | int i, n; |
| 471 | |
| 472 | opt = &qual_options[0]; |
| 473 | for (i = 0; (p = qual_options[i].option_name); i++) { |
| 474 | n = strlen(p); |
| 475 | if (strncmp(s, p, n) == 0 && s[n] == '=') { |
| 476 | opt = &qual_options[i]; |
| 477 | s += n + 1; |
| 478 | break; |
| 479 | } |
| 480 | } |
| 481 | not = 0; |
| 482 | if (*s == '!') { |
| 483 | not = 1; |
| 484 | s++; |
| 485 | } |
| 486 | if (strcmp(s, "none") == 0) { |
| 487 | not = 1 - not; |
| 488 | s = "all"; |
| 489 | } |
| 490 | if (strcmp(s, "all") == 0) { |
| 491 | for (i = 0; i < MAX_QUALS; i++) { |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 492 | qualify_one(i, opt->bitflag, not, -1); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 493 | } |
| 494 | return; |
| 495 | } |
| 496 | for (i = 0; i < MAX_QUALS; i++) { |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 497 | qualify_one(i, opt->bitflag, !not, -1); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 498 | } |
Denys Vlasenko | 5d64581 | 2011-08-20 12:48:18 +0200 | [diff] [blame] | 499 | copy = strdup(s); |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 500 | if (!copy) |
| 501 | die_out_of_memory(); |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 502 | for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 503 | if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) { |
Dmitry V. Levin | c18c703 | 2007-08-22 21:43:30 +0000 | [diff] [blame] | 504 | for (i = 0; i < nsyscalls0; i++) |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 505 | if (sysent0[i].sys_flags & n) |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 506 | qualify_one(i, opt->bitflag, not, 0); |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 507 | |
| 508 | #if SUPPORTED_PERSONALITIES >= 2 |
Dmitry V. Levin | c18c703 | 2007-08-22 21:43:30 +0000 | [diff] [blame] | 509 | for (i = 0; i < nsyscalls1; i++) |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 510 | if (sysent1[i].sys_flags & n) |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 511 | qualify_one(i, opt->bitflag, not, 1); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 512 | #endif |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 513 | |
| 514 | #if SUPPORTED_PERSONALITIES >= 3 |
Dmitry V. Levin | c18c703 | 2007-08-22 21:43:30 +0000 | [diff] [blame] | 515 | for (i = 0; i < nsyscalls2; i++) |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 516 | if (sysent2[i].sys_flags & n) |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 517 | qualify_one(i, opt->bitflag, not, 2); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 518 | #endif |
Dmitry V. Levin | c18c703 | 2007-08-22 21:43:30 +0000 | [diff] [blame] | 519 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 520 | continue; |
| 521 | } |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 522 | if (opt->qualify(p, opt->bitflag, not)) { |
Denys Vlasenko | 4c65c44 | 2012-03-08 11:54:10 +0100 | [diff] [blame] | 523 | error_msg_and_die("invalid %s '%s'", |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 524 | opt->argument_name, p); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 525 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 526 | } |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 527 | free(copy); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 528 | return; |
| 529 | } |
| 530 | |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 531 | #ifdef SYS_socket_subcall |
Roland McGrath | a4d4853 | 2005-06-08 20:45:28 +0000 | [diff] [blame] | 532 | static void |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 533 | decode_socket_subcall(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 534 | { |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 535 | unsigned long addr; |
| 536 | unsigned int i, size; |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 537 | |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 538 | if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_socket_nsubcalls) |
| 539 | return; |
| 540 | |
| 541 | tcp->scno = SYS_socket_subcall + tcp->u_arg[0]; |
| 542 | addr = tcp->u_arg[1]; |
| 543 | tcp->u_nargs = sysent[tcp->scno].nargs; |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 544 | size = current_wordsize; |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 545 | for (i = 0; i < tcp->u_nargs; ++i) { |
| 546 | if (size == sizeof(int)) { |
| 547 | unsigned int arg; |
| 548 | if (umove(tcp, addr, &arg) < 0) |
| 549 | arg = 0; |
| 550 | tcp->u_arg[i] = arg; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 551 | } |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 552 | else { |
| 553 | unsigned long arg; |
| 554 | if (umove(tcp, addr, &arg) < 0) |
| 555 | arg = 0; |
| 556 | tcp->u_arg[i] = arg; |
| 557 | } |
| 558 | addr += size; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 559 | } |
| 560 | } |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 561 | #endif |
Mike Frysinger | 3362e89 | 2012-03-15 01:09:19 -0400 | [diff] [blame] | 562 | |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 563 | #ifdef SYS_ipc_subcall |
| 564 | static void |
| 565 | decode_ipc_subcall(struct tcb *tcp) |
| 566 | { |
| 567 | unsigned int i; |
| 568 | |
| 569 | if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_ipc_nsubcalls) |
| 570 | return; |
| 571 | |
| 572 | tcp->scno = SYS_ipc_subcall + tcp->u_arg[0]; |
| 573 | tcp->u_nargs = sysent[tcp->scno].nargs; |
| 574 | for (i = 0; i < tcp->u_nargs; i++) |
| 575 | tcp->u_arg[i] = tcp->u_arg[i + 1]; |
| 576 | } |
| 577 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 578 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 579 | int |
| 580 | printargs(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 581 | { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 582 | if (entering(tcp)) { |
| 583 | int i; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 584 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 585 | for (i = 0; i < tcp->u_nargs; i++) |
| 586 | tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]); |
| 587 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 588 | return 0; |
| 589 | } |
| 590 | |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 591 | int |
| 592 | printargs_lu(struct tcb *tcp) |
| 593 | { |
| 594 | if (entering(tcp)) { |
| 595 | int i; |
| 596 | |
| 597 | for (i = 0; i < tcp->u_nargs; i++) |
| 598 | tprintf("%s%lu", i ? ", " : "", tcp->u_arg[i]); |
| 599 | } |
| 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | int |
| 604 | printargs_ld(struct tcb *tcp) |
| 605 | { |
| 606 | if (entering(tcp)) { |
| 607 | int i; |
| 608 | |
| 609 | for (i = 0; i < tcp->u_nargs; i++) |
| 610 | tprintf("%s%ld", i ? ", " : "", tcp->u_arg[i]); |
| 611 | } |
| 612 | return 0; |
| 613 | } |
| 614 | |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame^] | 615 | #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 616 | long |
| 617 | getrval2(struct tcb *tcp) |
| 618 | { |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame^] | 619 | long val; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 620 | |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame^] | 621 | # if defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 622 | val = regs.u_regs[U_REG_O1]; |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame^] | 623 | # elif defined(SH) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 624 | if (upeek(tcp, 4*(REG_REG0+1), &val) < 0) |
| 625 | return -1; |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame^] | 626 | # elif defined(IA64) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 627 | if (upeek(tcp, PT_R9, &val) < 0) |
| 628 | return -1; |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame^] | 629 | # endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 630 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 631 | return val; |
| 632 | } |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame^] | 633 | #endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 634 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 635 | int |
| 636 | is_restart_error(struct tcb *tcp) |
| 637 | { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 638 | switch (tcp->u_error) { |
| 639 | case ERESTARTSYS: |
| 640 | case ERESTARTNOINTR: |
| 641 | case ERESTARTNOHAND: |
| 642 | case ERESTART_RESTARTBLOCK: |
| 643 | return 1; |
| 644 | default: |
| 645 | break; |
| 646 | } |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 647 | return 0; |
| 648 | } |
| 649 | |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 650 | #if defined(I386) |
Denys Vlasenko | b11322f | 2012-01-10 16:40:35 +0100 | [diff] [blame] | 651 | struct pt_regs i386_regs; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 652 | #elif defined(X86_64) || defined(X32) |
Denys Vlasenko | e73a89d | 2012-01-18 11:07:24 +0100 | [diff] [blame] | 653 | /* |
| 654 | * On 32 bits, pt_regs and user_regs_struct are the same, |
| 655 | * but on 64 bits, user_regs_struct has six more fields: |
| 656 | * fs_base, gs_base, ds, es, fs, gs. |
| 657 | * PTRACE_GETREGS fills them too, so struct pt_regs would overflow. |
| 658 | */ |
| 659 | static struct user_regs_struct x86_64_regs; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 660 | #elif defined(IA64) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 661 | long r8, r10, psr; /* TODO: make static? */ |
| 662 | long ia32 = 0; /* not static */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 663 | #elif defined(POWERPC) |
Denys Vlasenko | 46dc8b2 | 2012-03-21 00:07:25 +0100 | [diff] [blame] | 664 | static long ppc_result; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 665 | #elif defined(M68K) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 666 | static long d0; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 667 | #elif defined(BFIN) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 668 | static long r0; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 669 | #elif defined(ARM) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 670 | struct pt_regs regs; /* not static */ |
Steve McIntyre | d8d3bd3 | 2012-10-24 17:58:16 +0100 | [diff] [blame] | 671 | #elif defined(AARCH64) |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 672 | static struct user_pt_regs aarch64_regs; |
| 673 | static struct arm_pt_regs regs; |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 674 | static struct iovec aarch64_io = { |
| 675 | .iov_base = &aarch64_regs |
| 676 | }; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 677 | #elif defined(ALPHA) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 678 | static long r0; |
| 679 | static long a3; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 680 | #elif defined(AVR32) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 681 | static struct pt_regs regs; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 682 | #elif defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 683 | struct pt_regs regs; /* not static */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 684 | static unsigned long trap; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 685 | #elif defined(LINUX_MIPSN32) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 686 | static long long a3; |
| 687 | static long long r2; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 688 | #elif defined(MIPS) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 689 | static long a3; |
| 690 | static long r2; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 691 | #elif defined(S390) || defined(S390X) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 692 | static long gpr2; |
| 693 | static long pc; |
| 694 | static long syscall_mode; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 695 | #elif defined(HPPA) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 696 | static long r28; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 697 | #elif defined(SH) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 698 | static long r0; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 699 | #elif defined(SH64) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 700 | static long r9; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 701 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 702 | static long r10; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 703 | #elif defined(MICROBLAZE) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 704 | static long r3; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 705 | #endif |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 706 | |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 707 | void |
| 708 | printcall(struct tcb *tcp) |
| 709 | { |
| 710 | #define PRINTBADPC tprintf(sizeof(long) == 4 ? "[????????] " : \ |
| 711 | sizeof(long) == 8 ? "[????????????????] " : \ |
| 712 | NULL /* crash */) |
| 713 | if (get_regs_error) { |
| 714 | PRINTBADPC; |
| 715 | return; |
| 716 | } |
| 717 | #if defined(I386) |
| 718 | tprintf("[%08lx] ", i386_regs.eip); |
| 719 | #elif defined(S390) || defined(S390X) |
| 720 | long psw; |
| 721 | if (upeek(tcp, PT_PSWADDR, &psw) < 0) { |
| 722 | PRINTBADPC; |
| 723 | return; |
| 724 | } |
| 725 | # ifdef S390 |
| 726 | tprintf("[%08lx] ", psw); |
| 727 | # elif S390X |
| 728 | tprintf("[%16lx] ", psw); |
| 729 | # endif |
| 730 | #elif defined(X86_64) || defined(X32) |
| 731 | tprintf("[%16lx] ", x86_64_regs.ip); |
| 732 | #elif defined(IA64) |
| 733 | long ip; |
| 734 | |
| 735 | if (upeek(tcp, PT_B0, &ip) < 0) { |
| 736 | PRINTBADPC; |
| 737 | return; |
| 738 | } |
| 739 | tprintf("[%08lx] ", ip); |
| 740 | #elif defined(POWERPC) |
| 741 | long pc; |
| 742 | |
| 743 | if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &pc) < 0) { |
| 744 | PRINTBADPC; |
| 745 | return; |
| 746 | } |
| 747 | # ifdef POWERPC64 |
| 748 | tprintf("[%016lx] ", pc); |
| 749 | # else |
| 750 | tprintf("[%08lx] ", pc); |
| 751 | # endif |
| 752 | #elif defined(M68K) |
| 753 | long pc; |
| 754 | |
| 755 | if (upeek(tcp, 4*PT_PC, &pc) < 0) { |
| 756 | tprints("[????????] "); |
| 757 | return; |
| 758 | } |
| 759 | tprintf("[%08lx] ", pc); |
| 760 | #elif defined(ALPHA) |
| 761 | long pc; |
| 762 | |
| 763 | if (upeek(tcp, REG_PC, &pc) < 0) { |
| 764 | tprints("[????????????????] "); |
| 765 | return; |
| 766 | } |
| 767 | tprintf("[%08lx] ", pc); |
| 768 | #elif defined(SPARC) |
| 769 | tprintf("[%08lx] ", regs.pc); |
| 770 | #elif defined(SPARC64) |
| 771 | tprintf("[%08lx] ", regs.tpc); |
| 772 | #elif defined(HPPA) |
| 773 | long pc; |
| 774 | |
| 775 | if (upeek(tcp, PT_IAOQ0, &pc) < 0) { |
| 776 | tprints("[????????] "); |
| 777 | return; |
| 778 | } |
| 779 | tprintf("[%08lx] ", pc); |
| 780 | #elif defined(MIPS) |
| 781 | long pc; |
| 782 | |
| 783 | if (upeek(tcp, REG_EPC, &pc) < 0) { |
| 784 | tprints("[????????] "); |
| 785 | return; |
| 786 | } |
| 787 | tprintf("[%08lx] ", pc); |
| 788 | #elif defined(SH) |
| 789 | long pc; |
| 790 | |
| 791 | if (upeek(tcp, 4*REG_PC, &pc) < 0) { |
| 792 | tprints("[????????] "); |
| 793 | return; |
| 794 | } |
| 795 | tprintf("[%08lx] ", pc); |
| 796 | #elif defined(SH64) |
| 797 | long pc; |
| 798 | |
| 799 | if (upeek(tcp, REG_PC, &pc) < 0) { |
| 800 | tprints("[????????????????] "); |
| 801 | return; |
| 802 | } |
| 803 | tprintf("[%08lx] ", pc); |
| 804 | #elif defined(ARM) |
| 805 | tprintf("[%08lx] ", regs.ARM_pc); |
| 806 | /*#elif defined(AARCH64) ??? */ |
| 807 | #elif defined(AVR32) |
| 808 | tprintf("[%08lx] ", regs.pc); |
| 809 | #elif defined(BFIN) |
| 810 | long pc; |
| 811 | |
| 812 | if (upeek(tcp, PT_PC, &pc) < 0) { |
| 813 | PRINTBADPC; |
| 814 | return; |
| 815 | } |
| 816 | tprintf("[%08lx] ", pc); |
| 817 | #elif defined(CRISV10) |
| 818 | long pc; |
| 819 | |
| 820 | if (upeek(tcp, 4*PT_IRP, &pc) < 0) { |
| 821 | PRINTBADPC; |
| 822 | return; |
| 823 | } |
| 824 | tprintf("[%08lx] ", pc); |
| 825 | #elif defined(CRISV32) |
| 826 | long pc; |
| 827 | |
| 828 | if (upeek(tcp, 4*PT_ERP, &pc) < 0) { |
| 829 | PRINTBADPC; |
| 830 | return; |
| 831 | } |
| 832 | tprintf("[%08lx] ", pc); |
| 833 | #endif /* architecture */ |
| 834 | } |
| 835 | |
| 836 | #ifndef get_regs |
| 837 | long get_regs_error; |
| 838 | void get_regs(pid_t pid) |
| 839 | { |
| 840 | # if defined(AVR32) |
| 841 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, ®s); |
| 842 | # elif defined(I386) |
| 843 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &i386_regs); |
| 844 | # elif defined(X86_64) || defined(X32) |
| 845 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &x86_64_regs); |
| 846 | # elif defined(AARCH64) |
| 847 | /*aarch64_io.iov_base = &aarch64_regs; - already is */ |
| 848 | aarch64_io.iov_len = sizeof(aarch64_regs); |
| 849 | get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, (void *)&aarch64_io); |
| 850 | if (get_regs_error) |
| 851 | return; |
| 852 | switch (aarch64_io.iov_len) { |
| 853 | case sizeof(regs): |
| 854 | /* We are in 32-bit mode */ |
| 855 | memcpy(®s, &aarch64_regs, sizeof(regs)); |
| 856 | break; |
| 857 | case sizeof(aarch64_regs): |
| 858 | /* We are in 64-bit mode */ |
| 859 | /* Data is already in aarch64_regs */ |
| 860 | break; |
| 861 | default: |
| 862 | get_regs_error = -1; |
| 863 | break; |
| 864 | } |
| 865 | # elif defined(ARM) |
| 866 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (void *)®s); |
| 867 | # elif defined(SPARC) || defined(SPARC64) |
| 868 | get_regs_error = ptrace(PTRACE_GETREGS, pid, (char *)®s, 0); |
| 869 | # endif |
| 870 | } |
| 871 | #endif |
| 872 | |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 873 | /* Returns: |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 874 | * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently. |
| 875 | * 1: ok, continue in trace_syscall_entering(). |
| 876 | * other: error, trace_syscall_entering() should print error indicator |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 877 | * ("????" etc) and bail out. |
| 878 | */ |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 879 | static int |
Denys Vlasenko | 06602d9 | 2011-08-24 17:53:52 +0200 | [diff] [blame] | 880 | get_scno(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 881 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 882 | long scno = 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 883 | |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 884 | #if defined(S390) || defined(S390X) |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 885 | if (upeek(tcp, PT_GPR2, &syscall_mode) < 0) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 886 | return -1; |
Roland McGrath | 2f924ca | 2003-06-26 22:23:28 +0000 | [diff] [blame] | 887 | |
| 888 | if (syscall_mode != -ENOSYS) { |
| 889 | /* |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 890 | * Since kernel version 2.5.44 the scno gets passed in gpr2. |
Roland McGrath | 2f924ca | 2003-06-26 22:23:28 +0000 | [diff] [blame] | 891 | */ |
| 892 | scno = syscall_mode; |
| 893 | } else { |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 894 | /* |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 895 | * Old style of "passing" the scno via the SVC instruction. |
| 896 | */ |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 897 | long opcode, offset_reg, tmp; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 898 | void *svc_addr; |
Denys Vlasenko | 7c9ba8b | 2011-08-19 19:46:32 +0200 | [diff] [blame] | 899 | static const int gpr_offset[16] = { |
| 900 | PT_GPR0, PT_GPR1, PT_ORIGGPR2, PT_GPR3, |
| 901 | PT_GPR4, PT_GPR5, PT_GPR6, PT_GPR7, |
| 902 | PT_GPR8, PT_GPR9, PT_GPR10, PT_GPR11, |
| 903 | PT_GPR12, PT_GPR13, PT_GPR14, PT_GPR15 |
| 904 | }; |
Roland McGrath | 761b5d7 | 2002-12-15 23:58:31 +0000 | [diff] [blame] | 905 | |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 906 | if (upeek(tcp, PT_PSWADDR, &pc) < 0) |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 907 | return -1; |
Roland McGrath | 96dc514 | 2003-01-20 10:23:04 +0000 | [diff] [blame] | 908 | errno = 0; |
Denys Vlasenko | fb03667 | 2009-01-23 16:30:26 +0000 | [diff] [blame] | 909 | opcode = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(pc-sizeof(long)), 0); |
Roland McGrath | 96dc514 | 2003-01-20 10:23:04 +0000 | [diff] [blame] | 910 | if (errno) { |
Dmitry V. Levin | 9a71bcd | 2012-09-17 23:20:54 +0000 | [diff] [blame] | 911 | perror_msg("%s", "peektext(pc-oneword)"); |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 912 | return -1; |
Roland McGrath | 96dc514 | 2003-01-20 10:23:04 +0000 | [diff] [blame] | 913 | } |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 914 | |
| 915 | /* |
| 916 | * We have to check if the SVC got executed directly or via an |
| 917 | * EXECUTE instruction. In case of EXECUTE it is necessary to do |
| 918 | * instruction decoding to derive the system call number. |
| 919 | * Unfortunately the opcode sizes of EXECUTE and SVC are differently, |
| 920 | * so that this doesn't work if a SVC opcode is part of an EXECUTE |
| 921 | * opcode. Since there is no way to find out the opcode size this |
| 922 | * is the best we can do... |
| 923 | */ |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 924 | if ((opcode & 0xff00) == 0x0a00) { |
| 925 | /* SVC opcode */ |
| 926 | scno = opcode & 0xff; |
Roland McGrath | 761b5d7 | 2002-12-15 23:58:31 +0000 | [diff] [blame] | 927 | } |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 928 | else { |
| 929 | /* SVC got executed by EXECUTE instruction */ |
| 930 | |
| 931 | /* |
| 932 | * Do instruction decoding of EXECUTE. If you really want to |
| 933 | * understand this, read the Principles of Operations. |
| 934 | */ |
| 935 | svc_addr = (void *) (opcode & 0xfff); |
| 936 | |
| 937 | tmp = 0; |
| 938 | offset_reg = (opcode & 0x000f0000) >> 16; |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 939 | if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0)) |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 940 | return -1; |
| 941 | svc_addr += tmp; |
| 942 | |
| 943 | tmp = 0; |
| 944 | offset_reg = (opcode & 0x0000f000) >> 12; |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 945 | if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0)) |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 946 | return -1; |
| 947 | svc_addr += tmp; |
| 948 | |
Denys Vlasenko | fb03667 | 2009-01-23 16:30:26 +0000 | [diff] [blame] | 949 | scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, svc_addr, 0); |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 950 | if (errno) |
| 951 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 952 | # if defined(S390X) |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 953 | scno >>= 48; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 954 | # else |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 955 | scno >>= 16; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 956 | # endif |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 957 | tmp = 0; |
| 958 | offset_reg = (opcode & 0x00f00000) >> 20; |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 959 | if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0)) |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 960 | return -1; |
| 961 | |
| 962 | scno = (scno | tmp) & 0xff; |
| 963 | } |
| 964 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 965 | #elif defined(POWERPC) |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 966 | if (upeek(tcp, sizeof(unsigned long)*PT_R0, &scno) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 967 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 968 | # ifdef POWERPC64 |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 969 | /* TODO: speed up strace by not doing this at every syscall. |
| 970 | * We only need to do it after execve. |
| 971 | */ |
| 972 | int currpers; |
| 973 | long val; |
Andreas Schwab | d69fa49 | 2010-07-12 21:39:57 +0200 | [diff] [blame] | 974 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 975 | /* Check for 64/32 bit mode. */ |
| 976 | if (upeek(tcp, sizeof(unsigned long)*PT_MSR, &val) < 0) |
| 977 | return -1; |
| 978 | /* SF is bit 0 of MSR */ |
| 979 | if (val < 0) |
| 980 | currpers = 0; |
| 981 | else |
| 982 | currpers = 1; |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 983 | update_personality(tcp, currpers); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 984 | # endif |
| 985 | #elif defined(AVR32) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 986 | scno = regs.r8; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 987 | #elif defined(BFIN) |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 988 | if (upeek(tcp, PT_ORIG_P0, &scno)) |
Dmitry V. Levin | 87ea1f4 | 2008-11-10 22:21:41 +0000 | [diff] [blame] | 989 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 990 | #elif defined(I386) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 991 | scno = i386_regs.orig_eax; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 992 | #elif defined(X86_64) || defined(X32) |
| 993 | # ifndef __X32_SYSCALL_BIT |
| 994 | # define __X32_SYSCALL_BIT 0x40000000 |
| 995 | # endif |
| 996 | # ifndef __X32_SYSCALL_MASK |
| 997 | # define __X32_SYSCALL_MASK __X32_SYSCALL_BIT |
| 998 | # endif |
| 999 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1000 | int currpers; |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1001 | scno = x86_64_regs.orig_rax; |
Michal Ludvig | 0e03550 | 2002-09-23 15:41:01 +0000 | [diff] [blame] | 1002 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1003 | /* Check CS register value. On x86-64 linux it is: |
| 1004 | * 0x33 for long mode (64 bit) |
| 1005 | * 0x23 for compatibility mode (32 bit) |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1006 | * Check DS register value. On x86-64 linux it is: |
| 1007 | * 0x2b for x32 mode (x86-64 in 32 bit) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1008 | */ |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1009 | switch (x86_64_regs.cs) { |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1010 | case 0x23: currpers = 1; break; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1011 | case 0x33: |
| 1012 | if (x86_64_regs.ds == 0x2b) { |
| 1013 | currpers = 2; |
| 1014 | scno &= ~__X32_SYSCALL_MASK; |
| 1015 | } else |
| 1016 | currpers = 0; |
| 1017 | break; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1018 | default: |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1019 | fprintf(stderr, "Unknown value CS=0x%08X while " |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1020 | "detecting personality of process " |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1021 | "PID=%d\n", (int)x86_64_regs.cs, tcp->pid); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1022 | currpers = current_personality; |
| 1023 | break; |
| 1024 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1025 | # if 0 |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1026 | /* This version analyzes the opcode of a syscall instruction. |
| 1027 | * (int 0x80 on i386 vs. syscall on x86-64) |
| 1028 | * It works, but is too complicated. |
| 1029 | */ |
| 1030 | unsigned long val, rip, i; |
Michal Ludvig | 0e03550 | 2002-09-23 15:41:01 +0000 | [diff] [blame] | 1031 | |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1032 | rip = x86_64_regs.rip; |
Roland McGrath | 761b5d7 | 2002-12-15 23:58:31 +0000 | [diff] [blame] | 1033 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1034 | /* sizeof(syscall) == sizeof(int 0x80) == 2 */ |
| 1035 | rip -= 2; |
| 1036 | errno = 0; |
Michal Ludvig | 0e03550 | 2002-09-23 15:41:01 +0000 | [diff] [blame] | 1037 | |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1038 | call = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)rip, (char *)0); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1039 | if (errno) |
| 1040 | fprintf(stderr, "ptrace_peektext failed: %s\n", |
| 1041 | strerror(errno)); |
| 1042 | switch (call & 0xffff) { |
| 1043 | /* x86-64: syscall = 0x0f 0x05 */ |
| 1044 | case 0x050f: currpers = 0; break; |
| 1045 | /* i386: int 0x80 = 0xcd 0x80 */ |
| 1046 | case 0x80cd: currpers = 1; break; |
| 1047 | default: |
| 1048 | currpers = current_personality; |
| 1049 | fprintf(stderr, |
| 1050 | "Unknown syscall opcode (0x%04X) while " |
| 1051 | "detecting personality of process " |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1052 | "PID=%d\n", (int)call, tcp->pid); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1053 | break; |
| 1054 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1055 | # endif |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1056 | # ifdef X32 |
H.J. Lu | 085e428 | 2012-04-17 11:05:04 -0700 | [diff] [blame] | 1057 | /* Value of currpers: |
| 1058 | * 0: 64 bit |
| 1059 | * 1: 32 bit |
| 1060 | * 2: X32 |
| 1061 | * Value of current_personality: |
| 1062 | * 0: X32 |
| 1063 | * 1: 32 bit |
| 1064 | */ |
| 1065 | switch (currpers) { |
| 1066 | case 0: |
| 1067 | fprintf(stderr, "syscall_%lu (...) in unsupported " |
| 1068 | "64-bit mode of process PID=%d\n", |
| 1069 | scno, tcp->pid); |
| 1070 | return 0; |
| 1071 | case 2: |
| 1072 | currpers = 0; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1073 | } |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1074 | # endif |
H.J. Lu | 085e428 | 2012-04-17 11:05:04 -0700 | [diff] [blame] | 1075 | update_personality(tcp, currpers); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1076 | #elif defined(IA64) |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 1077 | # define IA64_PSR_IS ((long)1 << 34) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1078 | if (upeek(tcp, PT_CR_IPSR, &psr) >= 0) |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 1079 | ia32 = (psr & IA64_PSR_IS) != 0; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1080 | if (ia32) { |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1081 | if (upeek(tcp, PT_R1, &scno) < 0) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1082 | return -1; |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 1083 | } else { |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1084 | if (upeek(tcp, PT_R15, &scno) < 0) |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 1085 | return -1; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1086 | } |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1087 | #elif defined(AARCH64) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1088 | switch (aarch64_io.iov_len) { |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1089 | case sizeof(aarch64_regs): |
| 1090 | /* We are in 64-bit mode */ |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1091 | scno = aarch64_regs.regs[8]; |
| 1092 | update_personality(tcp, 1); |
| 1093 | break; |
| 1094 | case sizeof(regs): |
| 1095 | /* We are in 32-bit mode */ |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1096 | scno = regs.uregs[7]; |
| 1097 | update_personality(tcp, 0); |
| 1098 | break; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1099 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1100 | #elif defined(ARM) |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 1101 | /* |
| 1102 | * We only need to grab the syscall number on syscall entry. |
| 1103 | */ |
| 1104 | if (regs.ARM_ip == 0) { |
| 1105 | /* |
| 1106 | * Note: we only deal with only 32-bit CPUs here. |
| 1107 | */ |
| 1108 | if (regs.ARM_cpsr & 0x20) { |
| 1109 | /* |
| 1110 | * Get the Thumb-mode system call number |
| 1111 | */ |
| 1112 | scno = regs.ARM_r7; |
| 1113 | } else { |
| 1114 | /* |
| 1115 | * Get the ARM-mode system call number |
| 1116 | */ |
| 1117 | errno = 0; |
Denys Vlasenko | fb03667 | 2009-01-23 16:30:26 +0000 | [diff] [blame] | 1118 | scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(regs.ARM_pc - 4), NULL); |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 1119 | if (errno) |
| 1120 | return -1; |
| 1121 | |
Roland McGrath | f691bd2 | 2006-04-25 07:34:41 +0000 | [diff] [blame] | 1122 | /* Handle the EABI syscall convention. We do not |
| 1123 | bother converting structures between the two |
| 1124 | ABIs, but basic functionality should work even |
| 1125 | if strace and the traced program have different |
| 1126 | ABIs. */ |
| 1127 | if (scno == 0xef000000) { |
| 1128 | scno = regs.ARM_r7; |
| 1129 | } else { |
| 1130 | if ((scno & 0x0ff00000) != 0x0f900000) { |
| 1131 | fprintf(stderr, "syscall: unknown syscall trap 0x%08lx\n", |
| 1132 | scno); |
| 1133 | return -1; |
| 1134 | } |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 1135 | |
Roland McGrath | f691bd2 | 2006-04-25 07:34:41 +0000 | [diff] [blame] | 1136 | /* |
| 1137 | * Fixup the syscall number |
| 1138 | */ |
| 1139 | scno &= 0x000fffff; |
| 1140 | } |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 1141 | } |
Roland McGrath | 5670331 | 2008-05-20 01:35:55 +0000 | [diff] [blame] | 1142 | if (scno & 0x0f0000) { |
| 1143 | /* |
| 1144 | * Handle ARM specific syscall |
| 1145 | */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1146 | update_personality(tcp, 1); |
Roland McGrath | 5670331 | 2008-05-20 01:35:55 +0000 | [diff] [blame] | 1147 | scno &= 0x0000ffff; |
| 1148 | } else |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1149 | update_personality(tcp, 0); |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 1150 | |
Roland McGrath | 0f87c49 | 2003-06-03 23:29:04 +0000 | [diff] [blame] | 1151 | } else { |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1152 | fprintf(stderr, "pid %d stray syscall entry\n", tcp->pid); |
| 1153 | tcp->flags |= TCB_INSYSCALL; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1154 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1155 | #elif defined(M68K) |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 1156 | if (upeek(tcp, 4*PT_ORIG_D0, &scno) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1157 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1158 | #elif defined(LINUX_MIPSN32) |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1159 | unsigned long long regs[38]; |
| 1160 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1161 | if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0) |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1162 | return -1; |
| 1163 | a3 = regs[REG_A3]; |
| 1164 | r2 = regs[REG_V0]; |
| 1165 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1166 | scno = r2; |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 1167 | if (!SCNO_IN_RANGE(scno)) { |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1168 | if (a3 == 0 || a3 == -1) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1169 | if (debug_flag) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1170 | fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno); |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1171 | return 0; |
| 1172 | } |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1173 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1174 | #elif defined(MIPS) |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 1175 | if (upeek(tcp, REG_A3, &a3) < 0) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 1176 | return -1; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1177 | if (upeek(tcp, REG_V0, &scno) < 0) |
| 1178 | return -1; |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 1179 | |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 1180 | if (!SCNO_IN_RANGE(scno)) { |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1181 | if (a3 == 0 || a3 == -1) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1182 | if (debug_flag) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1183 | fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno); |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1184 | return 0; |
| 1185 | } |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 1186 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1187 | #elif defined(ALPHA) |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 1188 | if (upeek(tcp, REG_A3, &a3) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1189 | return -1; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1190 | if (upeek(tcp, REG_R0, &scno) < 0) |
| 1191 | return -1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1192 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1193 | /* |
| 1194 | * Do some sanity checks to figure out if it's |
| 1195 | * really a syscall entry |
| 1196 | */ |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 1197 | if (!SCNO_IN_RANGE(scno)) { |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1198 | if (a3 == 0 || a3 == -1) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1199 | if (debug_flag) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1200 | fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1201 | return 0; |
| 1202 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1203 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1204 | #elif defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1205 | /* Disassemble the syscall trap. */ |
| 1206 | /* Retrieve the syscall trap instruction. */ |
| 1207 | errno = 0; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1208 | # if defined(SPARC64) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1209 | trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)regs.tpc, 0); |
| 1210 | trap >>= 32; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1211 | # else |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1212 | trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)regs.pc, 0); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1213 | # endif |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1214 | if (errno) |
Wichert Akkerman | c1652e2 | 2001-03-27 12:17:16 +0000 | [diff] [blame] | 1215 | return -1; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1216 | |
| 1217 | /* Disassemble the trap to see what personality to use. */ |
| 1218 | switch (trap) { |
| 1219 | case 0x91d02010: |
| 1220 | /* Linux/SPARC syscall trap. */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1221 | update_personality(tcp, 0); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1222 | break; |
| 1223 | case 0x91d0206d: |
| 1224 | /* Linux/SPARC64 syscall trap. */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1225 | update_personality(tcp, 2); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1226 | break; |
| 1227 | case 0x91d02000: |
| 1228 | /* SunOS syscall trap. (pers 1) */ |
| 1229 | fprintf(stderr, "syscall: SunOS no support\n"); |
| 1230 | return -1; |
| 1231 | case 0x91d02008: |
| 1232 | /* Solaris 2.x syscall trap. (per 2) */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1233 | update_personality(tcp, 1); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1234 | break; |
| 1235 | case 0x91d02009: |
| 1236 | /* NetBSD/FreeBSD syscall trap. */ |
| 1237 | fprintf(stderr, "syscall: NetBSD/FreeBSD not supported\n"); |
| 1238 | return -1; |
| 1239 | case 0x91d02027: |
| 1240 | /* Solaris 2.x gettimeofday */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1241 | update_personality(tcp, 1); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1242 | break; |
| 1243 | default: |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1244 | # if defined(SPARC64) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1245 | fprintf(stderr, "syscall: unknown syscall trap %08lx %016lx\n", trap, regs.tpc); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1246 | # else |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1247 | fprintf(stderr, "syscall: unknown syscall trap %08lx %08lx\n", trap, regs.pc); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1248 | # endif |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1249 | return -1; |
| 1250 | } |
| 1251 | |
| 1252 | /* Extract the system call number from the registers. */ |
| 1253 | if (trap == 0x91d02027) |
| 1254 | scno = 156; |
| 1255 | else |
| 1256 | scno = regs.u_regs[U_REG_G1]; |
| 1257 | if (scno == 0) { |
| 1258 | scno = regs.u_regs[U_REG_O0]; |
| 1259 | memmove(®s.u_regs[U_REG_O0], ®s.u_regs[U_REG_O1], 7*sizeof(regs.u_regs[0])); |
| 1260 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1261 | #elif defined(HPPA) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1262 | if (upeek(tcp, PT_GR20, &scno) < 0) |
| 1263 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1264 | #elif defined(SH) |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1265 | /* |
| 1266 | * In the new syscall ABI, the system call number is in R3. |
| 1267 | */ |
| 1268 | if (upeek(tcp, 4*(REG_REG0+3), &scno) < 0) |
| 1269 | return -1; |
Wichert Akkerman | ccef637 | 2002-05-01 16:39:22 +0000 | [diff] [blame] | 1270 | |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1271 | if (scno < 0) { |
| 1272 | /* Odd as it may seem, a glibc bug has been known to cause |
| 1273 | glibc to issue bogus negative syscall numbers. So for |
| 1274 | our purposes, make strace print what it *should* have been */ |
| 1275 | long correct_scno = (scno & 0xff); |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1276 | if (debug_flag) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 1277 | fprintf(stderr, |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1278 | "Detected glibc bug: bogus system call" |
| 1279 | " number = %ld, correcting to %ld\n", |
| 1280 | scno, |
| 1281 | correct_scno); |
| 1282 | scno = correct_scno; |
| 1283 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1284 | #elif defined(SH64) |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 1285 | if (upeek(tcp, REG_SYSCALL, &scno) < 0) |
Roland McGrath | e1e584b | 2003-06-02 19:18:58 +0000 | [diff] [blame] | 1286 | return -1; |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1287 | scno &= 0xFFFF; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1288 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1289 | if (upeek(tcp, 4*PT_R9, &scno) < 0) |
| 1290 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1291 | #elif defined(TILE) |
Chris Metcalf | c8c6698 | 2009-12-28 10:00:15 -0500 | [diff] [blame] | 1292 | if (upeek(tcp, PTREGS_OFFSET_REG(10), &scno) < 0) |
| 1293 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1294 | #elif defined(MICROBLAZE) |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1295 | if (upeek(tcp, 0, &scno) < 0) |
| 1296 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1297 | #endif |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1298 | |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1299 | #if defined(SH) |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1300 | /* new syscall ABI returns result in R0 */ |
| 1301 | if (upeek(tcp, 4*REG_REG0, (long *)&r0) < 0) |
| 1302 | return -1; |
Roland McGrath | f5a4777 | 2003-06-26 22:40:42 +0000 | [diff] [blame] | 1303 | #elif defined(SH64) |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1304 | /* ABI defines result returned in r9 */ |
| 1305 | if (upeek(tcp, REG_GENERAL(9), (long *)&r9) < 0) |
| 1306 | return -1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1307 | #endif |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1308 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1309 | tcp->scno = scno; |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1310 | return 1; |
| 1311 | } |
| 1312 | |
Denys Vlasenko | 20c41fd | 2011-08-25 10:23:00 +0200 | [diff] [blame] | 1313 | /* Called at each syscall entry. |
Denys Vlasenko | bc161ec | 2009-01-02 18:02:45 +0000 | [diff] [blame] | 1314 | * Returns: |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 1315 | * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently. |
| 1316 | * 1: ok, continue in trace_syscall_entering(). |
| 1317 | * other: error, trace_syscall_entering() should print error indicator |
Denys Vlasenko | bc161ec | 2009-01-02 18:02:45 +0000 | [diff] [blame] | 1318 | * ("????" etc) and bail out. |
| 1319 | */ |
Roland McGrath | a4d4853 | 2005-06-08 20:45:28 +0000 | [diff] [blame] | 1320 | static int |
Denys Vlasenko | 8b4454c | 2011-08-25 10:40:14 +0200 | [diff] [blame] | 1321 | syscall_fixup_on_sysenter(struct tcb *tcp) |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1322 | { |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1323 | /* A common case of "not a syscall entry" is post-execve SIGTRAP */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1324 | #if defined(I386) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1325 | if (i386_regs.eax != -ENOSYS) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1326 | if (debug_flag) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1327 | fprintf(stderr, "not a syscall entry (eax = %ld)\n", i386_regs.eax); |
| 1328 | return 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1329 | } |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1330 | #elif defined(X86_64) || defined(X32) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1331 | { |
| 1332 | long rax = x86_64_regs.rax; |
Denys Vlasenko | 18beb98 | 2011-08-24 16:59:23 +0200 | [diff] [blame] | 1333 | if (current_personality == 1) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1334 | rax = (int)rax; /* sign extend from 32 bits */ |
| 1335 | if (rax != -ENOSYS) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1336 | if (debug_flag) |
Denys Vlasenko | 18beb98 | 2011-08-24 16:59:23 +0200 | [diff] [blame] | 1337 | fprintf(stderr, "not a syscall entry (rax = %ld)\n", rax); |
| 1338 | return 0; |
| 1339 | } |
Michal Ludvig | 0e03550 | 2002-09-23 15:41:01 +0000 | [diff] [blame] | 1340 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1341 | #elif defined(S390) || defined(S390X) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1342 | /* TODO: we already fetched PT_GPR2 in get_scno |
| 1343 | * and stored it in syscall_mode, reuse it here |
| 1344 | * instead of re-fetching? |
| 1345 | */ |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 1346 | if (upeek(tcp, PT_GPR2, &gpr2) < 0) |
Wichert Akkerman | 12f75d1 | 2000-02-14 16:23:40 +0000 | [diff] [blame] | 1347 | return -1; |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1348 | if (syscall_mode != -ENOSYS) |
| 1349 | syscall_mode = tcp->scno; |
Denys Vlasenko | ece9879 | 2011-08-25 10:25:35 +0200 | [diff] [blame] | 1350 | if (gpr2 != syscall_mode) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1351 | if (debug_flag) |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1352 | fprintf(stderr, "not a syscall entry (gpr2 = %ld)\n", gpr2); |
Wichert Akkerman | 12f75d1 | 2000-02-14 16:23:40 +0000 | [diff] [blame] | 1353 | return 0; |
| 1354 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1355 | #elif defined(M68K) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1356 | /* TODO? Eliminate upeek's in arches below like we did in x86 */ |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 1357 | if (upeek(tcp, 4*PT_D0, &d0) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1358 | return -1; |
Denys Vlasenko | ece9879 | 2011-08-25 10:25:35 +0200 | [diff] [blame] | 1359 | if (d0 != -ENOSYS) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1360 | if (debug_flag) |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1361 | fprintf(stderr, "not a syscall entry (d0 = %ld)\n", d0); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1362 | return 0; |
| 1363 | } |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 1364 | #elif defined(IA64) |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 1365 | if (upeek(tcp, PT_R10, &r10) < 0) |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 1366 | return -1; |
Denys Vlasenko | 932fc7d | 2008-12-16 18:18:40 +0000 | [diff] [blame] | 1367 | if (upeek(tcp, PT_R8, &r8) < 0) |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 1368 | return -1; |
Denys Vlasenko | ece9879 | 2011-08-25 10:25:35 +0200 | [diff] [blame] | 1369 | if (ia32 && r8 != -ENOSYS) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1370 | if (debug_flag) |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1371 | fprintf(stderr, "not a syscall entry (r8 = %ld)\n", r8); |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 1372 | return 0; |
| 1373 | } |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1374 | #elif defined(CRISV10) || defined(CRISV32) |
Edgar E. Iglesias | eeb9ce3 | 2009-10-05 14:41:02 +0000 | [diff] [blame] | 1375 | if (upeek(tcp, 4*PT_R10, &r10) < 0) |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1376 | return -1; |
Denys Vlasenko | ece9879 | 2011-08-25 10:25:35 +0200 | [diff] [blame] | 1377 | if (r10 != -ENOSYS) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1378 | if (debug_flag) |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1379 | fprintf(stderr, "not a syscall entry (r10 = %ld)\n", r10); |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1380 | return 0; |
| 1381 | } |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1382 | #elif defined(MICROBLAZE) |
| 1383 | if (upeek(tcp, 3 * 4, &r3) < 0) |
| 1384 | return -1; |
Denys Vlasenko | ece9879 | 2011-08-25 10:25:35 +0200 | [diff] [blame] | 1385 | if (r3 != -ENOSYS) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1386 | if (debug_flag) |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1387 | fprintf(stderr, "not a syscall entry (r3 = %ld)\n", r3); |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1388 | return 0; |
| 1389 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1390 | #endif |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1391 | return 1; |
| 1392 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1393 | |
Denys Vlasenko | 146b944 | 2012-03-18 22:10:48 +0100 | [diff] [blame] | 1394 | static void |
| 1395 | internal_fork(struct tcb *tcp) |
| 1396 | { |
| 1397 | #if defined S390 || defined S390X || defined CRISV10 || defined CRISV32 |
| 1398 | # define ARG_FLAGS 1 |
| 1399 | #else |
| 1400 | # define ARG_FLAGS 0 |
| 1401 | #endif |
| 1402 | #ifndef CLONE_UNTRACED |
| 1403 | # define CLONE_UNTRACED 0x00800000 |
| 1404 | #endif |
| 1405 | if ((ptrace_setoptions |
| 1406 | & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK)) |
| 1407 | == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK)) |
| 1408 | return; |
| 1409 | |
| 1410 | if (!followfork) |
| 1411 | return; |
| 1412 | |
| 1413 | if (entering(tcp)) { |
| 1414 | /* |
| 1415 | * We won't see the new child if clone is called with |
| 1416 | * CLONE_UNTRACED, so we keep the same logic with that option |
| 1417 | * and don't trace it. |
| 1418 | */ |
| 1419 | if ((sysent[tcp->scno].sys_func == sys_clone) && |
| 1420 | (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED)) |
| 1421 | return; |
| 1422 | setbpt(tcp); |
| 1423 | } else { |
| 1424 | if (tcp->flags & TCB_BPTSET) |
| 1425 | clearbpt(tcp); |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | #if defined(TCB_WAITEXECVE) |
| 1430 | static void |
| 1431 | internal_exec(struct tcb *tcp) |
| 1432 | { |
| 1433 | /* Maybe we have post-execve SIGTRAP suppressed? */ |
| 1434 | if (ptrace_setoptions & PTRACE_O_TRACEEXEC) |
| 1435 | return; /* yes, no need to do anything */ |
| 1436 | |
| 1437 | if (exiting(tcp) && syserror(tcp)) |
| 1438 | /* Error in execve, no post-execve SIGTRAP expected */ |
| 1439 | tcp->flags &= ~TCB_WAITEXECVE; |
| 1440 | else |
| 1441 | tcp->flags |= TCB_WAITEXECVE; |
| 1442 | } |
| 1443 | #endif |
| 1444 | |
| 1445 | static void |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1446 | internal_syscall(struct tcb *tcp) |
Roland McGrath | c1e4592 | 2008-05-27 23:18:29 +0000 | [diff] [blame] | 1447 | { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1448 | /* |
| 1449 | * We must always trace a few critical system calls in order to |
| 1450 | * correctly support following forks in the presence of tracing |
| 1451 | * qualifiers. |
| 1452 | */ |
| 1453 | int (*func)(); |
| 1454 | |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 1455 | if (!SCNO_IN_RANGE(tcp->scno)) |
Denys Vlasenko | 146b944 | 2012-03-18 22:10:48 +0100 | [diff] [blame] | 1456 | return; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1457 | |
| 1458 | func = sysent[tcp->scno].sys_func; |
| 1459 | |
| 1460 | if ( sys_fork == func |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1461 | || sys_vfork == func |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1462 | || sys_clone == func |
Denys Vlasenko | 146b944 | 2012-03-18 22:10:48 +0100 | [diff] [blame] | 1463 | ) { |
| 1464 | internal_fork(tcp); |
| 1465 | return; |
| 1466 | } |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1467 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 1468 | #if defined(TCB_WAITEXECVE) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1469 | if ( sys_execve == func |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 1470 | # if defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1471 | || sys_execv == func |
Denys Vlasenko | a794974 | 2011-08-21 17:26:55 +0200 | [diff] [blame] | 1472 | # endif |
Denys Vlasenko | 146b944 | 2012-03-18 22:10:48 +0100 | [diff] [blame] | 1473 | ) { |
| 1474 | internal_exec(tcp); |
| 1475 | return; |
| 1476 | } |
Roland McGrath | c1e4592 | 2008-05-27 23:18:29 +0000 | [diff] [blame] | 1477 | #endif |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1478 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1479 | |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 1480 | /* Return -1 on error or 1 on success (never 0!) */ |
Roland McGrath | a4d4853 | 2005-06-08 20:45:28 +0000 | [diff] [blame] | 1481 | static int |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 1482 | get_syscall_args(struct tcb *tcp) |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1483 | { |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1484 | int i, nargs; |
| 1485 | |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 1486 | if (SCNO_IN_RANGE(tcp->scno)) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1487 | nargs = tcp->u_nargs = sysent[tcp->scno].nargs; |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1488 | else |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1489 | nargs = tcp->u_nargs = MAX_ARGS; |
| 1490 | |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1491 | #if defined(S390) || defined(S390X) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1492 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1493 | if (upeek(tcp, i==0 ? PT_ORIGGPR2 : PT_GPR2 + i*sizeof(long), &tcp->u_arg[i]) < 0) |
| 1494 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1495 | #elif defined(ALPHA) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1496 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1497 | if (upeek(tcp, REG_A0+i, &tcp->u_arg[i]) < 0) |
| 1498 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1499 | #elif defined(IA64) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1500 | if (!ia32) { |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1501 | unsigned long *out0, cfm, sof, sol; |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1502 | long rbs_end; |
| 1503 | /* be backwards compatible with kernel < 2.4.4... */ |
| 1504 | # ifndef PT_RBS_END |
| 1505 | # define PT_RBS_END PT_AR_BSP |
| 1506 | # endif |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 1507 | |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1508 | if (upeek(tcp, PT_RBS_END, &rbs_end) < 0) |
| 1509 | return -1; |
| 1510 | if (upeek(tcp, PT_CFM, (long *) &cfm) < 0) |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1511 | return -1; |
| 1512 | |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1513 | sof = (cfm >> 0) & 0x7f; |
| 1514 | sol = (cfm >> 7) & 0x7f; |
| 1515 | out0 = ia64_rse_skip_regs((unsigned long *) rbs_end, -sof + sol); |
| 1516 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1517 | for (i = 0; i < nargs; ++i) { |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1518 | if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i), |
| 1519 | sizeof(long), (char *) &tcp->u_arg[i]) < 0) |
| 1520 | return -1; |
| 1521 | } |
| 1522 | } else { |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1523 | static const int argreg[MAX_ARGS] = { PT_R11 /* EBX = out0 */, |
| 1524 | PT_R9 /* ECX = out1 */, |
| 1525 | PT_R10 /* EDX = out2 */, |
| 1526 | PT_R14 /* ESI = out3 */, |
| 1527 | PT_R15 /* EDI = out4 */, |
| 1528 | PT_R13 /* EBP = out5 */}; |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1529 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1530 | for (i = 0; i < nargs; ++i) { |
| 1531 | if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0) |
| 1532 | return -1; |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1533 | /* truncate away IVE sign-extension */ |
| 1534 | tcp->u_arg[i] &= 0xffffffff; |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1535 | } |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1536 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1537 | #elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1538 | /* N32 and N64 both use up to six registers. */ |
| 1539 | unsigned long long regs[38]; |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1540 | |
| 1541 | if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0) |
| 1542 | return -1; |
| 1543 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1544 | for (i = 0; i < nargs; ++i) { |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1545 | tcp->u_arg[i] = regs[REG_A0 + i]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1546 | # if defined(LINUX_MIPSN32) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1547 | tcp->ext_arg[i] = regs[REG_A0 + i]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1548 | # endif |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1549 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1550 | #elif defined(MIPS) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1551 | if (nargs > 4) { |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1552 | long sp; |
| 1553 | |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1554 | if (upeek(tcp, REG_SP, &sp) < 0) |
| 1555 | return -1; |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1556 | for (i = 0; i < 4; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1557 | if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0) |
| 1558 | return -1; |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1559 | umoven(tcp, sp + 16, (nargs - 4) * sizeof(tcp->u_arg[0]), |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1560 | (char *)(tcp->u_arg + 4)); |
| 1561 | } else { |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1562 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1563 | if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1564 | return -1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1565 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1566 | #elif defined(POWERPC) |
| 1567 | # ifndef PT_ORIG_R3 |
| 1568 | # define PT_ORIG_R3 34 |
| 1569 | # endif |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1570 | for (i = 0; i < nargs; ++i) { |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1571 | if (upeek(tcp, (i==0) ? |
| 1572 | (sizeof(unsigned long) * PT_ORIG_R3) : |
| 1573 | ((i+PT_R3) * sizeof(unsigned long)), |
| 1574 | &tcp->u_arg[i]) < 0) |
| 1575 | return -1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1576 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1577 | #elif defined(SPARC) || defined(SPARC64) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1578 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1579 | tcp->u_arg[i] = regs.u_regs[U_REG_O0 + i]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1580 | #elif defined(HPPA) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1581 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1582 | if (upeek(tcp, PT_GR26-4*i, &tcp->u_arg[i]) < 0) |
| 1583 | return -1; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1584 | #elif defined(ARM) || defined(AARCH64) |
| 1585 | # if defined(AARCH64) |
| 1586 | if (tcp->currpers == 1) |
| 1587 | for (i = 0; i < nargs; ++i) |
| 1588 | tcp->u_arg[i] = aarch64_regs.regs[i]; |
| 1589 | else |
| 1590 | # endif /* AARCH64 */ |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1591 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1592 | tcp->u_arg[i] = regs.uregs[i]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1593 | #elif defined(AVR32) |
Denys Vlasenko | b5b2589 | 2011-08-30 19:04:54 +0200 | [diff] [blame] | 1594 | (void)i; |
| 1595 | (void)nargs; |
| 1596 | tcp->u_arg[0] = regs.r12; |
| 1597 | tcp->u_arg[1] = regs.r11; |
| 1598 | tcp->u_arg[2] = regs.r10; |
| 1599 | tcp->u_arg[3] = regs.r9; |
| 1600 | tcp->u_arg[4] = regs.r5; |
| 1601 | tcp->u_arg[5] = regs.r3; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1602 | #elif defined(BFIN) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1603 | static const int argreg[MAX_ARGS] = { PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5 }; |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1604 | |
Denys Vlasenko | 4b887a5 | 2011-08-23 13:32:38 +0200 | [diff] [blame] | 1605 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1606 | if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0) |
| 1607 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1608 | #elif defined(SH) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1609 | static const int syscall_regs[MAX_ARGS] = { |
| 1610 | 4 * (REG_REG0+4), 4 * (REG_REG0+5), 4 * (REG_REG0+6), |
| 1611 | 4 * (REG_REG0+7), 4 * (REG_REG0 ), 4 * (REG_REG0+1) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1612 | }; |
| 1613 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1614 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 0b6c73c | 2011-06-23 22:22:34 +0200 | [diff] [blame] | 1615 | if (upeek(tcp, syscall_regs[i], &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1616 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1617 | #elif defined(SH64) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1618 | int i; |
| 1619 | /* Registers used by SH5 Linux system calls for parameters */ |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1620 | static const int syscall_regs[MAX_ARGS] = { 2, 3, 4, 5, 6, 7 }; |
Roland McGrath | e1e584b | 2003-06-02 19:18:58 +0000 | [diff] [blame] | 1621 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1622 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1623 | if (upeek(tcp, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0) |
| 1624 | return -1; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1625 | #elif defined(X86_64) || defined(X32) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1626 | (void)i; |
| 1627 | (void)nargs; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1628 | if (current_personality != 1) { /* x86-64 or x32 ABI */ |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1629 | tcp->u_arg[0] = x86_64_regs.rdi; |
| 1630 | tcp->u_arg[1] = x86_64_regs.rsi; |
| 1631 | tcp->u_arg[2] = x86_64_regs.rdx; |
| 1632 | tcp->u_arg[3] = x86_64_regs.r10; |
| 1633 | tcp->u_arg[4] = x86_64_regs.r8; |
| 1634 | tcp->u_arg[5] = x86_64_regs.r9; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1635 | # ifdef X32 |
| 1636 | tcp->ext_arg[0] = x86_64_regs.rdi; |
| 1637 | tcp->ext_arg[1] = x86_64_regs.rsi; |
| 1638 | tcp->ext_arg[2] = x86_64_regs.rdx; |
| 1639 | tcp->ext_arg[3] = x86_64_regs.r10; |
| 1640 | tcp->ext_arg[4] = x86_64_regs.r8; |
| 1641 | tcp->ext_arg[5] = x86_64_regs.r9; |
| 1642 | # endif |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1643 | } else { /* i386 ABI */ |
| 1644 | /* Sign-extend lower 32 bits */ |
| 1645 | tcp->u_arg[0] = (long)(int)x86_64_regs.rbx; |
| 1646 | tcp->u_arg[1] = (long)(int)x86_64_regs.rcx; |
| 1647 | tcp->u_arg[2] = (long)(int)x86_64_regs.rdx; |
| 1648 | tcp->u_arg[3] = (long)(int)x86_64_regs.rsi; |
| 1649 | tcp->u_arg[4] = (long)(int)x86_64_regs.rdi; |
| 1650 | tcp->u_arg[5] = (long)(int)x86_64_regs.rbp; |
| 1651 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1652 | #elif defined(MICROBLAZE) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1653 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1654 | if (upeek(tcp, (5 + i) * 4, &tcp->u_arg[i]) < 0) |
| 1655 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1656 | #elif defined(CRISV10) || defined(CRISV32) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1657 | static const int crisregs[MAX_ARGS] = { |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1658 | 4*PT_ORIG_R10, 4*PT_R11, 4*PT_R12, |
Denys Vlasenko | 0b6c73c | 2011-06-23 22:22:34 +0200 | [diff] [blame] | 1659 | 4*PT_R13 , 4*PT_MOF, 4*PT_SRP |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1660 | }; |
Roland McGrath | e1e584b | 2003-06-02 19:18:58 +0000 | [diff] [blame] | 1661 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1662 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1663 | if (upeek(tcp, crisregs[i], &tcp->u_arg[i]) < 0) |
| 1664 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1665 | #elif defined(TILE) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1666 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1667 | if (upeek(tcp, PTREGS_OFFSET_REG(i), &tcp->u_arg[i]) < 0) |
| 1668 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1669 | #elif defined(M68K) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1670 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1671 | if (upeek(tcp, (i < 5 ? i : i + 2)*4, &tcp->u_arg[i]) < 0) |
| 1672 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1673 | #elif defined(I386) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1674 | (void)i; |
| 1675 | (void)nargs; |
| 1676 | tcp->u_arg[0] = i386_regs.ebx; |
| 1677 | tcp->u_arg[1] = i386_regs.ecx; |
| 1678 | tcp->u_arg[2] = i386_regs.edx; |
| 1679 | tcp->u_arg[3] = i386_regs.esi; |
| 1680 | tcp->u_arg[4] = i386_regs.edi; |
| 1681 | tcp->u_arg[5] = i386_regs.ebp; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1682 | #else /* Other architecture (32bits specific) */ |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1683 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1684 | if (upeek(tcp, i*4, &tcp->u_arg[i]) < 0) |
| 1685 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1686 | #endif |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1687 | return 1; |
| 1688 | } |
| 1689 | |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 1690 | static int |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1691 | trace_syscall_entering(struct tcb *tcp) |
| 1692 | { |
| 1693 | int res, scno_good; |
| 1694 | |
Denys Vlasenko | 2ce12ed | 2011-08-24 17:25:32 +0200 | [diff] [blame] | 1695 | #if defined TCB_WAITEXECVE |
| 1696 | if (tcp->flags & TCB_WAITEXECVE) { |
| 1697 | /* This is the post-execve SIGTRAP. */ |
| 1698 | tcp->flags &= ~TCB_WAITEXECVE; |
| 1699 | return 0; |
| 1700 | } |
| 1701 | #endif |
| 1702 | |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1703 | scno_good = res = (get_regs_error ? -1 : get_scno(tcp)); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1704 | if (res == 0) |
| 1705 | return res; |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 1706 | if (res == 1) { |
Denys Vlasenko | 8b4454c | 2011-08-25 10:40:14 +0200 | [diff] [blame] | 1707 | res = syscall_fixup_on_sysenter(tcp); |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 1708 | if (res == 0) |
| 1709 | return res; |
| 1710 | if (res == 1) |
| 1711 | res = get_syscall_args(tcp); |
| 1712 | } |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1713 | |
| 1714 | if (res != 1) { |
| 1715 | printleader(tcp); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1716 | if (scno_good != 1) |
Denys Vlasenko | b7a6dae | 2012-03-20 16:48:35 +0100 | [diff] [blame] | 1717 | tprints("????" /* anti-trigraph gap */ "("); |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 1718 | else if (!SCNO_IN_RANGE(tcp->scno)) |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1719 | tprintf("syscall_%lu(", tcp->scno); |
| 1720 | else |
| 1721 | tprintf("%s(", sysent[tcp->scno].sys_name); |
| 1722 | /* |
| 1723 | * " <unavailable>" will be added later by the code which |
| 1724 | * detects ptrace errors. |
| 1725 | */ |
| 1726 | goto ret; |
| 1727 | } |
| 1728 | |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 1729 | #if defined(SYS_socket_subcall) || defined(SYS_ipc_subcall) |
| 1730 | while (SCNO_IN_RANGE(tcp->scno)) { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1731 | # ifdef SYS_socket_subcall |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 1732 | if (sysent[tcp->scno].sys_func == sys_socketcall) { |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 1733 | decode_socket_subcall(tcp); |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 1734 | break; |
| 1735 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1736 | # endif |
| 1737 | # ifdef SYS_ipc_subcall |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 1738 | if (sysent[tcp->scno].sys_func == sys_ipc) { |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 1739 | decode_ipc_subcall(tcp); |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 1740 | break; |
| 1741 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1742 | # endif |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 1743 | break; |
| 1744 | } |
| 1745 | #endif /* SYS_socket_subcall || SYS_ipc_subcall */ |
| 1746 | |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1747 | internal_syscall(tcp); |
| 1748 | |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 1749 | if ((SCNO_IN_RANGE(tcp->scno) && |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1750 | !(qual_flags[tcp->scno] & QUAL_TRACE)) || |
| 1751 | (tracing_paths && !pathtrace_match(tcp))) { |
| 1752 | tcp->flags |= TCB_INSYSCALL | TCB_FILTERED; |
| 1753 | return 0; |
| 1754 | } |
| 1755 | |
| 1756 | tcp->flags &= ~TCB_FILTERED; |
| 1757 | |
| 1758 | if (cflag == CFLAG_ONLY_STATS) { |
| 1759 | res = 0; |
| 1760 | goto ret; |
| 1761 | } |
| 1762 | |
| 1763 | printleader(tcp); |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 1764 | if (!SCNO_IN_RANGE(tcp->scno)) |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1765 | tprintf("syscall_%lu(", tcp->scno); |
| 1766 | else |
| 1767 | tprintf("%s(", sysent[tcp->scno].sys_name); |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 1768 | if (!SCNO_IN_RANGE(tcp->scno) || |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1769 | ((qual_flags[tcp->scno] & QUAL_RAW) && |
| 1770 | sysent[tcp->scno].sys_func != sys_exit)) |
| 1771 | res = printargs(tcp); |
| 1772 | else |
| 1773 | res = (*sysent[tcp->scno].sys_func)(tcp); |
| 1774 | |
Dmitry V. Levin | b742d8c | 2012-09-17 22:40:12 +0000 | [diff] [blame] | 1775 | fflush(tcp->outf); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1776 | ret: |
| 1777 | tcp->flags |= TCB_INSYSCALL; |
| 1778 | /* Measure the entrance time as late as possible to avoid errors. */ |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1779 | if (Tflag || cflag) |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1780 | gettimeofday(&tcp->etime, NULL); |
| 1781 | return res; |
| 1782 | } |
| 1783 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1784 | /* Returns: |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 1785 | * 1: ok, continue in trace_syscall_exiting(). |
| 1786 | * -1: error, trace_syscall_exiting() should print error indicator |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1787 | * ("????" etc) and bail out. |
| 1788 | */ |
| 1789 | static int |
| 1790 | get_syscall_result(struct tcb *tcp) |
| 1791 | { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1792 | #if defined(S390) || defined(S390X) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1793 | if (upeek(tcp, PT_GPR2, &gpr2) < 0) |
| 1794 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1795 | #elif defined(POWERPC) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1796 | # define SO_MASK 0x10000000 |
| 1797 | { |
| 1798 | long flags; |
| 1799 | if (upeek(tcp, sizeof(unsigned long)*PT_CCR, &flags) < 0) |
| 1800 | return -1; |
Denys Vlasenko | 46dc8b2 | 2012-03-21 00:07:25 +0100 | [diff] [blame] | 1801 | if (upeek(tcp, sizeof(unsigned long)*PT_R3, &ppc_result) < 0) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1802 | return -1; |
| 1803 | if (flags & SO_MASK) |
Denys Vlasenko | 46dc8b2 | 2012-03-21 00:07:25 +0100 | [diff] [blame] | 1804 | ppc_result = -ppc_result; |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1805 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1806 | #elif defined(AVR32) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1807 | /* already done by get_regs */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1808 | #elif defined(BFIN) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1809 | if (upeek(tcp, PT_R0, &r0) < 0) |
| 1810 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1811 | #elif defined(I386) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1812 | /* already done by get_regs */ |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1813 | #elif defined(X86_64) || defined(X32) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1814 | /* already done by get_regs */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1815 | #elif defined(IA64) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1816 | # define IA64_PSR_IS ((long)1 << 34) |
| 1817 | if (upeek(tcp, PT_CR_IPSR, &psr) >= 0) |
| 1818 | ia32 = (psr & IA64_PSR_IS) != 0; |
| 1819 | if (upeek(tcp, PT_R8, &r8) < 0) |
| 1820 | return -1; |
| 1821 | if (upeek(tcp, PT_R10, &r10) < 0) |
| 1822 | return -1; |
Steve McIntyre | d8d3bd3 | 2012-10-24 17:58:16 +0100 | [diff] [blame] | 1823 | #elif defined(AARCH64) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1824 | /* FIXME: uh, why do we do it on syscall *exit*? We did it on entry already... */ |
| 1825 | /* We are in 64-bit mode (personality 1) if register struct is aarch64_regs, |
| 1826 | * else it's personality 0. |
| 1827 | */ |
| 1828 | update_personality(tcp, aarch64_io.iov_len == sizeof(aarch64_regs)); |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1829 | #elif defined(ARM) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1830 | /* already done by get_regs */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1831 | #elif defined(M68K) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1832 | if (upeek(tcp, 4*PT_D0, &d0) < 0) |
| 1833 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1834 | #elif defined(LINUX_MIPSN32) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1835 | unsigned long long regs[38]; |
| 1836 | |
| 1837 | if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0) |
| 1838 | return -1; |
| 1839 | a3 = regs[REG_A3]; |
| 1840 | r2 = regs[REG_V0]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1841 | #elif defined(MIPS) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1842 | if (upeek(tcp, REG_A3, &a3) < 0) |
| 1843 | return -1; |
| 1844 | if (upeek(tcp, REG_V0, &r2) < 0) |
| 1845 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1846 | #elif defined(ALPHA) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1847 | if (upeek(tcp, REG_A3, &a3) < 0) |
| 1848 | return -1; |
| 1849 | if (upeek(tcp, REG_R0, &r0) < 0) |
| 1850 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1851 | #elif defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1852 | /* already done by get_regs */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1853 | #elif defined(HPPA) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1854 | if (upeek(tcp, PT_GR28, &r28) < 0) |
| 1855 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1856 | #elif defined(SH) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1857 | /* new syscall ABI returns result in R0 */ |
| 1858 | if (upeek(tcp, 4*REG_REG0, (long *)&r0) < 0) |
| 1859 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1860 | #elif defined(SH64) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1861 | /* ABI defines result returned in r9 */ |
| 1862 | if (upeek(tcp, REG_GENERAL(9), (long *)&r9) < 0) |
| 1863 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1864 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1865 | if (upeek(tcp, 4*PT_R10, &r10) < 0) |
| 1866 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1867 | #elif defined(TILE) |
| 1868 | #elif defined(MICROBLAZE) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1869 | if (upeek(tcp, 3 * 4, &r3) < 0) |
| 1870 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1871 | #endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1872 | return 1; |
| 1873 | } |
| 1874 | |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 1875 | /* Called at each syscall exit */ |
| 1876 | static void |
Denys Vlasenko | 20c41fd | 2011-08-25 10:23:00 +0200 | [diff] [blame] | 1877 | syscall_fixup_on_sysexit(struct tcb *tcp) |
| 1878 | { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1879 | #if defined(S390) || defined(S390X) |
Denys Vlasenko | 20c41fd | 2011-08-25 10:23:00 +0200 | [diff] [blame] | 1880 | if (syscall_mode != -ENOSYS) |
| 1881 | syscall_mode = tcp->scno; |
Denys Vlasenko | ece9879 | 2011-08-25 10:25:35 +0200 | [diff] [blame] | 1882 | if ((tcp->flags & TCB_WAITEXECVE) |
Denys Vlasenko | 20c41fd | 2011-08-25 10:23:00 +0200 | [diff] [blame] | 1883 | && (gpr2 == -ENOSYS || gpr2 == tcp->scno)) { |
| 1884 | /* |
| 1885 | * Return from execve. |
| 1886 | * Fake a return value of zero. We leave the TCB_WAITEXECVE |
| 1887 | * flag set for the post-execve SIGTRAP to see and reset. |
| 1888 | */ |
| 1889 | gpr2 = 0; |
| 1890 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1891 | #endif |
Denys Vlasenko | 20c41fd | 2011-08-25 10:23:00 +0200 | [diff] [blame] | 1892 | } |
| 1893 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1894 | /* |
| 1895 | * Check the syscall return value register value for whether it is |
| 1896 | * a negated errno code indicating an error, or a success return value. |
| 1897 | */ |
| 1898 | static inline int |
| 1899 | is_negated_errno(unsigned long int val) |
| 1900 | { |
| 1901 | unsigned long int max = -(long int) nerrnos; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1902 | #if SUPPORTED_PERSONALITIES > 1 |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 1903 | if (current_wordsize < sizeof(val)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1904 | val = (unsigned int) val; |
| 1905 | max = (unsigned int) max; |
| 1906 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1907 | #endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1908 | return val > max; |
| 1909 | } |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1910 | |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 1911 | /* Returns: |
| 1912 | * 1: ok, continue in trace_syscall_exiting(). |
| 1913 | * -1: error, trace_syscall_exiting() should print error indicator |
| 1914 | * ("????" etc) and bail out. |
| 1915 | */ |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1916 | static int |
| 1917 | get_error(struct tcb *tcp) |
| 1918 | { |
| 1919 | int u_error = 0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1920 | int check_errno = 1; |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 1921 | if (SCNO_IN_RANGE(tcp->scno) && |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1922 | sysent[tcp->scno].sys_flags & SYSCALL_NEVER_FAILS) { |
| 1923 | check_errno = 0; |
| 1924 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1925 | #if defined(S390) || defined(S390X) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1926 | if (check_errno && is_negated_errno(gpr2)) { |
| 1927 | tcp->u_rval = -1; |
| 1928 | u_error = -gpr2; |
| 1929 | } |
| 1930 | else { |
| 1931 | tcp->u_rval = gpr2; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1932 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1933 | #elif defined(I386) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1934 | if (check_errno && is_negated_errno(i386_regs.eax)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1935 | tcp->u_rval = -1; |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1936 | u_error = -i386_regs.eax; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1937 | } |
| 1938 | else { |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1939 | tcp->u_rval = i386_regs.eax; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1940 | } |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1941 | #elif defined(X86_64) || defined(X32) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1942 | if (check_errno && is_negated_errno(x86_64_regs.rax)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1943 | tcp->u_rval = -1; |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1944 | u_error = -x86_64_regs.rax; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1945 | } |
| 1946 | else { |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1947 | tcp->u_rval = x86_64_regs.rax; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1948 | # if defined(X32) |
| 1949 | tcp->u_lrval = x86_64_regs.rax; |
| 1950 | # endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1951 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1952 | #elif defined(IA64) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1953 | if (ia32) { |
| 1954 | int err; |
| 1955 | |
| 1956 | err = (int)r8; |
| 1957 | if (check_errno && is_negated_errno(err)) { |
| 1958 | tcp->u_rval = -1; |
| 1959 | u_error = -err; |
| 1960 | } |
| 1961 | else { |
| 1962 | tcp->u_rval = err; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1963 | } |
| 1964 | } else { |
| 1965 | if (check_errno && r10) { |
| 1966 | tcp->u_rval = -1; |
| 1967 | u_error = r8; |
| 1968 | } else { |
| 1969 | tcp->u_rval = r8; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1970 | } |
| 1971 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1972 | #elif defined(MIPS) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1973 | if (check_errno && a3) { |
| 1974 | tcp->u_rval = -1; |
| 1975 | u_error = r2; |
| 1976 | } else { |
| 1977 | tcp->u_rval = r2; |
H.J. Lu | dd0130b | 2012-04-16 12:16:45 +0200 | [diff] [blame] | 1978 | # if defined(LINUX_MIPSN32) |
| 1979 | tcp->u_lrval = r2; |
| 1980 | # endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1981 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1982 | #elif defined(POWERPC) |
Denys Vlasenko | 46dc8b2 | 2012-03-21 00:07:25 +0100 | [diff] [blame] | 1983 | if (check_errno && is_negated_errno(ppc_result)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1984 | tcp->u_rval = -1; |
Denys Vlasenko | 46dc8b2 | 2012-03-21 00:07:25 +0100 | [diff] [blame] | 1985 | u_error = -ppc_result; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1986 | } |
| 1987 | else { |
Denys Vlasenko | 46dc8b2 | 2012-03-21 00:07:25 +0100 | [diff] [blame] | 1988 | tcp->u_rval = ppc_result; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1989 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1990 | #elif defined(M68K) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1991 | if (check_errno && is_negated_errno(d0)) { |
| 1992 | tcp->u_rval = -1; |
| 1993 | u_error = -d0; |
| 1994 | } |
| 1995 | else { |
| 1996 | tcp->u_rval = d0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1997 | } |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1998 | #elif defined(ARM) || defined(AARCH64) |
| 1999 | # if defined(AARCH64) |
| 2000 | if (tcp->currpers == 1) { |
| 2001 | if (check_errno && is_negated_errno(aarch64_regs.regs[0])) { |
| 2002 | tcp->u_rval = -1; |
| 2003 | u_error = -aarch64_regs.regs[0]; |
| 2004 | } |
| 2005 | else { |
| 2006 | tcp->u_rval = aarch64_regs.regs[0]; |
| 2007 | } |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2008 | } |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 2009 | else |
| 2010 | # endif /* AARCH64 */ |
| 2011 | { |
| 2012 | if (check_errno && is_negated_errno(regs.ARM_r0)) { |
| 2013 | tcp->u_rval = -1; |
| 2014 | u_error = -regs.ARM_r0; |
| 2015 | } |
| 2016 | else { |
| 2017 | tcp->u_rval = regs.ARM_r0; |
| 2018 | } |
Steve McIntyre | d8d3bd3 | 2012-10-24 17:58:16 +0100 | [diff] [blame] | 2019 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2020 | #elif defined(AVR32) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2021 | if (check_errno && regs.r12 && (unsigned) -regs.r12 < nerrnos) { |
| 2022 | tcp->u_rval = -1; |
| 2023 | u_error = -regs.r12; |
| 2024 | } |
| 2025 | else { |
| 2026 | tcp->u_rval = regs.r12; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2027 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2028 | #elif defined(BFIN) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2029 | if (check_errno && is_negated_errno(r0)) { |
| 2030 | tcp->u_rval = -1; |
| 2031 | u_error = -r0; |
| 2032 | } else { |
| 2033 | tcp->u_rval = r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2034 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2035 | #elif defined(ALPHA) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2036 | if (check_errno && a3) { |
| 2037 | tcp->u_rval = -1; |
| 2038 | u_error = r0; |
| 2039 | } |
| 2040 | else { |
| 2041 | tcp->u_rval = r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2042 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2043 | #elif defined(SPARC) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2044 | if (check_errno && regs.psr & PSR_C) { |
| 2045 | tcp->u_rval = -1; |
| 2046 | u_error = regs.u_regs[U_REG_O0]; |
| 2047 | } |
| 2048 | else { |
| 2049 | tcp->u_rval = regs.u_regs[U_REG_O0]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2050 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2051 | #elif defined(SPARC64) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2052 | if (check_errno && regs.tstate & 0x1100000000UL) { |
| 2053 | tcp->u_rval = -1; |
| 2054 | u_error = regs.u_regs[U_REG_O0]; |
| 2055 | } |
| 2056 | else { |
| 2057 | tcp->u_rval = regs.u_regs[U_REG_O0]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2058 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2059 | #elif defined(HPPA) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2060 | if (check_errno && is_negated_errno(r28)) { |
| 2061 | tcp->u_rval = -1; |
| 2062 | u_error = -r28; |
| 2063 | } |
| 2064 | else { |
| 2065 | tcp->u_rval = r28; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2066 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2067 | #elif defined(SH) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2068 | if (check_errno && is_negated_errno(r0)) { |
| 2069 | tcp->u_rval = -1; |
| 2070 | u_error = -r0; |
| 2071 | } |
| 2072 | else { |
| 2073 | tcp->u_rval = r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2074 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2075 | #elif defined(SH64) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2076 | if (check_errno && is_negated_errno(r9)) { |
| 2077 | tcp->u_rval = -1; |
| 2078 | u_error = -r9; |
| 2079 | } |
| 2080 | else { |
| 2081 | tcp->u_rval = r9; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2082 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2083 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2084 | if (check_errno && r10 && (unsigned) -r10 < nerrnos) { |
| 2085 | tcp->u_rval = -1; |
| 2086 | u_error = -r10; |
| 2087 | } |
| 2088 | else { |
| 2089 | tcp->u_rval = r10; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2090 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2091 | #elif defined(TILE) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2092 | long rval; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2093 | if (upeek(tcp, PTREGS_OFFSET_REG(0), &rval) < 0) |
| 2094 | return -1; |
| 2095 | if (check_errno && rval < 0 && rval > -nerrnos) { |
| 2096 | tcp->u_rval = -1; |
| 2097 | u_error = -rval; |
| 2098 | } |
| 2099 | else { |
| 2100 | tcp->u_rval = rval; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2101 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2102 | #elif defined(MICROBLAZE) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2103 | if (check_errno && is_negated_errno(r3)) { |
| 2104 | tcp->u_rval = -1; |
| 2105 | u_error = -r3; |
| 2106 | } |
| 2107 | else { |
| 2108 | tcp->u_rval = r3; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2109 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2110 | #endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2111 | tcp->u_error = u_error; |
| 2112 | return 1; |
| 2113 | } |
| 2114 | |
| 2115 | static void |
| 2116 | dumpio(struct tcb *tcp) |
| 2117 | { |
| 2118 | if (syserror(tcp)) |
| 2119 | return; |
| 2120 | if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= MAX_QUALS) |
| 2121 | return; |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 2122 | if (!SCNO_IN_RANGE(tcp->scno)) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2123 | return; |
| 2124 | if (sysent[tcp->scno].sys_func == printargs) |
| 2125 | return; |
| 2126 | if (qual_flags[tcp->u_arg[0]] & QUAL_READ) { |
| 2127 | if (sysent[tcp->scno].sys_func == sys_read || |
| 2128 | sysent[tcp->scno].sys_func == sys_pread || |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2129 | sysent[tcp->scno].sys_func == sys_recv || |
| 2130 | sysent[tcp->scno].sys_func == sys_recvfrom) |
| 2131 | dumpstr(tcp, tcp->u_arg[1], tcp->u_rval); |
| 2132 | else if (sysent[tcp->scno].sys_func == sys_readv) |
| 2133 | dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
| 2134 | return; |
| 2135 | } |
| 2136 | if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) { |
| 2137 | if (sysent[tcp->scno].sys_func == sys_write || |
| 2138 | sysent[tcp->scno].sys_func == sys_pwrite || |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2139 | sysent[tcp->scno].sys_func == sys_send || |
| 2140 | sysent[tcp->scno].sys_func == sys_sendto) |
| 2141 | dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 2142 | else if (sysent[tcp->scno].sys_func == sys_writev) |
| 2143 | dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
| 2144 | return; |
| 2145 | } |
| 2146 | } |
| 2147 | |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2148 | static int |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2149 | trace_syscall_exiting(struct tcb *tcp) |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 2150 | { |
| 2151 | int sys_res; |
| 2152 | struct timeval tv; |
Denys Vlasenko | 1a5b5a7 | 2011-08-25 00:29:56 +0200 | [diff] [blame] | 2153 | int res; |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2154 | long u_error; |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 2155 | |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2156 | /* Measure the exit time as early as possible to avoid errors. */ |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 2157 | if (Tflag || cflag) |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2158 | gettimeofday(&tv, NULL); |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 2159 | |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 2160 | #if SUPPORTED_PERSONALITIES > 1 |
| 2161 | update_personality(tcp, tcp->currpers); |
| 2162 | #endif |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 2163 | res = (get_regs_error ? -1 : get_syscall_result(tcp)); |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 2164 | if (res == 1) { |
| 2165 | syscall_fixup_on_sysexit(tcp); /* never fails */ |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 2166 | res = get_error(tcp); /* returns 1 or -1 */ |
| 2167 | if (res == 1) { |
| 2168 | internal_syscall(tcp); |
| 2169 | if (filtered(tcp)) { |
| 2170 | goto ret; |
| 2171 | } |
| 2172 | } |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2175 | if (cflag) { |
| 2176 | struct timeval t = tv; |
Denys Vlasenko | c95a88f | 2011-08-21 17:47:40 +0200 | [diff] [blame] | 2177 | count_syscall(tcp, &t); |
Denys Vlasenko | 7b609d5 | 2011-06-22 14:32:43 +0200 | [diff] [blame] | 2178 | if (cflag == CFLAG_ONLY_STATS) { |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2179 | goto ret; |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2180 | } |
| 2181 | } |
| 2182 | |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2183 | /* If not in -ff mode, and printing_tcp != tcp, |
| 2184 | * then the log currently does not end with output |
| 2185 | * of _our syscall entry_, but with something else. |
| 2186 | * We need to say which syscall's return is this. |
| 2187 | * |
| 2188 | * Forced reprinting via TCB_REPRINT is used only by |
| 2189 | * "strace -ff -oLOG test/threaded_execve" corner case. |
| 2190 | * It's the only case when -ff mode needs reprinting. |
| 2191 | */ |
| 2192 | if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) { |
| 2193 | tcp->flags &= ~TCB_REPRINT; |
| 2194 | printleader(tcp); |
| 2195 | if (!SCNO_IN_RANGE(tcp->scno)) |
| 2196 | tprintf("<... syscall_%lu resumed> ", tcp->scno); |
| 2197 | else |
| 2198 | tprintf("<... %s resumed> ", sysent[tcp->scno].sys_name); |
| 2199 | } |
| 2200 | printing_tcp = tcp; |
| 2201 | |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2202 | if (res != 1) { |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2203 | /* There was error in one of prior ptrace ops */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 2204 | tprints(") "); |
Denys Vlasenko | 102ec49 | 2011-08-25 01:27:59 +0200 | [diff] [blame] | 2205 | tabto(); |
Denys Vlasenko | 000b601 | 2012-01-28 01:25:03 +0100 | [diff] [blame] | 2206 | tprints("= ? <unavailable>\n"); |
Denys Vlasenko | 7de265d | 2012-03-13 11:44:31 +0100 | [diff] [blame] | 2207 | line_ended(); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2208 | tcp->flags &= ~TCB_INSYSCALL; |
| 2209 | return res; |
| 2210 | } |
| 2211 | |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2212 | sys_res = 0; |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 2213 | if (!SCNO_IN_RANGE(tcp->scno) |
Denys Vlasenko | 7de265d | 2012-03-13 11:44:31 +0100 | [diff] [blame] | 2214 | || (qual_flags[tcp->scno] & QUAL_RAW)) { |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2215 | /* sys_res = printargs(tcp); - but it's nop on sysexit */ |
Denys Vlasenko | 7de265d | 2012-03-13 11:44:31 +0100 | [diff] [blame] | 2216 | } else { |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2217 | /* FIXME: not_failing_only (IOW, option -z) is broken: |
| 2218 | * failure of syscall is known only after syscall return. |
| 2219 | * Thus we end up with something like this on, say, ENOENT: |
| 2220 | * open("doesnt_exist", O_RDONLY <unfinished ...> |
| 2221 | * {next syscall decode} |
| 2222 | * whereas the intended result is that open(...) line |
| 2223 | * is not shown at all. |
| 2224 | */ |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2225 | if (not_failing_only && tcp->u_error) |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2226 | goto ret; /* ignore failed syscalls */ |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2227 | sys_res = (*sysent[tcp->scno].sys_func)(tcp); |
| 2228 | } |
| 2229 | |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 2230 | tprints(") "); |
Denys Vlasenko | 102ec49 | 2011-08-25 01:27:59 +0200 | [diff] [blame] | 2231 | tabto(); |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2232 | u_error = tcp->u_error; |
Denys Vlasenko | cb6f056 | 2011-08-25 01:13:43 +0200 | [diff] [blame] | 2233 | if (!SCNO_IN_RANGE(tcp->scno) || |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2234 | qual_flags[tcp->scno] & QUAL_RAW) { |
| 2235 | if (u_error) |
| 2236 | tprintf("= -1 (errno %ld)", u_error); |
| 2237 | else |
| 2238 | tprintf("= %#lx", tcp->u_rval); |
| 2239 | } |
| 2240 | else if (!(sys_res & RVAL_NONE) && u_error) { |
| 2241 | switch (u_error) { |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2242 | /* Blocked signals do not interrupt any syscalls. |
| 2243 | * In this case syscalls don't return ERESTARTfoo codes. |
| 2244 | * |
| 2245 | * Deadly signals set to SIG_DFL interrupt syscalls |
| 2246 | * and kill the process regardless of which of the codes below |
| 2247 | * is returned by the interrupted syscall. |
| 2248 | * In some cases, kernel forces a kernel-generated deadly |
| 2249 | * signal to be unblocked and set to SIG_DFL (and thus cause |
| 2250 | * death) if it is blocked or SIG_IGNed: for example, SIGSEGV |
| 2251 | * or SIGILL. (The alternative is to leave process spinning |
| 2252 | * forever on the faulty instruction - not useful). |
| 2253 | * |
| 2254 | * SIG_IGNed signals and non-deadly signals set to SIG_DFL |
| 2255 | * (for example, SIGCHLD, SIGWINCH) interrupt syscalls, |
| 2256 | * but kernel will always restart them. |
| 2257 | */ |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2258 | case ERESTARTSYS: |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2259 | /* Most common type of signal-interrupted syscall exit code. |
| 2260 | * The system call will be restarted with the same arguments |
| 2261 | * if SA_RESTART is set; otherwise, it will fail with EINTR. |
| 2262 | */ |
| 2263 | tprints("= ? ERESTARTSYS (To be restarted if SA_RESTART is set)"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2264 | break; |
| 2265 | case ERESTARTNOINTR: |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2266 | /* Rare. For example, fork() returns this if interrupted. |
| 2267 | * SA_RESTART is ignored (assumed set): the restart is unconditional. |
| 2268 | */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 2269 | tprints("= ? ERESTARTNOINTR (To be restarted)"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2270 | break; |
| 2271 | case ERESTARTNOHAND: |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2272 | /* pause(), rt_sigsuspend() etc use this code. |
| 2273 | * SA_RESTART is ignored (assumed not set): |
| 2274 | * syscall won't restart (will return EINTR instead) |
| 2275 | * even after signal with SA_RESTART set. |
| 2276 | * However, after SIG_IGN or SIG_DFL signal it will. |
| 2277 | */ |
| 2278 | tprints("= ? ERESTARTNOHAND (Interrupted by signal)"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2279 | break; |
| 2280 | case ERESTART_RESTARTBLOCK: |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2281 | /* Syscalls like nanosleep(), poll() which can't be |
| 2282 | * restarted with their original arguments use this |
| 2283 | * code. Kernel will execute restart_syscall() instead, |
| 2284 | * which changes arguments before restarting syscall. |
| 2285 | * SA_RESTART is ignored (assumed not set) similarly |
| 2286 | * to ERESTARTNOHAND. (Kernel can't honor SA_RESTART |
| 2287 | * since restart data is saved in "restart block" |
| 2288 | * in task struct, and if signal handler uses a syscall |
| 2289 | * which in turn saves another such restart block, |
| 2290 | * old data is lost and restart becomes impossible) |
| 2291 | */ |
| 2292 | tprints("= ? ERESTART_RESTARTBLOCK (Interrupted by signal)"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2293 | break; |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2294 | default: |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2295 | if (u_error < 0) |
Denys Vlasenko | a794974 | 2011-08-21 17:26:55 +0200 | [diff] [blame] | 2296 | tprintf("= -1 E??? (errno %ld)", u_error); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2297 | else if (u_error < nerrnos) |
Denys Vlasenko | a794974 | 2011-08-21 17:26:55 +0200 | [diff] [blame] | 2298 | tprintf("= -1 %s (%s)", errnoent[u_error], |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2299 | strerror(u_error)); |
| 2300 | else |
Denys Vlasenko | a794974 | 2011-08-21 17:26:55 +0200 | [diff] [blame] | 2301 | tprintf("= -1 ERRNO_%ld (%s)", u_error, |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2302 | strerror(u_error)); |
| 2303 | break; |
| 2304 | } |
| 2305 | if ((sys_res & RVAL_STR) && tcp->auxstr) |
| 2306 | tprintf(" (%s)", tcp->auxstr); |
| 2307 | } |
| 2308 | else { |
| 2309 | if (sys_res & RVAL_NONE) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 2310 | tprints("= ?"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2311 | else { |
| 2312 | switch (sys_res & RVAL_MASK) { |
| 2313 | case RVAL_HEX: |
| 2314 | tprintf("= %#lx", tcp->u_rval); |
| 2315 | break; |
| 2316 | case RVAL_OCTAL: |
| 2317 | tprintf("= %#lo", tcp->u_rval); |
| 2318 | break; |
| 2319 | case RVAL_UDECIMAL: |
| 2320 | tprintf("= %lu", tcp->u_rval); |
| 2321 | break; |
| 2322 | case RVAL_DECIMAL: |
| 2323 | tprintf("= %ld", tcp->u_rval); |
| 2324 | break; |
H.J. Lu | dd0130b | 2012-04-16 12:16:45 +0200 | [diff] [blame] | 2325 | #if defined(LINUX_MIPSN32) || defined(X32) |
| 2326 | /* |
| 2327 | case RVAL_LHEX: |
| 2328 | tprintf("= %#llx", tcp->u_lrval); |
| 2329 | break; |
| 2330 | case RVAL_LOCTAL: |
| 2331 | tprintf("= %#llo", tcp->u_lrval); |
| 2332 | break; |
| 2333 | */ |
| 2334 | case RVAL_LUDECIMAL: |
| 2335 | tprintf("= %llu", tcp->u_lrval); |
| 2336 | break; |
| 2337 | /* |
| 2338 | case RVAL_LDECIMAL: |
| 2339 | tprintf("= %lld", tcp->u_lrval); |
| 2340 | break; |
| 2341 | */ |
| 2342 | #endif |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2343 | default: |
| 2344 | fprintf(stderr, |
| 2345 | "invalid rval format\n"); |
| 2346 | break; |
| 2347 | } |
| 2348 | } |
| 2349 | if ((sys_res & RVAL_STR) && tcp->auxstr) |
| 2350 | tprintf(" (%s)", tcp->auxstr); |
| 2351 | } |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 2352 | if (Tflag) { |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2353 | tv_sub(&tv, &tv, &tcp->etime); |
| 2354 | tprintf(" <%ld.%06ld>", |
| 2355 | (long) tv.tv_sec, (long) tv.tv_usec); |
| 2356 | } |
Denys Vlasenko | 000b601 | 2012-01-28 01:25:03 +0100 | [diff] [blame] | 2357 | tprints("\n"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2358 | dumpio(tcp); |
Denys Vlasenko | 7de265d | 2012-03-13 11:44:31 +0100 | [diff] [blame] | 2359 | line_ended(); |
| 2360 | |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2361 | ret: |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2362 | tcp->flags &= ~TCB_INSYSCALL; |
| 2363 | return 0; |
| 2364 | } |
| 2365 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 2366 | int |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2367 | trace_syscall(struct tcb *tcp) |
| 2368 | { |
| 2369 | return exiting(tcp) ? |
| 2370 | trace_syscall_exiting(tcp) : trace_syscall_entering(tcp); |
| 2371 | } |