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