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