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