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