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