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