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