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; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 562 | unsigned int i, n, size; |
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 | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 571 | size = current_wordsize; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 572 | n = tcp->s_ent->nargs; |
| 573 | for (i = 0; i < n; ++i) { |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 574 | if (size == sizeof(int)) { |
| 575 | unsigned int arg; |
| 576 | if (umove(tcp, addr, &arg) < 0) |
| 577 | arg = 0; |
| 578 | tcp->u_arg[i] = arg; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 579 | } |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 580 | else { |
| 581 | unsigned long arg; |
| 582 | if (umove(tcp, addr, &arg) < 0) |
| 583 | arg = 0; |
| 584 | tcp->u_arg[i] = arg; |
| 585 | } |
| 586 | addr += size; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 587 | } |
| 588 | } |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 589 | #endif |
Mike Frysinger | 3362e89 | 2012-03-15 01:09:19 -0400 | [diff] [blame] | 590 | |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 591 | #ifdef SYS_ipc_subcall |
| 592 | static void |
| 593 | decode_ipc_subcall(struct tcb *tcp) |
| 594 | { |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 595 | unsigned int i, n; |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 596 | |
| 597 | if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_ipc_nsubcalls) |
| 598 | return; |
| 599 | |
| 600 | tcp->scno = SYS_ipc_subcall + tcp->u_arg[0]; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 601 | tcp->qual_flg = qual_flags[tcp->scno]; |
| 602 | tcp->s_ent = &sysent[tcp->scno]; |
| 603 | n = tcp->s_ent->nargs; |
| 604 | for (i = 0; i < n; i++) |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 605 | tcp->u_arg[i] = tcp->u_arg[i + 1]; |
| 606 | } |
| 607 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 608 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 609 | int |
| 610 | printargs(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 611 | { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 612 | if (entering(tcp)) { |
| 613 | int i; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 614 | int n = tcp->s_ent->nargs; |
| 615 | for (i = 0; i < n; i++) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 616 | tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]); |
| 617 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 618 | return 0; |
| 619 | } |
| 620 | |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 621 | int |
| 622 | printargs_lu(struct tcb *tcp) |
| 623 | { |
| 624 | if (entering(tcp)) { |
| 625 | int i; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 626 | int n = tcp->s_ent->nargs; |
| 627 | for (i = 0; i < n; i++) |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 628 | tprintf("%s%lu", i ? ", " : "", tcp->u_arg[i]); |
| 629 | } |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | int |
| 634 | printargs_ld(struct tcb *tcp) |
| 635 | { |
| 636 | if (entering(tcp)) { |
| 637 | int i; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 638 | int n = tcp->s_ent->nargs; |
| 639 | for (i = 0; i < n; i++) |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 640 | tprintf("%s%ld", i ? ", " : "", tcp->u_arg[i]); |
| 641 | } |
| 642 | return 0; |
| 643 | } |
| 644 | |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 645 | #if defined(I386) |
Denys Vlasenko | b51f364 | 2013-07-16 12:06:25 +0200 | [diff] [blame] | 646 | static struct user_regs_struct i386_regs; |
Dmitry V. Levin | f97a477 | 2015-02-15 00:08:11 +0000 | [diff] [blame] | 647 | long *const i386_esp_ptr = &i386_regs.esp; |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 648 | # define ARCH_REGS_FOR_GETREGS i386_regs |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 649 | #elif defined(X86_64) || defined(X32) |
Denys Vlasenko | e73a89d | 2012-01-18 11:07:24 +0100 | [diff] [blame] | 650 | /* |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 651 | * On i386, pt_regs and user_regs_struct are the same, |
| 652 | * but on 64 bit x86, user_regs_struct has six more fields: |
Denys Vlasenko | e73a89d | 2012-01-18 11:07:24 +0100 | [diff] [blame] | 653 | * fs_base, gs_base, ds, es, fs, gs. |
| 654 | * PTRACE_GETREGS fills them too, so struct pt_regs would overflow. |
| 655 | */ |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 656 | struct i386_user_regs_struct { |
| 657 | uint32_t ebx; |
| 658 | uint32_t ecx; |
| 659 | uint32_t edx; |
| 660 | uint32_t esi; |
| 661 | uint32_t edi; |
| 662 | uint32_t ebp; |
| 663 | uint32_t eax; |
| 664 | uint32_t xds; |
| 665 | uint32_t xes; |
| 666 | uint32_t xfs; |
| 667 | uint32_t xgs; |
| 668 | uint32_t orig_eax; |
| 669 | uint32_t eip; |
| 670 | uint32_t xcs; |
| 671 | uint32_t eflags; |
| 672 | uint32_t esp; |
| 673 | uint32_t xss; |
| 674 | }; |
| 675 | static union { |
| 676 | struct user_regs_struct x86_64_r; |
| 677 | struct i386_user_regs_struct i386_r; |
| 678 | } x86_regs_union; |
| 679 | # define x86_64_regs x86_regs_union.x86_64_r |
| 680 | # define i386_regs x86_regs_union.i386_r |
Denys Vlasenko | b51f364 | 2013-07-16 12:06:25 +0200 | [diff] [blame] | 681 | uint32_t *const i386_esp_ptr = &i386_regs.esp; |
Dmitry V. Levin | ccb4fda | 2015-03-04 12:19:55 +0000 | [diff] [blame] | 682 | 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] | 683 | static struct iovec x86_io = { |
| 684 | .iov_base = &x86_regs_union |
| 685 | }; |
Dmitry V. Levin | d6db1db | 2015-02-13 23:41:04 +0000 | [diff] [blame] | 686 | # define ARCH_REGS_FOR_GETREGSET x86_regs_union |
| 687 | # define ARCH_IOVEC_FOR_GETREGSET x86_io |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 688 | #elif defined(IA64) |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame^] | 689 | static struct pt_all_user_regs ia64_regs; |
| 690 | unsigned long *const ia64_frame_ptr = &ia64_regs.gr[12]; |
| 691 | # define IA64_PSR_IS ((long)1 << 34) |
| 692 | # define ia64_ia32mode (ia64_regs.cr_ipsr & IA64_PSR_IS) |
| 693 | # define ARCH_REGS_FOR_GETREGS ia64_regs |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 694 | #elif defined(POWERPC) |
Dmitry V. Levin | 23ce9e4 | 2015-02-08 13:05:53 +0000 | [diff] [blame] | 695 | struct pt_regs ppc_regs; /* not static */ |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 696 | # define ARCH_REGS_FOR_GETREGS ppc_regs |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 697 | #elif defined(M68K) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 698 | static long m68k_d0; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 699 | #elif defined(BFIN) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 700 | static long bfin_r0; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 701 | #elif defined(ARM) |
Dmitry V. Levin | 5b9b7e1 | 2015-03-04 23:05:53 +0000 | [diff] [blame] | 702 | static struct pt_regs arm_regs; |
| 703 | long *const arm_sp_ptr = &arm_regs.ARM_sp; |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 704 | # define ARCH_REGS_FOR_GETREGS arm_regs |
Steve McIntyre | d8d3bd3 | 2012-10-24 17:58:16 +0100 | [diff] [blame] | 705 | #elif defined(AARCH64) |
Dmitry V. Levin | 5503dd2 | 2015-02-13 02:12:14 +0000 | [diff] [blame] | 706 | struct arm_pt_regs { |
| 707 | int uregs[18]; |
| 708 | }; |
| 709 | # define ARM_cpsr uregs[16] |
| 710 | # define ARM_pc uregs[15] |
| 711 | # define ARM_lr uregs[14] |
| 712 | # define ARM_sp uregs[13] |
| 713 | # define ARM_ip uregs[12] |
| 714 | # define ARM_fp uregs[11] |
| 715 | # define ARM_r10 uregs[10] |
| 716 | # define ARM_r9 uregs[9] |
| 717 | # define ARM_r8 uregs[8] |
| 718 | # define ARM_r7 uregs[7] |
| 719 | # define ARM_r6 uregs[6] |
| 720 | # define ARM_r5 uregs[5] |
| 721 | # define ARM_r4 uregs[4] |
| 722 | # define ARM_r3 uregs[3] |
| 723 | # define ARM_r2 uregs[2] |
| 724 | # define ARM_r1 uregs[1] |
| 725 | # define ARM_r0 uregs[0] |
| 726 | # define ARM_ORIG_r0 uregs[17] |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 727 | static union { |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 728 | struct user_pt_regs aarch64_r; |
| 729 | struct arm_pt_regs arm_r; |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 730 | } arm_regs_union; |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 731 | # define aarch64_regs arm_regs_union.aarch64_r |
| 732 | # define arm_regs arm_regs_union.arm_r |
Dmitry V. Levin | 47e289b | 2015-03-05 04:10:52 +0000 | [diff] [blame] | 733 | uint64_t *const aarch64_sp_ptr = (uint64_t *) &aarch64_regs.sp; |
| 734 | uint32_t *const arm_sp_ptr = (uint32_t *) &arm_regs.ARM_sp; |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 735 | static struct iovec aarch64_io = { |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 736 | .iov_base = &arm_regs_union |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 737 | }; |
Dmitry V. Levin | d6db1db | 2015-02-13 23:41:04 +0000 | [diff] [blame] | 738 | # define ARCH_REGS_FOR_GETREGSET arm_regs_union |
| 739 | # define ARCH_IOVEC_FOR_GETREGSET aarch64_io |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 740 | #elif defined(ALPHA) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 741 | static long alpha_r0; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 742 | static long alpha_a3; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 743 | #elif defined(AVR32) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 744 | static struct pt_regs avr32_regs; |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 745 | # define ARCH_REGS_FOR_GETREGS avr32_regs |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 746 | #elif defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 747 | struct pt_regs sparc_regs; /* not static */ |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 748 | # define ARCH_REGS_FOR_GETREGS sparc_regs |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 749 | #elif defined(MIPS) |
Dmitry V. Levin | 4f2d1ae | 2015-02-15 03:27:13 +0000 | [diff] [blame] | 750 | struct mips_regs mips_regs; /* not static */ |
| 751 | /* PTRACE_GETREGS on MIPS is available since linux v2.6.15. */ |
| 752 | # define ARCH_REGS_FOR_GETREGS mips_regs |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 753 | #elif defined(S390) || defined(S390X) |
Dmitry V. Levin | 20eca8a | 2015-03-05 22:10:15 +0000 | [diff] [blame] | 754 | /* PTRACE_GETREGSET on S390 is available since linux v2.6.27. */ |
| 755 | static struct user_regs_struct s390_regset; |
| 756 | unsigned long *const s390_frame_ptr = &s390_regset.gprs[15]; |
| 757 | # define ARCH_REGS_FOR_GETREGSET s390_regset |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 758 | #elif defined(HPPA) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 759 | static long hppa_r28; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 760 | #elif defined(SH) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 761 | static long sh_r0; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 762 | #elif defined(SH64) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 763 | static long sh64_r9; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 764 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 765 | static long cris_r10; |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 766 | #elif defined(TILE) |
Dmitry V. Levin | 23ce9e4 | 2015-02-08 13:05:53 +0000 | [diff] [blame] | 767 | struct pt_regs tile_regs; /* not static */ |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 768 | # define ARCH_REGS_FOR_GETREGS tile_regs |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 769 | #elif defined(MICROBLAZE) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 770 | static long microblaze_r3; |
Christian Svensson | 492f81f | 2013-02-14 13:26:27 +0100 | [diff] [blame] | 771 | #elif defined(OR1K) |
| 772 | static struct user_regs_struct or1k_regs; |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 773 | # define ARCH_REGS_FOR_GETREGSET or1k_regs |
James Hogan | 5f999a8 | 2013-02-22 14:44:10 +0000 | [diff] [blame] | 774 | #elif defined(METAG) |
| 775 | static struct user_gp_regs metag_regs; |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 776 | # define ARCH_REGS_FOR_GETREGSET metag_regs |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 777 | #elif defined(XTENSA) |
| 778 | static long xtensa_a2; |
Vineet Gupta | 7daacbb | 2013-08-16 12:47:06 +0530 | [diff] [blame] | 779 | # elif defined(ARC) |
| 780 | static struct user_regs_struct arc_regs; |
| 781 | # define ARCH_REGS_FOR_GETREGSET arc_regs |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 782 | #endif |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 783 | |
Dmitry V. Levin | 9a176c9 | 2015-02-13 21:56:50 +0000 | [diff] [blame] | 784 | static long get_regs_error; |
| 785 | |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame^] | 786 | #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH) |
| 787 | long |
| 788 | getrval2(struct tcb *tcp) |
| 789 | { |
| 790 | long val; |
| 791 | |
| 792 | # if defined(SPARC) || defined(SPARC64) |
| 793 | val = sparc_regs.u_regs[U_REG_O1]; |
| 794 | # elif defined(SH) |
| 795 | if (upeek(tcp->pid, 4*(REG_REG0+1), &val) < 0) |
| 796 | return -1; |
| 797 | # elif defined(IA64) |
| 798 | val = ia64_regs.gr[9]; |
| 799 | # endif |
| 800 | |
| 801 | return val; |
| 802 | } |
| 803 | #endif |
| 804 | |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 805 | void |
Denys Vlasenko | 5a2483b | 2013-07-01 12:49:14 +0200 | [diff] [blame] | 806 | print_pc(struct tcb *tcp) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 807 | { |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 808 | const char *fmt; |
| 809 | const char *bad; |
| 810 | |
Dmitry V. Levin | b2d9ff2 | 2015-02-23 13:43:20 +0000 | [diff] [blame] | 811 | #ifdef current_wordsize |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 812 | # define pc_wordsize current_wordsize |
Dmitry V. Levin | b2d9ff2 | 2015-02-23 13:43:20 +0000 | [diff] [blame] | 813 | #else |
| 814 | # define pc_wordsize personality_wordsize[tcp->currpers] |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 815 | #endif |
| 816 | |
| 817 | if (pc_wordsize == 4) { |
| 818 | fmt = "[%08lx] "; |
| 819 | bad = "[????????] "; |
| 820 | } else { |
| 821 | fmt = "[%016lx] "; |
| 822 | bad = "[????????????????] "; |
| 823 | } |
| 824 | |
| 825 | #undef pc_wordsize |
| 826 | #define PRINTBADPC tprints(bad) |
| 827 | |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 828 | if (get_regs_error) { |
| 829 | PRINTBADPC; |
| 830 | return; |
| 831 | } |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 832 | |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 833 | #if defined(I386) |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 834 | tprintf(fmt, i386_regs.eip); |
| 835 | #elif defined(X86_64) || defined(X32) |
| 836 | if (x86_io.iov_len == sizeof(i386_regs)) |
| 837 | tprintf(fmt, (unsigned long) i386_regs.eip); |
| 838 | else |
| 839 | tprintf(fmt, (unsigned long) x86_64_regs.rip); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 840 | #elif defined(S390) || defined(S390X) |
Dmitry V. Levin | 20eca8a | 2015-03-05 22:10:15 +0000 | [diff] [blame] | 841 | tprintf(fmt, s390_regset.psw.addr); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 842 | #elif defined(IA64) |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame^] | 843 | tprintf(fmt, ia64_regs.br[0]); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 844 | #elif defined(POWERPC) |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 845 | tprintf(fmt, ppc_regs.nip); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 846 | #elif defined(M68K) |
| 847 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 848 | if (upeek(tcp->pid, 4*PT_PC, &pc) < 0) { |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 849 | PRINTBADPC; |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 850 | return; |
| 851 | } |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 852 | tprintf(fmt, pc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 853 | #elif defined(ALPHA) |
| 854 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 855 | if (upeek(tcp->pid, REG_PC, &pc) < 0) { |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 856 | PRINTBADPC; |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 857 | return; |
| 858 | } |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 859 | tprintf(fmt, pc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 860 | #elif defined(SPARC) |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 861 | tprintf(fmt, sparc_regs.pc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 862 | #elif defined(SPARC64) |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 863 | tprintf(fmt, sparc_regs.tpc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 864 | #elif defined(HPPA) |
| 865 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 866 | if (upeek(tcp->pid, PT_IAOQ0, &pc) < 0) { |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 867 | PRINTBADPC; |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 868 | return; |
| 869 | } |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 870 | tprintf(fmt, pc); |
Dmitry V. Levin | 4f2d1ae | 2015-02-15 03:27:13 +0000 | [diff] [blame] | 871 | #elif defined MIPS |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 872 | tprintf(fmt, (unsigned long) mips_REG_EPC); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 873 | #elif defined(SH) |
| 874 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 875 | if (upeek(tcp->pid, 4*REG_PC, &pc) < 0) { |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 876 | PRINTBADPC; |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 877 | return; |
| 878 | } |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 879 | tprintf(fmt, pc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 880 | #elif defined(SH64) |
| 881 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 882 | if (upeek(tcp->pid, REG_PC, &pc) < 0) { |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 883 | PRINTBADPC; |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 884 | return; |
| 885 | } |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 886 | tprintf(fmt, pc); |
Dmitry V. Levin | d819fe8 | 2015-03-02 03:38:27 +0000 | [diff] [blame] | 887 | #elif defined(AARCH64) |
| 888 | if (aarch64_io.iov_len == sizeof(arm_regs)) |
| 889 | tprintf(fmt, (unsigned long) arm_regs.ARM_pc); |
| 890 | else |
| 891 | tprintf(fmt, (unsigned long) aarch64_regs.pc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 892 | #elif defined(ARM) |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 893 | tprintf(fmt, arm_regs.ARM_pc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 894 | #elif defined(AVR32) |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 895 | tprintf(fmt, avr32_regs.pc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 896 | #elif defined(BFIN) |
| 897 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 898 | if (upeek(tcp->pid, PT_PC, &pc) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 899 | PRINTBADPC; |
| 900 | return; |
| 901 | } |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 902 | tprintf(fmt, pc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 903 | #elif defined(CRISV10) |
| 904 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 905 | if (upeek(tcp->pid, 4*PT_IRP, &pc) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 906 | PRINTBADPC; |
| 907 | return; |
| 908 | } |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 909 | tprintf(fmt, pc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 910 | #elif defined(CRISV32) |
| 911 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 912 | if (upeek(tcp->pid, 4*PT_ERP, &pc) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 913 | PRINTBADPC; |
| 914 | return; |
| 915 | } |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 916 | tprintf(fmt, pc); |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 917 | #elif defined(TILE) |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 918 | tprintf(fmt, (unsigned long) tile_regs.pc); |
Christian Svensson | 492f81f | 2013-02-14 13:26:27 +0100 | [diff] [blame] | 919 | #elif defined(OR1K) |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 920 | tprintf(fmt, or1k_regs.pc); |
James Hogan | 5f999a8 | 2013-02-22 14:44:10 +0000 | [diff] [blame] | 921 | #elif defined(METAG) |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 922 | tprintf(fmt, metag_regs.pc); |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 923 | #elif defined(XTENSA) |
| 924 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 925 | if (upeek(tcp->pid, REG_PC, &pc) < 0) { |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 926 | PRINTBADPC; |
| 927 | return; |
| 928 | } |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 929 | tprintf(fmt, pc); |
Vineet Gupta | 7daacbb | 2013-08-16 12:47:06 +0530 | [diff] [blame] | 930 | #elif defined(ARC) |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 931 | tprintf(fmt, arc_regs.efa); |
| 932 | #else |
| 933 | # warning print_pc is not implemented for this architecture |
| 934 | PRINTBADPC; |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 935 | #endif /* architecture */ |
| 936 | } |
| 937 | |
Dmitry V. Levin | cf7248d | 2015-01-11 17:26:29 +0000 | [diff] [blame] | 938 | /* |
| 939 | * Shuffle syscall numbers so that we don't have huge gaps in syscall table. |
| 940 | * The shuffling should be an involution: shuffle_scno(shuffle_scno(n)) == n. |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 941 | */ |
Elliott Hughes | 7a28f7f | 2014-03-03 23:45:26 +0000 | [diff] [blame] | 942 | #if defined(ARM) || defined(AARCH64) /* So far only 32-bit ARM needs this */ |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 943 | static long |
| 944 | shuffle_scno(unsigned long scno) |
| 945 | { |
Dmitry V. Levin | cf7248d | 2015-01-11 17:26:29 +0000 | [diff] [blame] | 946 | if (scno < ARM_FIRST_SHUFFLED_SYSCALL) |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 947 | return scno; |
| 948 | |
| 949 | /* __ARM_NR_cmpxchg? Swap with LAST_ORDINARY+1 */ |
Dmitry V. Levin | cf7248d | 2015-01-11 17:26:29 +0000 | [diff] [blame] | 950 | if (scno == ARM_FIRST_SHUFFLED_SYSCALL) |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 951 | return 0x000ffff0; |
Dmitry V. Levin | cf7248d | 2015-01-11 17:26:29 +0000 | [diff] [blame] | 952 | if (scno == 0x000ffff0) |
| 953 | return ARM_FIRST_SHUFFLED_SYSCALL; |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 954 | |
Dmitry V. Levin | cf7248d | 2015-01-11 17:26:29 +0000 | [diff] [blame] | 955 | #define ARM_SECOND_SHUFFLED_SYSCALL (ARM_FIRST_SHUFFLED_SYSCALL + 1) |
| 956 | /* |
| 957 | * Is it ARM specific syscall? |
| 958 | * Swap [0x000f0000, 0x000f0000 + LAST_SPECIAL] range |
| 959 | * with [SECOND_SHUFFLED, SECOND_SHUFFLED + LAST_SPECIAL] range. |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 960 | */ |
Dmitry V. Levin | cf7248d | 2015-01-11 17:26:29 +0000 | [diff] [blame] | 961 | if (scno >= 0x000f0000 && |
| 962 | scno <= 0x000f0000 + ARM_LAST_SPECIAL_SYSCALL) { |
| 963 | return scno - 0x000f0000 + ARM_SECOND_SHUFFLED_SYSCALL; |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 964 | } |
Dmitry V. Levin | cf7248d | 2015-01-11 17:26:29 +0000 | [diff] [blame] | 965 | if (scno <= ARM_SECOND_SHUFFLED_SYSCALL + ARM_LAST_SPECIAL_SYSCALL) { |
| 966 | return scno + 0x000f0000 - ARM_SECOND_SHUFFLED_SYSCALL; |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | return scno; |
| 970 | } |
| 971 | #else |
| 972 | # define shuffle_scno(scno) ((long)(scno)) |
| 973 | #endif |
| 974 | |
| 975 | static char* |
| 976 | undefined_scno_name(struct tcb *tcp) |
| 977 | { |
| 978 | static char buf[sizeof("syscall_%lu") + sizeof(long)*3]; |
| 979 | |
| 980 | sprintf(buf, "syscall_%lu", shuffle_scno(tcp->scno)); |
| 981 | return buf; |
| 982 | } |
| 983 | |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 984 | #ifdef POWERPC |
| 985 | /* |
Denys Vlasenko | 7f5a132 | 2013-06-28 14:36:39 +0200 | [diff] [blame] | 986 | * PTRACE_GETREGS was added to the PowerPC kernel in v2.6.23, |
| 987 | * we provide a slow fallback for old kernels. |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 988 | */ |
Denys Vlasenko | 7f5a132 | 2013-06-28 14:36:39 +0200 | [diff] [blame] | 989 | static int powerpc_getregs_old(pid_t pid) |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 990 | { |
| 991 | int i; |
| 992 | long r; |
| 993 | |
Denys Vlasenko | 6b3016e | 2013-06-28 14:51:50 +0200 | [diff] [blame] | 994 | if (iflag) { |
Anton Blanchard | 9459dfb | 2013-07-12 12:24:02 +0200 | [diff] [blame] | 995 | r = upeek(pid, sizeof(long) * PT_NIP, (long *)&ppc_regs.nip); |
Denys Vlasenko | 6b3016e | 2013-06-28 14:51:50 +0200 | [diff] [blame] | 996 | if (r) |
| 997 | goto out; |
| 998 | } |
| 999 | #ifdef POWERPC64 /* else we never use it */ |
Anton Blanchard | 9459dfb | 2013-07-12 12:24:02 +0200 | [diff] [blame] | 1000 | r = upeek(pid, sizeof(long) * PT_MSR, (long *)&ppc_regs.msr); |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1001 | if (r) |
| 1002 | goto out; |
Denys Vlasenko | 6b3016e | 2013-06-28 14:51:50 +0200 | [diff] [blame] | 1003 | #endif |
Anton Blanchard | 9459dfb | 2013-07-12 12:24:02 +0200 | [diff] [blame] | 1004 | r = upeek(pid, sizeof(long) * PT_CCR, (long *)&ppc_regs.ccr); |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1005 | if (r) |
| 1006 | goto out; |
Anton Blanchard | 9459dfb | 2013-07-12 12:24:02 +0200 | [diff] [blame] | 1007 | 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] | 1008 | if (r) |
| 1009 | goto out; |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1010 | for (i = 0; i <= 8; i++) { |
Anton Blanchard | 9459dfb | 2013-07-12 12:24:02 +0200 | [diff] [blame] | 1011 | r = upeek(pid, sizeof(long) * (PT_R0 + i), |
| 1012 | (long *)&ppc_regs.gpr[i]); |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1013 | if (r) |
| 1014 | goto out; |
| 1015 | } |
Denys Vlasenko | 7f5a132 | 2013-06-28 14:36:39 +0200 | [diff] [blame] | 1016 | out: |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1017 | return r; |
| 1018 | } |
| 1019 | #endif |
| 1020 | |
Dmitry V. Levin | 9a176c9 | 2015-02-13 21:56:50 +0000 | [diff] [blame] | 1021 | void |
| 1022 | clear_regs(void) |
| 1023 | { |
| 1024 | get_regs_error = -1; |
| 1025 | } |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1026 | |
Dmitry V. Levin | d6db1db | 2015-02-13 23:41:04 +0000 | [diff] [blame] | 1027 | #if defined ARCH_REGS_FOR_GETREGSET |
| 1028 | static long |
| 1029 | get_regset(pid_t pid) |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1030 | { |
Dmitry V. Levin | d6db1db | 2015-02-13 23:41:04 +0000 | [diff] [blame] | 1031 | # ifdef ARCH_IOVEC_FOR_GETREGSET |
| 1032 | /* variable iovec */ |
| 1033 | ARCH_IOVEC_FOR_GETREGSET.iov_len = sizeof(ARCH_REGS_FOR_GETREGSET); |
| 1034 | return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, |
| 1035 | &ARCH_IOVEC_FOR_GETREGSET); |
| 1036 | # else |
| 1037 | /* constant iovec */ |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1038 | static struct iovec io = { |
| 1039 | .iov_base = &ARCH_REGS_FOR_GETREGSET, |
| 1040 | .iov_len = sizeof(ARCH_REGS_FOR_GETREGSET) |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1041 | }; |
Dmitry V. Levin | d6db1db | 2015-02-13 23:41:04 +0000 | [diff] [blame] | 1042 | return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &io); |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1043 | |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1044 | # endif |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1045 | } |
Dmitry V. Levin | d6db1db | 2015-02-13 23:41:04 +0000 | [diff] [blame] | 1046 | #endif /* ARCH_REGS_FOR_GETREGSET */ |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1047 | |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1048 | void |
| 1049 | get_regs(pid_t pid) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1050 | { |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 1051 | #ifdef ARCH_REGS_FOR_GETREGSET |
| 1052 | # ifdef X86_64 |
| 1053 | /* Try PTRACE_GETREGSET first, fallback to PTRACE_GETREGS. */ |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1054 | static int getregset_support; |
| 1055 | |
| 1056 | if (getregset_support >= 0) { |
Dmitry V. Levin | d6db1db | 2015-02-13 23:41:04 +0000 | [diff] [blame] | 1057 | get_regs_error = get_regset(pid); |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1058 | if (getregset_support > 0) |
| 1059 | return; |
| 1060 | if (get_regs_error >= 0) { |
| 1061 | getregset_support = 1; |
| 1062 | return; |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1063 | } |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1064 | if (errno == EPERM || errno == ESRCH) |
| 1065 | return; |
| 1066 | getregset_support = -1; |
| 1067 | } |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1068 | /* Use old method, with unreliable heuristical detection of 32-bitness. */ |
| 1069 | x86_io.iov_len = sizeof(x86_64_regs); |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1070 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &x86_64_regs); |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1071 | if (!get_regs_error && x86_64_regs.cs == 0x23) { |
| 1072 | x86_io.iov_len = sizeof(i386_regs); |
| 1073 | /* |
| 1074 | * The order is important: i386_regs and x86_64_regs |
| 1075 | * are overlaid in memory! |
| 1076 | */ |
| 1077 | i386_regs.ebx = x86_64_regs.rbx; |
| 1078 | i386_regs.ecx = x86_64_regs.rcx; |
| 1079 | i386_regs.edx = x86_64_regs.rdx; |
| 1080 | i386_regs.esi = x86_64_regs.rsi; |
| 1081 | i386_regs.edi = x86_64_regs.rdi; |
| 1082 | i386_regs.ebp = x86_64_regs.rbp; |
| 1083 | i386_regs.eax = x86_64_regs.rax; |
| 1084 | /* i386_regs.xds = x86_64_regs.ds; unused by strace */ |
| 1085 | /* i386_regs.xes = x86_64_regs.es; ditto... */ |
| 1086 | /* i386_regs.xfs = x86_64_regs.fs; */ |
| 1087 | /* i386_regs.xgs = x86_64_regs.gs; */ |
| 1088 | i386_regs.orig_eax = x86_64_regs.orig_rax; |
| 1089 | i386_regs.eip = x86_64_regs.rip; |
| 1090 | /* i386_regs.xcs = x86_64_regs.cs; */ |
| 1091 | /* i386_regs.eflags = x86_64_regs.eflags; */ |
| 1092 | i386_regs.esp = x86_64_regs.rsp; |
| 1093 | /* i386_regs.xss = x86_64_regs.ss; */ |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1094 | } |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 1095 | # else /* !X86_64 */ |
| 1096 | /* Assume that PTRACE_GETREGSET works. */ |
| 1097 | get_regs_error = get_regset(pid); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1098 | # endif |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 1099 | #elif defined ARCH_REGS_FOR_GETREGS |
| 1100 | # if defined SPARC || defined SPARC64 |
| 1101 | /* SPARC systems have the meaning of data and addr reversed */ |
| 1102 | get_regs_error = ptrace(PTRACE_GETREGS, pid, (char *)&ARCH_REGS_FOR_GETREGS, 0); |
| 1103 | # elif defined POWERPC |
| 1104 | static bool old_kernel = 0; |
| 1105 | if (old_kernel) |
| 1106 | goto old; |
| 1107 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS); |
| 1108 | if (get_regs_error && errno == EIO) { |
| 1109 | old_kernel = 1; |
| 1110 | old: |
| 1111 | get_regs_error = powerpc_getregs_old(pid); |
| 1112 | } |
| 1113 | # else |
| 1114 | /* Assume that PTRACE_GETREGS works. */ |
| 1115 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS); |
| 1116 | # endif |
| 1117 | |
| 1118 | #else /* !ARCH_REGS_FOR_GETREGSET && !ARCH_REGS_FOR_GETREGS */ |
| 1119 | # warning get_regs is not implemented for this architecture yet |
| 1120 | get_regs_error = 0; |
| 1121 | #endif |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1122 | } |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1123 | |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1124 | /* Returns: |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 1125 | * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently. |
| 1126 | * 1: ok, continue in trace_syscall_entering(). |
| 1127 | * other: error, trace_syscall_entering() should print error indicator |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1128 | * ("????" etc) and bail out. |
| 1129 | */ |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 1130 | static int |
Denys Vlasenko | 06602d9 | 2011-08-24 17:53:52 +0200 | [diff] [blame] | 1131 | get_scno(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1132 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1133 | long scno = 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1134 | |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1135 | #if defined(S390) || defined(S390X) |
Dmitry V. Levin | 20eca8a | 2015-03-05 22:10:15 +0000 | [diff] [blame] | 1136 | scno = s390_regset.gprs[2]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1137 | #elif defined(POWERPC) |
Anton Blanchard | ce6e33b | 2013-06-26 15:53:33 +0200 | [diff] [blame] | 1138 | scno = ppc_regs.gpr[0]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1139 | # ifdef POWERPC64 |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 1140 | unsigned int currpers; |
Andreas Schwab | d69fa49 | 2010-07-12 21:39:57 +0200 | [diff] [blame] | 1141 | |
James Yang | a78d777 | 2014-02-18 15:32:43 -0600 | [diff] [blame] | 1142 | /* |
| 1143 | * Check for 64/32 bit mode. |
| 1144 | * Embedded implementations covered by Book E extension of PPC use |
| 1145 | * bit 0 (CM) of 32-bit Machine state register (MSR). |
| 1146 | * Other implementations use bit 0 (SF) of 64-bit MSR. |
| 1147 | */ |
| 1148 | currpers = (ppc_regs.msr & 0x8000000080000000) ? 0 : 1; |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1149 | update_personality(tcp, currpers); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1150 | # endif |
| 1151 | #elif defined(AVR32) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1152 | scno = avr32_regs.r8; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1153 | #elif defined(BFIN) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1154 | if (upeek(tcp->pid, PT_ORIG_P0, &scno)) |
Dmitry V. Levin | 87ea1f4 | 2008-11-10 22:21:41 +0000 | [diff] [blame] | 1155 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1156 | #elif defined(I386) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1157 | scno = i386_regs.orig_eax; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1158 | #elif defined(X86_64) || defined(X32) |
| 1159 | # ifndef __X32_SYSCALL_BIT |
| 1160 | # define __X32_SYSCALL_BIT 0x40000000 |
| 1161 | # endif |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 1162 | unsigned int currpers; |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1163 | # if 1 |
| 1164 | /* GETREGSET of NT_PRSTATUS tells us regset size, |
| 1165 | * which unambiguously detects i386. |
| 1166 | * |
| 1167 | * Linux kernel distinguishes x86-64 and x32 processes |
| 1168 | * solely by looking at __X32_SYSCALL_BIT: |
| 1169 | * arch/x86/include/asm/compat.h::is_x32_task(): |
| 1170 | * if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT) |
| 1171 | * return true; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1172 | */ |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1173 | if (x86_io.iov_len == sizeof(i386_regs)) { |
| 1174 | scno = i386_regs.orig_eax; |
| 1175 | currpers = 1; |
| 1176 | } else { |
| 1177 | scno = x86_64_regs.orig_rax; |
| 1178 | currpers = 0; |
| 1179 | if (scno & __X32_SYSCALL_BIT) { |
Dmitry V. Levin | c394832 | 2015-02-05 16:15:46 +0000 | [diff] [blame] | 1180 | /* |
| 1181 | * Syscall number -1 requires special treatment: |
| 1182 | * it might be a side effect of SECCOMP_RET_ERRNO |
| 1183 | * filtering that sets orig_rax to -1 |
| 1184 | * in some versions of linux kernel. |
| 1185 | * If that is the case, then |
| 1186 | * __X32_SYSCALL_BIT logic does not apply. |
| 1187 | */ |
| 1188 | if ((long long) x86_64_regs.orig_rax != -1) { |
| 1189 | scno -= __X32_SYSCALL_BIT; |
| 1190 | currpers = 2; |
| 1191 | } else { |
| 1192 | # ifdef X32 |
| 1193 | currpers = 2; |
| 1194 | # endif |
| 1195 | } |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1196 | } |
| 1197 | } |
| 1198 | # elif 0 |
| 1199 | /* cs = 0x33 for long mode (native 64 bit and x32) |
| 1200 | * cs = 0x23 for compatibility mode (32 bit) |
| 1201 | * ds = 0x2b for x32 mode (x86-64 in 32 bit) |
| 1202 | */ |
| 1203 | scno = x86_64_regs.orig_rax; |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1204 | switch (x86_64_regs.cs) { |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1205 | case 0x23: currpers = 1; break; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1206 | case 0x33: |
| 1207 | if (x86_64_regs.ds == 0x2b) { |
| 1208 | currpers = 2; |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 1209 | scno &= ~__X32_SYSCALL_BIT; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1210 | } else |
| 1211 | currpers = 0; |
| 1212 | break; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1213 | default: |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1214 | fprintf(stderr, "Unknown value CS=0x%08X while " |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1215 | "detecting personality of process " |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1216 | "PID=%d\n", (int)x86_64_regs.cs, tcp->pid); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1217 | currpers = current_personality; |
| 1218 | break; |
| 1219 | } |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1220 | # elif 0 |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1221 | /* This version analyzes the opcode of a syscall instruction. |
| 1222 | * (int 0x80 on i386 vs. syscall on x86-64) |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1223 | * It works, but is too complicated, and strictly speaking, unreliable. |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1224 | */ |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1225 | unsigned long call, rip = x86_64_regs.rip; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1226 | /* sizeof(syscall) == sizeof(int 0x80) == 2 */ |
| 1227 | rip -= 2; |
| 1228 | errno = 0; |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1229 | call = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)rip, (char *)0); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1230 | if (errno) |
| 1231 | fprintf(stderr, "ptrace_peektext failed: %s\n", |
| 1232 | strerror(errno)); |
| 1233 | switch (call & 0xffff) { |
| 1234 | /* x86-64: syscall = 0x0f 0x05 */ |
| 1235 | case 0x050f: currpers = 0; break; |
| 1236 | /* i386: int 0x80 = 0xcd 0x80 */ |
| 1237 | case 0x80cd: currpers = 1; break; |
| 1238 | default: |
| 1239 | currpers = current_personality; |
| 1240 | fprintf(stderr, |
| 1241 | "Unknown syscall opcode (0x%04X) while " |
| 1242 | "detecting personality of process " |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1243 | "PID=%d\n", (int)call, tcp->pid); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1244 | break; |
| 1245 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1246 | # endif |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 1247 | |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1248 | # ifdef X32 |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 1249 | /* If we are built for a x32 system, then personality 0 is x32 |
| 1250 | * (not x86_64), and stracing of x86_64 apps is not supported. |
| 1251 | * Stracing of i386 apps is still supported. |
H.J. Lu | 085e428 | 2012-04-17 11:05:04 -0700 | [diff] [blame] | 1252 | */ |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 1253 | if (currpers == 0) { |
| 1254 | fprintf(stderr, "syscall_%lu(...) in unsupported " |
| 1255 | "64-bit mode of process PID=%d\n", |
| 1256 | scno, tcp->pid); |
| 1257 | return 0; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1258 | } |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 1259 | currpers &= ~2; /* map 2,1 to 0,1 */ |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1260 | # endif |
H.J. Lu | 085e428 | 2012-04-17 11:05:04 -0700 | [diff] [blame] | 1261 | update_personality(tcp, currpers); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1262 | #elif defined(IA64) |
Denys Vlasenko | c09646a | 2013-07-01 12:28:17 +0200 | [diff] [blame] | 1263 | if (ia64_ia32mode) { |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame^] | 1264 | scno = ia64_regs.gr[0]; |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 1265 | } else { |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame^] | 1266 | scno = ia64_regs.gr[15]; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1267 | } |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1268 | #elif defined(AARCH64) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1269 | switch (aarch64_io.iov_len) { |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1270 | case sizeof(aarch64_regs): |
| 1271 | /* We are in 64-bit mode */ |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1272 | scno = aarch64_regs.regs[8]; |
| 1273 | update_personality(tcp, 1); |
| 1274 | break; |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 1275 | case sizeof(arm_regs): |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1276 | /* We are in 32-bit mode */ |
Denys Vlasenko | 8b7aa2b | 2013-07-04 09:54:19 +0200 | [diff] [blame] | 1277 | /* Note: we don't support OABI, unlike 32-bit ARM build */ |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 1278 | scno = arm_regs.ARM_r7; |
Elliott Hughes | 7a28f7f | 2014-03-03 23:45:26 +0000 | [diff] [blame] | 1279 | scno = shuffle_scno(scno); |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1280 | update_personality(tcp, 0); |
| 1281 | break; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1282 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1283 | #elif defined(ARM) |
Denys Vlasenko | e7030e5 | 2013-02-20 18:08:25 +0100 | [diff] [blame] | 1284 | if (arm_regs.ARM_ip != 0) { |
| 1285 | /* It is not a syscall entry */ |
| 1286 | fprintf(stderr, "pid %d stray syscall exit\n", tcp->pid); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1287 | tcp->flags |= TCB_INSYSCALL; |
Denys Vlasenko | e7030e5 | 2013-02-20 18:08:25 +0100 | [diff] [blame] | 1288 | return 0; |
| 1289 | } |
| 1290 | /* Note: we support only 32-bit CPUs, not 26-bit */ |
| 1291 | |
Dmitry V. Levin | 0160e16 | 2014-03-18 23:37:43 +0000 | [diff] [blame] | 1292 | # if !defined(__ARM_EABI__) || ENABLE_ARM_OABI |
Denys Vlasenko | 8b7aa2b | 2013-07-04 09:54:19 +0200 | [diff] [blame] | 1293 | if (arm_regs.ARM_cpsr & 0x20) |
Denys Vlasenko | e7030e5 | 2013-02-20 18:08:25 +0100 | [diff] [blame] | 1294 | /* Thumb mode */ |
Denys Vlasenko | 8b7aa2b | 2013-07-04 09:54:19 +0200 | [diff] [blame] | 1295 | goto scno_in_r7; |
| 1296 | /* ARM mode */ |
| 1297 | /* Check EABI/OABI by examining SVC insn's low 24 bits */ |
| 1298 | errno = 0; |
| 1299 | scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(arm_regs.ARM_pc - 4), NULL); |
| 1300 | if (errno) |
| 1301 | return -1; |
| 1302 | /* EABI syscall convention? */ |
Dmitry V. Levin | 03b4454 | 2015-01-14 07:21:36 +0000 | [diff] [blame] | 1303 | if ((unsigned long) scno != 0xef000000) { |
Denys Vlasenko | 8b7aa2b | 2013-07-04 09:54:19 +0200 | [diff] [blame] | 1304 | /* No, it's OABI */ |
| 1305 | if ((scno & 0x0ff00000) != 0x0f900000) { |
| 1306 | fprintf(stderr, "pid %d unknown syscall trap 0x%08lx\n", |
| 1307 | tcp->pid, scno); |
Denys Vlasenko | e7030e5 | 2013-02-20 18:08:25 +0100 | [diff] [blame] | 1308 | return -1; |
Denys Vlasenko | e7030e5 | 2013-02-20 18:08:25 +0100 | [diff] [blame] | 1309 | } |
Denys Vlasenko | 8b7aa2b | 2013-07-04 09:54:19 +0200 | [diff] [blame] | 1310 | /* Fixup the syscall number */ |
| 1311 | scno &= 0x000fffff; |
| 1312 | } else { |
| 1313 | scno_in_r7: |
| 1314 | scno = arm_regs.ARM_r7; |
Denys Vlasenko | e7030e5 | 2013-02-20 18:08:25 +0100 | [diff] [blame] | 1315 | } |
Dmitry V. Levin | 0160e16 | 2014-03-18 23:37:43 +0000 | [diff] [blame] | 1316 | # else /* __ARM_EABI__ || !ENABLE_ARM_OABI */ |
Denys Vlasenko | 8b7aa2b | 2013-07-04 09:54:19 +0200 | [diff] [blame] | 1317 | scno = arm_regs.ARM_r7; |
| 1318 | # endif |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 1319 | scno = shuffle_scno(scno); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1320 | #elif defined(M68K) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1321 | if (upeek(tcp->pid, 4*PT_ORIG_D0, &scno) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1322 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1323 | #elif defined(MIPS) |
Dmitry V. Levin | 4f2d1ae | 2015-02-15 03:27:13 +0000 | [diff] [blame] | 1324 | scno = mips_REG_V0; |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 1325 | |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1326 | if (!SCNO_IN_RANGE(scno)) { |
Dmitry V. Levin | f677715 | 2015-03-02 15:06:51 +0000 | [diff] [blame] | 1327 | if (mips_REG_A3 == 0 || mips_REG_A3 == (uint64_t) -1) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1328 | if (debug_flag) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1329 | fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno); |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1330 | return 0; |
| 1331 | } |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 1332 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1333 | #elif defined(ALPHA) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1334 | if (upeek(tcp->pid, REG_A3, &alpha_a3) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1335 | return -1; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1336 | if (upeek(tcp->pid, REG_R0, &scno) < 0) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1337 | return -1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1338 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1339 | /* |
| 1340 | * Do some sanity checks to figure out if it's |
| 1341 | * really a syscall entry |
| 1342 | */ |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1343 | if (!SCNO_IN_RANGE(scno)) { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1344 | if (alpha_a3 == 0 || alpha_a3 == -1) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1345 | if (debug_flag) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1346 | fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1347 | return 0; |
| 1348 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1349 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1350 | #elif defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1351 | /* Disassemble the syscall trap. */ |
| 1352 | /* Retrieve the syscall trap instruction. */ |
Denys Vlasenko | 4645582 | 2013-02-05 17:02:59 +0100 | [diff] [blame] | 1353 | unsigned long trap; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1354 | errno = 0; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1355 | # if defined(SPARC64) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1356 | trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.tpc, 0); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1357 | trap >>= 32; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1358 | # else |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1359 | trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.pc, 0); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1360 | # endif |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1361 | if (errno) |
Wichert Akkerman | c1652e2 | 2001-03-27 12:17:16 +0000 | [diff] [blame] | 1362 | return -1; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1363 | |
| 1364 | /* Disassemble the trap to see what personality to use. */ |
| 1365 | switch (trap) { |
| 1366 | case 0x91d02010: |
| 1367 | /* Linux/SPARC syscall trap. */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1368 | update_personality(tcp, 0); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1369 | break; |
| 1370 | case 0x91d0206d: |
| 1371 | /* Linux/SPARC64 syscall trap. */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1372 | update_personality(tcp, 2); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1373 | break; |
| 1374 | case 0x91d02000: |
| 1375 | /* SunOS syscall trap. (pers 1) */ |
| 1376 | fprintf(stderr, "syscall: SunOS no support\n"); |
| 1377 | return -1; |
| 1378 | case 0x91d02008: |
| 1379 | /* Solaris 2.x syscall trap. (per 2) */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1380 | update_personality(tcp, 1); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1381 | break; |
| 1382 | case 0x91d02009: |
| 1383 | /* NetBSD/FreeBSD syscall trap. */ |
| 1384 | fprintf(stderr, "syscall: NetBSD/FreeBSD not supported\n"); |
| 1385 | return -1; |
| 1386 | case 0x91d02027: |
| 1387 | /* Solaris 2.x gettimeofday */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1388 | update_personality(tcp, 1); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1389 | break; |
| 1390 | default: |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1391 | # if defined(SPARC64) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1392 | 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] | 1393 | # else |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1394 | 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] | 1395 | # endif |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1396 | return -1; |
| 1397 | } |
| 1398 | |
| 1399 | /* Extract the system call number from the registers. */ |
| 1400 | if (trap == 0x91d02027) |
| 1401 | scno = 156; |
| 1402 | else |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1403 | scno = sparc_regs.u_regs[U_REG_G1]; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1404 | if (scno == 0) { |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1405 | scno = sparc_regs.u_regs[U_REG_O0]; |
| 1406 | 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] | 1407 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1408 | #elif defined(HPPA) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1409 | if (upeek(tcp->pid, PT_GR20, &scno) < 0) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1410 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1411 | #elif defined(SH) |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1412 | /* |
| 1413 | * In the new syscall ABI, the system call number is in R3. |
| 1414 | */ |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1415 | if (upeek(tcp->pid, 4*(REG_REG0+3), &scno) < 0) |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1416 | return -1; |
Wichert Akkerman | ccef637 | 2002-05-01 16:39:22 +0000 | [diff] [blame] | 1417 | |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1418 | if (scno < 0) { |
| 1419 | /* Odd as it may seem, a glibc bug has been known to cause |
| 1420 | glibc to issue bogus negative syscall numbers. So for |
| 1421 | our purposes, make strace print what it *should* have been */ |
| 1422 | long correct_scno = (scno & 0xff); |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1423 | if (debug_flag) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 1424 | fprintf(stderr, |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1425 | "Detected glibc bug: bogus system call" |
| 1426 | " number = %ld, correcting to %ld\n", |
| 1427 | scno, |
| 1428 | correct_scno); |
| 1429 | scno = correct_scno; |
| 1430 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1431 | #elif defined(SH64) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1432 | if (upeek(tcp->pid, REG_SYSCALL, &scno) < 0) |
Roland McGrath | e1e584b | 2003-06-02 19:18:58 +0000 | [diff] [blame] | 1433 | return -1; |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1434 | scno &= 0xFFFF; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1435 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1436 | if (upeek(tcp->pid, 4*PT_R9, &scno) < 0) |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1437 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1438 | #elif defined(TILE) |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 1439 | unsigned int currpers; |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 1440 | scno = tile_regs.regs[10]; |
| 1441 | # ifdef __tilepro__ |
| 1442 | currpers = 1; |
| 1443 | # else |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 1444 | # ifndef PT_FLAGS_COMPAT |
| 1445 | # define PT_FLAGS_COMPAT 0x10000 /* from Linux 3.8 on */ |
| 1446 | # endif |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 1447 | if (tile_regs.flags & PT_FLAGS_COMPAT) |
| 1448 | currpers = 1; |
| 1449 | else |
| 1450 | currpers = 0; |
| 1451 | # endif |
| 1452 | update_personality(tcp, currpers); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1453 | #elif defined(MICROBLAZE) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1454 | if (upeek(tcp->pid, 0, &scno) < 0) |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1455 | return -1; |
Christian Svensson | 492f81f | 2013-02-14 13:26:27 +0100 | [diff] [blame] | 1456 | #elif defined(OR1K) |
| 1457 | scno = or1k_regs.gpr[11]; |
James Hogan | 5f999a8 | 2013-02-22 14:44:10 +0000 | [diff] [blame] | 1458 | #elif defined(METAG) |
| 1459 | scno = metag_regs.dx[0][1]; /* syscall number in D1Re0 (D1.0) */ |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 1460 | #elif defined(XTENSA) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1461 | if (upeek(tcp->pid, SYSCALL_NR, &scno) < 0) |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 1462 | return -1; |
Vineet Gupta | 7daacbb | 2013-08-16 12:47:06 +0530 | [diff] [blame] | 1463 | # elif defined(ARC) |
| 1464 | scno = arc_regs.scratch.r8; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1465 | #endif |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1466 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1467 | tcp->scno = scno; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1468 | if (SCNO_IS_VALID(tcp->scno)) { |
| 1469 | tcp->s_ent = &sysent[scno]; |
| 1470 | tcp->qual_flg = qual_flags[scno]; |
| 1471 | } else { |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 1472 | static const struct_sysent unknown = { |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1473 | .nargs = MAX_ARGS, |
| 1474 | .sys_flags = 0, |
| 1475 | .sys_func = printargs, |
| 1476 | .sys_name = "unknown", /* not used */ |
| 1477 | }; |
| 1478 | tcp->s_ent = &unknown; |
| 1479 | tcp->qual_flg = UNDEFINED_SCNO | QUAL_RAW | DEFAULT_QUAL_FLAGS; |
| 1480 | } |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1481 | return 1; |
| 1482 | } |
| 1483 | |
Dmitry V. Levin | d70c41d | 2015-02-05 23:43:06 +0000 | [diff] [blame] | 1484 | /* |
| 1485 | * Cannot rely on __kernel_[u]long_t being defined, |
| 1486 | * it is quite a recent feature of <asm/posix_types.h>. |
| 1487 | */ |
| 1488 | #ifdef __kernel_long_t |
| 1489 | typedef __kernel_long_t kernel_long_t; |
| 1490 | typedef __kernel_ulong_t kernel_ulong_t; |
| 1491 | #else |
| 1492 | # ifdef X32 |
| 1493 | typedef long long kernel_long_t; |
| 1494 | typedef unsigned long long kernel_ulong_t; |
| 1495 | # else |
| 1496 | typedef long kernel_long_t; |
| 1497 | typedef unsigned long kernel_ulong_t; |
| 1498 | # endif |
| 1499 | #endif |
| 1500 | |
| 1501 | /* |
| 1502 | * Check the syscall return value register value for whether it is |
| 1503 | * a negated errno code indicating an error, or a success return value. |
| 1504 | */ |
| 1505 | static inline bool |
| 1506 | is_negated_errno(kernel_ulong_t val) |
| 1507 | { |
Dmitry V. Levin | fb585db | 2015-02-19 16:58:52 +0000 | [diff] [blame] | 1508 | /* Linux kernel defines MAX_ERRNO to 4095. */ |
| 1509 | kernel_ulong_t max = -(kernel_long_t) 4095; |
Dmitry V. Levin | d70c41d | 2015-02-05 23:43:06 +0000 | [diff] [blame] | 1510 | |
| 1511 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 1512 | if (current_wordsize < sizeof(val)) { |
| 1513 | val = (uint32_t) val; |
| 1514 | max = (uint32_t) max; |
| 1515 | } |
| 1516 | #elif defined X32 |
| 1517 | /* |
| 1518 | * current_wordsize is 4 even in personality 0 (native X32) |
| 1519 | * but truncation _must not_ be done in it. |
| 1520 | * can't check current_wordsize here! |
| 1521 | */ |
| 1522 | if (current_personality != 0) { |
| 1523 | val = (uint32_t) val; |
| 1524 | max = (uint32_t) max; |
| 1525 | } |
| 1526 | #endif |
| 1527 | |
Dmitry V. Levin | fb585db | 2015-02-19 16:58:52 +0000 | [diff] [blame] | 1528 | return val >= max; |
Dmitry V. Levin | d70c41d | 2015-02-05 23:43:06 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 1531 | /* Return -1 on error or 1 on success (never 0!) */ |
Roland McGrath | a4d4853 | 2005-06-08 20:45:28 +0000 | [diff] [blame] | 1532 | static int |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 1533 | get_syscall_args(struct tcb *tcp) |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1534 | { |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1535 | int i, nargs; |
| 1536 | |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1537 | nargs = tcp->s_ent->nargs; |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1538 | |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1539 | #if defined(S390) || defined(S390X) |
Dmitry V. Levin | 20eca8a | 2015-03-05 22:10:15 +0000 | [diff] [blame] | 1540 | (void)i; |
| 1541 | (void)nargs; |
| 1542 | tcp->u_arg[0] = s390_regset.orig_gpr2; |
| 1543 | tcp->u_arg[1] = s390_regset.gprs[3]; |
| 1544 | tcp->u_arg[2] = s390_regset.gprs[4]; |
| 1545 | tcp->u_arg[3] = s390_regset.gprs[5]; |
| 1546 | tcp->u_arg[4] = s390_regset.gprs[6]; |
| 1547 | tcp->u_arg[5] = s390_regset.gprs[7]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1548 | #elif defined(ALPHA) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1549 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1550 | if (upeek(tcp->pid, REG_A0+i, &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1551 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1552 | #elif defined(IA64) |
Denys Vlasenko | c09646a | 2013-07-01 12:28:17 +0200 | [diff] [blame] | 1553 | if (!ia64_ia32mode) { |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame^] | 1554 | unsigned long *rbs_end = |
| 1555 | (unsigned long *) ia64_regs.ar[PT_AUR_BSP]; |
| 1556 | unsigned long sof = (ia64_regs.cfm >> 0) & 0x7f; |
| 1557 | unsigned long sol = (ia64_regs.cfm >> 7) & 0x7f; |
| 1558 | unsigned long *out0 = ia64_rse_skip_regs(rbs_end, -sof + sol); |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1559 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1560 | for (i = 0; i < nargs; ++i) { |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1561 | if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i), |
| 1562 | sizeof(long), (char *) &tcp->u_arg[i]) < 0) |
| 1563 | return -1; |
| 1564 | } |
| 1565 | } else { |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame^] | 1566 | (void)i; |
| 1567 | (void)nargs; |
| 1568 | /* truncate away IVE sign-extension */ |
| 1569 | tcp->u_arg[0] = 0xffffffff & ia64_regs.gr[11]; /* EBX */ |
| 1570 | tcp->u_arg[1] = 0xffffffff & ia64_regs.gr[ 9]; /* ECX */ |
| 1571 | tcp->u_arg[2] = 0xffffffff & ia64_regs.gr[10]; /* EDX */ |
| 1572 | tcp->u_arg[3] = 0xffffffff & ia64_regs.gr[14]; /* ESI */ |
| 1573 | tcp->u_arg[4] = 0xffffffff & ia64_regs.gr[15]; /* EDI */ |
| 1574 | tcp->u_arg[5] = 0xffffffff & ia64_regs.gr[13]; /* EBP */ |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1575 | } |
Dmitry V. Levin | 4f2d1ae | 2015-02-15 03:27:13 +0000 | [diff] [blame] | 1576 | #elif defined LINUX_MIPSN64 |
| 1577 | (void)i; |
| 1578 | (void)nargs; |
| 1579 | tcp->u_arg[0] = mips_REG_A0; |
| 1580 | tcp->u_arg[1] = mips_REG_A1; |
| 1581 | tcp->u_arg[2] = mips_REG_A2; |
| 1582 | tcp->u_arg[3] = mips_REG_A3; |
| 1583 | tcp->u_arg[4] = mips_REG_A4; |
| 1584 | tcp->u_arg[5] = mips_REG_A5; |
| 1585 | #elif defined LINUX_MIPSN32 |
| 1586 | (void)i; |
| 1587 | (void)nargs; |
| 1588 | tcp->u_arg[0] = tcp->ext_arg[0] = mips_REG_A0; |
| 1589 | tcp->u_arg[1] = tcp->ext_arg[1] = mips_REG_A1; |
| 1590 | tcp->u_arg[2] = tcp->ext_arg[2] = mips_REG_A2; |
| 1591 | tcp->u_arg[3] = tcp->ext_arg[3] = mips_REG_A3; |
| 1592 | tcp->u_arg[4] = tcp->ext_arg[4] = mips_REG_A4; |
| 1593 | tcp->u_arg[5] = tcp->ext_arg[5] = mips_REG_A5; |
| 1594 | #elif defined LINUX_MIPSO32 |
| 1595 | (void)i; |
| 1596 | (void)nargs; |
| 1597 | tcp->u_arg[0] = mips_REG_A0; |
| 1598 | tcp->u_arg[1] = mips_REG_A1; |
| 1599 | tcp->u_arg[2] = mips_REG_A2; |
| 1600 | tcp->u_arg[3] = mips_REG_A3; |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1601 | if (nargs > 4) { |
Dmitry V. Levin | 4f2d1ae | 2015-02-15 03:27:13 +0000 | [diff] [blame] | 1602 | umoven(tcp, mips_REG_SP + 4 * 4, |
| 1603 | (nargs - 4) * sizeof(tcp->u_arg[0]), |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1604 | (char *)(tcp->u_arg + 4)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1605 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1606 | #elif defined(POWERPC) |
Anton Blanchard | ce6e33b | 2013-06-26 15:53:33 +0200 | [diff] [blame] | 1607 | (void)i; |
| 1608 | (void)nargs; |
| 1609 | tcp->u_arg[0] = ppc_regs.orig_gpr3; |
| 1610 | tcp->u_arg[1] = ppc_regs.gpr[4]; |
| 1611 | tcp->u_arg[2] = ppc_regs.gpr[5]; |
| 1612 | tcp->u_arg[3] = ppc_regs.gpr[6]; |
| 1613 | tcp->u_arg[4] = ppc_regs.gpr[7]; |
| 1614 | tcp->u_arg[5] = ppc_regs.gpr[8]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1615 | #elif defined(SPARC) || defined(SPARC64) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1616 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1617 | tcp->u_arg[i] = sparc_regs.u_regs[U_REG_O0 + i]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1618 | #elif defined(HPPA) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1619 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1620 | 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] | 1621 | return -1; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1622 | #elif defined(ARM) || defined(AARCH64) |
| 1623 | # if defined(AARCH64) |
| 1624 | if (tcp->currpers == 1) |
| 1625 | for (i = 0; i < nargs; ++i) |
| 1626 | tcp->u_arg[i] = aarch64_regs.regs[i]; |
| 1627 | else |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 1628 | # endif |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1629 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 401374e | 2013-02-06 18:24:39 +0100 | [diff] [blame] | 1630 | tcp->u_arg[i] = arm_regs.uregs[i]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1631 | #elif defined(AVR32) |
Denys Vlasenko | b5b2589 | 2011-08-30 19:04:54 +0200 | [diff] [blame] | 1632 | (void)i; |
| 1633 | (void)nargs; |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1634 | tcp->u_arg[0] = avr32_regs.r12; |
| 1635 | tcp->u_arg[1] = avr32_regs.r11; |
| 1636 | tcp->u_arg[2] = avr32_regs.r10; |
| 1637 | tcp->u_arg[3] = avr32_regs.r9; |
| 1638 | tcp->u_arg[4] = avr32_regs.r5; |
| 1639 | tcp->u_arg[5] = avr32_regs.r3; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1640 | #elif defined(BFIN) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1641 | 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] | 1642 | |
Denys Vlasenko | 4b887a5 | 2011-08-23 13:32:38 +0200 | [diff] [blame] | 1643 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1644 | if (upeek(tcp->pid, argreg[i], &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1645 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1646 | #elif defined(SH) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1647 | static const int syscall_regs[MAX_ARGS] = { |
| 1648 | 4 * (REG_REG0+4), 4 * (REG_REG0+5), 4 * (REG_REG0+6), |
| 1649 | 4 * (REG_REG0+7), 4 * (REG_REG0 ), 4 * (REG_REG0+1) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1650 | }; |
| 1651 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1652 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1653 | if (upeek(tcp->pid, syscall_regs[i], &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1654 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1655 | #elif defined(SH64) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1656 | int i; |
| 1657 | /* Registers used by SH5 Linux system calls for parameters */ |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1658 | 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] | 1659 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1660 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1661 | 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] | 1662 | return -1; |
Denys Vlasenko | 6cf3605 | 2013-02-15 15:01:38 +0100 | [diff] [blame] | 1663 | #elif defined(I386) |
| 1664 | (void)i; |
| 1665 | (void)nargs; |
| 1666 | tcp->u_arg[0] = i386_regs.ebx; |
| 1667 | tcp->u_arg[1] = i386_regs.ecx; |
| 1668 | tcp->u_arg[2] = i386_regs.edx; |
| 1669 | tcp->u_arg[3] = i386_regs.esi; |
| 1670 | tcp->u_arg[4] = i386_regs.edi; |
| 1671 | tcp->u_arg[5] = i386_regs.ebp; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1672 | #elif defined(X86_64) || defined(X32) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1673 | (void)i; |
| 1674 | (void)nargs; |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1675 | if (x86_io.iov_len != sizeof(i386_regs)) { |
| 1676 | /* x86-64 or x32 ABI */ |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1677 | tcp->u_arg[0] = x86_64_regs.rdi; |
| 1678 | tcp->u_arg[1] = x86_64_regs.rsi; |
| 1679 | tcp->u_arg[2] = x86_64_regs.rdx; |
| 1680 | tcp->u_arg[3] = x86_64_regs.r10; |
| 1681 | tcp->u_arg[4] = x86_64_regs.r8; |
| 1682 | tcp->u_arg[5] = x86_64_regs.r9; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1683 | # ifdef X32 |
| 1684 | tcp->ext_arg[0] = x86_64_regs.rdi; |
| 1685 | tcp->ext_arg[1] = x86_64_regs.rsi; |
| 1686 | tcp->ext_arg[2] = x86_64_regs.rdx; |
| 1687 | tcp->ext_arg[3] = x86_64_regs.r10; |
| 1688 | tcp->ext_arg[4] = x86_64_regs.r8; |
| 1689 | tcp->ext_arg[5] = x86_64_regs.r9; |
| 1690 | # endif |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1691 | } else { |
| 1692 | /* i386 ABI */ |
Denys Vlasenko | 6cf3605 | 2013-02-15 15:01:38 +0100 | [diff] [blame] | 1693 | /* Zero-extend from 32 bits */ |
| 1694 | /* Use widen_to_long(tcp->u_arg[N]) in syscall handlers |
| 1695 | * if you need to use *sign-extended* parameter. |
| 1696 | */ |
| 1697 | tcp->u_arg[0] = (long)(uint32_t)i386_regs.ebx; |
| 1698 | tcp->u_arg[1] = (long)(uint32_t)i386_regs.ecx; |
| 1699 | tcp->u_arg[2] = (long)(uint32_t)i386_regs.edx; |
| 1700 | tcp->u_arg[3] = (long)(uint32_t)i386_regs.esi; |
| 1701 | tcp->u_arg[4] = (long)(uint32_t)i386_regs.edi; |
| 1702 | tcp->u_arg[5] = (long)(uint32_t)i386_regs.ebp; |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1703 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1704 | #elif defined(MICROBLAZE) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1705 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1706 | if (upeek(tcp->pid, (5 + i) * 4, &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1707 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1708 | #elif defined(CRISV10) || defined(CRISV32) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1709 | static const int crisregs[MAX_ARGS] = { |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1710 | 4*PT_ORIG_R10, 4*PT_R11, 4*PT_R12, |
Denys Vlasenko | 0b6c73c | 2011-06-23 22:22:34 +0200 | [diff] [blame] | 1711 | 4*PT_R13 , 4*PT_MOF, 4*PT_SRP |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1712 | }; |
Roland McGrath | e1e584b | 2003-06-02 19:18:58 +0000 | [diff] [blame] | 1713 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1714 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1715 | if (upeek(tcp->pid, crisregs[i], &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1716 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1717 | #elif defined(TILE) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1718 | for (i = 0; i < nargs; ++i) |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 1719 | tcp->u_arg[i] = tile_regs.regs[i]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1720 | #elif defined(M68K) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1721 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1722 | 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] | 1723 | return -1; |
Christian Svensson | 492f81f | 2013-02-14 13:26:27 +0100 | [diff] [blame] | 1724 | #elif defined(OR1K) |
| 1725 | (void)nargs; |
| 1726 | for (i = 0; i < 6; ++i) |
| 1727 | tcp->u_arg[i] = or1k_regs.gpr[3 + i]; |
James Hogan | 5f999a8 | 2013-02-22 14:44:10 +0000 | [diff] [blame] | 1728 | #elif defined(METAG) |
| 1729 | for (i = 0; i < nargs; i++) |
| 1730 | /* arguments go backwards from D1Ar1 (D1.3) */ |
| 1731 | tcp->u_arg[i] = ((unsigned long *)&metag_regs.dx[3][1])[-i]; |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 1732 | #elif defined(XTENSA) |
| 1733 | /* arg0: a6, arg1: a3, arg2: a4, arg3: a5, arg4: a8, arg5: a9 */ |
| 1734 | static const int xtensaregs[MAX_ARGS] = { 6, 3, 4, 5, 8, 9 }; |
| 1735 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1736 | 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] | 1737 | return -1; |
Vineet Gupta | 7daacbb | 2013-08-16 12:47:06 +0530 | [diff] [blame] | 1738 | # elif defined(ARC) |
| 1739 | long *arc_args = &arc_regs.scratch.r0; |
| 1740 | for (i = 0; i < nargs; ++i) |
| 1741 | tcp->u_arg[i] = *arc_args--; |
| 1742 | |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1743 | #else /* Other architecture (32bits specific) */ |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1744 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1745 | if (upeek(tcp->pid, i*4, &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1746 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1747 | #endif |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1748 | return 1; |
| 1749 | } |
| 1750 | |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 1751 | static int |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1752 | trace_syscall_entering(struct tcb *tcp) |
| 1753 | { |
| 1754 | int res, scno_good; |
| 1755 | |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1756 | scno_good = res = (get_regs_error ? -1 : get_scno(tcp)); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1757 | if (res == 0) |
| 1758 | return res; |
Dmitry V. Levin | 23ce9e4 | 2015-02-08 13:05:53 +0000 | [diff] [blame] | 1759 | if (res == 1) |
| 1760 | res = get_syscall_args(tcp); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1761 | |
| 1762 | if (res != 1) { |
| 1763 | printleader(tcp); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1764 | if (scno_good != 1) |
Denys Vlasenko | b7a6dae | 2012-03-20 16:48:35 +0100 | [diff] [blame] | 1765 | tprints("????" /* anti-trigraph gap */ "("); |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1766 | else if (tcp->qual_flg & UNDEFINED_SCNO) |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 1767 | tprintf("%s(", undefined_scno_name(tcp)); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1768 | else |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1769 | tprintf("%s(", tcp->s_ent->sys_name); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1770 | /* |
| 1771 | * " <unavailable>" will be added later by the code which |
| 1772 | * detects ptrace errors. |
| 1773 | */ |
| 1774 | goto ret; |
| 1775 | } |
| 1776 | |
Denys Vlasenko | 2a3d275 | 2013-05-14 16:07:46 +0200 | [diff] [blame] | 1777 | if ( sys_execve == tcp->s_ent->sys_func |
| 1778 | # if defined(SPARC) || defined(SPARC64) |
| 1779 | || sys_execv == tcp->s_ent->sys_func |
| 1780 | # endif |
| 1781 | ) { |
| 1782 | hide_log_until_execve = 0; |
| 1783 | } |
| 1784 | |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 1785 | #if defined(SYS_socket_subcall) || defined(SYS_ipc_subcall) |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1786 | while (1) { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1787 | # ifdef SYS_socket_subcall |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1788 | if (tcp->s_ent->sys_func == sys_socketcall) { |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 1789 | decode_socket_subcall(tcp); |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 1790 | break; |
| 1791 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1792 | # endif |
| 1793 | # ifdef SYS_ipc_subcall |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1794 | if (tcp->s_ent->sys_func == sys_ipc) { |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 1795 | decode_ipc_subcall(tcp); |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 1796 | break; |
| 1797 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1798 | # endif |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 1799 | break; |
| 1800 | } |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1801 | #endif |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 1802 | |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1803 | if (!(tcp->qual_flg & QUAL_TRACE) |
| 1804 | || (tracing_paths && !pathtrace_match(tcp)) |
| 1805 | ) { |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1806 | tcp->flags |= TCB_INSYSCALL | TCB_FILTERED; |
| 1807 | return 0; |
| 1808 | } |
| 1809 | |
| 1810 | tcp->flags &= ~TCB_FILTERED; |
| 1811 | |
Denys Vlasenko | 2a3d275 | 2013-05-14 16:07:46 +0200 | [diff] [blame] | 1812 | if (cflag == CFLAG_ONLY_STATS || hide_log_until_execve) { |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1813 | res = 0; |
| 1814 | goto ret; |
| 1815 | } |
| 1816 | |
Masatake YAMATO | ed69fc2 | 2014-04-16 15:33:35 +0900 | [diff] [blame] | 1817 | #ifdef USE_LIBUNWIND |
| 1818 | if (stack_trace_enabled) { |
| 1819 | if (tcp->s_ent->sys_flags & STACKTRACE_CAPTURE_ON_ENTER) |
| 1820 | unwind_capture_stacktrace(tcp); |
| 1821 | } |
| 1822 | #endif |
| 1823 | |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1824 | printleader(tcp); |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1825 | if (tcp->qual_flg & UNDEFINED_SCNO) |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 1826 | tprintf("%s(", undefined_scno_name(tcp)); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1827 | else |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1828 | tprintf("%s(", tcp->s_ent->sys_name); |
| 1829 | if ((tcp->qual_flg & QUAL_RAW) && tcp->s_ent->sys_func != sys_exit) |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1830 | res = printargs(tcp); |
| 1831 | else |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1832 | res = tcp->s_ent->sys_func(tcp); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1833 | |
Dmitry V. Levin | b742d8c | 2012-09-17 22:40:12 +0000 | [diff] [blame] | 1834 | fflush(tcp->outf); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1835 | ret: |
| 1836 | tcp->flags |= TCB_INSYSCALL; |
| 1837 | /* Measure the entrance time as late as possible to avoid errors. */ |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1838 | if (Tflag || cflag) |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1839 | gettimeofday(&tcp->etime, NULL); |
| 1840 | return res; |
| 1841 | } |
| 1842 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1843 | /* Returns: |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 1844 | * 1: ok, continue in trace_syscall_exiting(). |
| 1845 | * -1: error, trace_syscall_exiting() should print error indicator |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1846 | * ("????" etc) and bail out. |
| 1847 | */ |
| 1848 | static int |
| 1849 | get_syscall_result(struct tcb *tcp) |
| 1850 | { |
Dmitry V. Levin | 5d09224 | 2015-02-13 23:06:36 +0000 | [diff] [blame] | 1851 | #if defined ARCH_REGS_FOR_GETREGSET || defined ARCH_REGS_FOR_GETREGS |
| 1852 | /* already done by get_regs */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1853 | #elif defined(BFIN) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1854 | if (upeek(tcp->pid, PT_R0, &bfin_r0) < 0) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1855 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1856 | #elif defined(M68K) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1857 | if (upeek(tcp->pid, 4*PT_D0, &m68k_d0) < 0) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1858 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1859 | #elif defined(ALPHA) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1860 | if (upeek(tcp->pid, REG_A3, &alpha_a3) < 0) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1861 | return -1; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1862 | if (upeek(tcp->pid, REG_R0, &alpha_r0) < 0) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1863 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1864 | #elif defined(HPPA) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1865 | if (upeek(tcp->pid, PT_GR28, &hppa_r28) < 0) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1866 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1867 | #elif defined(SH) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1868 | /* new syscall ABI returns result in R0 */ |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1869 | if (upeek(tcp->pid, 4*REG_REG0, (long *)&sh_r0) < 0) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1870 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1871 | #elif defined(SH64) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1872 | /* ABI defines result returned in r9 */ |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1873 | if (upeek(tcp->pid, REG_GENERAL(9), (long *)&sh64_r9) < 0) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1874 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1875 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1876 | if (upeek(tcp->pid, 4*PT_R10, &cris_r10) < 0) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1877 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1878 | #elif defined(MICROBLAZE) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1879 | if (upeek(tcp->pid, 3 * 4, µblaze_r3) < 0) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1880 | return -1; |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 1881 | #elif defined(XTENSA) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1882 | if (upeek(tcp->pid, REG_A_BASE + 2, &xtensa_a2) < 0) |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 1883 | return -1; |
Dmitry V. Levin | 5d09224 | 2015-02-13 23:06:36 +0000 | [diff] [blame] | 1884 | #else |
| 1885 | # error get_syscall_result is not implemented for this architecture |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1886 | #endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1887 | return 1; |
| 1888 | } |
| 1889 | |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 1890 | /* Returns: |
| 1891 | * 1: ok, continue in trace_syscall_exiting(). |
| 1892 | * -1: error, trace_syscall_exiting() should print error indicator |
| 1893 | * ("????" etc) and bail out. |
| 1894 | */ |
Denys Vlasenko | c956ef0 | 2013-02-16 14:25:56 +0100 | [diff] [blame] | 1895 | static void |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1896 | get_error(struct tcb *tcp) |
| 1897 | { |
| 1898 | int u_error = 0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1899 | int check_errno = 1; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1900 | if (tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1901 | check_errno = 0; |
| 1902 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1903 | #if defined(S390) || defined(S390X) |
Dmitry V. Levin | 20eca8a | 2015-03-05 22:10:15 +0000 | [diff] [blame] | 1904 | if (check_errno && is_negated_errno(s390_regset.gprs[2])) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1905 | tcp->u_rval = -1; |
Dmitry V. Levin | 20eca8a | 2015-03-05 22:10:15 +0000 | [diff] [blame] | 1906 | u_error = -s390_regset.gprs[2]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1907 | } |
| 1908 | else { |
Dmitry V. Levin | 20eca8a | 2015-03-05 22:10:15 +0000 | [diff] [blame] | 1909 | tcp->u_rval = s390_regset.gprs[2]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1910 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1911 | #elif defined(I386) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1912 | if (check_errno && is_negated_errno(i386_regs.eax)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1913 | tcp->u_rval = -1; |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1914 | u_error = -i386_regs.eax; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1915 | } |
| 1916 | else { |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1917 | tcp->u_rval = i386_regs.eax; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1918 | } |
Dmitry V. Levin | f46ab5f | 2015-02-05 18:50:24 +0000 | [diff] [blame] | 1919 | #elif defined(X86_64) || defined(X32) |
| 1920 | /* |
| 1921 | * In X32, return value is 64-bit (llseek uses one). |
| 1922 | * Using merely "long rax" would not work. |
| 1923 | */ |
| 1924 | kernel_long_t rax; |
| 1925 | |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1926 | if (x86_io.iov_len == sizeof(i386_regs)) { |
| 1927 | /* Sign extend from 32 bits */ |
Dmitry V. Levin | f46ab5f | 2015-02-05 18:50:24 +0000 | [diff] [blame] | 1928 | rax = (int32_t) i386_regs.eax; |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1929 | } else { |
| 1930 | rax = x86_64_regs.rax; |
| 1931 | } |
| 1932 | if (check_errno && is_negated_errno(rax)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1933 | tcp->u_rval = -1; |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1934 | u_error = -rax; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1935 | } |
| 1936 | else { |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1937 | tcp->u_rval = rax; |
Dmitry V. Levin | f46ab5f | 2015-02-05 18:50:24 +0000 | [diff] [blame] | 1938 | # ifdef X32 |
| 1939 | /* tcp->u_rval contains a truncated value */ |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1940 | tcp->u_lrval = rax; |
Dmitry V. Levin | f46ab5f | 2015-02-05 18:50:24 +0000 | [diff] [blame] | 1941 | # endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1942 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1943 | #elif defined(IA64) |
Denys Vlasenko | c09646a | 2013-07-01 12:28:17 +0200 | [diff] [blame] | 1944 | if (ia64_ia32mode) { |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame^] | 1945 | int err = ia64_regs.gr[8]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1946 | if (check_errno && is_negated_errno(err)) { |
| 1947 | tcp->u_rval = -1; |
| 1948 | u_error = -err; |
| 1949 | } |
| 1950 | else { |
| 1951 | tcp->u_rval = err; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1952 | } |
| 1953 | } else { |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame^] | 1954 | if (check_errno && ia64_regs.gr[10]) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1955 | tcp->u_rval = -1; |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame^] | 1956 | u_error = ia64_regs.gr[8]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1957 | } else { |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame^] | 1958 | tcp->u_rval = ia64_regs.gr[8]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1959 | } |
| 1960 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1961 | #elif defined(MIPS) |
Dmitry V. Levin | 4f2d1ae | 2015-02-15 03:27:13 +0000 | [diff] [blame] | 1962 | if (check_errno && mips_REG_A3) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1963 | tcp->u_rval = -1; |
Dmitry V. Levin | 4f2d1ae | 2015-02-15 03:27:13 +0000 | [diff] [blame] | 1964 | u_error = mips_REG_V0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1965 | } else { |
Dmitry V. Levin | 4f2d1ae | 2015-02-15 03:27:13 +0000 | [diff] [blame] | 1966 | # if defined LINUX_MIPSN32 |
| 1967 | tcp->u_lrval = mips_REG_V0; |
H.J. Lu | dd0130b | 2012-04-16 12:16:45 +0200 | [diff] [blame] | 1968 | # endif |
Dmitry V. Levin | 4f2d1ae | 2015-02-15 03:27:13 +0000 | [diff] [blame] | 1969 | tcp->u_rval = mips_REG_V0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1970 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1971 | #elif defined(POWERPC) |
Denys Vlasenko | 44a6d04 | 2013-06-28 16:47:38 +0200 | [diff] [blame] | 1972 | if (check_errno && (ppc_regs.ccr & 0x10000000)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1973 | tcp->u_rval = -1; |
Denys Vlasenko | 44a6d04 | 2013-06-28 16:47:38 +0200 | [diff] [blame] | 1974 | u_error = ppc_regs.gpr[3]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1975 | } |
| 1976 | else { |
Denys Vlasenko | 44a6d04 | 2013-06-28 16:47:38 +0200 | [diff] [blame] | 1977 | tcp->u_rval = ppc_regs.gpr[3]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1978 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1979 | #elif defined(M68K) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1980 | if (check_errno && is_negated_errno(m68k_d0)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1981 | tcp->u_rval = -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1982 | u_error = -m68k_d0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1983 | } |
| 1984 | else { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1985 | tcp->u_rval = m68k_d0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1986 | } |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1987 | #elif defined(ARM) || defined(AARCH64) |
| 1988 | # if defined(AARCH64) |
| 1989 | if (tcp->currpers == 1) { |
| 1990 | if (check_errno && is_negated_errno(aarch64_regs.regs[0])) { |
| 1991 | tcp->u_rval = -1; |
| 1992 | u_error = -aarch64_regs.regs[0]; |
| 1993 | } |
| 1994 | else { |
| 1995 | tcp->u_rval = aarch64_regs.regs[0]; |
| 1996 | } |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1997 | } |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1998 | else |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 1999 | # endif |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 2000 | { |
Denys Vlasenko | 401374e | 2013-02-06 18:24:39 +0100 | [diff] [blame] | 2001 | if (check_errno && is_negated_errno(arm_regs.ARM_r0)) { |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 2002 | tcp->u_rval = -1; |
Denys Vlasenko | 401374e | 2013-02-06 18:24:39 +0100 | [diff] [blame] | 2003 | u_error = -arm_regs.ARM_r0; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 2004 | } |
| 2005 | else { |
Denys Vlasenko | 401374e | 2013-02-06 18:24:39 +0100 | [diff] [blame] | 2006 | tcp->u_rval = arm_regs.ARM_r0; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 2007 | } |
Steve McIntyre | d8d3bd3 | 2012-10-24 17:58:16 +0100 | [diff] [blame] | 2008 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2009 | #elif defined(AVR32) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2010 | if (check_errno && avr32_regs.r12 && (unsigned) -avr32_regs.r12 < nerrnos) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2011 | tcp->u_rval = -1; |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2012 | u_error = -avr32_regs.r12; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2013 | } |
| 2014 | else { |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2015 | tcp->u_rval = avr32_regs.r12; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2016 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2017 | #elif defined(BFIN) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2018 | if (check_errno && is_negated_errno(bfin_r0)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2019 | tcp->u_rval = -1; |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2020 | u_error = -bfin_r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2021 | } else { |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2022 | tcp->u_rval = bfin_r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2023 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2024 | #elif defined(ALPHA) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2025 | if (check_errno && alpha_a3) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2026 | tcp->u_rval = -1; |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2027 | u_error = alpha_r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2028 | } |
| 2029 | else { |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2030 | tcp->u_rval = alpha_r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2031 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2032 | #elif defined(SPARC) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2033 | if (check_errno && sparc_regs.psr & PSR_C) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2034 | tcp->u_rval = -1; |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2035 | u_error = sparc_regs.u_regs[U_REG_O0]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2036 | } |
| 2037 | else { |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2038 | tcp->u_rval = sparc_regs.u_regs[U_REG_O0]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2039 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2040 | #elif defined(SPARC64) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2041 | if (check_errno && sparc_regs.tstate & 0x1100000000UL) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2042 | tcp->u_rval = -1; |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2043 | u_error = sparc_regs.u_regs[U_REG_O0]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2044 | } |
| 2045 | else { |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2046 | tcp->u_rval = sparc_regs.u_regs[U_REG_O0]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2047 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2048 | #elif defined(HPPA) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2049 | if (check_errno && is_negated_errno(hppa_r28)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2050 | tcp->u_rval = -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2051 | u_error = -hppa_r28; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2052 | } |
| 2053 | else { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2054 | tcp->u_rval = hppa_r28; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2055 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2056 | #elif defined(SH) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2057 | if (check_errno && is_negated_errno(sh_r0)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2058 | tcp->u_rval = -1; |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2059 | u_error = -sh_r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2060 | } |
| 2061 | else { |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2062 | tcp->u_rval = sh_r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2063 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2064 | #elif defined(SH64) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2065 | if (check_errno && is_negated_errno(sh64_r9)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2066 | tcp->u_rval = -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2067 | u_error = -sh64_r9; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2068 | } |
| 2069 | else { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2070 | tcp->u_rval = sh64_r9; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2071 | } |
James Hogan | 5f999a8 | 2013-02-22 14:44:10 +0000 | [diff] [blame] | 2072 | #elif defined(METAG) |
| 2073 | /* result pointer in D0Re0 (D0.0) */ |
| 2074 | if (check_errno && is_negated_errno(metag_regs.dx[0][0])) { |
| 2075 | tcp->u_rval = -1; |
| 2076 | u_error = -metag_regs.dx[0][0]; |
| 2077 | } |
| 2078 | else { |
| 2079 | tcp->u_rval = metag_regs.dx[0][0]; |
| 2080 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2081 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2082 | if (check_errno && cris_r10 && (unsigned) -cris_r10 < nerrnos) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2083 | tcp->u_rval = -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2084 | u_error = -cris_r10; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2085 | } |
| 2086 | else { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2087 | tcp->u_rval = cris_r10; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2088 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2089 | #elif defined(TILE) |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 2090 | /* |
| 2091 | * The standard tile calling convention returns the value (or negative |
| 2092 | * errno) in r0, and zero (or positive errno) in r1. |
| 2093 | * Until at least kernel 3.8, however, the r1 value is not reflected |
| 2094 | * in ptregs at this point, so we use r0 here. |
| 2095 | */ |
| 2096 | if (check_errno && is_negated_errno(tile_regs.regs[0])) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2097 | tcp->u_rval = -1; |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 2098 | u_error = -tile_regs.regs[0]; |
| 2099 | } else { |
| 2100 | tcp->u_rval = tile_regs.regs[0]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2101 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2102 | #elif defined(MICROBLAZE) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2103 | if (check_errno && is_negated_errno(microblaze_r3)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2104 | tcp->u_rval = -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2105 | u_error = -microblaze_r3; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2106 | } |
| 2107 | else { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2108 | tcp->u_rval = microblaze_r3; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2109 | } |
Christian Svensson | 492f81f | 2013-02-14 13:26:27 +0100 | [diff] [blame] | 2110 | #elif defined(OR1K) |
| 2111 | if (check_errno && is_negated_errno(or1k_regs.gpr[11])) { |
| 2112 | tcp->u_rval = -1; |
| 2113 | u_error = -or1k_regs.gpr[11]; |
| 2114 | } |
| 2115 | else { |
| 2116 | tcp->u_rval = or1k_regs.gpr[11]; |
| 2117 | } |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 2118 | #elif defined(XTENSA) |
| 2119 | if (check_errno && is_negated_errno(xtensa_a2)) { |
| 2120 | tcp->u_rval = -1; |
| 2121 | u_error = -xtensa_a2; |
| 2122 | } |
| 2123 | else { |
| 2124 | tcp->u_rval = xtensa_a2; |
| 2125 | } |
Vineet Gupta | 7daacbb | 2013-08-16 12:47:06 +0530 | [diff] [blame] | 2126 | #elif defined(ARC) |
| 2127 | if (check_errno && is_negated_errno(arc_regs.scratch.r0)) { |
| 2128 | tcp->u_rval = -1; |
| 2129 | u_error = -arc_regs.scratch.r0; |
| 2130 | } |
| 2131 | else { |
| 2132 | tcp->u_rval = arc_regs.scratch.r0; |
| 2133 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2134 | #endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2135 | tcp->u_error = u_error; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | static void |
| 2139 | dumpio(struct tcb *tcp) |
| 2140 | { |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2141 | int (*func)(); |
| 2142 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2143 | if (syserror(tcp)) |
| 2144 | return; |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 2145 | if ((unsigned long) tcp->u_arg[0] >= num_quals) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2146 | return; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2147 | func = tcp->s_ent->sys_func; |
| 2148 | if (func == printargs) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2149 | return; |
| 2150 | if (qual_flags[tcp->u_arg[0]] & QUAL_READ) { |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2151 | if (func == sys_read || |
| 2152 | func == sys_pread || |
| 2153 | func == sys_recv || |
Aurelien Jacobs | dc52121 | 2015-01-31 23:57:00 +0100 | [diff] [blame] | 2154 | func == sys_recvfrom) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2155 | dumpstr(tcp, tcp->u_arg[1], tcp->u_rval); |
Aurelien Jacobs | dc52121 | 2015-01-31 23:57:00 +0100 | [diff] [blame] | 2156 | return; |
| 2157 | } else if (func == sys_readv) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2158 | dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
Aurelien Jacobs | dc52121 | 2015-01-31 23:57:00 +0100 | [diff] [blame] | 2159 | return; |
Masatake YAMATO | 02f9f6b | 2014-10-15 22:11:43 +0900 | [diff] [blame] | 2160 | #if HAVE_SENDMSG |
Aurelien Jacobs | dc52121 | 2015-01-31 23:57:00 +0100 | [diff] [blame] | 2161 | } else if (func == sys_recvmsg) { |
Masatake YAMATO | 02f9f6b | 2014-10-15 22:11:43 +0900 | [diff] [blame] | 2162 | dumpiov_in_msghdr(tcp, tcp->u_arg[1]); |
Aurelien Jacobs | dc52121 | 2015-01-31 23:57:00 +0100 | [diff] [blame] | 2163 | return; |
| 2164 | } else if (func == sys_recvmmsg) { |
Masatake YAMATO | a807dce | 2014-11-07 01:23:26 +0900 | [diff] [blame] | 2165 | dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]); |
Aurelien Jacobs | dc52121 | 2015-01-31 23:57:00 +0100 | [diff] [blame] | 2166 | return; |
Masatake YAMATO | 02f9f6b | 2014-10-15 22:11:43 +0900 | [diff] [blame] | 2167 | #endif |
Aurelien Jacobs | dc52121 | 2015-01-31 23:57:00 +0100 | [diff] [blame] | 2168 | } |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2169 | } |
| 2170 | if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) { |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2171 | if (func == sys_write || |
| 2172 | func == sys_pwrite || |
| 2173 | func == sys_send || |
| 2174 | func == sys_sendto) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2175 | dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2176 | else if (func == sys_writev) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2177 | dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
Masatake YAMATO | 02f9f6b | 2014-10-15 22:11:43 +0900 | [diff] [blame] | 2178 | #if HAVE_SENDMSG |
| 2179 | else if (func == sys_sendmsg) |
| 2180 | dumpiov_in_msghdr(tcp, tcp->u_arg[1]); |
Masatake YAMATO | a807dce | 2014-11-07 01:23:26 +0900 | [diff] [blame] | 2181 | else if (func == sys_sendmmsg) |
| 2182 | dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]); |
Masatake YAMATO | 02f9f6b | 2014-10-15 22:11:43 +0900 | [diff] [blame] | 2183 | #endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2184 | } |
| 2185 | } |
| 2186 | |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2187 | static int |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2188 | trace_syscall_exiting(struct tcb *tcp) |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 2189 | { |
| 2190 | int sys_res; |
| 2191 | struct timeval tv; |
Denys Vlasenko | 1a5b5a7 | 2011-08-25 00:29:56 +0200 | [diff] [blame] | 2192 | int res; |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2193 | long u_error; |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 2194 | |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2195 | /* Measure the exit time as early as possible to avoid errors. */ |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 2196 | if (Tflag || cflag) |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2197 | gettimeofday(&tv, NULL); |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 2198 | |
Masatake YAMATO | ed69fc2 | 2014-04-16 15:33:35 +0900 | [diff] [blame] | 2199 | #ifdef USE_LIBUNWIND |
| 2200 | if (stack_trace_enabled) { |
| 2201 | if (tcp->s_ent->sys_flags & STACKTRACE_INVALIDATE_CACHE) |
| 2202 | unwind_cache_invalidate(tcp); |
| 2203 | } |
| 2204 | #endif |
| 2205 | |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 2206 | #if SUPPORTED_PERSONALITIES > 1 |
| 2207 | update_personality(tcp, tcp->currpers); |
| 2208 | #endif |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 2209 | res = (get_regs_error ? -1 : get_syscall_result(tcp)); |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 2210 | if (res == 1) { |
Denys Vlasenko | c956ef0 | 2013-02-16 14:25:56 +0100 | [diff] [blame] | 2211 | get_error(tcp); /* never fails */ |
Denys Vlasenko | 2a3d275 | 2013-05-14 16:07:46 +0200 | [diff] [blame] | 2212 | if (filtered(tcp) || hide_log_until_execve) |
Denys Vlasenko | c956ef0 | 2013-02-16 14:25:56 +0100 | [diff] [blame] | 2213 | goto ret; |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 2214 | } |
| 2215 | |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2216 | if (cflag) { |
Dmitry V. Levin | ac5133d | 2014-05-29 18:10:00 +0000 | [diff] [blame] | 2217 | count_syscall(tcp, &tv); |
Denys Vlasenko | 7b609d5 | 2011-06-22 14:32:43 +0200 | [diff] [blame] | 2218 | if (cflag == CFLAG_ONLY_STATS) { |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2219 | goto ret; |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2220 | } |
| 2221 | } |
| 2222 | |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2223 | /* If not in -ff mode, and printing_tcp != tcp, |
| 2224 | * then the log currently does not end with output |
| 2225 | * of _our syscall entry_, but with something else. |
| 2226 | * We need to say which syscall's return is this. |
| 2227 | * |
| 2228 | * Forced reprinting via TCB_REPRINT is used only by |
| 2229 | * "strace -ff -oLOG test/threaded_execve" corner case. |
| 2230 | * It's the only case when -ff mode needs reprinting. |
| 2231 | */ |
| 2232 | if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) { |
| 2233 | tcp->flags &= ~TCB_REPRINT; |
| 2234 | printleader(tcp); |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2235 | if (tcp->qual_flg & UNDEFINED_SCNO) |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 2236 | tprintf("<... %s resumed> ", undefined_scno_name(tcp)); |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2237 | else |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2238 | tprintf("<... %s resumed> ", tcp->s_ent->sys_name); |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2239 | } |
| 2240 | printing_tcp = tcp; |
| 2241 | |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2242 | if (res != 1) { |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2243 | /* There was error in one of prior ptrace ops */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 2244 | tprints(") "); |
Denys Vlasenko | 102ec49 | 2011-08-25 01:27:59 +0200 | [diff] [blame] | 2245 | tabto(); |
Denys Vlasenko | 000b601 | 2012-01-28 01:25:03 +0100 | [diff] [blame] | 2246 | tprints("= ? <unavailable>\n"); |
Denys Vlasenko | 7de265d | 2012-03-13 11:44:31 +0100 | [diff] [blame] | 2247 | line_ended(); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2248 | tcp->flags &= ~TCB_INSYSCALL; |
| 2249 | return res; |
| 2250 | } |
| 2251 | |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2252 | sys_res = 0; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2253 | if (tcp->qual_flg & QUAL_RAW) { |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2254 | /* sys_res = printargs(tcp); - but it's nop on sysexit */ |
Denys Vlasenko | 7de265d | 2012-03-13 11:44:31 +0100 | [diff] [blame] | 2255 | } else { |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2256 | /* FIXME: not_failing_only (IOW, option -z) is broken: |
| 2257 | * failure of syscall is known only after syscall return. |
| 2258 | * Thus we end up with something like this on, say, ENOENT: |
| 2259 | * open("doesnt_exist", O_RDONLY <unfinished ...> |
| 2260 | * {next syscall decode} |
| 2261 | * whereas the intended result is that open(...) line |
| 2262 | * is not shown at all. |
| 2263 | */ |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2264 | if (not_failing_only && tcp->u_error) |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2265 | goto ret; /* ignore failed syscalls */ |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2266 | sys_res = tcp->s_ent->sys_func(tcp); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 2269 | tprints(") "); |
Denys Vlasenko | 102ec49 | 2011-08-25 01:27:59 +0200 | [diff] [blame] | 2270 | tabto(); |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2271 | u_error = tcp->u_error; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2272 | if (tcp->qual_flg & QUAL_RAW) { |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2273 | if (u_error) |
| 2274 | tprintf("= -1 (errno %ld)", u_error); |
| 2275 | else |
| 2276 | tprintf("= %#lx", tcp->u_rval); |
| 2277 | } |
| 2278 | else if (!(sys_res & RVAL_NONE) && u_error) { |
| 2279 | switch (u_error) { |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2280 | /* Blocked signals do not interrupt any syscalls. |
| 2281 | * In this case syscalls don't return ERESTARTfoo codes. |
| 2282 | * |
| 2283 | * Deadly signals set to SIG_DFL interrupt syscalls |
| 2284 | * and kill the process regardless of which of the codes below |
| 2285 | * is returned by the interrupted syscall. |
| 2286 | * In some cases, kernel forces a kernel-generated deadly |
| 2287 | * signal to be unblocked and set to SIG_DFL (and thus cause |
| 2288 | * death) if it is blocked or SIG_IGNed: for example, SIGSEGV |
| 2289 | * or SIGILL. (The alternative is to leave process spinning |
| 2290 | * forever on the faulty instruction - not useful). |
| 2291 | * |
| 2292 | * SIG_IGNed signals and non-deadly signals set to SIG_DFL |
| 2293 | * (for example, SIGCHLD, SIGWINCH) interrupt syscalls, |
| 2294 | * but kernel will always restart them. |
| 2295 | */ |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2296 | case ERESTARTSYS: |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2297 | /* Most common type of signal-interrupted syscall exit code. |
| 2298 | * The system call will be restarted with the same arguments |
| 2299 | * if SA_RESTART is set; otherwise, it will fail with EINTR. |
| 2300 | */ |
| 2301 | tprints("= ? ERESTARTSYS (To be restarted if SA_RESTART is set)"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2302 | break; |
| 2303 | case ERESTARTNOINTR: |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2304 | /* Rare. For example, fork() returns this if interrupted. |
| 2305 | * SA_RESTART is ignored (assumed set): the restart is unconditional. |
| 2306 | */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 2307 | tprints("= ? ERESTARTNOINTR (To be restarted)"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2308 | break; |
| 2309 | case ERESTARTNOHAND: |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2310 | /* pause(), rt_sigsuspend() etc use this code. |
| 2311 | * SA_RESTART is ignored (assumed not set): |
| 2312 | * syscall won't restart (will return EINTR instead) |
Denys Vlasenko | 30c0323 | 2013-02-19 16:59:26 +0100 | [diff] [blame] | 2313 | * even after signal with SA_RESTART set. However, |
| 2314 | * after SIG_IGN or SIG_DFL signal it will restart |
| 2315 | * (thus the name "restart only if has no handler"). |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2316 | */ |
Denys Vlasenko | aba6292 | 2013-03-05 16:56:35 +0100 | [diff] [blame] | 2317 | tprints("= ? ERESTARTNOHAND (To be restarted if no handler)"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2318 | break; |
| 2319 | case ERESTART_RESTARTBLOCK: |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2320 | /* Syscalls like nanosleep(), poll() which can't be |
| 2321 | * restarted with their original arguments use this |
| 2322 | * code. Kernel will execute restart_syscall() instead, |
| 2323 | * which changes arguments before restarting syscall. |
| 2324 | * SA_RESTART is ignored (assumed not set) similarly |
| 2325 | * to ERESTARTNOHAND. (Kernel can't honor SA_RESTART |
| 2326 | * since restart data is saved in "restart block" |
| 2327 | * in task struct, and if signal handler uses a syscall |
| 2328 | * which in turn saves another such restart block, |
| 2329 | * old data is lost and restart becomes impossible) |
| 2330 | */ |
| 2331 | tprints("= ? ERESTART_RESTARTBLOCK (Interrupted by signal)"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2332 | break; |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2333 | default: |
Dmitry V. Levin | b2f8c77 | 2015-02-23 03:10:25 +0000 | [diff] [blame] | 2334 | if ((unsigned long) u_error < nerrnos |
| 2335 | && errnoent[u_error]) |
Denys Vlasenko | a794974 | 2011-08-21 17:26:55 +0200 | [diff] [blame] | 2336 | tprintf("= -1 %s (%s)", errnoent[u_error], |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2337 | strerror(u_error)); |
| 2338 | else |
Dmitry V. Levin | b2f8c77 | 2015-02-23 03:10:25 +0000 | [diff] [blame] | 2339 | tprintf("= -1 ERRNO_%lu (%s)", u_error, |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2340 | strerror(u_error)); |
| 2341 | break; |
| 2342 | } |
| 2343 | if ((sys_res & RVAL_STR) && tcp->auxstr) |
| 2344 | tprintf(" (%s)", tcp->auxstr); |
| 2345 | } |
| 2346 | else { |
| 2347 | if (sys_res & RVAL_NONE) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 2348 | tprints("= ?"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2349 | else { |
| 2350 | switch (sys_res & RVAL_MASK) { |
| 2351 | case RVAL_HEX: |
Dmitry V. Levin | d93d9f8 | 2015-02-28 23:41:11 +0000 | [diff] [blame] | 2352 | #if SUPPORTED_PERSONALITIES > 1 |
| 2353 | if (current_wordsize < sizeof(long)) |
| 2354 | tprintf("= %#x", |
| 2355 | (unsigned int) tcp->u_rval); |
| 2356 | else |
| 2357 | #endif |
| 2358 | tprintf("= %#lx", tcp->u_rval); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2359 | break; |
| 2360 | case RVAL_OCTAL: |
| 2361 | tprintf("= %#lo", tcp->u_rval); |
| 2362 | break; |
| 2363 | case RVAL_UDECIMAL: |
| 2364 | tprintf("= %lu", tcp->u_rval); |
| 2365 | break; |
| 2366 | case RVAL_DECIMAL: |
| 2367 | tprintf("= %ld", tcp->u_rval); |
| 2368 | break; |
Zubin Mithra | 64aa1b1 | 2014-06-04 08:30:41 +0530 | [diff] [blame] | 2369 | case RVAL_FD: |
| 2370 | if (show_fd_path) { |
| 2371 | tprints("= "); |
| 2372 | printfd(tcp, tcp->u_rval); |
| 2373 | } |
| 2374 | else |
| 2375 | tprintf("= %ld", tcp->u_rval); |
| 2376 | break; |
H.J. Lu | dd0130b | 2012-04-16 12:16:45 +0200 | [diff] [blame] | 2377 | #if defined(LINUX_MIPSN32) || defined(X32) |
| 2378 | /* |
| 2379 | case RVAL_LHEX: |
| 2380 | tprintf("= %#llx", tcp->u_lrval); |
| 2381 | break; |
| 2382 | case RVAL_LOCTAL: |
| 2383 | tprintf("= %#llo", tcp->u_lrval); |
| 2384 | break; |
| 2385 | */ |
| 2386 | case RVAL_LUDECIMAL: |
| 2387 | tprintf("= %llu", tcp->u_lrval); |
| 2388 | break; |
| 2389 | /* |
| 2390 | case RVAL_LDECIMAL: |
| 2391 | tprintf("= %lld", tcp->u_lrval); |
| 2392 | break; |
| 2393 | */ |
| 2394 | #endif |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2395 | default: |
| 2396 | fprintf(stderr, |
| 2397 | "invalid rval format\n"); |
| 2398 | break; |
| 2399 | } |
| 2400 | } |
| 2401 | if ((sys_res & RVAL_STR) && tcp->auxstr) |
| 2402 | tprintf(" (%s)", tcp->auxstr); |
| 2403 | } |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 2404 | if (Tflag) { |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2405 | tv_sub(&tv, &tv, &tcp->etime); |
| 2406 | tprintf(" <%ld.%06ld>", |
| 2407 | (long) tv.tv_sec, (long) tv.tv_usec); |
| 2408 | } |
Denys Vlasenko | 000b601 | 2012-01-28 01:25:03 +0100 | [diff] [blame] | 2409 | tprints("\n"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2410 | dumpio(tcp); |
Denys Vlasenko | 7de265d | 2012-03-13 11:44:31 +0100 | [diff] [blame] | 2411 | line_ended(); |
| 2412 | |
Luca Clementi | 327064b | 2013-07-23 00:11:35 -0700 | [diff] [blame] | 2413 | #ifdef USE_LIBUNWIND |
| 2414 | if (stack_trace_enabled) |
Masatake YAMATO | 6141392 | 2014-04-16 15:33:02 +0900 | [diff] [blame] | 2415 | unwind_print_stacktrace(tcp); |
Luca Clementi | 327064b | 2013-07-23 00:11:35 -0700 | [diff] [blame] | 2416 | #endif |
| 2417 | |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2418 | ret: |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2419 | tcp->flags &= ~TCB_INSYSCALL; |
| 2420 | return 0; |
| 2421 | } |
| 2422 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 2423 | int |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2424 | trace_syscall(struct tcb *tcp) |
| 2425 | { |
| 2426 | return exiting(tcp) ? |
| 2427 | trace_syscall_exiting(tcp) : trace_syscall_entering(tcp); |
| 2428 | } |