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