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