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