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