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