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