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