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