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