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