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