Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 3 | * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> |
| 4 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
| 6 | * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 7 | * Linux for s390 port by D.J. Barrow |
| 8 | * <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
| 18 | * documentation and/or other materials provided with the distribution. |
| 19 | * 3. The name of the author may not be used to endorse or promote products |
| 20 | * derived from this software without specific prior written permission. |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 25 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 32 | */ |
| 33 | |
| 34 | #include "defs.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 35 | #include <sys/param.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | |
Dmitry V. Levin | 5503dd2 | 2015-02-13 02:12:14 +0000 | [diff] [blame] | 37 | /* for struct iovec */ |
| 38 | #include <sys/uio.h> |
Maarten ter Huurne | 40c174b | 2014-10-20 01:02:48 +0200 | [diff] [blame] | 39 | |
Dmitry V. Levin | 7211dbc | 2015-02-28 12:20:21 +0000 | [diff] [blame] | 40 | #include "regs.h" |
Dmitry V. Levin | fadf379 | 2015-02-13 00:26:38 +0000 | [diff] [blame] | 41 | #include "ptrace.h" |
Wichert Akkerman | 15dea97 | 1999-10-06 13:06:34 +0000 | [diff] [blame] | 42 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 43 | #if defined(SPARC64) |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 44 | # undef PTRACE_GETREGS |
| 45 | # define PTRACE_GETREGS PTRACE_GETREGS64 |
| 46 | # undef PTRACE_SETREGS |
| 47 | # define PTRACE_SETREGS PTRACE_SETREGS64 |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 48 | #endif |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 49 | |
Dmitry V. Levin | 5503dd2 | 2015-02-13 02:12:14 +0000 | [diff] [blame] | 50 | #if defined SPARC64 |
| 51 | # include <asm/psrcompat.h> |
| 52 | #elif defined SPARC |
| 53 | # include <asm/psr.h> |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 54 | #endif |
| 55 | |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame] | 56 | #ifdef IA64 |
| 57 | # include <asm/rse.h> |
| 58 | #endif |
| 59 | |
Dmitry V. Levin | 4c3f2ae | 2015-02-13 22:53:00 +0000 | [diff] [blame] | 60 | #ifndef NT_PRSTATUS |
| 61 | # define NT_PRSTATUS 1 |
| 62 | #endif |
| 63 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 64 | #ifndef NSIG |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 65 | # warning: NSIG is not defined, using 32 |
| 66 | # define NSIG 32 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 67 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 68 | |
| 69 | #include "syscall.h" |
| 70 | |
| 71 | /* Define these shorthand notations to simplify the syscallent files. */ |
Roland McGrath | 2fe7b13 | 2005-07-05 03:25:35 +0000 | [diff] [blame] | 72 | #define TD TRACE_DESC |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 73 | #define TF TRACE_FILE |
| 74 | #define TI TRACE_IPC |
| 75 | #define TN TRACE_NETWORK |
| 76 | #define TP TRACE_PROCESS |
| 77 | #define TS TRACE_SIGNAL |
Namhyung Kim | 9679296 | 2012-10-24 11:41:57 +0900 | [diff] [blame] | 78 | #define TM TRACE_MEMORY |
Dmitry V. Levin | 50a218d | 2011-01-18 17:36:20 +0000 | [diff] [blame] | 79 | #define NF SYSCALL_NEVER_FAILS |
Denys Vlasenko | ac1ce77 | 2011-08-23 13:24:17 +0200 | [diff] [blame] | 80 | #define MA MAX_ARGS |
Masatake YAMATO | 1d78d22 | 2014-04-16 15:33:11 +0900 | [diff] [blame] | 81 | #define SI STACKTRACE_INVALIDATE_CACHE |
| 82 | #define SE STACKTRACE_CAPTURE_ON_ENTER |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 83 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 84 | const struct_sysent sysent0[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 85 | #include "syscallent.h" |
| 86 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 87 | |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 88 | #if SUPPORTED_PERSONALITIES > 1 |
| 89 | static const struct_sysent sysent1[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 90 | # include "syscallent1.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 91 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 92 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 93 | |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 94 | #if SUPPORTED_PERSONALITIES > 2 |
| 95 | static const struct_sysent sysent2[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 96 | # include "syscallent2.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 97 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 98 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 99 | |
| 100 | /* Now undef them since short defines cause wicked namespace pollution. */ |
Roland McGrath | 2fe7b13 | 2005-07-05 03:25:35 +0000 | [diff] [blame] | 101 | #undef TD |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 102 | #undef TF |
| 103 | #undef TI |
| 104 | #undef TN |
| 105 | #undef TP |
| 106 | #undef TS |
Namhyung Kim | 9679296 | 2012-10-24 11:41:57 +0900 | [diff] [blame] | 107 | #undef TM |
Dmitry V. Levin | 50a218d | 2011-01-18 17:36:20 +0000 | [diff] [blame] | 108 | #undef NF |
Denys Vlasenko | ac1ce77 | 2011-08-23 13:24:17 +0200 | [diff] [blame] | 109 | #undef MA |
Masatake YAMATO | 1d78d22 | 2014-04-16 15:33:11 +0900 | [diff] [blame] | 110 | #undef SI |
| 111 | #undef SE |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 112 | |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 113 | /* |
Dmitry V. Levin | df7aa2b | 2015-01-19 17:02:16 +0000 | [diff] [blame] | 114 | * `ioctlent[012].h' files are automatically generated by the auxiliary |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 115 | * program `ioctlsort', such that the list is sorted by the `code' field. |
| 116 | * This has the side-effect of resolving the _IO.. macros into |
| 117 | * plain integers, eliminating the need to include here everything |
| 118 | * in "/usr/include". |
| 119 | */ |
| 120 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 121 | const char *const errnoent0[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 122 | #include "errnoent.h" |
| 123 | }; |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 124 | const char *const signalent0[] = { |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 125 | #include "signalent.h" |
| 126 | }; |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 127 | const struct_ioctlent ioctlent0[] = { |
Dmitry V. Levin | df7aa2b | 2015-01-19 17:02:16 +0000 | [diff] [blame] | 128 | #include "ioctlent0.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 129 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 130 | |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 131 | #if SUPPORTED_PERSONALITIES > 1 |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 132 | static const char *const errnoent1[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 133 | # include "errnoent1.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 134 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 135 | static const char *const signalent1[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 136 | # include "signalent1.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 137 | }; |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 138 | static const struct_ioctlent ioctlent1[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 139 | # include "ioctlent1.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 140 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 141 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 142 | |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 143 | #if SUPPORTED_PERSONALITIES > 2 |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 144 | static const char *const errnoent2[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 145 | # include "errnoent2.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 146 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 147 | static const char *const signalent2[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 148 | # include "signalent2.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 149 | }; |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 150 | static const struct_ioctlent ioctlent2[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 151 | # include "ioctlent2.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 152 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 153 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 154 | |
Dmitry V. Levin | e6f5524 | 2013-02-26 22:02:30 +0000 | [diff] [blame] | 155 | enum { |
| 156 | nsyscalls0 = ARRAY_SIZE(sysent0) |
| 157 | #if SUPPORTED_PERSONALITIES > 1 |
| 158 | , nsyscalls1 = ARRAY_SIZE(sysent1) |
| 159 | # if SUPPORTED_PERSONALITIES > 2 |
| 160 | , nsyscalls2 = ARRAY_SIZE(sysent2) |
| 161 | # endif |
| 162 | #endif |
| 163 | }; |
| 164 | |
| 165 | enum { |
| 166 | nerrnos0 = ARRAY_SIZE(errnoent0) |
| 167 | #if SUPPORTED_PERSONALITIES > 1 |
| 168 | , nerrnos1 = ARRAY_SIZE(errnoent1) |
| 169 | # if SUPPORTED_PERSONALITIES > 2 |
| 170 | , nerrnos2 = ARRAY_SIZE(errnoent2) |
| 171 | # endif |
| 172 | #endif |
| 173 | }; |
| 174 | |
| 175 | enum { |
| 176 | nsignals0 = ARRAY_SIZE(signalent0) |
| 177 | #if SUPPORTED_PERSONALITIES > 1 |
| 178 | , nsignals1 = ARRAY_SIZE(signalent1) |
| 179 | # if SUPPORTED_PERSONALITIES > 2 |
| 180 | , nsignals2 = ARRAY_SIZE(signalent2) |
| 181 | # endif |
| 182 | #endif |
| 183 | }; |
| 184 | |
| 185 | enum { |
| 186 | nioctlents0 = ARRAY_SIZE(ioctlent0) |
| 187 | #if SUPPORTED_PERSONALITIES > 1 |
| 188 | , nioctlents1 = ARRAY_SIZE(ioctlent1) |
| 189 | # if SUPPORTED_PERSONALITIES > 2 |
| 190 | , nioctlents2 = ARRAY_SIZE(ioctlent2) |
| 191 | # endif |
| 192 | #endif |
| 193 | }; |
| 194 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 195 | #if SUPPORTED_PERSONALITIES > 1 |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 196 | const struct_sysent *sysent = sysent0; |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 197 | const char *const *errnoent = errnoent0; |
| 198 | const char *const *signalent = signalent0; |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 199 | const struct_ioctlent *ioctlent = ioctlent0; |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 200 | #endif |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 201 | unsigned nsyscalls = nsyscalls0; |
| 202 | unsigned nerrnos = nerrnos0; |
| 203 | unsigned nsignals = nsignals0; |
| 204 | unsigned nioctlents = nioctlents0; |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 205 | |
| 206 | unsigned num_quals; |
| 207 | qualbits_t *qual_vec[SUPPORTED_PERSONALITIES]; |
| 208 | |
| 209 | static const unsigned nsyscall_vec[SUPPORTED_PERSONALITIES] = { |
| 210 | nsyscalls0, |
| 211 | #if SUPPORTED_PERSONALITIES > 1 |
| 212 | nsyscalls1, |
| 213 | #endif |
| 214 | #if SUPPORTED_PERSONALITIES > 2 |
| 215 | nsyscalls2, |
| 216 | #endif |
| 217 | }; |
| 218 | static const struct_sysent *const sysent_vec[SUPPORTED_PERSONALITIES] = { |
| 219 | sysent0, |
| 220 | #if SUPPORTED_PERSONALITIES > 1 |
| 221 | sysent1, |
| 222 | #endif |
| 223 | #if SUPPORTED_PERSONALITIES > 2 |
| 224 | sysent2, |
| 225 | #endif |
| 226 | }; |
| 227 | |
| 228 | enum { |
| 229 | MAX_NSYSCALLS1 = (nsyscalls0 |
| 230 | #if SUPPORTED_PERSONALITIES > 1 |
| 231 | > nsyscalls1 ? nsyscalls0 : nsyscalls1 |
| 232 | #endif |
| 233 | ), |
| 234 | MAX_NSYSCALLS2 = (MAX_NSYSCALLS1 |
| 235 | #if SUPPORTED_PERSONALITIES > 2 |
| 236 | > nsyscalls2 ? MAX_NSYSCALLS1 : nsyscalls2 |
| 237 | #endif |
| 238 | ), |
| 239 | MAX_NSYSCALLS = MAX_NSYSCALLS2, |
| 240 | /* We are ready for arches with up to 255 signals, |
| 241 | * even though the largest known signo is on MIPS and it is 128. |
| 242 | * The number of existing syscalls on all arches is |
| 243 | * larger that 255 anyway, so it is just a pedantic matter. |
| 244 | */ |
| 245 | MIN_QUALS = MAX_NSYSCALLS > 255 ? MAX_NSYSCALLS : 255 |
| 246 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 247 | |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 248 | #if SUPPORTED_PERSONALITIES > 1 |
Denys Vlasenko | ae8643e | 2013-02-15 14:55:14 +0100 | [diff] [blame] | 249 | unsigned current_personality; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 250 | |
Denys Vlasenko | ae8643e | 2013-02-15 14:55:14 +0100 | [diff] [blame] | 251 | # ifndef current_wordsize |
| 252 | unsigned current_wordsize; |
| 253 | static const int personality_wordsize[SUPPORTED_PERSONALITIES] = { |
Roland McGrath | 4b2dcca | 2006-01-12 10:18:53 +0000 | [diff] [blame] | 254 | PERSONALITY0_WORDSIZE, |
Roland McGrath | 4b2dcca | 2006-01-12 10:18:53 +0000 | [diff] [blame] | 255 | PERSONALITY1_WORDSIZE, |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 256 | # if SUPPORTED_PERSONALITIES > 2 |
Roland McGrath | 4b2dcca | 2006-01-12 10:18:53 +0000 | [diff] [blame] | 257 | PERSONALITY2_WORDSIZE, |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 258 | # endif |
Denys Vlasenko | 5c774b2 | 2011-08-20 01:50:09 +0200 | [diff] [blame] | 259 | }; |
Denys Vlasenko | ae8643e | 2013-02-15 14:55:14 +0100 | [diff] [blame] | 260 | # endif |
Roland McGrath | 4b2dcca | 2006-01-12 10:18:53 +0000 | [diff] [blame] | 261 | |
Denys Vlasenko | 5c774b2 | 2011-08-20 01:50:09 +0200 | [diff] [blame] | 262 | void |
Dmitry V. Levin | 3abe8b2 | 2006-12-20 22:37:21 +0000 | [diff] [blame] | 263 | set_personality(int personality) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 264 | { |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 265 | nsyscalls = nsyscall_vec[personality]; |
| 266 | sysent = sysent_vec[personality]; |
| 267 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 268 | switch (personality) { |
| 269 | case 0: |
| 270 | errnoent = errnoent0; |
| 271 | nerrnos = nerrnos0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 272 | ioctlent = ioctlent0; |
| 273 | nioctlents = nioctlents0; |
| 274 | signalent = signalent0; |
| 275 | nsignals = nsignals0; |
| 276 | break; |
| 277 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 278 | case 1: |
| 279 | errnoent = errnoent1; |
| 280 | nerrnos = nerrnos1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 281 | ioctlent = ioctlent1; |
| 282 | nioctlents = nioctlents1; |
| 283 | signalent = signalent1; |
| 284 | nsignals = nsignals1; |
| 285 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 286 | |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 287 | # if SUPPORTED_PERSONALITIES > 2 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 288 | case 2: |
| 289 | errnoent = errnoent2; |
| 290 | nerrnos = nerrnos2; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 291 | ioctlent = ioctlent2; |
| 292 | nioctlents = nioctlents2; |
| 293 | signalent = signalent2; |
| 294 | nsignals = nsignals2; |
| 295 | break; |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 296 | # endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | current_personality = personality; |
Denys Vlasenko | ae8643e | 2013-02-15 14:55:14 +0100 | [diff] [blame] | 300 | # ifndef current_wordsize |
| 301 | current_wordsize = personality_wordsize[personality]; |
| 302 | # endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 305 | static void |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 306 | update_personality(struct tcb *tcp, unsigned int personality) |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 307 | { |
| 308 | if (personality == current_personality) |
| 309 | return; |
| 310 | set_personality(personality); |
| 311 | |
| 312 | if (personality == tcp->currpers) |
| 313 | return; |
| 314 | tcp->currpers = personality; |
| 315 | |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 316 | # if defined(POWERPC64) |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 317 | if (!qflag) { |
| 318 | static const char *const names[] = {"64 bit", "32 bit"}; |
| 319 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 320 | tcp->pid, names[personality]); |
| 321 | } |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 322 | # elif defined(X86_64) |
| 323 | if (!qflag) { |
| 324 | static const char *const names[] = {"64 bit", "32 bit", "x32"}; |
| 325 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 326 | tcp->pid, names[personality]); |
| 327 | } |
H.J. Lu | 085e428 | 2012-04-17 11:05:04 -0700 | [diff] [blame] | 328 | # elif defined(X32) |
| 329 | if (!qflag) { |
| 330 | static const char *const names[] = {"x32", "32 bit"}; |
| 331 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 332 | tcp->pid, names[personality]); |
| 333 | } |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 334 | # elif defined(AARCH64) |
| 335 | if (!qflag) { |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 336 | static const char *const names[] = {"32-bit", "AArch64"}; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 337 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 338 | tcp->pid, names[personality]); |
| 339 | } |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 340 | # elif defined(TILE) |
| 341 | if (!qflag) { |
| 342 | static const char *const names[] = {"64-bit", "32-bit"}; |
| 343 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 344 | tcp->pid, names[personality]); |
| 345 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 346 | # endif |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 347 | } |
| 348 | #endif |
Roland McGrath | e10e62a | 2004-09-04 04:20:43 +0000 | [diff] [blame] | 349 | |
Denys Vlasenko | c1540fe | 2013-02-21 16:17:08 +0100 | [diff] [blame] | 350 | static int qual_syscall(), qual_signal(), qual_desc(); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 351 | |
Roland McGrath | e10e62a | 2004-09-04 04:20:43 +0000 | [diff] [blame] | 352 | static const struct qual_options { |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 353 | unsigned int bitflag; |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 354 | const char *option_name; |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 355 | int (*qualify)(const char *, int, int); |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 356 | const char *argument_name; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 357 | } qual_options[] = { |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 358 | { QUAL_TRACE, "trace", qual_syscall, "system call" }, |
| 359 | { QUAL_TRACE, "t", qual_syscall, "system call" }, |
| 360 | { QUAL_ABBREV, "abbrev", qual_syscall, "system call" }, |
| 361 | { QUAL_ABBREV, "a", qual_syscall, "system call" }, |
| 362 | { QUAL_VERBOSE, "verbose", qual_syscall, "system call" }, |
| 363 | { QUAL_VERBOSE, "v", qual_syscall, "system call" }, |
| 364 | { QUAL_RAW, "raw", qual_syscall, "system call" }, |
| 365 | { QUAL_RAW, "x", qual_syscall, "system call" }, |
| 366 | { QUAL_SIGNAL, "signal", qual_signal, "signal" }, |
| 367 | { QUAL_SIGNAL, "signals", qual_signal, "signal" }, |
| 368 | { QUAL_SIGNAL, "s", qual_signal, "signal" }, |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 369 | { QUAL_READ, "read", qual_desc, "descriptor" }, |
| 370 | { QUAL_READ, "reads", qual_desc, "descriptor" }, |
| 371 | { QUAL_READ, "r", qual_desc, "descriptor" }, |
| 372 | { QUAL_WRITE, "write", qual_desc, "descriptor" }, |
| 373 | { QUAL_WRITE, "writes", qual_desc, "descriptor" }, |
| 374 | { QUAL_WRITE, "w", qual_desc, "descriptor" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 375 | { 0, NULL, NULL, NULL }, |
| 376 | }; |
| 377 | |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 378 | static void |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 379 | reallocate_qual(const unsigned int n) |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 380 | { |
| 381 | unsigned p; |
| 382 | qualbits_t *qp; |
| 383 | for (p = 0; p < SUPPORTED_PERSONALITIES; p++) { |
| 384 | qp = qual_vec[p] = realloc(qual_vec[p], n * sizeof(qualbits_t)); |
| 385 | if (!qp) |
| 386 | die_out_of_memory(); |
| 387 | memset(&qp[num_quals], 0, (n - num_quals) * sizeof(qualbits_t)); |
| 388 | } |
| 389 | num_quals = n; |
| 390 | } |
| 391 | |
| 392 | static void |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 393 | qualify_one(const unsigned int n, unsigned int bitflag, const int not, const int pers) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 394 | { |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 395 | int p; |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 396 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 397 | if (num_quals <= n) |
| 398 | reallocate_qual(n + 1); |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 399 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 400 | for (p = 0; p < SUPPORTED_PERSONALITIES; p++) { |
| 401 | if (pers == p || pers < 0) { |
| 402 | if (not) |
| 403 | qual_vec[p][n] &= ~bitflag; |
| 404 | else |
| 405 | qual_vec[p][n] |= bitflag; |
| 406 | } |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 407 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | static int |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 411 | qual_syscall(const char *s, const unsigned int bitflag, const int not) |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 412 | { |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 413 | int p; |
| 414 | unsigned int i; |
Roland McGrath | fe6b352 | 2005-02-02 04:40:11 +0000 | [diff] [blame] | 415 | int rc = -1; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 416 | |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 417 | if (*s >= '0' && *s <= '9') { |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 418 | i = string_to_uint(s); |
Denys Vlasenko | b43dacd | 2013-02-23 18:19:28 +0100 | [diff] [blame] | 419 | if (i >= MAX_NSYSCALLS) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 420 | return -1; |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 421 | qualify_one(i, bitflag, not, -1); |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 422 | return 0; |
Roland McGrath | 48a035f | 2006-01-12 09:45:56 +0000 | [diff] [blame] | 423 | } |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 424 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 425 | for (p = 0; p < SUPPORTED_PERSONALITIES; p++) { |
| 426 | for (i = 0; i < nsyscall_vec[p]; i++) { |
| 427 | if (sysent_vec[p][i].sys_name |
| 428 | && strcmp(s, sysent_vec[p][i].sys_name) == 0 |
| 429 | ) { |
Dmitry V. Levin | 7b9e45e | 2013-03-01 15:50:22 +0000 | [diff] [blame] | 430 | qualify_one(i, bitflag, not, p); |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 431 | rc = 0; |
| 432 | } |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 433 | } |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 434 | } |
Dmitry V. Levin | c18c703 | 2007-08-22 21:43:30 +0000 | [diff] [blame] | 435 | |
Roland McGrath | fe6b352 | 2005-02-02 04:40:11 +0000 | [diff] [blame] | 436 | return rc; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static int |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 440 | qual_signal(const char *s, const unsigned int bitflag, const int not) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 441 | { |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 442 | unsigned int i; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 443 | |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 444 | if (*s >= '0' && *s <= '9') { |
Dmitry V. Levin | ccee169 | 2012-03-25 21:49:48 +0000 | [diff] [blame] | 445 | int signo = string_to_uint(s); |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 446 | if (signo < 0 || signo > 255) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 447 | return -1; |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 448 | qualify_one(signo, bitflag, not, -1); |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 449 | return 0; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 450 | } |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 451 | if (strncasecmp(s, "SIG", 3) == 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 452 | s += 3; |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 453 | for (i = 0; i <= NSIG; i++) { |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 454 | if (strcasecmp(s, signame(i) + 3) == 0) { |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 455 | qualify_one(i, bitflag, not, -1); |
Roland McGrath | 76421df | 2005-02-02 03:51:18 +0000 | [diff] [blame] | 456 | return 0; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 457 | } |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 458 | } |
Roland McGrath | 76421df | 2005-02-02 03:51:18 +0000 | [diff] [blame] | 459 | return -1; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | static int |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 463 | qual_desc(const char *s, const unsigned int bitflag, const int not) |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 464 | { |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 465 | if (*s >= '0' && *s <= '9') { |
Dmitry V. Levin | ccee169 | 2012-03-25 21:49:48 +0000 | [diff] [blame] | 466 | int desc = string_to_uint(s); |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 467 | if (desc < 0 || desc > 0x7fff) /* paranoia */ |
Roland McGrath | fe6b352 | 2005-02-02 04:40:11 +0000 | [diff] [blame] | 468 | return -1; |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 469 | qualify_one(desc, bitflag, not, -1); |
Roland McGrath | 2b61902 | 2003-04-10 18:58:20 +0000 | [diff] [blame] | 470 | return 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 471 | } |
| 472 | return -1; |
| 473 | } |
| 474 | |
| 475 | static int |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 476 | lookup_class(const char *s) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 477 | { |
| 478 | if (strcmp(s, "file") == 0) |
| 479 | return TRACE_FILE; |
| 480 | if (strcmp(s, "ipc") == 0) |
| 481 | return TRACE_IPC; |
| 482 | if (strcmp(s, "network") == 0) |
| 483 | return TRACE_NETWORK; |
| 484 | if (strcmp(s, "process") == 0) |
| 485 | return TRACE_PROCESS; |
| 486 | if (strcmp(s, "signal") == 0) |
| 487 | return TRACE_SIGNAL; |
Roland McGrath | 2fe7b13 | 2005-07-05 03:25:35 +0000 | [diff] [blame] | 488 | if (strcmp(s, "desc") == 0) |
| 489 | return TRACE_DESC; |
Namhyung Kim | 9679296 | 2012-10-24 11:41:57 +0900 | [diff] [blame] | 490 | if (strcmp(s, "memory") == 0) |
| 491 | return TRACE_MEMORY; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 492 | return -1; |
| 493 | } |
| 494 | |
| 495 | void |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 496 | qualify(const char *s) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 497 | { |
Roland McGrath | e10e62a | 2004-09-04 04:20:43 +0000 | [diff] [blame] | 498 | const struct qual_options *opt; |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 499 | char *copy; |
| 500 | const char *p; |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 501 | int not; |
| 502 | unsigned int i; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 503 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 504 | if (num_quals == 0) |
| 505 | reallocate_qual(MIN_QUALS); |
| 506 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 507 | opt = &qual_options[0]; |
| 508 | for (i = 0; (p = qual_options[i].option_name); i++) { |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 509 | unsigned int len = strlen(p); |
| 510 | if (strncmp(s, p, len) == 0 && s[len] == '=') { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 511 | opt = &qual_options[i]; |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 512 | s += len + 1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 513 | break; |
| 514 | } |
| 515 | } |
| 516 | not = 0; |
| 517 | if (*s == '!') { |
| 518 | not = 1; |
| 519 | s++; |
| 520 | } |
| 521 | if (strcmp(s, "none") == 0) { |
| 522 | not = 1 - not; |
| 523 | s = "all"; |
| 524 | } |
| 525 | if (strcmp(s, "all") == 0) { |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 526 | for (i = 0; i < num_quals; i++) { |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 527 | qualify_one(i, opt->bitflag, not, -1); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 528 | } |
| 529 | return; |
| 530 | } |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 531 | for (i = 0; i < num_quals; i++) { |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 532 | qualify_one(i, opt->bitflag, !not, -1); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 533 | } |
Denys Vlasenko | 5d64581 | 2011-08-20 12:48:18 +0200 | [diff] [blame] | 534 | copy = strdup(s); |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 535 | if (!copy) |
| 536 | die_out_of_memory(); |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 537 | for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) { |
Dmitry V. Levin | 3ed5d02 | 2014-09-10 13:46:04 +0000 | [diff] [blame] | 538 | int n; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 539 | if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) { |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 540 | unsigned pers; |
| 541 | for (pers = 0; pers < SUPPORTED_PERSONALITIES; pers++) { |
| 542 | for (i = 0; i < nsyscall_vec[pers]; i++) |
| 543 | if (sysent_vec[pers][i].sys_flags & n) |
Dmitry V. Levin | 7b9e45e | 2013-03-01 15:50:22 +0000 | [diff] [blame] | 544 | qualify_one(i, opt->bitflag, not, pers); |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 545 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 546 | continue; |
| 547 | } |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 548 | if (opt->qualify(p, opt->bitflag, not)) { |
Denys Vlasenko | 4c65c44 | 2012-03-08 11:54:10 +0100 | [diff] [blame] | 549 | error_msg_and_die("invalid %s '%s'", |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 550 | opt->argument_name, p); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 551 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 552 | } |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 553 | free(copy); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 554 | return; |
| 555 | } |
| 556 | |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 557 | #ifdef SYS_socket_subcall |
Roland McGrath | a4d4853 | 2005-06-08 20:45:28 +0000 | [diff] [blame] | 558 | static void |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 559 | decode_socket_subcall(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 560 | { |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 561 | unsigned long addr; |
Dmitry V. Levin | c215569 | 2015-03-22 15:52:40 +0000 | [diff] [blame] | 562 | unsigned int n; |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 563 | |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 564 | if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_socket_nsubcalls) |
| 565 | return; |
| 566 | |
| 567 | tcp->scno = SYS_socket_subcall + tcp->u_arg[0]; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 568 | tcp->qual_flg = qual_flags[tcp->scno]; |
| 569 | tcp->s_ent = &sysent[tcp->scno]; |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 570 | addr = tcp->u_arg[1]; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 571 | n = tcp->s_ent->nargs; |
Dmitry V. Levin | c215569 | 2015-03-22 15:52:40 +0000 | [diff] [blame] | 572 | if (sizeof(tcp->u_arg[0]) == current_wordsize) { |
| 573 | memset(tcp->u_arg, 0, n * sizeof(tcp->u_arg[0])); |
| 574 | (void) umoven(tcp, addr, n * sizeof(tcp->u_arg[0]), tcp->u_arg); |
| 575 | } else { |
| 576 | unsigned int args[n]; |
| 577 | unsigned int i; |
| 578 | |
| 579 | memset(args, 0, sizeof(args)); |
| 580 | (void) umove(tcp, addr, &args); |
| 581 | for (i = 0; i < n; ++i) |
| 582 | tcp->u_arg[i] = args[i]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 583 | } |
| 584 | } |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 585 | #endif |
Mike Frysinger | 3362e89 | 2012-03-15 01:09:19 -0400 | [diff] [blame] | 586 | |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 587 | #ifdef SYS_ipc_subcall |
| 588 | static void |
| 589 | decode_ipc_subcall(struct tcb *tcp) |
| 590 | { |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 591 | unsigned int i, n; |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 592 | |
| 593 | if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_ipc_nsubcalls) |
| 594 | return; |
| 595 | |
| 596 | tcp->scno = SYS_ipc_subcall + tcp->u_arg[0]; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 597 | tcp->qual_flg = qual_flags[tcp->scno]; |
| 598 | tcp->s_ent = &sysent[tcp->scno]; |
| 599 | n = tcp->s_ent->nargs; |
| 600 | for (i = 0; i < n; i++) |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 601 | tcp->u_arg[i] = tcp->u_arg[i + 1]; |
| 602 | } |
| 603 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 604 | |
Dmitry V. Levin | f34b97f | 2015-04-17 09:14:19 +0000 | [diff] [blame^] | 605 | #ifdef LINUX_MIPSO32 |
| 606 | static void |
| 607 | decode_mips_subcall(struct tcb *tcp) |
| 608 | { |
| 609 | if (!SCNO_IS_VALID(tcp->u_arg[0])) |
| 610 | return; |
| 611 | tcp->scno = tcp->u_arg[0]; |
| 612 | tcp->qual_flg = qual_flags[tcp->scno]; |
| 613 | tcp->s_ent = &sysent[tcp->scno]; |
| 614 | memmove(&tcp->u_arg[0], &tcp->u_arg[1], |
| 615 | sizeof(tcp->u_arg) - sizeof(tcp->u_arg[0])); |
| 616 | /* |
| 617 | * Fetching the last arg of 7-arg syscalls (fadvise64_64 |
| 618 | * and sync_file_range) would require additional code, |
| 619 | * see linux/mips/get_syscall_args.c |
| 620 | */ |
| 621 | } |
| 622 | |
| 623 | SYS_FUNC(syscall) |
| 624 | { |
| 625 | return printargs(tcp); |
| 626 | } |
| 627 | #endif |
| 628 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 629 | int |
| 630 | printargs(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 631 | { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 632 | if (entering(tcp)) { |
| 633 | int i; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 634 | int n = tcp->s_ent->nargs; |
| 635 | for (i = 0; i < n; i++) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 636 | tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]); |
| 637 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 638 | return 0; |
| 639 | } |
| 640 | |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 641 | int |
| 642 | printargs_lu(struct tcb *tcp) |
| 643 | { |
| 644 | if (entering(tcp)) { |
| 645 | int i; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 646 | int n = tcp->s_ent->nargs; |
| 647 | for (i = 0; i < n; i++) |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 648 | tprintf("%s%lu", i ? ", " : "", tcp->u_arg[i]); |
| 649 | } |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | int |
| 654 | printargs_ld(struct tcb *tcp) |
| 655 | { |
| 656 | if (entering(tcp)) { |
| 657 | int i; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 658 | int n = tcp->s_ent->nargs; |
| 659 | for (i = 0; i < n; i++) |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 660 | tprintf("%s%ld", i ? ", " : "", tcp->u_arg[i]); |
| 661 | } |
| 662 | return 0; |
| 663 | } |
| 664 | |
Dmitry V. Levin | 1b78607 | 2015-03-22 18:09:55 +0000 | [diff] [blame] | 665 | static void |
| 666 | dumpio(struct tcb *tcp) |
| 667 | { |
| 668 | int (*func)(); |
| 669 | |
| 670 | if (syserror(tcp)) |
| 671 | return; |
| 672 | if ((unsigned long) tcp->u_arg[0] >= num_quals) |
| 673 | return; |
| 674 | func = tcp->s_ent->sys_func; |
| 675 | if (func == printargs) |
| 676 | return; |
| 677 | if (qual_flags[tcp->u_arg[0]] & QUAL_READ) { |
| 678 | if (func == sys_read || |
| 679 | func == sys_pread || |
| 680 | func == sys_recv || |
| 681 | func == sys_recvfrom) { |
| 682 | dumpstr(tcp, tcp->u_arg[1], tcp->u_rval); |
| 683 | return; |
| 684 | } else if (func == sys_readv) { |
| 685 | dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
| 686 | return; |
| 687 | #if HAVE_SENDMSG |
| 688 | } else if (func == sys_recvmsg) { |
| 689 | dumpiov_in_msghdr(tcp, tcp->u_arg[1]); |
| 690 | return; |
| 691 | } else if (func == sys_recvmmsg) { |
| 692 | dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]); |
| 693 | return; |
| 694 | #endif |
| 695 | } |
| 696 | } |
| 697 | if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) { |
| 698 | if (func == sys_write || |
| 699 | func == sys_pwrite || |
| 700 | func == sys_send || |
| 701 | func == sys_sendto) |
| 702 | dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 703 | else if (func == sys_writev) |
| 704 | dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
| 705 | #if HAVE_SENDMSG |
| 706 | else if (func == sys_sendmsg) |
| 707 | dumpiov_in_msghdr(tcp, tcp->u_arg[1]); |
| 708 | else if (func == sys_sendmmsg) |
| 709 | dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]); |
| 710 | #endif |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | /* |
| 715 | * Shuffle syscall numbers so that we don't have huge gaps in syscall table. |
| 716 | * The shuffling should be an involution: shuffle_scno(shuffle_scno(n)) == n. |
| 717 | */ |
| 718 | #if defined(ARM) || defined(AARCH64) /* So far only 32-bit ARM needs this */ |
| 719 | static long |
| 720 | shuffle_scno(unsigned long scno) |
| 721 | { |
| 722 | if (scno < ARM_FIRST_SHUFFLED_SYSCALL) |
| 723 | return scno; |
| 724 | |
| 725 | /* __ARM_NR_cmpxchg? Swap with LAST_ORDINARY+1 */ |
| 726 | if (scno == ARM_FIRST_SHUFFLED_SYSCALL) |
| 727 | return 0x000ffff0; |
| 728 | if (scno == 0x000ffff0) |
| 729 | return ARM_FIRST_SHUFFLED_SYSCALL; |
| 730 | |
| 731 | #define ARM_SECOND_SHUFFLED_SYSCALL (ARM_FIRST_SHUFFLED_SYSCALL + 1) |
| 732 | /* |
| 733 | * Is it ARM specific syscall? |
| 734 | * Swap [0x000f0000, 0x000f0000 + LAST_SPECIAL] range |
| 735 | * with [SECOND_SHUFFLED, SECOND_SHUFFLED + LAST_SPECIAL] range. |
| 736 | */ |
| 737 | if (scno >= 0x000f0000 && |
| 738 | scno <= 0x000f0000 + ARM_LAST_SPECIAL_SYSCALL) { |
| 739 | return scno - 0x000f0000 + ARM_SECOND_SHUFFLED_SYSCALL; |
| 740 | } |
| 741 | if (scno <= ARM_SECOND_SHUFFLED_SYSCALL + ARM_LAST_SPECIAL_SYSCALL) { |
| 742 | return scno + 0x000f0000 - ARM_SECOND_SHUFFLED_SYSCALL; |
| 743 | } |
| 744 | |
| 745 | return scno; |
| 746 | } |
| 747 | #else |
| 748 | # define shuffle_scno(scno) ((long)(scno)) |
| 749 | #endif |
| 750 | |
| 751 | static char* |
| 752 | undefined_scno_name(struct tcb *tcp) |
| 753 | { |
| 754 | static char buf[sizeof("syscall_%lu") + sizeof(long)*3]; |
| 755 | |
| 756 | sprintf(buf, "syscall_%lu", shuffle_scno(tcp->scno)); |
| 757 | return buf; |
| 758 | } |
| 759 | |
| 760 | static long get_regs_error; |
| 761 | |
| 762 | void |
| 763 | clear_regs(void) |
| 764 | { |
| 765 | get_regs_error = -1; |
| 766 | } |
| 767 | |
| 768 | static int get_syscall_args(struct tcb *); |
| 769 | static int get_syscall_result(struct tcb *); |
| 770 | |
| 771 | static int |
| 772 | trace_syscall_entering(struct tcb *tcp) |
| 773 | { |
| 774 | int res, scno_good; |
| 775 | |
| 776 | scno_good = res = get_scno(tcp); |
| 777 | if (res == 0) |
| 778 | return res; |
| 779 | if (res == 1) |
| 780 | res = get_syscall_args(tcp); |
| 781 | |
| 782 | if (res != 1) { |
| 783 | printleader(tcp); |
| 784 | if (scno_good != 1) |
| 785 | tprints("????" /* anti-trigraph gap */ "("); |
| 786 | else if (tcp->qual_flg & UNDEFINED_SCNO) |
| 787 | tprintf("%s(", undefined_scno_name(tcp)); |
| 788 | else |
| 789 | tprintf("%s(", tcp->s_ent->sys_name); |
| 790 | /* |
| 791 | * " <unavailable>" will be added later by the code which |
| 792 | * detects ptrace errors. |
| 793 | */ |
| 794 | goto ret; |
| 795 | } |
| 796 | |
Dmitry V. Levin | f34b97f | 2015-04-17 09:14:19 +0000 | [diff] [blame^] | 797 | #ifdef LINUX_MIPSO32 |
| 798 | if (sys_syscall == tcp->s_ent->sys_func) |
| 799 | decode_mips_subcall(tcp); |
| 800 | #endif |
| 801 | |
Dmitry V. Levin | 1b78607 | 2015-03-22 18:09:55 +0000 | [diff] [blame] | 802 | if ( sys_execve == tcp->s_ent->sys_func |
| 803 | # if defined(SPARC) || defined(SPARC64) |
| 804 | || sys_execv == tcp->s_ent->sys_func |
| 805 | # endif |
| 806 | ) { |
| 807 | hide_log_until_execve = 0; |
| 808 | } |
| 809 | |
| 810 | #if defined(SYS_socket_subcall) || defined(SYS_ipc_subcall) |
| 811 | while (1) { |
| 812 | # ifdef SYS_socket_subcall |
| 813 | if (tcp->s_ent->sys_func == sys_socketcall) { |
| 814 | decode_socket_subcall(tcp); |
| 815 | break; |
| 816 | } |
| 817 | # endif |
| 818 | # ifdef SYS_ipc_subcall |
| 819 | if (tcp->s_ent->sys_func == sys_ipc) { |
| 820 | decode_ipc_subcall(tcp); |
| 821 | break; |
| 822 | } |
| 823 | # endif |
| 824 | break; |
| 825 | } |
| 826 | #endif |
| 827 | |
| 828 | if (!(tcp->qual_flg & QUAL_TRACE) |
| 829 | || (tracing_paths && !pathtrace_match(tcp)) |
| 830 | ) { |
| 831 | tcp->flags |= TCB_INSYSCALL | TCB_FILTERED; |
| 832 | return 0; |
| 833 | } |
| 834 | |
| 835 | tcp->flags &= ~TCB_FILTERED; |
| 836 | |
| 837 | if (cflag == CFLAG_ONLY_STATS || hide_log_until_execve) { |
| 838 | res = 0; |
| 839 | goto ret; |
| 840 | } |
| 841 | |
| 842 | #ifdef USE_LIBUNWIND |
| 843 | if (stack_trace_enabled) { |
| 844 | if (tcp->s_ent->sys_flags & STACKTRACE_CAPTURE_ON_ENTER) |
| 845 | unwind_capture_stacktrace(tcp); |
| 846 | } |
| 847 | #endif |
| 848 | |
| 849 | printleader(tcp); |
| 850 | if (tcp->qual_flg & UNDEFINED_SCNO) |
| 851 | tprintf("%s(", undefined_scno_name(tcp)); |
| 852 | else |
| 853 | tprintf("%s(", tcp->s_ent->sys_name); |
| 854 | if ((tcp->qual_flg & QUAL_RAW) && tcp->s_ent->sys_func != sys_exit) |
| 855 | res = printargs(tcp); |
| 856 | else |
| 857 | res = tcp->s_ent->sys_func(tcp); |
| 858 | |
| 859 | fflush(tcp->outf); |
| 860 | ret: |
| 861 | tcp->flags |= TCB_INSYSCALL; |
| 862 | /* Measure the entrance time as late as possible to avoid errors. */ |
| 863 | if (Tflag || cflag) |
| 864 | gettimeofday(&tcp->etime, NULL); |
| 865 | return res; |
| 866 | } |
| 867 | |
| 868 | static int |
| 869 | trace_syscall_exiting(struct tcb *tcp) |
| 870 | { |
| 871 | int sys_res; |
| 872 | struct timeval tv; |
| 873 | int res; |
| 874 | long u_error; |
| 875 | |
| 876 | /* Measure the exit time as early as possible to avoid errors. */ |
| 877 | if (Tflag || cflag) |
| 878 | gettimeofday(&tv, NULL); |
| 879 | |
| 880 | #ifdef USE_LIBUNWIND |
| 881 | if (stack_trace_enabled) { |
| 882 | if (tcp->s_ent->sys_flags & STACKTRACE_INVALIDATE_CACHE) |
| 883 | unwind_cache_invalidate(tcp); |
| 884 | } |
| 885 | #endif |
| 886 | |
| 887 | #if SUPPORTED_PERSONALITIES > 1 |
| 888 | update_personality(tcp, tcp->currpers); |
| 889 | #endif |
| 890 | res = (get_regs_error ? -1 : get_syscall_result(tcp)); |
| 891 | if (res == 1) { |
| 892 | if (filtered(tcp) || hide_log_until_execve) |
| 893 | goto ret; |
| 894 | } |
| 895 | |
| 896 | if (cflag) { |
| 897 | count_syscall(tcp, &tv); |
| 898 | if (cflag == CFLAG_ONLY_STATS) { |
| 899 | goto ret; |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | /* If not in -ff mode, and printing_tcp != tcp, |
| 904 | * then the log currently does not end with output |
| 905 | * of _our syscall entry_, but with something else. |
| 906 | * We need to say which syscall's return is this. |
| 907 | * |
| 908 | * Forced reprinting via TCB_REPRINT is used only by |
| 909 | * "strace -ff -oLOG test/threaded_execve" corner case. |
| 910 | * It's the only case when -ff mode needs reprinting. |
| 911 | */ |
| 912 | if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) { |
| 913 | tcp->flags &= ~TCB_REPRINT; |
| 914 | printleader(tcp); |
| 915 | if (tcp->qual_flg & UNDEFINED_SCNO) |
| 916 | tprintf("<... %s resumed> ", undefined_scno_name(tcp)); |
| 917 | else |
| 918 | tprintf("<... %s resumed> ", tcp->s_ent->sys_name); |
| 919 | } |
| 920 | printing_tcp = tcp; |
| 921 | |
| 922 | tcp->s_prev_ent = NULL; |
| 923 | if (res != 1) { |
| 924 | /* There was error in one of prior ptrace ops */ |
| 925 | tprints(") "); |
| 926 | tabto(); |
| 927 | tprints("= ? <unavailable>\n"); |
| 928 | line_ended(); |
| 929 | tcp->flags &= ~TCB_INSYSCALL; |
| 930 | return res; |
| 931 | } |
| 932 | tcp->s_prev_ent = tcp->s_ent; |
| 933 | |
| 934 | sys_res = 0; |
| 935 | if (tcp->qual_flg & QUAL_RAW) { |
| 936 | /* sys_res = printargs(tcp); - but it's nop on sysexit */ |
| 937 | } else { |
| 938 | /* FIXME: not_failing_only (IOW, option -z) is broken: |
| 939 | * failure of syscall is known only after syscall return. |
| 940 | * Thus we end up with something like this on, say, ENOENT: |
| 941 | * open("doesnt_exist", O_RDONLY <unfinished ...> |
| 942 | * {next syscall decode} |
| 943 | * whereas the intended result is that open(...) line |
| 944 | * is not shown at all. |
| 945 | */ |
| 946 | if (not_failing_only && tcp->u_error) |
| 947 | goto ret; /* ignore failed syscalls */ |
| 948 | sys_res = tcp->s_ent->sys_func(tcp); |
| 949 | } |
| 950 | |
| 951 | tprints(") "); |
| 952 | tabto(); |
| 953 | u_error = tcp->u_error; |
| 954 | if (tcp->qual_flg & QUAL_RAW) { |
| 955 | if (u_error) |
| 956 | tprintf("= -1 (errno %ld)", u_error); |
| 957 | else |
| 958 | tprintf("= %#lx", tcp->u_rval); |
| 959 | } |
| 960 | else if (!(sys_res & RVAL_NONE) && u_error) { |
| 961 | switch (u_error) { |
| 962 | /* Blocked signals do not interrupt any syscalls. |
| 963 | * In this case syscalls don't return ERESTARTfoo codes. |
| 964 | * |
| 965 | * Deadly signals set to SIG_DFL interrupt syscalls |
| 966 | * and kill the process regardless of which of the codes below |
| 967 | * is returned by the interrupted syscall. |
| 968 | * In some cases, kernel forces a kernel-generated deadly |
| 969 | * signal to be unblocked and set to SIG_DFL (and thus cause |
| 970 | * death) if it is blocked or SIG_IGNed: for example, SIGSEGV |
| 971 | * or SIGILL. (The alternative is to leave process spinning |
| 972 | * forever on the faulty instruction - not useful). |
| 973 | * |
| 974 | * SIG_IGNed signals and non-deadly signals set to SIG_DFL |
| 975 | * (for example, SIGCHLD, SIGWINCH) interrupt syscalls, |
| 976 | * but kernel will always restart them. |
| 977 | */ |
| 978 | case ERESTARTSYS: |
| 979 | /* Most common type of signal-interrupted syscall exit code. |
| 980 | * The system call will be restarted with the same arguments |
| 981 | * if SA_RESTART is set; otherwise, it will fail with EINTR. |
| 982 | */ |
| 983 | tprints("= ? ERESTARTSYS (To be restarted if SA_RESTART is set)"); |
| 984 | break; |
| 985 | case ERESTARTNOINTR: |
| 986 | /* Rare. For example, fork() returns this if interrupted. |
| 987 | * SA_RESTART is ignored (assumed set): the restart is unconditional. |
| 988 | */ |
| 989 | tprints("= ? ERESTARTNOINTR (To be restarted)"); |
| 990 | break; |
| 991 | case ERESTARTNOHAND: |
| 992 | /* pause(), rt_sigsuspend() etc use this code. |
| 993 | * SA_RESTART is ignored (assumed not set): |
| 994 | * syscall won't restart (will return EINTR instead) |
| 995 | * even after signal with SA_RESTART set. However, |
| 996 | * after SIG_IGN or SIG_DFL signal it will restart |
| 997 | * (thus the name "restart only if has no handler"). |
| 998 | */ |
| 999 | tprints("= ? ERESTARTNOHAND (To be restarted if no handler)"); |
| 1000 | break; |
| 1001 | case ERESTART_RESTARTBLOCK: |
| 1002 | /* Syscalls like nanosleep(), poll() which can't be |
| 1003 | * restarted with their original arguments use this |
| 1004 | * code. Kernel will execute restart_syscall() instead, |
| 1005 | * which changes arguments before restarting syscall. |
| 1006 | * SA_RESTART is ignored (assumed not set) similarly |
| 1007 | * to ERESTARTNOHAND. (Kernel can't honor SA_RESTART |
| 1008 | * since restart data is saved in "restart block" |
| 1009 | * in task struct, and if signal handler uses a syscall |
| 1010 | * which in turn saves another such restart block, |
| 1011 | * old data is lost and restart becomes impossible) |
| 1012 | */ |
| 1013 | tprints("= ? ERESTART_RESTARTBLOCK (Interrupted by signal)"); |
| 1014 | break; |
| 1015 | default: |
| 1016 | if ((unsigned long) u_error < nerrnos |
| 1017 | && errnoent[u_error]) |
| 1018 | tprintf("= -1 %s (%s)", errnoent[u_error], |
| 1019 | strerror(u_error)); |
| 1020 | else |
| 1021 | tprintf("= -1 ERRNO_%lu (%s)", u_error, |
| 1022 | strerror(u_error)); |
| 1023 | break; |
| 1024 | } |
| 1025 | if ((sys_res & RVAL_STR) && tcp->auxstr) |
| 1026 | tprintf(" (%s)", tcp->auxstr); |
| 1027 | } |
| 1028 | else { |
| 1029 | if (sys_res & RVAL_NONE) |
| 1030 | tprints("= ?"); |
| 1031 | else { |
| 1032 | switch (sys_res & RVAL_MASK) { |
| 1033 | case RVAL_HEX: |
| 1034 | #if SUPPORTED_PERSONALITIES > 1 |
| 1035 | if (current_wordsize < sizeof(long)) |
| 1036 | tprintf("= %#x", |
| 1037 | (unsigned int) tcp->u_rval); |
| 1038 | else |
| 1039 | #endif |
| 1040 | tprintf("= %#lx", tcp->u_rval); |
| 1041 | break; |
| 1042 | case RVAL_OCTAL: |
| 1043 | tprintf("= %#lo", tcp->u_rval); |
| 1044 | break; |
| 1045 | case RVAL_UDECIMAL: |
| 1046 | tprintf("= %lu", tcp->u_rval); |
| 1047 | break; |
| 1048 | case RVAL_DECIMAL: |
| 1049 | tprintf("= %ld", tcp->u_rval); |
| 1050 | break; |
| 1051 | case RVAL_FD: |
| 1052 | if (show_fd_path) { |
| 1053 | tprints("= "); |
| 1054 | printfd(tcp, tcp->u_rval); |
| 1055 | } |
| 1056 | else |
| 1057 | tprintf("= %ld", tcp->u_rval); |
| 1058 | break; |
| 1059 | #if defined(LINUX_MIPSN32) || defined(X32) |
| 1060 | /* |
| 1061 | case RVAL_LHEX: |
| 1062 | tprintf("= %#llx", tcp->u_lrval); |
| 1063 | break; |
| 1064 | case RVAL_LOCTAL: |
| 1065 | tprintf("= %#llo", tcp->u_lrval); |
| 1066 | break; |
| 1067 | */ |
| 1068 | case RVAL_LUDECIMAL: |
| 1069 | tprintf("= %llu", tcp->u_lrval); |
| 1070 | break; |
| 1071 | /* |
| 1072 | case RVAL_LDECIMAL: |
| 1073 | tprintf("= %lld", tcp->u_lrval); |
| 1074 | break; |
| 1075 | */ |
| 1076 | #endif |
| 1077 | default: |
| 1078 | fprintf(stderr, |
| 1079 | "invalid rval format\n"); |
| 1080 | break; |
| 1081 | } |
| 1082 | } |
| 1083 | if ((sys_res & RVAL_STR) && tcp->auxstr) |
| 1084 | tprintf(" (%s)", tcp->auxstr); |
| 1085 | } |
| 1086 | if (Tflag) { |
| 1087 | tv_sub(&tv, &tv, &tcp->etime); |
| 1088 | tprintf(" <%ld.%06ld>", |
| 1089 | (long) tv.tv_sec, (long) tv.tv_usec); |
| 1090 | } |
| 1091 | tprints("\n"); |
| 1092 | dumpio(tcp); |
| 1093 | line_ended(); |
| 1094 | |
| 1095 | #ifdef USE_LIBUNWIND |
| 1096 | if (stack_trace_enabled) |
| 1097 | unwind_print_stacktrace(tcp); |
| 1098 | #endif |
| 1099 | |
| 1100 | ret: |
| 1101 | tcp->flags &= ~TCB_INSYSCALL; |
| 1102 | return 0; |
| 1103 | } |
| 1104 | |
| 1105 | int |
| 1106 | trace_syscall(struct tcb *tcp) |
| 1107 | { |
| 1108 | return exiting(tcp) ? |
| 1109 | trace_syscall_exiting(tcp) : trace_syscall_entering(tcp); |
| 1110 | } |
| 1111 | |
| 1112 | /* |
| 1113 | * Cannot rely on __kernel_[u]long_t being defined, |
| 1114 | * it is quite a recent feature of <asm/posix_types.h>. |
| 1115 | */ |
| 1116 | #ifdef __kernel_long_t |
| 1117 | typedef __kernel_long_t kernel_long_t; |
| 1118 | typedef __kernel_ulong_t kernel_ulong_t; |
| 1119 | #else |
| 1120 | # ifdef X32 |
| 1121 | typedef long long kernel_long_t; |
| 1122 | typedef unsigned long long kernel_ulong_t; |
| 1123 | # else |
| 1124 | typedef long kernel_long_t; |
| 1125 | typedef unsigned long kernel_ulong_t; |
| 1126 | # endif |
| 1127 | #endif |
| 1128 | |
| 1129 | /* |
| 1130 | * Check the syscall return value register value for whether it is |
| 1131 | * a negated errno code indicating an error, or a success return value. |
| 1132 | */ |
| 1133 | static inline bool |
| 1134 | is_negated_errno(kernel_ulong_t val) |
| 1135 | { |
| 1136 | /* Linux kernel defines MAX_ERRNO to 4095. */ |
| 1137 | kernel_ulong_t max = -(kernel_long_t) 4095; |
| 1138 | |
| 1139 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 1140 | if (current_wordsize < sizeof(val)) { |
| 1141 | val = (uint32_t) val; |
| 1142 | max = (uint32_t) max; |
| 1143 | } |
| 1144 | #elif defined X32 |
| 1145 | /* |
| 1146 | * current_wordsize is 4 even in personality 0 (native X32) |
| 1147 | * but truncation _must not_ be done in it. |
| 1148 | * can't check current_wordsize here! |
| 1149 | */ |
| 1150 | if (current_personality != 0) { |
| 1151 | val = (uint32_t) val; |
| 1152 | max = (uint32_t) max; |
| 1153 | } |
| 1154 | #endif |
| 1155 | |
| 1156 | return val >= max; |
| 1157 | } |
| 1158 | |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 1159 | #include "arch_regs.c" |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 1160 | |
Dmitry V. Levin | 78ed3f3 | 2015-03-23 00:04:27 +0000 | [diff] [blame] | 1161 | #ifdef HAVE_GETRVAL2 |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 1162 | # include "arch_getrval2.c" |
Dmitry V. Levin | 48f0890 | 2015-03-05 23:30:02 +0000 | [diff] [blame] | 1163 | #endif |
| 1164 | |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1165 | void |
Denys Vlasenko | 5a2483b | 2013-07-01 12:49:14 +0200 | [diff] [blame] | 1166 | print_pc(struct tcb *tcp) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1167 | { |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 1168 | const char *fmt; |
| 1169 | const char *bad; |
| 1170 | |
Dmitry V. Levin | b2d9ff2 | 2015-02-23 13:43:20 +0000 | [diff] [blame] | 1171 | #ifdef current_wordsize |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 1172 | # define pc_wordsize current_wordsize |
Dmitry V. Levin | b2d9ff2 | 2015-02-23 13:43:20 +0000 | [diff] [blame] | 1173 | #else |
| 1174 | # define pc_wordsize personality_wordsize[tcp->currpers] |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 1175 | #endif |
| 1176 | |
| 1177 | if (pc_wordsize == 4) { |
| 1178 | fmt = "[%08lx] "; |
| 1179 | bad = "[????????] "; |
| 1180 | } else { |
| 1181 | fmt = "[%016lx] "; |
| 1182 | bad = "[????????????????] "; |
| 1183 | } |
| 1184 | |
| 1185 | #undef pc_wordsize |
| 1186 | #define PRINTBADPC tprints(bad) |
| 1187 | |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1188 | if (get_regs_error) { |
| 1189 | PRINTBADPC; |
| 1190 | return; |
| 1191 | } |
Dmitry V. Levin | e96cb62 | 2015-02-15 15:52:02 +0000 | [diff] [blame] | 1192 | |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 1193 | #include "print_pc.c" |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1194 | } |
| 1195 | |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 1196 | #if defined X86_64 || defined POWERPC |
| 1197 | # include "getregs_old.c" |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1198 | #endif |
| 1199 | |
Dmitry V. Levin | d6db1db | 2015-02-13 23:41:04 +0000 | [diff] [blame] | 1200 | #if defined ARCH_REGS_FOR_GETREGSET |
| 1201 | static long |
| 1202 | get_regset(pid_t pid) |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1203 | { |
Dmitry V. Levin | d6db1db | 2015-02-13 23:41:04 +0000 | [diff] [blame] | 1204 | # ifdef ARCH_IOVEC_FOR_GETREGSET |
| 1205 | /* variable iovec */ |
| 1206 | ARCH_IOVEC_FOR_GETREGSET.iov_len = sizeof(ARCH_REGS_FOR_GETREGSET); |
| 1207 | return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, |
| 1208 | &ARCH_IOVEC_FOR_GETREGSET); |
| 1209 | # else |
| 1210 | /* constant iovec */ |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1211 | static struct iovec io = { |
| 1212 | .iov_base = &ARCH_REGS_FOR_GETREGSET, |
| 1213 | .iov_len = sizeof(ARCH_REGS_FOR_GETREGSET) |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1214 | }; |
Dmitry V. Levin | d6db1db | 2015-02-13 23:41:04 +0000 | [diff] [blame] | 1215 | return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &io); |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1216 | |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1217 | # endif |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1218 | } |
Dmitry V. Levin | d6db1db | 2015-02-13 23:41:04 +0000 | [diff] [blame] | 1219 | #endif /* ARCH_REGS_FOR_GETREGSET */ |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1220 | |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1221 | void |
| 1222 | get_regs(pid_t pid) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1223 | { |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 1224 | #ifdef ARCH_REGS_FOR_GETREGSET |
| 1225 | # ifdef X86_64 |
| 1226 | /* Try PTRACE_GETREGSET first, fallback to PTRACE_GETREGS. */ |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1227 | static int getregset_support; |
| 1228 | |
| 1229 | if (getregset_support >= 0) { |
Dmitry V. Levin | d6db1db | 2015-02-13 23:41:04 +0000 | [diff] [blame] | 1230 | get_regs_error = get_regset(pid); |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1231 | if (getregset_support > 0) |
| 1232 | return; |
| 1233 | if (get_regs_error >= 0) { |
| 1234 | getregset_support = 1; |
| 1235 | return; |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1236 | } |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1237 | if (errno == EPERM || errno == ESRCH) |
| 1238 | return; |
| 1239 | getregset_support = -1; |
| 1240 | } |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 1241 | getregs_old(pid); |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 1242 | # else /* !X86_64 */ |
| 1243 | /* Assume that PTRACE_GETREGSET works. */ |
| 1244 | get_regs_error = get_regset(pid); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1245 | # endif |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 1246 | #elif defined ARCH_REGS_FOR_GETREGS |
| 1247 | # if defined SPARC || defined SPARC64 |
| 1248 | /* SPARC systems have the meaning of data and addr reversed */ |
| 1249 | get_regs_error = ptrace(PTRACE_GETREGS, pid, (char *)&ARCH_REGS_FOR_GETREGS, 0); |
| 1250 | # elif defined POWERPC |
| 1251 | static bool old_kernel = 0; |
| 1252 | if (old_kernel) |
| 1253 | goto old; |
| 1254 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS); |
| 1255 | if (get_regs_error && errno == EIO) { |
| 1256 | old_kernel = 1; |
| 1257 | old: |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 1258 | get_regs_error = getregs_old(pid); |
Dmitry V. Levin | 7abf2e8 | 2015-02-13 23:56:54 +0000 | [diff] [blame] | 1259 | } |
| 1260 | # else |
| 1261 | /* Assume that PTRACE_GETREGS works. */ |
| 1262 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS); |
| 1263 | # endif |
| 1264 | |
| 1265 | #else /* !ARCH_REGS_FOR_GETREGSET && !ARCH_REGS_FOR_GETREGS */ |
| 1266 | # warning get_regs is not implemented for this architecture yet |
| 1267 | get_regs_error = 0; |
| 1268 | #endif |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1269 | } |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1270 | |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1271 | /* Returns: |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 1272 | * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently. |
| 1273 | * 1: ok, continue in trace_syscall_entering(). |
| 1274 | * other: error, trace_syscall_entering() should print error indicator |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1275 | * ("????" etc) and bail out. |
| 1276 | */ |
Denys Vlasenko | 8497b62 | 2015-03-21 17:51:52 +0100 | [diff] [blame] | 1277 | int |
Denys Vlasenko | 06602d9 | 2011-08-24 17:53:52 +0200 | [diff] [blame] | 1278 | get_scno(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1279 | { |
Dmitry V. Levin | 144cda2 | 2015-03-23 18:48:32 +0000 | [diff] [blame] | 1280 | if (get_regs_error) |
| 1281 | return -1; |
| 1282 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1283 | long scno = 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1284 | |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 1285 | #include "get_scno.c" |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1286 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1287 | tcp->scno = scno; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1288 | if (SCNO_IS_VALID(tcp->scno)) { |
| 1289 | tcp->s_ent = &sysent[scno]; |
| 1290 | tcp->qual_flg = qual_flags[scno]; |
| 1291 | } else { |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 1292 | static const struct_sysent unknown = { |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1293 | .nargs = MAX_ARGS, |
| 1294 | .sys_flags = 0, |
| 1295 | .sys_func = printargs, |
Denys Vlasenko | cc59f14 | 2015-04-07 12:46:59 +0200 | [diff] [blame] | 1296 | .sys_name = "system call", |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1297 | }; |
| 1298 | tcp->s_ent = &unknown; |
| 1299 | tcp->qual_flg = UNDEFINED_SCNO | QUAL_RAW | DEFAULT_QUAL_FLAGS; |
Dmitry V. Levin | ea00900 | 2015-03-24 01:59:07 +0000 | [diff] [blame] | 1300 | if (debug_flag) |
| 1301 | fprintf(stderr, "pid %d invalid syscall %ld\n", |
| 1302 | tcp->pid, scno); |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1303 | } |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1304 | return 1; |
| 1305 | } |
| 1306 | |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 1307 | /* Return -1 on error or 1 on success (never 0!) */ |
Roland McGrath | a4d4853 | 2005-06-08 20:45:28 +0000 | [diff] [blame] | 1308 | static int |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 1309 | get_syscall_args(struct tcb *tcp) |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1310 | { |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 1311 | #include "get_syscall_args.c" |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1312 | return 1; |
| 1313 | } |
| 1314 | |
Denys Vlasenko | c956ef0 | 2013-02-16 14:25:56 +0100 | [diff] [blame] | 1315 | static void |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1316 | get_error(struct tcb *tcp) |
| 1317 | { |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 1318 | const bool check_errno = !(tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS); |
| 1319 | tcp->u_error = 0; |
Dmitry V. Levin | f46ab5f | 2015-02-05 18:50:24 +0000 | [diff] [blame] | 1320 | |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 1321 | #include "get_error.c" |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1322 | } |
| 1323 | |
Dmitry V. Levin | 1b78607 | 2015-03-22 18:09:55 +0000 | [diff] [blame] | 1324 | /* Returns: |
| 1325 | * 1: ok, continue in trace_syscall_exiting(). |
| 1326 | * -1: error, trace_syscall_exiting() should print error indicator |
| 1327 | * ("????" etc) and bail out. |
| 1328 | */ |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1329 | static int |
Dmitry V. Levin | 1b78607 | 2015-03-22 18:09:55 +0000 | [diff] [blame] | 1330 | get_syscall_result(struct tcb *tcp) |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1331 | { |
Dmitry V. Levin | 1b78607 | 2015-03-22 18:09:55 +0000 | [diff] [blame] | 1332 | #if defined ARCH_REGS_FOR_GETREGSET || defined ARCH_REGS_FOR_GETREGS |
| 1333 | /* already done by get_regs */ |
Dmitry V. Levin | 1b78607 | 2015-03-22 18:09:55 +0000 | [diff] [blame] | 1334 | #else |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 1335 | # include "get_syscall_result.c" |
Masatake YAMATO | ed69fc2 | 2014-04-16 15:33:35 +0900 | [diff] [blame] | 1336 | #endif |
Dmitry V. Levin | 1b78607 | 2015-03-22 18:09:55 +0000 | [diff] [blame] | 1337 | get_error(tcp); |
| 1338 | return 1; |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 1339 | } |