Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 3 | * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> |
| 4 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
| 6 | * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 7 | * Linux for s390 port by D.J. Barrow |
| 8 | * <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
| 18 | * documentation and/or other materials provided with the distribution. |
| 19 | * 3. The name of the author may not be used to endorse or promote products |
| 20 | * derived from this software without specific prior written permission. |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 25 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 32 | */ |
| 33 | |
| 34 | #include "defs.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 35 | #include <sys/user.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 | |
Wichert Akkerman | 15dea97 | 1999-10-06 13:06:34 +0000 | [diff] [blame] | 38 | #ifdef HAVE_SYS_REG_H |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 39 | # include <sys/reg.h> |
| 40 | # ifndef PTRACE_PEEKUSR |
| 41 | # define PTRACE_PEEKUSR PTRACE_PEEKUSER |
| 42 | # endif |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 43 | #elif defined(HAVE_LINUX_PTRACE_H) |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 44 | # undef PTRACE_SYSCALL |
Roland McGrath | ce9f074 | 2004-03-01 21:29:22 +0000 | [diff] [blame] | 45 | # ifdef HAVE_STRUCT_IA64_FPREG |
| 46 | # define ia64_fpreg XXX_ia64_fpreg |
| 47 | # endif |
| 48 | # ifdef HAVE_STRUCT_PT_ALL_USER_REGS |
| 49 | # define pt_all_user_regs XXX_pt_all_user_regs |
| 50 | # endif |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 51 | # include <linux/ptrace.h> |
Roland McGrath | ce9f074 | 2004-03-01 21:29:22 +0000 | [diff] [blame] | 52 | # undef ia64_fpreg |
| 53 | # undef pt_all_user_regs |
Wichert Akkerman | 15dea97 | 1999-10-06 13:06:34 +0000 | [diff] [blame] | 54 | #endif |
| 55 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 56 | #if defined(SPARC64) |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 57 | # undef PTRACE_GETREGS |
| 58 | # define PTRACE_GETREGS PTRACE_GETREGS64 |
| 59 | # undef PTRACE_SETREGS |
| 60 | # define PTRACE_SETREGS PTRACE_SETREGS64 |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 61 | #endif |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 62 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 63 | #if defined(IA64) |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 64 | # include <asm/ptrace_offsets.h> |
| 65 | # include <asm/rse.h> |
| 66 | #endif |
| 67 | |
Dmitry V. Levin | 32c049a | 2013-03-18 00:59:27 +0000 | [diff] [blame] | 68 | /* for struct iovec */ |
| 69 | #include <sys/uio.h> |
| 70 | /* for NT_PRSTATUS */ |
| 71 | #ifdef HAVE_ELF_H |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 72 | # include <elf.h> |
| 73 | #endif |
| 74 | |
Steve McIntyre | d8d3bd3 | 2012-10-24 17:58:16 +0100 | [diff] [blame] | 75 | #if defined(AARCH64) |
| 76 | # include <asm/ptrace.h> |
James Hogan | 5f999a8 | 2013-02-22 14:44:10 +0000 | [diff] [blame] | 77 | #endif |
| 78 | |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 79 | #if defined(XTENSA) |
| 80 | # include <asm/ptrace.h> |
| 81 | #endif |
| 82 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 83 | #ifndef ERESTARTSYS |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 84 | # define ERESTARTSYS 512 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 85 | #endif |
Denys Vlasenko | 3da9693 | 2012-03-17 03:17:15 +0100 | [diff] [blame] | 86 | #ifndef ERESTARTNOINTR |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 87 | # define ERESTARTNOINTR 513 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 88 | #endif |
Denys Vlasenko | 3da9693 | 2012-03-17 03:17:15 +0100 | [diff] [blame] | 89 | #ifndef ERESTARTNOHAND |
| 90 | # define ERESTARTNOHAND 514 /* restart if no handler */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 91 | #endif |
Denys Vlasenko | 3da9693 | 2012-03-17 03:17:15 +0100 | [diff] [blame] | 92 | #ifndef ERESTART_RESTARTBLOCK |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 93 | # define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */ |
Roland McGrath | 9c555e7 | 2003-07-09 09:47:59 +0000 | [diff] [blame] | 94 | #endif |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 95 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 96 | #ifndef NSIG |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 97 | # warning: NSIG is not defined, using 32 |
| 98 | # define NSIG 32 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 99 | #endif |
| 100 | #ifdef ARM |
Denys Vlasenko | 041b3ee | 2011-08-18 12:48:56 +0200 | [diff] [blame] | 101 | /* Ugh. Is this really correct? ARM has no RT signals?! */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 102 | # undef NSIG |
| 103 | # define NSIG 32 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 104 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 105 | |
| 106 | #include "syscall.h" |
| 107 | |
| 108 | /* Define these shorthand notations to simplify the syscallent files. */ |
Roland McGrath | 2fe7b13 | 2005-07-05 03:25:35 +0000 | [diff] [blame] | 109 | #define TD TRACE_DESC |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 110 | #define TF TRACE_FILE |
| 111 | #define TI TRACE_IPC |
| 112 | #define TN TRACE_NETWORK |
| 113 | #define TP TRACE_PROCESS |
| 114 | #define TS TRACE_SIGNAL |
Namhyung Kim | 9679296 | 2012-10-24 11:41:57 +0900 | [diff] [blame] | 115 | #define TM TRACE_MEMORY |
Dmitry V. Levin | 50a218d | 2011-01-18 17:36:20 +0000 | [diff] [blame] | 116 | #define NF SYSCALL_NEVER_FAILS |
Denys Vlasenko | ac1ce77 | 2011-08-23 13:24:17 +0200 | [diff] [blame] | 117 | #define MA MAX_ARGS |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 118 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 119 | const struct_sysent sysent0[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 120 | #include "syscallent.h" |
| 121 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 122 | |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 123 | #if SUPPORTED_PERSONALITIES > 1 |
| 124 | static const struct_sysent sysent1[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 125 | # include "syscallent1.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 126 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 127 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 128 | |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 129 | #if SUPPORTED_PERSONALITIES > 2 |
| 130 | static const struct_sysent sysent2[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 131 | # include "syscallent2.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 132 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 133 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 134 | |
| 135 | /* Now undef them since short defines cause wicked namespace pollution. */ |
Roland McGrath | 2fe7b13 | 2005-07-05 03:25:35 +0000 | [diff] [blame] | 136 | #undef TD |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 137 | #undef TF |
| 138 | #undef TI |
| 139 | #undef TN |
| 140 | #undef TP |
| 141 | #undef TS |
Namhyung Kim | 9679296 | 2012-10-24 11:41:57 +0900 | [diff] [blame] | 142 | #undef TM |
Dmitry V. Levin | 50a218d | 2011-01-18 17:36:20 +0000 | [diff] [blame] | 143 | #undef NF |
Denys Vlasenko | ac1ce77 | 2011-08-23 13:24:17 +0200 | [diff] [blame] | 144 | #undef MA |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 145 | |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 146 | /* |
| 147 | * `ioctlent.h' may be generated from `ioctlent.raw' by the auxiliary |
| 148 | * program `ioctlsort', such that the list is sorted by the `code' field. |
| 149 | * This has the side-effect of resolving the _IO.. macros into |
| 150 | * plain integers, eliminating the need to include here everything |
| 151 | * in "/usr/include". |
| 152 | */ |
| 153 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 154 | const char *const errnoent0[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 155 | #include "errnoent.h" |
| 156 | }; |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 157 | const char *const signalent0[] = { |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 158 | #include "signalent.h" |
| 159 | }; |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 160 | const struct_ioctlent ioctlent0[] = { |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 161 | #include "ioctlent.h" |
| 162 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 163 | |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 164 | #if SUPPORTED_PERSONALITIES > 1 |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 165 | static const char *const errnoent1[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 166 | # include "errnoent1.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 167 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 168 | static const char *const signalent1[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 169 | # include "signalent1.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 170 | }; |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 171 | static const struct_ioctlent ioctlent1[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 172 | # include "ioctlent1.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 173 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 174 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 175 | |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 176 | #if SUPPORTED_PERSONALITIES > 2 |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 177 | static const char *const errnoent2[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 178 | # include "errnoent2.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 179 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 180 | static const char *const signalent2[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 181 | # include "signalent2.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 182 | }; |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 183 | static const struct_ioctlent ioctlent2[] = { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 184 | # include "ioctlent2.h" |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 185 | }; |
Denys Vlasenko | 39fca62 | 2011-08-20 02:12:33 +0200 | [diff] [blame] | 186 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 187 | |
Dmitry V. Levin | e6f5524 | 2013-02-26 22:02:30 +0000 | [diff] [blame] | 188 | enum { |
| 189 | nsyscalls0 = ARRAY_SIZE(sysent0) |
| 190 | #if SUPPORTED_PERSONALITIES > 1 |
| 191 | , nsyscalls1 = ARRAY_SIZE(sysent1) |
| 192 | # if SUPPORTED_PERSONALITIES > 2 |
| 193 | , nsyscalls2 = ARRAY_SIZE(sysent2) |
| 194 | # endif |
| 195 | #endif |
| 196 | }; |
| 197 | |
| 198 | enum { |
| 199 | nerrnos0 = ARRAY_SIZE(errnoent0) |
| 200 | #if SUPPORTED_PERSONALITIES > 1 |
| 201 | , nerrnos1 = ARRAY_SIZE(errnoent1) |
| 202 | # if SUPPORTED_PERSONALITIES > 2 |
| 203 | , nerrnos2 = ARRAY_SIZE(errnoent2) |
| 204 | # endif |
| 205 | #endif |
| 206 | }; |
| 207 | |
| 208 | enum { |
| 209 | nsignals0 = ARRAY_SIZE(signalent0) |
| 210 | #if SUPPORTED_PERSONALITIES > 1 |
| 211 | , nsignals1 = ARRAY_SIZE(signalent1) |
| 212 | # if SUPPORTED_PERSONALITIES > 2 |
| 213 | , nsignals2 = ARRAY_SIZE(signalent2) |
| 214 | # endif |
| 215 | #endif |
| 216 | }; |
| 217 | |
| 218 | enum { |
| 219 | nioctlents0 = ARRAY_SIZE(ioctlent0) |
| 220 | #if SUPPORTED_PERSONALITIES > 1 |
| 221 | , nioctlents1 = ARRAY_SIZE(ioctlent1) |
| 222 | # if SUPPORTED_PERSONALITIES > 2 |
| 223 | , nioctlents2 = ARRAY_SIZE(ioctlent2) |
| 224 | # endif |
| 225 | #endif |
| 226 | }; |
| 227 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 228 | #if SUPPORTED_PERSONALITIES > 1 |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 229 | const struct_sysent *sysent = sysent0; |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 230 | const char *const *errnoent = errnoent0; |
| 231 | const char *const *signalent = signalent0; |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 232 | const struct_ioctlent *ioctlent = ioctlent0; |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 233 | #endif |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 234 | unsigned nsyscalls = nsyscalls0; |
| 235 | unsigned nerrnos = nerrnos0; |
| 236 | unsigned nsignals = nsignals0; |
| 237 | unsigned nioctlents = nioctlents0; |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 238 | |
| 239 | unsigned num_quals; |
| 240 | qualbits_t *qual_vec[SUPPORTED_PERSONALITIES]; |
| 241 | |
| 242 | static const unsigned nsyscall_vec[SUPPORTED_PERSONALITIES] = { |
| 243 | nsyscalls0, |
| 244 | #if SUPPORTED_PERSONALITIES > 1 |
| 245 | nsyscalls1, |
| 246 | #endif |
| 247 | #if SUPPORTED_PERSONALITIES > 2 |
| 248 | nsyscalls2, |
| 249 | #endif |
| 250 | }; |
| 251 | static const struct_sysent *const sysent_vec[SUPPORTED_PERSONALITIES] = { |
| 252 | sysent0, |
| 253 | #if SUPPORTED_PERSONALITIES > 1 |
| 254 | sysent1, |
| 255 | #endif |
| 256 | #if SUPPORTED_PERSONALITIES > 2 |
| 257 | sysent2, |
| 258 | #endif |
| 259 | }; |
| 260 | |
| 261 | enum { |
| 262 | MAX_NSYSCALLS1 = (nsyscalls0 |
| 263 | #if SUPPORTED_PERSONALITIES > 1 |
| 264 | > nsyscalls1 ? nsyscalls0 : nsyscalls1 |
| 265 | #endif |
| 266 | ), |
| 267 | MAX_NSYSCALLS2 = (MAX_NSYSCALLS1 |
| 268 | #if SUPPORTED_PERSONALITIES > 2 |
| 269 | > nsyscalls2 ? MAX_NSYSCALLS1 : nsyscalls2 |
| 270 | #endif |
| 271 | ), |
| 272 | MAX_NSYSCALLS = MAX_NSYSCALLS2, |
| 273 | /* We are ready for arches with up to 255 signals, |
| 274 | * even though the largest known signo is on MIPS and it is 128. |
| 275 | * The number of existing syscalls on all arches is |
| 276 | * larger that 255 anyway, so it is just a pedantic matter. |
| 277 | */ |
| 278 | MIN_QUALS = MAX_NSYSCALLS > 255 ? MAX_NSYSCALLS : 255 |
| 279 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 280 | |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 281 | #if SUPPORTED_PERSONALITIES > 1 |
Denys Vlasenko | ae8643e | 2013-02-15 14:55:14 +0100 | [diff] [blame] | 282 | unsigned current_personality; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 283 | |
Denys Vlasenko | ae8643e | 2013-02-15 14:55:14 +0100 | [diff] [blame] | 284 | # ifndef current_wordsize |
| 285 | unsigned current_wordsize; |
| 286 | static const int personality_wordsize[SUPPORTED_PERSONALITIES] = { |
Roland McGrath | 4b2dcca | 2006-01-12 10:18:53 +0000 | [diff] [blame] | 287 | PERSONALITY0_WORDSIZE, |
Roland McGrath | 4b2dcca | 2006-01-12 10:18:53 +0000 | [diff] [blame] | 288 | PERSONALITY1_WORDSIZE, |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 289 | # if SUPPORTED_PERSONALITIES > 2 |
Roland McGrath | 4b2dcca | 2006-01-12 10:18:53 +0000 | [diff] [blame] | 290 | PERSONALITY2_WORDSIZE, |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 291 | # endif |
Denys Vlasenko | 5c774b2 | 2011-08-20 01:50:09 +0200 | [diff] [blame] | 292 | }; |
Denys Vlasenko | ae8643e | 2013-02-15 14:55:14 +0100 | [diff] [blame] | 293 | # endif |
Roland McGrath | 4b2dcca | 2006-01-12 10:18:53 +0000 | [diff] [blame] | 294 | |
Denys Vlasenko | 5c774b2 | 2011-08-20 01:50:09 +0200 | [diff] [blame] | 295 | void |
Dmitry V. Levin | 3abe8b2 | 2006-12-20 22:37:21 +0000 | [diff] [blame] | 296 | set_personality(int personality) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 297 | { |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 298 | nsyscalls = nsyscall_vec[personality]; |
| 299 | sysent = sysent_vec[personality]; |
| 300 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 301 | switch (personality) { |
| 302 | case 0: |
| 303 | errnoent = errnoent0; |
| 304 | nerrnos = nerrnos0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 305 | ioctlent = ioctlent0; |
| 306 | nioctlents = nioctlents0; |
| 307 | signalent = signalent0; |
| 308 | nsignals = nsignals0; |
| 309 | break; |
| 310 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 311 | case 1: |
| 312 | errnoent = errnoent1; |
| 313 | nerrnos = nerrnos1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 314 | ioctlent = ioctlent1; |
| 315 | nioctlents = nioctlents1; |
| 316 | signalent = signalent1; |
| 317 | nsignals = nsignals1; |
| 318 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 319 | |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 320 | # if SUPPORTED_PERSONALITIES > 2 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 321 | case 2: |
| 322 | errnoent = errnoent2; |
| 323 | nerrnos = nerrnos2; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 324 | ioctlent = ioctlent2; |
| 325 | nioctlents = nioctlents2; |
| 326 | signalent = signalent2; |
| 327 | nsignals = nsignals2; |
| 328 | break; |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 329 | # endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | current_personality = personality; |
Denys Vlasenko | ae8643e | 2013-02-15 14:55:14 +0100 | [diff] [blame] | 333 | # ifndef current_wordsize |
| 334 | current_wordsize = personality_wordsize[personality]; |
| 335 | # endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 338 | static void |
| 339 | update_personality(struct tcb *tcp, int personality) |
| 340 | { |
| 341 | if (personality == current_personality) |
| 342 | return; |
| 343 | set_personality(personality); |
| 344 | |
| 345 | if (personality == tcp->currpers) |
| 346 | return; |
| 347 | tcp->currpers = personality; |
| 348 | |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 349 | # if defined(POWERPC64) |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 350 | if (!qflag) { |
| 351 | static const char *const names[] = {"64 bit", "32 bit"}; |
| 352 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 353 | tcp->pid, names[personality]); |
| 354 | } |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 355 | # elif defined(X86_64) |
| 356 | if (!qflag) { |
| 357 | static const char *const names[] = {"64 bit", "32 bit", "x32"}; |
| 358 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 359 | tcp->pid, names[personality]); |
| 360 | } |
H.J. Lu | 085e428 | 2012-04-17 11:05:04 -0700 | [diff] [blame] | 361 | # elif defined(X32) |
| 362 | if (!qflag) { |
| 363 | static const char *const names[] = {"x32", "32 bit"}; |
| 364 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 365 | tcp->pid, names[personality]); |
| 366 | } |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 367 | # elif defined(AARCH64) |
| 368 | if (!qflag) { |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 369 | static const char *const names[] = {"32-bit", "AArch64"}; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 370 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 371 | tcp->pid, names[personality]); |
| 372 | } |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 373 | # elif defined(TILE) |
| 374 | if (!qflag) { |
| 375 | static const char *const names[] = {"64-bit", "32-bit"}; |
| 376 | fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n", |
| 377 | tcp->pid, names[personality]); |
| 378 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 379 | # endif |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 380 | } |
| 381 | #endif |
Roland McGrath | e10e62a | 2004-09-04 04:20:43 +0000 | [diff] [blame] | 382 | |
Denys Vlasenko | c1540fe | 2013-02-21 16:17:08 +0100 | [diff] [blame] | 383 | static int qual_syscall(), qual_signal(), qual_desc(); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 384 | |
Roland McGrath | e10e62a | 2004-09-04 04:20:43 +0000 | [diff] [blame] | 385 | static const struct qual_options { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 386 | int bitflag; |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 387 | const char *option_name; |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 388 | int (*qualify)(const char *, int, int); |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 389 | const char *argument_name; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 390 | } qual_options[] = { |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 391 | { QUAL_TRACE, "trace", qual_syscall, "system call" }, |
| 392 | { QUAL_TRACE, "t", qual_syscall, "system call" }, |
| 393 | { QUAL_ABBREV, "abbrev", qual_syscall, "system call" }, |
| 394 | { QUAL_ABBREV, "a", qual_syscall, "system call" }, |
| 395 | { QUAL_VERBOSE, "verbose", qual_syscall, "system call" }, |
| 396 | { QUAL_VERBOSE, "v", qual_syscall, "system call" }, |
| 397 | { QUAL_RAW, "raw", qual_syscall, "system call" }, |
| 398 | { QUAL_RAW, "x", qual_syscall, "system call" }, |
| 399 | { QUAL_SIGNAL, "signal", qual_signal, "signal" }, |
| 400 | { QUAL_SIGNAL, "signals", qual_signal, "signal" }, |
| 401 | { QUAL_SIGNAL, "s", qual_signal, "signal" }, |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 402 | { QUAL_READ, "read", qual_desc, "descriptor" }, |
| 403 | { QUAL_READ, "reads", qual_desc, "descriptor" }, |
| 404 | { QUAL_READ, "r", qual_desc, "descriptor" }, |
| 405 | { QUAL_WRITE, "write", qual_desc, "descriptor" }, |
| 406 | { QUAL_WRITE, "writes", qual_desc, "descriptor" }, |
| 407 | { QUAL_WRITE, "w", qual_desc, "descriptor" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 408 | { 0, NULL, NULL, NULL }, |
| 409 | }; |
| 410 | |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 411 | static void |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 412 | reallocate_qual(int n) |
| 413 | { |
| 414 | unsigned p; |
| 415 | qualbits_t *qp; |
| 416 | for (p = 0; p < SUPPORTED_PERSONALITIES; p++) { |
| 417 | qp = qual_vec[p] = realloc(qual_vec[p], n * sizeof(qualbits_t)); |
| 418 | if (!qp) |
| 419 | die_out_of_memory(); |
| 420 | memset(&qp[num_quals], 0, (n - num_quals) * sizeof(qualbits_t)); |
| 421 | } |
| 422 | num_quals = n; |
| 423 | } |
| 424 | |
| 425 | static void |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 426 | qualify_one(int n, int bitflag, int not, int pers) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 427 | { |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 428 | unsigned p; |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 429 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 430 | if (num_quals <= n) |
| 431 | reallocate_qual(n + 1); |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 432 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 433 | for (p = 0; p < SUPPORTED_PERSONALITIES; p++) { |
| 434 | if (pers == p || pers < 0) { |
| 435 | if (not) |
| 436 | qual_vec[p][n] &= ~bitflag; |
| 437 | else |
| 438 | qual_vec[p][n] |= bitflag; |
| 439 | } |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 440 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | static int |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 444 | qual_syscall(const char *s, int bitflag, int not) |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 445 | { |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 446 | unsigned p; |
| 447 | unsigned i; |
Roland McGrath | fe6b352 | 2005-02-02 04:40:11 +0000 | [diff] [blame] | 448 | int rc = -1; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 449 | |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 450 | if (*s >= '0' && *s <= '9') { |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 451 | i = string_to_uint(s); |
Denys Vlasenko | b43dacd | 2013-02-23 18:19:28 +0100 | [diff] [blame] | 452 | if (i >= MAX_NSYSCALLS) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 453 | return -1; |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 454 | qualify_one(i, bitflag, not, -1); |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 455 | return 0; |
Roland McGrath | 48a035f | 2006-01-12 09:45:56 +0000 | [diff] [blame] | 456 | } |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 457 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 458 | for (p = 0; p < SUPPORTED_PERSONALITIES; p++) { |
| 459 | for (i = 0; i < nsyscall_vec[p]; i++) { |
| 460 | if (sysent_vec[p][i].sys_name |
| 461 | && strcmp(s, sysent_vec[p][i].sys_name) == 0 |
| 462 | ) { |
Dmitry V. Levin | 7b9e45e | 2013-03-01 15:50:22 +0000 | [diff] [blame] | 463 | qualify_one(i, bitflag, not, p); |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 464 | rc = 0; |
| 465 | } |
Roland McGrath | 138c6a3 | 2006-01-12 09:50:49 +0000 | [diff] [blame] | 466 | } |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 467 | } |
Dmitry V. Levin | c18c703 | 2007-08-22 21:43:30 +0000 | [diff] [blame] | 468 | |
Roland McGrath | fe6b352 | 2005-02-02 04:40:11 +0000 | [diff] [blame] | 469 | return rc; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | static int |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 473 | qual_signal(const char *s, int bitflag, int not) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 474 | { |
| 475 | int i; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +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 signo = string_to_uint(s); |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 479 | if (signo < 0 || signo > 255) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 480 | return -1; |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 481 | qualify_one(signo, bitflag, not, -1); |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 482 | return 0; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 483 | } |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 484 | if (strncasecmp(s, "SIG", 3) == 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 485 | s += 3; |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 486 | for (i = 0; i <= NSIG; i++) { |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 487 | if (strcasecmp(s, signame(i) + 3) == 0) { |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 488 | qualify_one(i, bitflag, not, -1); |
Roland McGrath | 76421df | 2005-02-02 03:51:18 +0000 | [diff] [blame] | 489 | return 0; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 490 | } |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 491 | } |
Roland McGrath | 76421df | 2005-02-02 03:51:18 +0000 | [diff] [blame] | 492 | return -1; |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | static int |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 496 | qual_desc(const char *s, int bitflag, int not) |
Roland McGrath | 9797ceb | 2002-12-30 10:23:00 +0000 | [diff] [blame] | 497 | { |
Denys Vlasenko | e4cc7c5 | 2012-03-23 11:29:01 +0100 | [diff] [blame] | 498 | if (*s >= '0' && *s <= '9') { |
Dmitry V. Levin | ccee169 | 2012-03-25 21:49:48 +0000 | [diff] [blame] | 499 | int desc = string_to_uint(s); |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 500 | if (desc < 0 || desc > 0x7fff) /* paranoia */ |
Roland McGrath | fe6b352 | 2005-02-02 04:40:11 +0000 | [diff] [blame] | 501 | return -1; |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 502 | qualify_one(desc, bitflag, not, -1); |
Roland McGrath | 2b61902 | 2003-04-10 18:58:20 +0000 | [diff] [blame] | 503 | return 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 504 | } |
| 505 | return -1; |
| 506 | } |
| 507 | |
| 508 | static int |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 509 | lookup_class(const char *s) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 510 | { |
| 511 | if (strcmp(s, "file") == 0) |
| 512 | return TRACE_FILE; |
| 513 | if (strcmp(s, "ipc") == 0) |
| 514 | return TRACE_IPC; |
| 515 | if (strcmp(s, "network") == 0) |
| 516 | return TRACE_NETWORK; |
| 517 | if (strcmp(s, "process") == 0) |
| 518 | return TRACE_PROCESS; |
| 519 | if (strcmp(s, "signal") == 0) |
| 520 | return TRACE_SIGNAL; |
Roland McGrath | 2fe7b13 | 2005-07-05 03:25:35 +0000 | [diff] [blame] | 521 | if (strcmp(s, "desc") == 0) |
| 522 | return TRACE_DESC; |
Namhyung Kim | 9679296 | 2012-10-24 11:41:57 +0900 | [diff] [blame] | 523 | if (strcmp(s, "memory") == 0) |
| 524 | return TRACE_MEMORY; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 525 | return -1; |
| 526 | } |
| 527 | |
| 528 | void |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 529 | qualify(const char *s) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 530 | { |
Roland McGrath | e10e62a | 2004-09-04 04:20:43 +0000 | [diff] [blame] | 531 | const struct qual_options *opt; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 532 | int not; |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 533 | char *copy; |
| 534 | const char *p; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 535 | int i, n; |
| 536 | |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 537 | if (num_quals == 0) |
| 538 | reallocate_qual(MIN_QUALS); |
| 539 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 540 | opt = &qual_options[0]; |
| 541 | for (i = 0; (p = qual_options[i].option_name); i++) { |
| 542 | n = strlen(p); |
| 543 | if (strncmp(s, p, n) == 0 && s[n] == '=') { |
| 544 | opt = &qual_options[i]; |
| 545 | s += n + 1; |
| 546 | break; |
| 547 | } |
| 548 | } |
| 549 | not = 0; |
| 550 | if (*s == '!') { |
| 551 | not = 1; |
| 552 | s++; |
| 553 | } |
| 554 | if (strcmp(s, "none") == 0) { |
| 555 | not = 1 - not; |
| 556 | s = "all"; |
| 557 | } |
| 558 | if (strcmp(s, "all") == 0) { |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 559 | for (i = 0; i < num_quals; i++) { |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 560 | qualify_one(i, opt->bitflag, not, -1); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 561 | } |
| 562 | return; |
| 563 | } |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 564 | for (i = 0; i < num_quals; i++) { |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 565 | qualify_one(i, opt->bitflag, !not, -1); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 566 | } |
Denys Vlasenko | 5d64581 | 2011-08-20 12:48:18 +0200 | [diff] [blame] | 567 | copy = strdup(s); |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 568 | if (!copy) |
| 569 | die_out_of_memory(); |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 570 | for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 571 | if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) { |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 572 | unsigned pers; |
| 573 | for (pers = 0; pers < SUPPORTED_PERSONALITIES; pers++) { |
| 574 | for (i = 0; i < nsyscall_vec[pers]; i++) |
| 575 | if (sysent_vec[pers][i].sys_flags & n) |
Dmitry V. Levin | 7b9e45e | 2013-03-01 15:50:22 +0000 | [diff] [blame] | 576 | qualify_one(i, opt->bitflag, not, pers); |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 577 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 578 | continue; |
| 579 | } |
Dmitry V. Levin | 35d0572 | 2010-09-15 16:18:20 +0000 | [diff] [blame] | 580 | if (opt->qualify(p, opt->bitflag, not)) { |
Denys Vlasenko | 4c65c44 | 2012-03-08 11:54:10 +0100 | [diff] [blame] | 581 | error_msg_and_die("invalid %s '%s'", |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 582 | opt->argument_name, p); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 583 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 584 | } |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 585 | free(copy); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 586 | return; |
| 587 | } |
| 588 | |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 589 | #ifdef SYS_socket_subcall |
Roland McGrath | a4d4853 | 2005-06-08 20:45:28 +0000 | [diff] [blame] | 590 | static void |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 591 | decode_socket_subcall(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 592 | { |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 593 | unsigned long addr; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 594 | unsigned int i, n, size; |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 595 | |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 596 | if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_socket_nsubcalls) |
| 597 | return; |
| 598 | |
| 599 | tcp->scno = SYS_socket_subcall + tcp->u_arg[0]; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 600 | tcp->qual_flg = qual_flags[tcp->scno]; |
| 601 | tcp->s_ent = &sysent[tcp->scno]; |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 602 | addr = tcp->u_arg[1]; |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 603 | size = current_wordsize; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 604 | n = tcp->s_ent->nargs; |
| 605 | for (i = 0; i < n; ++i) { |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 606 | if (size == sizeof(int)) { |
| 607 | unsigned int arg; |
| 608 | if (umove(tcp, addr, &arg) < 0) |
| 609 | arg = 0; |
| 610 | tcp->u_arg[i] = arg; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 611 | } |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 612 | else { |
| 613 | unsigned long arg; |
| 614 | if (umove(tcp, addr, &arg) < 0) |
| 615 | arg = 0; |
| 616 | tcp->u_arg[i] = arg; |
| 617 | } |
| 618 | addr += size; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 619 | } |
| 620 | } |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 621 | #endif |
Mike Frysinger | 3362e89 | 2012-03-15 01:09:19 -0400 | [diff] [blame] | 622 | |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 623 | #ifdef SYS_ipc_subcall |
| 624 | static void |
| 625 | decode_ipc_subcall(struct tcb *tcp) |
| 626 | { |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 627 | unsigned int i, n; |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 628 | |
| 629 | if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_ipc_nsubcalls) |
| 630 | return; |
| 631 | |
| 632 | tcp->scno = SYS_ipc_subcall + tcp->u_arg[0]; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 633 | tcp->qual_flg = qual_flags[tcp->scno]; |
| 634 | tcp->s_ent = &sysent[tcp->scno]; |
| 635 | n = tcp->s_ent->nargs; |
| 636 | for (i = 0; i < n; i++) |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 637 | tcp->u_arg[i] = tcp->u_arg[i + 1]; |
| 638 | } |
| 639 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 640 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 641 | int |
| 642 | printargs(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 643 | { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 644 | if (entering(tcp)) { |
| 645 | int i; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 646 | int n = tcp->s_ent->nargs; |
| 647 | for (i = 0; i < n; i++) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 648 | tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]); |
| 649 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 650 | return 0; |
| 651 | } |
| 652 | |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 653 | int |
| 654 | printargs_lu(struct tcb *tcp) |
| 655 | { |
| 656 | if (entering(tcp)) { |
| 657 | int i; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 658 | int n = tcp->s_ent->nargs; |
| 659 | for (i = 0; i < n; i++) |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 660 | tprintf("%s%lu", i ? ", " : "", tcp->u_arg[i]); |
| 661 | } |
| 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | int |
| 666 | printargs_ld(struct tcb *tcp) |
| 667 | { |
| 668 | if (entering(tcp)) { |
| 669 | int i; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 670 | int n = tcp->s_ent->nargs; |
| 671 | for (i = 0; i < n; i++) |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 672 | tprintf("%s%ld", i ? ", " : "", tcp->u_arg[i]); |
| 673 | } |
| 674 | return 0; |
| 675 | } |
| 676 | |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame] | 677 | #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 678 | long |
| 679 | getrval2(struct tcb *tcp) |
| 680 | { |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame] | 681 | long val; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 682 | |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame] | 683 | # if defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 684 | val = sparc_regs.u_regs[U_REG_O1]; |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame] | 685 | # elif defined(SH) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 686 | if (upeek(tcp->pid, 4*(REG_REG0+1), &val) < 0) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 687 | return -1; |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame] | 688 | # elif defined(IA64) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 689 | if (upeek(tcp->pid, PT_R9, &val) < 0) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 690 | return -1; |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame] | 691 | # endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 692 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 693 | return val; |
| 694 | } |
Denys Vlasenko | 1ebe08d | 2013-02-05 16:55:23 +0100 | [diff] [blame] | 695 | #endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 696 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 697 | int |
| 698 | is_restart_error(struct tcb *tcp) |
| 699 | { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 700 | switch (tcp->u_error) { |
| 701 | case ERESTARTSYS: |
| 702 | case ERESTARTNOINTR: |
| 703 | case ERESTARTNOHAND: |
| 704 | case ERESTART_RESTARTBLOCK: |
| 705 | return 1; |
| 706 | default: |
| 707 | break; |
| 708 | } |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 709 | return 0; |
| 710 | } |
| 711 | |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 712 | #if defined(I386) |
Denys Vlasenko | 2550d48 | 2013-02-15 21:04:28 +0100 | [diff] [blame] | 713 | struct user_regs_struct i386_regs; |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 714 | # define ARCH_REGS_FOR_GETREGSET i386_regs |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 715 | #elif defined(X86_64) || defined(X32) |
Denys Vlasenko | e73a89d | 2012-01-18 11:07:24 +0100 | [diff] [blame] | 716 | /* |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 717 | * On i386, pt_regs and user_regs_struct are the same, |
| 718 | * but on 64 bit x86, user_regs_struct has six more fields: |
Denys Vlasenko | e73a89d | 2012-01-18 11:07:24 +0100 | [diff] [blame] | 719 | * fs_base, gs_base, ds, es, fs, gs. |
| 720 | * PTRACE_GETREGS fills them too, so struct pt_regs would overflow. |
| 721 | */ |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 722 | struct i386_user_regs_struct { |
| 723 | uint32_t ebx; |
| 724 | uint32_t ecx; |
| 725 | uint32_t edx; |
| 726 | uint32_t esi; |
| 727 | uint32_t edi; |
| 728 | uint32_t ebp; |
| 729 | uint32_t eax; |
| 730 | uint32_t xds; |
| 731 | uint32_t xes; |
| 732 | uint32_t xfs; |
| 733 | uint32_t xgs; |
| 734 | uint32_t orig_eax; |
| 735 | uint32_t eip; |
| 736 | uint32_t xcs; |
| 737 | uint32_t eflags; |
| 738 | uint32_t esp; |
| 739 | uint32_t xss; |
| 740 | }; |
| 741 | static union { |
| 742 | struct user_regs_struct x86_64_r; |
| 743 | struct i386_user_regs_struct i386_r; |
| 744 | } x86_regs_union; |
| 745 | # define x86_64_regs x86_regs_union.x86_64_r |
| 746 | # define i386_regs x86_regs_union.i386_r |
| 747 | static struct iovec x86_io = { |
| 748 | .iov_base = &x86_regs_union |
| 749 | }; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 750 | #elif defined(IA64) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 751 | long ia32 = 0; /* not static */ |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 752 | static long ia64_r8, ia64_r10; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 753 | #elif defined(POWERPC) |
Anton Blanchard | ce6e33b | 2013-06-26 15:53:33 +0200 | [diff] [blame] | 754 | struct pt_regs ppc_regs; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 755 | #elif defined(M68K) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 756 | static long m68k_d0; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 757 | #elif defined(BFIN) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 758 | static long bfin_r0; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 759 | #elif defined(ARM) |
Denys Vlasenko | 401374e | 2013-02-06 18:24:39 +0100 | [diff] [blame] | 760 | struct pt_regs arm_regs; /* not static */ |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 761 | # define ARCH_REGS_FOR_GETREGSET arm_regs |
Steve McIntyre | d8d3bd3 | 2012-10-24 17:58:16 +0100 | [diff] [blame] | 762 | #elif defined(AARCH64) |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 763 | static union { |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 764 | struct user_pt_regs aarch64_r; |
| 765 | struct arm_pt_regs arm_r; |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 766 | } arm_regs_union; |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 767 | # define aarch64_regs arm_regs_union.aarch64_r |
| 768 | # define arm_regs arm_regs_union.arm_r |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 769 | static struct iovec aarch64_io = { |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 770 | .iov_base = &arm_regs_union |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 771 | }; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 772 | #elif defined(ALPHA) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 773 | static long alpha_r0; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 774 | static long alpha_a3; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 775 | #elif defined(AVR32) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 776 | static struct pt_regs avr32_regs; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 777 | #elif defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 778 | struct pt_regs sparc_regs; /* not static */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 779 | #elif defined(LINUX_MIPSN32) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 780 | static long long mips_a3; |
| 781 | static long long mips_r2; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 782 | #elif defined(MIPS) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 783 | static long mips_a3; |
| 784 | static long mips_r2; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 785 | #elif defined(S390) || defined(S390X) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 786 | static long gpr2; |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 787 | static long syscall_mode; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 788 | #elif defined(HPPA) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 789 | static long hppa_r28; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 790 | #elif defined(SH) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 791 | static long sh_r0; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 792 | #elif defined(SH64) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 793 | static long sh64_r9; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 794 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 795 | static long cris_r10; |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 796 | #elif defined(TILE) |
| 797 | struct pt_regs tile_regs; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 798 | #elif defined(MICROBLAZE) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 799 | static long microblaze_r3; |
Christian Svensson | 492f81f | 2013-02-14 13:26:27 +0100 | [diff] [blame] | 800 | #elif defined(OR1K) |
| 801 | static struct user_regs_struct or1k_regs; |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 802 | # define ARCH_REGS_FOR_GETREGSET or1k_regs |
James Hogan | 5f999a8 | 2013-02-22 14:44:10 +0000 | [diff] [blame] | 803 | #elif defined(METAG) |
| 804 | static struct user_gp_regs metag_regs; |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 805 | # define ARCH_REGS_FOR_GETREGSET metag_regs |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 806 | #elif defined(XTENSA) |
| 807 | static long xtensa_a2; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 808 | #endif |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 809 | |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 810 | void |
| 811 | printcall(struct tcb *tcp) |
| 812 | { |
| 813 | #define PRINTBADPC tprintf(sizeof(long) == 4 ? "[????????] " : \ |
| 814 | sizeof(long) == 8 ? "[????????????????] " : \ |
| 815 | NULL /* crash */) |
| 816 | if (get_regs_error) { |
| 817 | PRINTBADPC; |
| 818 | return; |
| 819 | } |
| 820 | #if defined(I386) |
| 821 | tprintf("[%08lx] ", i386_regs.eip); |
| 822 | #elif defined(S390) || defined(S390X) |
| 823 | long psw; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 824 | if (upeek(tcp->pid, PT_PSWADDR, &psw) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 825 | PRINTBADPC; |
| 826 | return; |
| 827 | } |
| 828 | # ifdef S390 |
| 829 | tprintf("[%08lx] ", psw); |
| 830 | # elif S390X |
Dmitry V. Levin | ddba73e | 2013-02-05 19:01:58 +0000 | [diff] [blame] | 831 | tprintf("[%016lx] ", psw); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 832 | # endif |
| 833 | #elif defined(X86_64) || defined(X32) |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 834 | if (x86_io.iov_len == sizeof(i386_regs)) { |
| 835 | tprintf("[%08x] ", (unsigned) i386_regs.eip); |
| 836 | } else { |
| 837 | # if defined(X86_64) |
| 838 | tprintf("[%016lx] ", (unsigned long) x86_64_regs.rip); |
| 839 | # elif defined(X32) |
| 840 | /* Note: this truncates 64-bit rip to 32 bits */ |
| 841 | tprintf("[%08lx] ", (unsigned long) x86_64_regs.rip); |
| 842 | # endif |
| 843 | } |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 844 | #elif defined(IA64) |
| 845 | long ip; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 846 | if (upeek(tcp->pid, PT_B0, &ip) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 847 | PRINTBADPC; |
| 848 | return; |
| 849 | } |
| 850 | tprintf("[%08lx] ", ip); |
| 851 | #elif defined(POWERPC) |
Anton Blanchard | ce6e33b | 2013-06-26 15:53:33 +0200 | [diff] [blame] | 852 | long pc = ppc_regs.nip; |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 853 | # ifdef POWERPC64 |
| 854 | tprintf("[%016lx] ", pc); |
| 855 | # else |
| 856 | tprintf("[%08lx] ", pc); |
| 857 | # endif |
| 858 | #elif defined(M68K) |
| 859 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 860 | if (upeek(tcp->pid, 4*PT_PC, &pc) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 861 | tprints("[????????] "); |
| 862 | return; |
| 863 | } |
| 864 | tprintf("[%08lx] ", pc); |
| 865 | #elif defined(ALPHA) |
| 866 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 867 | if (upeek(tcp->pid, REG_PC, &pc) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 868 | tprints("[????????????????] "); |
| 869 | return; |
| 870 | } |
| 871 | tprintf("[%08lx] ", pc); |
| 872 | #elif defined(SPARC) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 873 | tprintf("[%08lx] ", sparc_regs.pc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 874 | #elif defined(SPARC64) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 875 | tprintf("[%08lx] ", sparc_regs.tpc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 876 | #elif defined(HPPA) |
| 877 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 878 | if (upeek(tcp->pid, PT_IAOQ0, &pc) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 879 | tprints("[????????] "); |
| 880 | return; |
| 881 | } |
| 882 | tprintf("[%08lx] ", pc); |
| 883 | #elif defined(MIPS) |
| 884 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 885 | if (upeek(tcp->pid, REG_EPC, &pc) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 886 | tprints("[????????] "); |
| 887 | return; |
| 888 | } |
| 889 | tprintf("[%08lx] ", pc); |
| 890 | #elif defined(SH) |
| 891 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 892 | if (upeek(tcp->pid, 4*REG_PC, &pc) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 893 | tprints("[????????] "); |
| 894 | return; |
| 895 | } |
| 896 | tprintf("[%08lx] ", pc); |
| 897 | #elif defined(SH64) |
| 898 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 899 | if (upeek(tcp->pid, REG_PC, &pc) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 900 | tprints("[????????????????] "); |
| 901 | return; |
| 902 | } |
| 903 | tprintf("[%08lx] ", pc); |
| 904 | #elif defined(ARM) |
Denys Vlasenko | 401374e | 2013-02-06 18:24:39 +0100 | [diff] [blame] | 905 | tprintf("[%08lx] ", arm_regs.ARM_pc); |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 906 | #elif defined(AARCH64) |
| 907 | /* tprintf("[%016lx] ", aarch64_regs.regs[???]); */ |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 908 | #elif defined(AVR32) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 909 | tprintf("[%08lx] ", avr32_regs.pc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 910 | #elif defined(BFIN) |
| 911 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 912 | if (upeek(tcp->pid, PT_PC, &pc) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 913 | PRINTBADPC; |
| 914 | return; |
| 915 | } |
| 916 | tprintf("[%08lx] ", pc); |
| 917 | #elif defined(CRISV10) |
| 918 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 919 | if (upeek(tcp->pid, 4*PT_IRP, &pc) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 920 | PRINTBADPC; |
| 921 | return; |
| 922 | } |
| 923 | tprintf("[%08lx] ", pc); |
| 924 | #elif defined(CRISV32) |
| 925 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 926 | if (upeek(tcp->pid, 4*PT_ERP, &pc) < 0) { |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 927 | PRINTBADPC; |
| 928 | return; |
| 929 | } |
| 930 | tprintf("[%08lx] ", pc); |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 931 | #elif defined(TILE) |
| 932 | # ifdef _LP64 |
Chris Metcalf | af8dc6b | 2013-02-05 13:02:42 -0500 | [diff] [blame] | 933 | tprintf("[%016lx] ", (unsigned long) tile_regs.pc); |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 934 | # else |
Chris Metcalf | af8dc6b | 2013-02-05 13:02:42 -0500 | [diff] [blame] | 935 | tprintf("[%08lx] ", (unsigned long) tile_regs.pc); |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 936 | # endif |
Christian Svensson | 492f81f | 2013-02-14 13:26:27 +0100 | [diff] [blame] | 937 | #elif defined(OR1K) |
| 938 | tprintf("[%08lx] ", or1k_regs.pc); |
James Hogan | 5f999a8 | 2013-02-22 14:44:10 +0000 | [diff] [blame] | 939 | #elif defined(METAG) |
| 940 | tprintf("[%08lx] ", metag_regs.pc); |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 941 | #elif defined(XTENSA) |
| 942 | long pc; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 943 | if (upeek(tcp->pid, REG_PC, &pc) < 0) { |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 944 | PRINTBADPC; |
| 945 | return; |
| 946 | } |
| 947 | tprintf("[%08lx] ", pc); |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 948 | #endif /* architecture */ |
| 949 | } |
| 950 | |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 951 | /* Shuffle syscall numbers so that we don't have huge gaps in syscall table. |
| 952 | * The shuffling should be reversible: shuffle_scno(shuffle_scno(n)) == n. |
| 953 | */ |
| 954 | #if defined(ARM) /* So far only ARM needs this */ |
| 955 | static long |
| 956 | shuffle_scno(unsigned long scno) |
| 957 | { |
| 958 | if (scno <= ARM_LAST_ORDINARY_SYSCALL) |
| 959 | return scno; |
| 960 | |
| 961 | /* __ARM_NR_cmpxchg? Swap with LAST_ORDINARY+1 */ |
| 962 | if (scno == 0x000ffff0) |
| 963 | return ARM_LAST_ORDINARY_SYSCALL+1; |
| 964 | if (scno == ARM_LAST_ORDINARY_SYSCALL+1) |
| 965 | return 0x000ffff0; |
| 966 | |
| 967 | /* Is it ARM specific syscall? |
| 968 | * Swap with [LAST_ORDINARY+2, LAST_ORDINARY+2 + LAST_SPECIAL] range. |
| 969 | */ |
| 970 | if (scno >= 0x000f0000 |
| 971 | && scno <= 0x000f0000 + ARM_LAST_SPECIAL_SYSCALL |
| 972 | ) { |
| 973 | return scno - 0x000f0000 + (ARM_LAST_ORDINARY_SYSCALL+2); |
| 974 | } |
| 975 | if (/* scno >= ARM_LAST_ORDINARY_SYSCALL+2 - always true */ 1 |
| 976 | && scno <= (ARM_LAST_ORDINARY_SYSCALL+2) + ARM_LAST_SPECIAL_SYSCALL |
| 977 | ) { |
| 978 | return scno + 0x000f0000 - (ARM_LAST_ORDINARY_SYSCALL+2); |
| 979 | } |
| 980 | |
| 981 | return scno; |
| 982 | } |
| 983 | #else |
| 984 | # define shuffle_scno(scno) ((long)(scno)) |
| 985 | #endif |
| 986 | |
| 987 | static char* |
| 988 | undefined_scno_name(struct tcb *tcp) |
| 989 | { |
| 990 | static char buf[sizeof("syscall_%lu") + sizeof(long)*3]; |
| 991 | |
| 992 | sprintf(buf, "syscall_%lu", shuffle_scno(tcp->scno)); |
| 993 | return buf; |
| 994 | } |
| 995 | |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 996 | #ifdef POWERPC |
| 997 | /* |
Denys Vlasenko | 7f5a132 | 2013-06-28 14:36:39 +0200 | [diff] [blame] | 998 | * PTRACE_GETREGS was added to the PowerPC kernel in v2.6.23, |
| 999 | * we provide a slow fallback for old kernels. |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1000 | */ |
Denys Vlasenko | 7f5a132 | 2013-06-28 14:36:39 +0200 | [diff] [blame] | 1001 | static int powerpc_getregs_old(pid_t pid) |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1002 | { |
| 1003 | int i; |
| 1004 | long r; |
| 1005 | |
Denys Vlasenko | 6b3016e | 2013-06-28 14:51:50 +0200 | [diff] [blame] | 1006 | if (iflag) { |
| 1007 | r = upeek(pid, sizeof(long) * PT_NIP, &ppc_regs.nip); |
| 1008 | if (r) |
| 1009 | goto out; |
| 1010 | } |
| 1011 | #ifdef POWERPC64 /* else we never use it */ |
Denys Vlasenko | 7f5a132 | 2013-06-28 14:36:39 +0200 | [diff] [blame] | 1012 | r = upeek(pid, sizeof(long) * PT_MSR, &ppc_regs.msr); |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1013 | if (r) |
| 1014 | goto out; |
Denys Vlasenko | 6b3016e | 2013-06-28 14:51:50 +0200 | [diff] [blame] | 1015 | #endif |
Denys Vlasenko | 7f5a132 | 2013-06-28 14:36:39 +0200 | [diff] [blame] | 1016 | r = upeek(pid, sizeof(long) * PT_CCR, &ppc_regs.ccr); |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1017 | if (r) |
| 1018 | goto out; |
Denys Vlasenko | 7f5a132 | 2013-06-28 14:36:39 +0200 | [diff] [blame] | 1019 | r = upeek(pid, sizeof(long) * PT_ORIG_R3, &ppc_regs.orig_gpr3); |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1020 | if (r) |
| 1021 | goto out; |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1022 | for (i = 0; i <= 8; i++) { |
Denys Vlasenko | 7f5a132 | 2013-06-28 14:36:39 +0200 | [diff] [blame] | 1023 | r = upeek(pid, sizeof(long) * (PT_R0 + i), &ppc_regs.gpr[i]); |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1024 | if (r) |
| 1025 | goto out; |
| 1026 | } |
Denys Vlasenko | 7f5a132 | 2013-06-28 14:36:39 +0200 | [diff] [blame] | 1027 | out: |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1028 | return r; |
| 1029 | } |
| 1030 | #endif |
| 1031 | |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1032 | #ifndef get_regs |
| 1033 | long get_regs_error; |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1034 | |
| 1035 | #if defined(PTRACE_GETREGSET) && defined(NT_PRSTATUS) |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1036 | static void get_regset(pid_t pid) |
| 1037 | { |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1038 | /* constant iovec */ |
| 1039 | # if defined(ARM) \ |
| 1040 | || defined(I386) \ |
| 1041 | || defined(METAG) \ |
| 1042 | || defined(OR1K) |
| 1043 | static struct iovec io = { |
| 1044 | .iov_base = &ARCH_REGS_FOR_GETREGSET, |
| 1045 | .iov_len = sizeof(ARCH_REGS_FOR_GETREGSET) |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1046 | }; |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1047 | get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &io); |
| 1048 | |
| 1049 | /* variable iovec */ |
| 1050 | # elif defined(X86_64) || defined(X32) |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1051 | /* x86_io.iov_base = &x86_regs_union; - already is */ |
| 1052 | x86_io.iov_len = sizeof(x86_regs_union); |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1053 | get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &x86_io); |
| 1054 | # elif defined(AARCH64) |
| 1055 | /* aarch64_io.iov_base = &arm_regs_union; - already is */ |
| 1056 | aarch64_io.iov_len = sizeof(arm_regs_union); |
| 1057 | get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &aarch64_io); |
| 1058 | # else |
| 1059 | # warning both PTRACE_GETREGSET and NT_PRSTATUS are available but not yet used |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1060 | # endif |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1061 | } |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1062 | #endif /* PTRACE_GETREGSET && NT_PRSTATUS */ |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1063 | |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1064 | void |
| 1065 | get_regs(pid_t pid) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1066 | { |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1067 | /* PTRACE_GETREGSET only */ |
| 1068 | # if defined(METAG) || defined(OR1K) || defined(X32) || defined(AARCH64) |
| 1069 | get_regset(pid); |
| 1070 | |
| 1071 | /* PTRACE_GETREGS only */ |
| 1072 | # elif defined(AVR32) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1073 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &avr32_regs); |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1074 | # elif defined(TILE) |
| 1075 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &tile_regs); |
| 1076 | # elif defined(SPARC) || defined(SPARC64) |
| 1077 | get_regs_error = ptrace(PTRACE_GETREGS, pid, (char *)&sparc_regs, 0); |
Anton Blanchard | ce6e33b | 2013-06-26 15:53:33 +0200 | [diff] [blame] | 1078 | # elif defined(POWERPC) |
Denys Vlasenko | 7eb8932 | 2013-06-28 14:41:30 +0200 | [diff] [blame] | 1079 | static bool old_kernel = 0; |
| 1080 | if (old_kernel) |
| 1081 | goto old; |
Anton Blanchard | ce6e33b | 2013-06-26 15:53:33 +0200 | [diff] [blame] | 1082 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &ppc_regs); |
Denys Vlasenko | 7eb8932 | 2013-06-28 14:41:30 +0200 | [diff] [blame] | 1083 | if (get_regs_error && errno == EIO) { |
| 1084 | old_kernel = 1; |
| 1085 | old: |
Anton Blanchard | 14d51a6 | 2013-06-26 14:42:37 +1000 | [diff] [blame] | 1086 | get_regs_error = powerpc_getregs_old(pid); |
Denys Vlasenko | 7eb8932 | 2013-06-28 14:41:30 +0200 | [diff] [blame] | 1087 | } |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1088 | |
| 1089 | /* try PTRACE_GETREGSET first, fallback to PTRACE_GETREGS */ |
| 1090 | # else |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1091 | # if defined(PTRACE_GETREGSET) && defined(NT_PRSTATUS) |
| 1092 | static int getregset_support; |
| 1093 | |
| 1094 | if (getregset_support >= 0) { |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1095 | get_regset(pid); |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1096 | if (getregset_support > 0) |
| 1097 | return; |
| 1098 | if (get_regs_error >= 0) { |
| 1099 | getregset_support = 1; |
| 1100 | return; |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1101 | } |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1102 | if (errno == EPERM || errno == ESRCH) |
| 1103 | return; |
| 1104 | getregset_support = -1; |
| 1105 | } |
| 1106 | # endif /* PTRACE_GETREGSET && NT_PRSTATUS */ |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1107 | # if defined(ARM) |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1108 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &arm_regs); |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1109 | # elif defined(I386) |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1110 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &i386_regs); |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1111 | # elif defined(X86_64) |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1112 | /* Use old method, with unreliable heuristical detection of 32-bitness. */ |
| 1113 | x86_io.iov_len = sizeof(x86_64_regs); |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1114 | get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &x86_64_regs); |
Dmitry V. Levin | 27e3ae9 | 2013-03-17 23:18:35 +0000 | [diff] [blame] | 1115 | if (!get_regs_error && x86_64_regs.cs == 0x23) { |
| 1116 | x86_io.iov_len = sizeof(i386_regs); |
| 1117 | /* |
| 1118 | * The order is important: i386_regs and x86_64_regs |
| 1119 | * are overlaid in memory! |
| 1120 | */ |
| 1121 | i386_regs.ebx = x86_64_regs.rbx; |
| 1122 | i386_regs.ecx = x86_64_regs.rcx; |
| 1123 | i386_regs.edx = x86_64_regs.rdx; |
| 1124 | i386_regs.esi = x86_64_regs.rsi; |
| 1125 | i386_regs.edi = x86_64_regs.rdi; |
| 1126 | i386_regs.ebp = x86_64_regs.rbp; |
| 1127 | i386_regs.eax = x86_64_regs.rax; |
| 1128 | /* i386_regs.xds = x86_64_regs.ds; unused by strace */ |
| 1129 | /* i386_regs.xes = x86_64_regs.es; ditto... */ |
| 1130 | /* i386_regs.xfs = x86_64_regs.fs; */ |
| 1131 | /* i386_regs.xgs = x86_64_regs.gs; */ |
| 1132 | i386_regs.orig_eax = x86_64_regs.orig_rax; |
| 1133 | i386_regs.eip = x86_64_regs.rip; |
| 1134 | /* i386_regs.xcs = x86_64_regs.cs; */ |
| 1135 | /* i386_regs.eflags = x86_64_regs.eflags; */ |
| 1136 | i386_regs.esp = x86_64_regs.rsp; |
| 1137 | /* i386_regs.xss = x86_64_regs.ss; */ |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1138 | } |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1139 | # else |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1140 | # error unhandled architecture |
Dmitry V. Levin | faa177e | 2013-03-17 23:48:45 +0000 | [diff] [blame] | 1141 | # endif /* ARM || I386 || X86_64 */ |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1142 | # endif |
| 1143 | } |
Dmitry V. Levin | b787b10 | 2013-03-18 10:17:14 +0000 | [diff] [blame] | 1144 | #endif /* !get_regs */ |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1145 | |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1146 | /* Returns: |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 1147 | * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently. |
| 1148 | * 1: ok, continue in trace_syscall_entering(). |
| 1149 | * other: error, trace_syscall_entering() should print error indicator |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1150 | * ("????" etc) and bail out. |
| 1151 | */ |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 1152 | static int |
Denys Vlasenko | 06602d9 | 2011-08-24 17:53:52 +0200 | [diff] [blame] | 1153 | get_scno(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1154 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1155 | long scno = 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1156 | |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1157 | #if defined(S390) || defined(S390X) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1158 | if (upeek(tcp->pid, PT_GPR2, &syscall_mode) < 0) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1159 | return -1; |
Roland McGrath | 2f924ca | 2003-06-26 22:23:28 +0000 | [diff] [blame] | 1160 | |
| 1161 | if (syscall_mode != -ENOSYS) { |
| 1162 | /* |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 1163 | * Since kernel version 2.5.44 the scno gets passed in gpr2. |
Roland McGrath | 2f924ca | 2003-06-26 22:23:28 +0000 | [diff] [blame] | 1164 | */ |
| 1165 | scno = syscall_mode; |
| 1166 | } else { |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 1167 | /* |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1168 | * Old style of "passing" the scno via the SVC instruction. |
| 1169 | */ |
Denys Vlasenko | 7ba8e72 | 2013-02-08 15:50:05 +0100 | [diff] [blame] | 1170 | long psw; |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1171 | long opcode, offset_reg, tmp; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1172 | void *svc_addr; |
Denys Vlasenko | 7c9ba8b | 2011-08-19 19:46:32 +0200 | [diff] [blame] | 1173 | static const int gpr_offset[16] = { |
| 1174 | PT_GPR0, PT_GPR1, PT_ORIGGPR2, PT_GPR3, |
| 1175 | PT_GPR4, PT_GPR5, PT_GPR6, PT_GPR7, |
| 1176 | PT_GPR8, PT_GPR9, PT_GPR10, PT_GPR11, |
| 1177 | PT_GPR12, PT_GPR13, PT_GPR14, PT_GPR15 |
| 1178 | }; |
Roland McGrath | 761b5d7 | 2002-12-15 23:58:31 +0000 | [diff] [blame] | 1179 | |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1180 | if (upeek(tcp->pid, PT_PSWADDR, &psw) < 0) |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1181 | return -1; |
Roland McGrath | 96dc514 | 2003-01-20 10:23:04 +0000 | [diff] [blame] | 1182 | errno = 0; |
Denys Vlasenko | 7ba8e72 | 2013-02-08 15:50:05 +0100 | [diff] [blame] | 1183 | opcode = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(psw - sizeof(long)), 0); |
Roland McGrath | 96dc514 | 2003-01-20 10:23:04 +0000 | [diff] [blame] | 1184 | if (errno) { |
Denys Vlasenko | 905e8e0 | 2013-02-26 12:30:09 +0100 | [diff] [blame] | 1185 | perror_msg("peektext(psw-oneword)"); |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1186 | return -1; |
Roland McGrath | 96dc514 | 2003-01-20 10:23:04 +0000 | [diff] [blame] | 1187 | } |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1188 | |
| 1189 | /* |
| 1190 | * We have to check if the SVC got executed directly or via an |
| 1191 | * EXECUTE instruction. In case of EXECUTE it is necessary to do |
| 1192 | * instruction decoding to derive the system call number. |
| 1193 | * Unfortunately the opcode sizes of EXECUTE and SVC are differently, |
| 1194 | * so that this doesn't work if a SVC opcode is part of an EXECUTE |
| 1195 | * opcode. Since there is no way to find out the opcode size this |
| 1196 | * is the best we can do... |
| 1197 | */ |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1198 | if ((opcode & 0xff00) == 0x0a00) { |
| 1199 | /* SVC opcode */ |
| 1200 | scno = opcode & 0xff; |
Roland McGrath | 761b5d7 | 2002-12-15 23:58:31 +0000 | [diff] [blame] | 1201 | } |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1202 | else { |
| 1203 | /* SVC got executed by EXECUTE instruction */ |
| 1204 | |
| 1205 | /* |
| 1206 | * Do instruction decoding of EXECUTE. If you really want to |
| 1207 | * understand this, read the Principles of Operations. |
| 1208 | */ |
| 1209 | svc_addr = (void *) (opcode & 0xfff); |
| 1210 | |
| 1211 | tmp = 0; |
| 1212 | offset_reg = (opcode & 0x000f0000) >> 16; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1213 | if (offset_reg && (upeek(tcp->pid, gpr_offset[offset_reg], &tmp) < 0)) |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1214 | return -1; |
| 1215 | svc_addr += tmp; |
| 1216 | |
| 1217 | tmp = 0; |
| 1218 | offset_reg = (opcode & 0x0000f000) >> 12; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1219 | if (offset_reg && (upeek(tcp->pid, gpr_offset[offset_reg], &tmp) < 0)) |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1220 | return -1; |
| 1221 | svc_addr += tmp; |
| 1222 | |
Denys Vlasenko | fb03667 | 2009-01-23 16:30:26 +0000 | [diff] [blame] | 1223 | scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, svc_addr, 0); |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1224 | if (errno) |
| 1225 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1226 | # if defined(S390X) |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1227 | scno >>= 48; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1228 | # else |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1229 | scno >>= 16; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1230 | # endif |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1231 | tmp = 0; |
| 1232 | offset_reg = (opcode & 0x00f00000) >> 20; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1233 | if (offset_reg && (upeek(tcp->pid, gpr_offset[offset_reg], &tmp) < 0)) |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1234 | return -1; |
| 1235 | |
| 1236 | scno = (scno | tmp) & 0xff; |
| 1237 | } |
| 1238 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1239 | #elif defined(POWERPC) |
Anton Blanchard | ce6e33b | 2013-06-26 15:53:33 +0200 | [diff] [blame] | 1240 | scno = ppc_regs.gpr[0]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1241 | # ifdef POWERPC64 |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1242 | int currpers; |
Andreas Schwab | d69fa49 | 2010-07-12 21:39:57 +0200 | [diff] [blame] | 1243 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1244 | /* Check for 64/32 bit mode. */ |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1245 | /* SF is bit 0 of MSR */ |
Anton Blanchard | ce6e33b | 2013-06-26 15:53:33 +0200 | [diff] [blame] | 1246 | if ((ppc_regs.msr >> 63) & 1) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1247 | currpers = 0; |
| 1248 | else |
| 1249 | currpers = 1; |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1250 | update_personality(tcp, currpers); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1251 | # endif |
| 1252 | #elif defined(AVR32) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1253 | scno = avr32_regs.r8; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1254 | #elif defined(BFIN) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1255 | if (upeek(tcp->pid, PT_ORIG_P0, &scno)) |
Dmitry V. Levin | 87ea1f4 | 2008-11-10 22:21:41 +0000 | [diff] [blame] | 1256 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1257 | #elif defined(I386) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1258 | scno = i386_regs.orig_eax; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1259 | #elif defined(X86_64) || defined(X32) |
| 1260 | # ifndef __X32_SYSCALL_BIT |
| 1261 | # define __X32_SYSCALL_BIT 0x40000000 |
| 1262 | # endif |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1263 | int currpers; |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1264 | # if 1 |
| 1265 | /* GETREGSET of NT_PRSTATUS tells us regset size, |
| 1266 | * which unambiguously detects i386. |
| 1267 | * |
| 1268 | * Linux kernel distinguishes x86-64 and x32 processes |
| 1269 | * solely by looking at __X32_SYSCALL_BIT: |
| 1270 | * arch/x86/include/asm/compat.h::is_x32_task(): |
| 1271 | * if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT) |
| 1272 | * return true; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1273 | */ |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1274 | if (x86_io.iov_len == sizeof(i386_regs)) { |
| 1275 | scno = i386_regs.orig_eax; |
| 1276 | currpers = 1; |
| 1277 | } else { |
| 1278 | scno = x86_64_regs.orig_rax; |
| 1279 | currpers = 0; |
| 1280 | if (scno & __X32_SYSCALL_BIT) { |
| 1281 | scno -= __X32_SYSCALL_BIT; |
| 1282 | currpers = 2; |
| 1283 | } |
| 1284 | } |
| 1285 | # elif 0 |
| 1286 | /* cs = 0x33 for long mode (native 64 bit and x32) |
| 1287 | * cs = 0x23 for compatibility mode (32 bit) |
| 1288 | * ds = 0x2b for x32 mode (x86-64 in 32 bit) |
| 1289 | */ |
| 1290 | scno = x86_64_regs.orig_rax; |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1291 | switch (x86_64_regs.cs) { |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1292 | case 0x23: currpers = 1; break; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1293 | case 0x33: |
| 1294 | if (x86_64_regs.ds == 0x2b) { |
| 1295 | currpers = 2; |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 1296 | scno &= ~__X32_SYSCALL_BIT; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1297 | } else |
| 1298 | currpers = 0; |
| 1299 | break; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1300 | default: |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1301 | fprintf(stderr, "Unknown value CS=0x%08X while " |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1302 | "detecting personality of process " |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1303 | "PID=%d\n", (int)x86_64_regs.cs, tcp->pid); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1304 | currpers = current_personality; |
| 1305 | break; |
| 1306 | } |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1307 | # elif 0 |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1308 | /* This version analyzes the opcode of a syscall instruction. |
| 1309 | * (int 0x80 on i386 vs. syscall on x86-64) |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1310 | * It works, but is too complicated, and strictly speaking, unreliable. |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1311 | */ |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1312 | unsigned long call, rip = x86_64_regs.rip; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1313 | /* sizeof(syscall) == sizeof(int 0x80) == 2 */ |
| 1314 | rip -= 2; |
| 1315 | errno = 0; |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1316 | call = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)rip, (char *)0); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1317 | if (errno) |
| 1318 | fprintf(stderr, "ptrace_peektext failed: %s\n", |
| 1319 | strerror(errno)); |
| 1320 | switch (call & 0xffff) { |
| 1321 | /* x86-64: syscall = 0x0f 0x05 */ |
| 1322 | case 0x050f: currpers = 0; break; |
| 1323 | /* i386: int 0x80 = 0xcd 0x80 */ |
| 1324 | case 0x80cd: currpers = 1; break; |
| 1325 | default: |
| 1326 | currpers = current_personality; |
| 1327 | fprintf(stderr, |
| 1328 | "Unknown syscall opcode (0x%04X) while " |
| 1329 | "detecting personality of process " |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1330 | "PID=%d\n", (int)call, tcp->pid); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1331 | break; |
| 1332 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1333 | # endif |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 1334 | |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1335 | # ifdef X32 |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 1336 | /* If we are built for a x32 system, then personality 0 is x32 |
| 1337 | * (not x86_64), and stracing of x86_64 apps is not supported. |
| 1338 | * Stracing of i386 apps is still supported. |
H.J. Lu | 085e428 | 2012-04-17 11:05:04 -0700 | [diff] [blame] | 1339 | */ |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 1340 | if (currpers == 0) { |
| 1341 | fprintf(stderr, "syscall_%lu(...) in unsupported " |
| 1342 | "64-bit mode of process PID=%d\n", |
| 1343 | scno, tcp->pid); |
| 1344 | return 0; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1345 | } |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 1346 | currpers &= ~2; /* map 2,1 to 0,1 */ |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1347 | # endif |
H.J. Lu | 085e428 | 2012-04-17 11:05:04 -0700 | [diff] [blame] | 1348 | update_personality(tcp, currpers); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1349 | #elif defined(IA64) |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 1350 | # define IA64_PSR_IS ((long)1 << 34) |
Denys Vlasenko | 4bdb6bb | 2013-02-06 18:09:31 +0100 | [diff] [blame] | 1351 | long psr; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1352 | if (upeek(tcp->pid, PT_CR_IPSR, &psr) >= 0) |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 1353 | ia32 = (psr & IA64_PSR_IS) != 0; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1354 | if (ia32) { |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1355 | if (upeek(tcp->pid, PT_R1, &scno) < 0) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1356 | return -1; |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 1357 | } else { |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1358 | if (upeek(tcp->pid, PT_R15, &scno) < 0) |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 1359 | return -1; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1360 | } |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1361 | #elif defined(AARCH64) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1362 | switch (aarch64_io.iov_len) { |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1363 | case sizeof(aarch64_regs): |
| 1364 | /* We are in 64-bit mode */ |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1365 | scno = aarch64_regs.regs[8]; |
| 1366 | update_personality(tcp, 1); |
| 1367 | break; |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 1368 | case sizeof(arm_regs): |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1369 | /* We are in 32-bit mode */ |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 1370 | scno = arm_regs.ARM_r7; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1371 | update_personality(tcp, 0); |
| 1372 | break; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1373 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1374 | #elif defined(ARM) |
Denys Vlasenko | e7030e5 | 2013-02-20 18:08:25 +0100 | [diff] [blame] | 1375 | if (arm_regs.ARM_ip != 0) { |
| 1376 | /* It is not a syscall entry */ |
| 1377 | fprintf(stderr, "pid %d stray syscall exit\n", tcp->pid); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1378 | tcp->flags |= TCB_INSYSCALL; |
Denys Vlasenko | e7030e5 | 2013-02-20 18:08:25 +0100 | [diff] [blame] | 1379 | return 0; |
| 1380 | } |
| 1381 | /* Note: we support only 32-bit CPUs, not 26-bit */ |
| 1382 | |
| 1383 | if (arm_regs.ARM_cpsr & 0x20) { |
| 1384 | /* Thumb mode */ |
| 1385 | scno = arm_regs.ARM_r7; |
| 1386 | } else { |
| 1387 | /* ARM mode */ |
| 1388 | errno = 0; |
| 1389 | scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(arm_regs.ARM_pc - 4), NULL); |
| 1390 | if (errno) |
| 1391 | return -1; |
| 1392 | |
| 1393 | /* EABI syscall convention? */ |
| 1394 | if (scno == 0xef000000) { |
| 1395 | scno = arm_regs.ARM_r7; /* yes */ |
| 1396 | } else { |
| 1397 | if ((scno & 0x0ff00000) != 0x0f900000) { |
| 1398 | fprintf(stderr, "pid %d unknown syscall trap 0x%08lx\n", |
| 1399 | tcp->pid, scno); |
| 1400 | return -1; |
| 1401 | } |
| 1402 | /* Fixup the syscall number */ |
| 1403 | scno &= 0x000fffff; |
| 1404 | } |
| 1405 | } |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 1406 | |
| 1407 | scno = shuffle_scno(scno); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1408 | #elif defined(M68K) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1409 | if (upeek(tcp->pid, 4*PT_ORIG_D0, &scno) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1410 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1411 | #elif defined(LINUX_MIPSN32) |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1412 | unsigned long long regs[38]; |
| 1413 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1414 | if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0) |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1415 | return -1; |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 1416 | mips_a3 = regs[REG_A3]; |
| 1417 | mips_r2 = regs[REG_V0]; |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1418 | |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 1419 | scno = mips_r2; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1420 | if (!SCNO_IN_RANGE(scno)) { |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 1421 | if (mips_a3 == 0 || mips_a3 == -1) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1422 | if (debug_flag) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1423 | fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno); |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1424 | return 0; |
| 1425 | } |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1426 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1427 | #elif defined(MIPS) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1428 | if (upeek(tcp->pid, REG_A3, &mips_a3) < 0) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 1429 | return -1; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1430 | if (upeek(tcp->pid, REG_V0, &scno) < 0) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1431 | return -1; |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 1432 | |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1433 | if (!SCNO_IN_RANGE(scno)) { |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 1434 | if (mips_a3 == 0 || mips_a3 == -1) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1435 | if (debug_flag) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1436 | fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno); |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1437 | return 0; |
| 1438 | } |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 1439 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1440 | #elif defined(ALPHA) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1441 | if (upeek(tcp->pid, REG_A3, &alpha_a3) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1442 | return -1; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1443 | if (upeek(tcp->pid, REG_R0, &scno) < 0) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1444 | return -1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1445 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1446 | /* |
| 1447 | * Do some sanity checks to figure out if it's |
| 1448 | * really a syscall entry |
| 1449 | */ |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1450 | if (!SCNO_IN_RANGE(scno)) { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1451 | if (alpha_a3 == 0 || alpha_a3 == -1) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1452 | if (debug_flag) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1453 | fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1454 | return 0; |
| 1455 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1456 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1457 | #elif defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1458 | /* Disassemble the syscall trap. */ |
| 1459 | /* Retrieve the syscall trap instruction. */ |
Denys Vlasenko | 4645582 | 2013-02-05 17:02:59 +0100 | [diff] [blame] | 1460 | unsigned long trap; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1461 | errno = 0; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1462 | # if defined(SPARC64) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1463 | trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.tpc, 0); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1464 | trap >>= 32; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1465 | # else |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1466 | trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.pc, 0); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1467 | # endif |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1468 | if (errno) |
Wichert Akkerman | c1652e2 | 2001-03-27 12:17:16 +0000 | [diff] [blame] | 1469 | return -1; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1470 | |
| 1471 | /* Disassemble the trap to see what personality to use. */ |
| 1472 | switch (trap) { |
| 1473 | case 0x91d02010: |
| 1474 | /* Linux/SPARC syscall trap. */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1475 | update_personality(tcp, 0); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1476 | break; |
| 1477 | case 0x91d0206d: |
| 1478 | /* Linux/SPARC64 syscall trap. */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1479 | update_personality(tcp, 2); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1480 | break; |
| 1481 | case 0x91d02000: |
| 1482 | /* SunOS syscall trap. (pers 1) */ |
| 1483 | fprintf(stderr, "syscall: SunOS no support\n"); |
| 1484 | return -1; |
| 1485 | case 0x91d02008: |
| 1486 | /* Solaris 2.x syscall trap. (per 2) */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1487 | update_personality(tcp, 1); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1488 | break; |
| 1489 | case 0x91d02009: |
| 1490 | /* NetBSD/FreeBSD syscall trap. */ |
| 1491 | fprintf(stderr, "syscall: NetBSD/FreeBSD not supported\n"); |
| 1492 | return -1; |
| 1493 | case 0x91d02027: |
| 1494 | /* Solaris 2.x gettimeofday */ |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 1495 | update_personality(tcp, 1); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1496 | break; |
| 1497 | default: |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1498 | # if defined(SPARC64) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1499 | fprintf(stderr, "syscall: unknown syscall trap %08lx %016lx\n", trap, sparc_regs.tpc); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1500 | # else |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1501 | fprintf(stderr, "syscall: unknown syscall trap %08lx %08lx\n", trap, sparc_regs.pc); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1502 | # endif |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1503 | return -1; |
| 1504 | } |
| 1505 | |
| 1506 | /* Extract the system call number from the registers. */ |
| 1507 | if (trap == 0x91d02027) |
| 1508 | scno = 156; |
| 1509 | else |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1510 | scno = sparc_regs.u_regs[U_REG_G1]; |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1511 | if (scno == 0) { |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1512 | scno = sparc_regs.u_regs[U_REG_O0]; |
| 1513 | memmove(&sparc_regs.u_regs[U_REG_O0], &sparc_regs.u_regs[U_REG_O1], 7*sizeof(sparc_regs.u_regs[0])); |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1514 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1515 | #elif defined(HPPA) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1516 | if (upeek(tcp->pid, PT_GR20, &scno) < 0) |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1517 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1518 | #elif defined(SH) |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1519 | /* |
| 1520 | * In the new syscall ABI, the system call number is in R3. |
| 1521 | */ |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1522 | if (upeek(tcp->pid, 4*(REG_REG0+3), &scno) < 0) |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1523 | return -1; |
Wichert Akkerman | ccef637 | 2002-05-01 16:39:22 +0000 | [diff] [blame] | 1524 | |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1525 | if (scno < 0) { |
| 1526 | /* Odd as it may seem, a glibc bug has been known to cause |
| 1527 | glibc to issue bogus negative syscall numbers. So for |
| 1528 | our purposes, make strace print what it *should* have been */ |
| 1529 | long correct_scno = (scno & 0xff); |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1530 | if (debug_flag) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 1531 | fprintf(stderr, |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1532 | "Detected glibc bug: bogus system call" |
| 1533 | " number = %ld, correcting to %ld\n", |
| 1534 | scno, |
| 1535 | correct_scno); |
| 1536 | scno = correct_scno; |
| 1537 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1538 | #elif defined(SH64) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1539 | if (upeek(tcp->pid, REG_SYSCALL, &scno) < 0) |
Roland McGrath | e1e584b | 2003-06-02 19:18:58 +0000 | [diff] [blame] | 1540 | return -1; |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 1541 | scno &= 0xFFFF; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1542 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1543 | if (upeek(tcp->pid, 4*PT_R9, &scno) < 0) |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1544 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1545 | #elif defined(TILE) |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 1546 | int currpers; |
| 1547 | scno = tile_regs.regs[10]; |
| 1548 | # ifdef __tilepro__ |
| 1549 | currpers = 1; |
| 1550 | # else |
Denys Vlasenko | 59aea0a | 2013-02-11 12:29:36 +0100 | [diff] [blame] | 1551 | # ifndef PT_FLAGS_COMPAT |
| 1552 | # define PT_FLAGS_COMPAT 0x10000 /* from Linux 3.8 on */ |
| 1553 | # endif |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 1554 | if (tile_regs.flags & PT_FLAGS_COMPAT) |
| 1555 | currpers = 1; |
| 1556 | else |
| 1557 | currpers = 0; |
| 1558 | # endif |
| 1559 | update_personality(tcp, currpers); |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1560 | #elif defined(MICROBLAZE) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1561 | if (upeek(tcp->pid, 0, &scno) < 0) |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1562 | return -1; |
Christian Svensson | 492f81f | 2013-02-14 13:26:27 +0100 | [diff] [blame] | 1563 | #elif defined(OR1K) |
| 1564 | scno = or1k_regs.gpr[11]; |
James Hogan | 5f999a8 | 2013-02-22 14:44:10 +0000 | [diff] [blame] | 1565 | #elif defined(METAG) |
| 1566 | scno = metag_regs.dx[0][1]; /* syscall number in D1Re0 (D1.0) */ |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 1567 | #elif defined(XTENSA) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1568 | if (upeek(tcp->pid, SYSCALL_NR, &scno) < 0) |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 1569 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1570 | #endif |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1571 | |
Denys Vlasenko | 8cd1acd | 2011-08-24 16:52:57 +0200 | [diff] [blame] | 1572 | tcp->scno = scno; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1573 | if (SCNO_IS_VALID(tcp->scno)) { |
| 1574 | tcp->s_ent = &sysent[scno]; |
| 1575 | tcp->qual_flg = qual_flags[scno]; |
| 1576 | } else { |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 1577 | static const struct_sysent unknown = { |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1578 | .nargs = MAX_ARGS, |
| 1579 | .sys_flags = 0, |
| 1580 | .sys_func = printargs, |
| 1581 | .sys_name = "unknown", /* not used */ |
| 1582 | }; |
| 1583 | tcp->s_ent = &unknown; |
| 1584 | tcp->qual_flg = UNDEFINED_SCNO | QUAL_RAW | DEFAULT_QUAL_FLAGS; |
| 1585 | } |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1586 | return 1; |
| 1587 | } |
| 1588 | |
Denys Vlasenko | 20c41fd | 2011-08-25 10:23:00 +0200 | [diff] [blame] | 1589 | /* Called at each syscall entry. |
Denys Vlasenko | bc161ec | 2009-01-02 18:02:45 +0000 | [diff] [blame] | 1590 | * Returns: |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 1591 | * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently. |
| 1592 | * 1: ok, continue in trace_syscall_entering(). |
| 1593 | * other: error, trace_syscall_entering() should print error indicator |
Denys Vlasenko | bc161ec | 2009-01-02 18:02:45 +0000 | [diff] [blame] | 1594 | * ("????" etc) and bail out. |
| 1595 | */ |
Roland McGrath | a4d4853 | 2005-06-08 20:45:28 +0000 | [diff] [blame] | 1596 | static int |
Denys Vlasenko | 8b4454c | 2011-08-25 10:40:14 +0200 | [diff] [blame] | 1597 | syscall_fixup_on_sysenter(struct tcb *tcp) |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1598 | { |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1599 | /* A common case of "not a syscall entry" is post-execve SIGTRAP */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1600 | #if defined(I386) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1601 | if (i386_regs.eax != -ENOSYS) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1602 | if (debug_flag) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1603 | fprintf(stderr, "not a syscall entry (eax = %ld)\n", i386_regs.eax); |
| 1604 | return 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1605 | } |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1606 | #elif defined(X86_64) || defined(X32) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1607 | { |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1608 | long rax; |
| 1609 | if (x86_io.iov_len == sizeof(i386_regs)) { |
| 1610 | /* Sign extend from 32 bits */ |
| 1611 | rax = (int32_t)i386_regs.eax; |
| 1612 | } else { |
| 1613 | /* Note: in X32 build, this truncates 64 to 32 bits */ |
| 1614 | rax = x86_64_regs.rax; |
| 1615 | } |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1616 | if (rax != -ENOSYS) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1617 | if (debug_flag) |
Denys Vlasenko | 18beb98 | 2011-08-24 16:59:23 +0200 | [diff] [blame] | 1618 | fprintf(stderr, "not a syscall entry (rax = %ld)\n", rax); |
| 1619 | return 0; |
| 1620 | } |
Michal Ludvig | 0e03550 | 2002-09-23 15:41:01 +0000 | [diff] [blame] | 1621 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1622 | #elif defined(S390) || defined(S390X) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1623 | /* TODO: we already fetched PT_GPR2 in get_scno |
| 1624 | * and stored it in syscall_mode, reuse it here |
| 1625 | * instead of re-fetching? |
| 1626 | */ |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1627 | if (upeek(tcp->pid, PT_GPR2, &gpr2) < 0) |
Wichert Akkerman | 12f75d1 | 2000-02-14 16:23:40 +0000 | [diff] [blame] | 1628 | return -1; |
Michal Ludvig | 882eda8 | 2002-11-11 12:50:47 +0000 | [diff] [blame] | 1629 | if (syscall_mode != -ENOSYS) |
| 1630 | syscall_mode = tcp->scno; |
Denys Vlasenko | ece9879 | 2011-08-25 10:25:35 +0200 | [diff] [blame] | 1631 | if (gpr2 != syscall_mode) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1632 | if (debug_flag) |
Denys Vlasenko | b88f961 | 2011-08-21 18:03:23 +0200 | [diff] [blame] | 1633 | fprintf(stderr, "not a syscall entry (gpr2 = %ld)\n", gpr2); |
Wichert Akkerman | 12f75d1 | 2000-02-14 16:23:40 +0000 | [diff] [blame] | 1634 | return 0; |
| 1635 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1636 | #elif defined(M68K) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 1637 | /* TODO? Eliminate upeek's in arches below like we did in x86 */ |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1638 | if (upeek(tcp->pid, 4*PT_D0, &m68k_d0) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1639 | return -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1640 | if (m68k_d0 != -ENOSYS) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1641 | if (debug_flag) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1642 | fprintf(stderr, "not a syscall entry (d0 = %ld)\n", m68k_d0); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1643 | return 0; |
| 1644 | } |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 1645 | #elif defined(IA64) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1646 | if (upeek(tcp->pid, PT_R10, &ia64_r10) < 0) |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 1647 | return -1; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1648 | if (upeek(tcp->pid, PT_R8, &ia64_r8) < 0) |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 1649 | return -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1650 | if (ia32 && ia64_r8 != -ENOSYS) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1651 | if (debug_flag) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1652 | fprintf(stderr, "not a syscall entry (r8 = %ld)\n", ia64_r8); |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 1653 | return 0; |
| 1654 | } |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1655 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1656 | if (upeek(tcp->pid, 4*PT_R10, &cris_r10) < 0) |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1657 | return -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1658 | if (cris_r10 != -ENOSYS) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1659 | if (debug_flag) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1660 | fprintf(stderr, "not a syscall entry (r10 = %ld)\n", cris_r10); |
Denys Vlasenko | ea0e6e8 | 2009-02-25 17:08:40 +0000 | [diff] [blame] | 1661 | return 0; |
| 1662 | } |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1663 | #elif defined(MICROBLAZE) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1664 | if (upeek(tcp->pid, 3 * 4, µblaze_r3) < 0) |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1665 | return -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1666 | if (microblaze_r3 != -ENOSYS) { |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 1667 | if (debug_flag) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 1668 | fprintf(stderr, "not a syscall entry (r3 = %ld)\n", microblaze_r3); |
Edgar E. Iglesias | 939caba | 2010-07-06 14:21:07 +0200 | [diff] [blame] | 1669 | return 0; |
| 1670 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1671 | #endif |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1672 | return 1; |
| 1673 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1674 | |
Denys Vlasenko | 146b944 | 2012-03-18 22:10:48 +0100 | [diff] [blame] | 1675 | static void |
| 1676 | internal_fork(struct tcb *tcp) |
| 1677 | { |
| 1678 | #if defined S390 || defined S390X || defined CRISV10 || defined CRISV32 |
| 1679 | # define ARG_FLAGS 1 |
| 1680 | #else |
| 1681 | # define ARG_FLAGS 0 |
| 1682 | #endif |
| 1683 | #ifndef CLONE_UNTRACED |
| 1684 | # define CLONE_UNTRACED 0x00800000 |
| 1685 | #endif |
| 1686 | if ((ptrace_setoptions |
| 1687 | & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK)) |
| 1688 | == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK)) |
| 1689 | return; |
| 1690 | |
| 1691 | if (!followfork) |
| 1692 | return; |
| 1693 | |
| 1694 | if (entering(tcp)) { |
| 1695 | /* |
| 1696 | * We won't see the new child if clone is called with |
| 1697 | * CLONE_UNTRACED, so we keep the same logic with that option |
| 1698 | * and don't trace it. |
| 1699 | */ |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1700 | if ((tcp->s_ent->sys_func == sys_clone) |
| 1701 | && (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED) |
| 1702 | ) |
Denys Vlasenko | 146b944 | 2012-03-18 22:10:48 +0100 | [diff] [blame] | 1703 | return; |
| 1704 | setbpt(tcp); |
| 1705 | } else { |
| 1706 | if (tcp->flags & TCB_BPTSET) |
| 1707 | clearbpt(tcp); |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | #if defined(TCB_WAITEXECVE) |
| 1712 | static void |
| 1713 | internal_exec(struct tcb *tcp) |
| 1714 | { |
| 1715 | /* Maybe we have post-execve SIGTRAP suppressed? */ |
| 1716 | if (ptrace_setoptions & PTRACE_O_TRACEEXEC) |
| 1717 | return; /* yes, no need to do anything */ |
| 1718 | |
| 1719 | if (exiting(tcp) && syserror(tcp)) |
| 1720 | /* Error in execve, no post-execve SIGTRAP expected */ |
| 1721 | tcp->flags &= ~TCB_WAITEXECVE; |
| 1722 | else |
| 1723 | tcp->flags |= TCB_WAITEXECVE; |
| 1724 | } |
| 1725 | #endif |
| 1726 | |
| 1727 | static void |
Denys Vlasenko | 8d4ca0c | 2013-02-06 13:18:42 +0100 | [diff] [blame] | 1728 | syscall_fixup_for_fork_exec(struct tcb *tcp) |
Roland McGrath | c1e4592 | 2008-05-27 23:18:29 +0000 | [diff] [blame] | 1729 | { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1730 | /* |
| 1731 | * We must always trace a few critical system calls in order to |
| 1732 | * correctly support following forks in the presence of tracing |
| 1733 | * qualifiers. |
| 1734 | */ |
| 1735 | int (*func)(); |
| 1736 | |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1737 | func = tcp->s_ent->sys_func; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1738 | |
| 1739 | if ( sys_fork == func |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1740 | || sys_vfork == func |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1741 | || sys_clone == func |
Denys Vlasenko | 146b944 | 2012-03-18 22:10:48 +0100 | [diff] [blame] | 1742 | ) { |
| 1743 | internal_fork(tcp); |
| 1744 | return; |
| 1745 | } |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1746 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 1747 | #if defined(TCB_WAITEXECVE) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1748 | if ( sys_execve == func |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 1749 | # if defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 1750 | || sys_execv == func |
Denys Vlasenko | a794974 | 2011-08-21 17:26:55 +0200 | [diff] [blame] | 1751 | # endif |
Denys Vlasenko | 146b944 | 2012-03-18 22:10:48 +0100 | [diff] [blame] | 1752 | ) { |
| 1753 | internal_exec(tcp); |
| 1754 | return; |
| 1755 | } |
Roland McGrath | c1e4592 | 2008-05-27 23:18:29 +0000 | [diff] [blame] | 1756 | #endif |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1757 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1758 | |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 1759 | /* Return -1 on error or 1 on success (never 0!) */ |
Roland McGrath | a4d4853 | 2005-06-08 20:45:28 +0000 | [diff] [blame] | 1760 | static int |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 1761 | get_syscall_args(struct tcb *tcp) |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1762 | { |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1763 | int i, nargs; |
| 1764 | |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 1765 | nargs = tcp->s_ent->nargs; |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1766 | |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1767 | #if defined(S390) || defined(S390X) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1768 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1769 | if (upeek(tcp->pid, i==0 ? PT_ORIGGPR2 : PT_GPR2 + i*sizeof(long), &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1770 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1771 | #elif defined(ALPHA) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1772 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1773 | if (upeek(tcp->pid, REG_A0+i, &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1774 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1775 | #elif defined(IA64) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1776 | if (!ia32) { |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1777 | unsigned long *out0, cfm, sof, sol; |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1778 | long rbs_end; |
| 1779 | /* be backwards compatible with kernel < 2.4.4... */ |
| 1780 | # ifndef PT_RBS_END |
| 1781 | # define PT_RBS_END PT_AR_BSP |
| 1782 | # endif |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 1783 | |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1784 | if (upeek(tcp->pid, PT_RBS_END, &rbs_end) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1785 | return -1; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1786 | if (upeek(tcp->pid, PT_CFM, (long *) &cfm) < 0) |
Roland McGrath | 542c2c6 | 2008-05-20 01:11:56 +0000 | [diff] [blame] | 1787 | return -1; |
| 1788 | |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1789 | sof = (cfm >> 0) & 0x7f; |
| 1790 | sol = (cfm >> 7) & 0x7f; |
| 1791 | out0 = ia64_rse_skip_regs((unsigned long *) rbs_end, -sof + sol); |
| 1792 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1793 | for (i = 0; i < nargs; ++i) { |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1794 | if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i), |
| 1795 | sizeof(long), (char *) &tcp->u_arg[i]) < 0) |
| 1796 | return -1; |
| 1797 | } |
| 1798 | } else { |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1799 | static const int argreg[MAX_ARGS] = { PT_R11 /* EBX = out0 */, |
| 1800 | PT_R9 /* ECX = out1 */, |
| 1801 | PT_R10 /* EDX = out2 */, |
| 1802 | PT_R14 /* ESI = out3 */, |
| 1803 | PT_R15 /* EDI = out4 */, |
| 1804 | PT_R13 /* EBP = out5 */}; |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1805 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1806 | for (i = 0; i < nargs; ++i) { |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1807 | if (upeek(tcp->pid, argreg[i], &tcp->u_arg[i]) < 0) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1808 | return -1; |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1809 | /* truncate away IVE sign-extension */ |
| 1810 | tcp->u_arg[i] &= 0xffffffff; |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1811 | } |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1812 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1813 | #elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1814 | /* N32 and N64 both use up to six registers. */ |
| 1815 | unsigned long long regs[38]; |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1816 | |
| 1817 | if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0) |
| 1818 | return -1; |
| 1819 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1820 | for (i = 0; i < nargs; ++i) { |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1821 | tcp->u_arg[i] = regs[REG_A0 + i]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1822 | # if defined(LINUX_MIPSN32) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1823 | tcp->ext_arg[i] = regs[REG_A0 + i]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1824 | # endif |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1825 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1826 | #elif defined(MIPS) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1827 | if (nargs > 4) { |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1828 | long sp; |
| 1829 | |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1830 | if (upeek(tcp->pid, REG_SP, &sp) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1831 | return -1; |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1832 | for (i = 0; i < 4; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1833 | if (upeek(tcp->pid, REG_A0 + i, &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1834 | return -1; |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1835 | umoven(tcp, sp + 16, (nargs - 4) * sizeof(tcp->u_arg[0]), |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1836 | (char *)(tcp->u_arg + 4)); |
| 1837 | } else { |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1838 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1839 | if (upeek(tcp->pid, REG_A0 + i, &tcp->u_arg[i]) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1840 | return -1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1841 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1842 | #elif defined(POWERPC) |
Anton Blanchard | ce6e33b | 2013-06-26 15:53:33 +0200 | [diff] [blame] | 1843 | (void)i; |
| 1844 | (void)nargs; |
| 1845 | tcp->u_arg[0] = ppc_regs.orig_gpr3; |
| 1846 | tcp->u_arg[1] = ppc_regs.gpr[4]; |
| 1847 | tcp->u_arg[2] = ppc_regs.gpr[5]; |
| 1848 | tcp->u_arg[3] = ppc_regs.gpr[6]; |
| 1849 | tcp->u_arg[4] = ppc_regs.gpr[7]; |
| 1850 | tcp->u_arg[5] = ppc_regs.gpr[8]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1851 | #elif defined(SPARC) || defined(SPARC64) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1852 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1853 | tcp->u_arg[i] = sparc_regs.u_regs[U_REG_O0 + i]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1854 | #elif defined(HPPA) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1855 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1856 | if (upeek(tcp->pid, PT_GR26-4*i, &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1857 | return -1; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 1858 | #elif defined(ARM) || defined(AARCH64) |
| 1859 | # if defined(AARCH64) |
| 1860 | if (tcp->currpers == 1) |
| 1861 | for (i = 0; i < nargs; ++i) |
| 1862 | tcp->u_arg[i] = aarch64_regs.regs[i]; |
| 1863 | else |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 1864 | # endif |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1865 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 401374e | 2013-02-06 18:24:39 +0100 | [diff] [blame] | 1866 | tcp->u_arg[i] = arm_regs.uregs[i]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1867 | #elif defined(AVR32) |
Denys Vlasenko | b5b2589 | 2011-08-30 19:04:54 +0200 | [diff] [blame] | 1868 | (void)i; |
| 1869 | (void)nargs; |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 1870 | tcp->u_arg[0] = avr32_regs.r12; |
| 1871 | tcp->u_arg[1] = avr32_regs.r11; |
| 1872 | tcp->u_arg[2] = avr32_regs.r10; |
| 1873 | tcp->u_arg[3] = avr32_regs.r9; |
| 1874 | tcp->u_arg[4] = avr32_regs.r5; |
| 1875 | tcp->u_arg[5] = avr32_regs.r3; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1876 | #elif defined(BFIN) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1877 | static const int argreg[MAX_ARGS] = { PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5 }; |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1878 | |
Denys Vlasenko | 4b887a5 | 2011-08-23 13:32:38 +0200 | [diff] [blame] | 1879 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1880 | if (upeek(tcp->pid, argreg[i], &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1881 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1882 | #elif defined(SH) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1883 | static const int syscall_regs[MAX_ARGS] = { |
| 1884 | 4 * (REG_REG0+4), 4 * (REG_REG0+5), 4 * (REG_REG0+6), |
| 1885 | 4 * (REG_REG0+7), 4 * (REG_REG0 ), 4 * (REG_REG0+1) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1886 | }; |
| 1887 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1888 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1889 | if (upeek(tcp->pid, syscall_regs[i], &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1890 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1891 | #elif defined(SH64) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1892 | int i; |
| 1893 | /* Registers used by SH5 Linux system calls for parameters */ |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1894 | static const int syscall_regs[MAX_ARGS] = { 2, 3, 4, 5, 6, 7 }; |
Roland McGrath | e1e584b | 2003-06-02 19:18:58 +0000 | [diff] [blame] | 1895 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1896 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1897 | if (upeek(tcp->pid, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1898 | return -1; |
Denys Vlasenko | 6cf3605 | 2013-02-15 15:01:38 +0100 | [diff] [blame] | 1899 | #elif defined(I386) |
| 1900 | (void)i; |
| 1901 | (void)nargs; |
| 1902 | tcp->u_arg[0] = i386_regs.ebx; |
| 1903 | tcp->u_arg[1] = i386_regs.ecx; |
| 1904 | tcp->u_arg[2] = i386_regs.edx; |
| 1905 | tcp->u_arg[3] = i386_regs.esi; |
| 1906 | tcp->u_arg[4] = i386_regs.edi; |
| 1907 | tcp->u_arg[5] = i386_regs.ebp; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1908 | #elif defined(X86_64) || defined(X32) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1909 | (void)i; |
| 1910 | (void)nargs; |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1911 | if (x86_io.iov_len != sizeof(i386_regs)) { |
| 1912 | /* x86-64 or x32 ABI */ |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1913 | tcp->u_arg[0] = x86_64_regs.rdi; |
| 1914 | tcp->u_arg[1] = x86_64_regs.rsi; |
| 1915 | tcp->u_arg[2] = x86_64_regs.rdx; |
| 1916 | tcp->u_arg[3] = x86_64_regs.r10; |
| 1917 | tcp->u_arg[4] = x86_64_regs.r8; |
| 1918 | tcp->u_arg[5] = x86_64_regs.r9; |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 1919 | # ifdef X32 |
| 1920 | tcp->ext_arg[0] = x86_64_regs.rdi; |
| 1921 | tcp->ext_arg[1] = x86_64_regs.rsi; |
| 1922 | tcp->ext_arg[2] = x86_64_regs.rdx; |
| 1923 | tcp->ext_arg[3] = x86_64_regs.r10; |
| 1924 | tcp->ext_arg[4] = x86_64_regs.r8; |
| 1925 | tcp->ext_arg[5] = x86_64_regs.r9; |
| 1926 | # endif |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 1927 | } else { |
| 1928 | /* i386 ABI */ |
Denys Vlasenko | 6cf3605 | 2013-02-15 15:01:38 +0100 | [diff] [blame] | 1929 | /* Zero-extend from 32 bits */ |
| 1930 | /* Use widen_to_long(tcp->u_arg[N]) in syscall handlers |
| 1931 | * if you need to use *sign-extended* parameter. |
| 1932 | */ |
| 1933 | tcp->u_arg[0] = (long)(uint32_t)i386_regs.ebx; |
| 1934 | tcp->u_arg[1] = (long)(uint32_t)i386_regs.ecx; |
| 1935 | tcp->u_arg[2] = (long)(uint32_t)i386_regs.edx; |
| 1936 | tcp->u_arg[3] = (long)(uint32_t)i386_regs.esi; |
| 1937 | tcp->u_arg[4] = (long)(uint32_t)i386_regs.edi; |
| 1938 | tcp->u_arg[5] = (long)(uint32_t)i386_regs.ebp; |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 1939 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1940 | #elif defined(MICROBLAZE) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1941 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1942 | if (upeek(tcp->pid, (5 + i) * 4, &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1943 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1944 | #elif defined(CRISV10) || defined(CRISV32) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1945 | static const int crisregs[MAX_ARGS] = { |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1946 | 4*PT_ORIG_R10, 4*PT_R11, 4*PT_R12, |
Denys Vlasenko | 0b6c73c | 2011-06-23 22:22:34 +0200 | [diff] [blame] | 1947 | 4*PT_R13 , 4*PT_MOF, 4*PT_SRP |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1948 | }; |
Roland McGrath | e1e584b | 2003-06-02 19:18:58 +0000 | [diff] [blame] | 1949 | |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1950 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1951 | if (upeek(tcp->pid, crisregs[i], &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1952 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1953 | #elif defined(TILE) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1954 | for (i = 0; i < nargs; ++i) |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 1955 | tcp->u_arg[i] = tile_regs.regs[i]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1956 | #elif defined(M68K) |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1957 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1958 | if (upeek(tcp->pid, (i < 5 ? i : i + 2)*4, &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1959 | return -1; |
Christian Svensson | 492f81f | 2013-02-14 13:26:27 +0100 | [diff] [blame] | 1960 | #elif defined(OR1K) |
| 1961 | (void)nargs; |
| 1962 | for (i = 0; i < 6; ++i) |
| 1963 | tcp->u_arg[i] = or1k_regs.gpr[3 + i]; |
James Hogan | 5f999a8 | 2013-02-22 14:44:10 +0000 | [diff] [blame] | 1964 | #elif defined(METAG) |
| 1965 | for (i = 0; i < nargs; i++) |
| 1966 | /* arguments go backwards from D1Ar1 (D1.3) */ |
| 1967 | tcp->u_arg[i] = ((unsigned long *)&metag_regs.dx[3][1])[-i]; |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 1968 | #elif defined(XTENSA) |
| 1969 | /* arg0: a6, arg1: a3, arg2: a4, arg3: a5, arg4: a8, arg5: a9 */ |
| 1970 | static const int xtensaregs[MAX_ARGS] = { 6, 3, 4, 5, 8, 9 }; |
| 1971 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1972 | if (upeek(tcp->pid, REG_A_BASE + xtensaregs[i], &tcp->u_arg[i]) < 0) |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 1973 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1974 | #else /* Other architecture (32bits specific) */ |
Dmitry V. Levin | 5f731c4 | 2011-08-23 16:24:20 +0000 | [diff] [blame] | 1975 | for (i = 0; i < nargs; ++i) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 1976 | if (upeek(tcp->pid, i*4, &tcp->u_arg[i]) < 0) |
Denys Vlasenko | f5d099c | 2011-06-23 22:10:54 +0200 | [diff] [blame] | 1977 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 1978 | #endif |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 1979 | return 1; |
| 1980 | } |
| 1981 | |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 1982 | static int |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1983 | trace_syscall_entering(struct tcb *tcp) |
| 1984 | { |
| 1985 | int res, scno_good; |
| 1986 | |
Denys Vlasenko | 2ce12ed | 2011-08-24 17:25:32 +0200 | [diff] [blame] | 1987 | #if defined TCB_WAITEXECVE |
| 1988 | if (tcp->flags & TCB_WAITEXECVE) { |
| 1989 | /* This is the post-execve SIGTRAP. */ |
| 1990 | tcp->flags &= ~TCB_WAITEXECVE; |
| 1991 | return 0; |
| 1992 | } |
| 1993 | #endif |
| 1994 | |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 1995 | scno_good = res = (get_regs_error ? -1 : get_scno(tcp)); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 1996 | if (res == 0) |
| 1997 | return res; |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 1998 | if (res == 1) { |
Denys Vlasenko | 8b4454c | 2011-08-25 10:40:14 +0200 | [diff] [blame] | 1999 | res = syscall_fixup_on_sysenter(tcp); |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 2000 | if (res == 0) |
| 2001 | return res; |
| 2002 | if (res == 1) |
| 2003 | res = get_syscall_args(tcp); |
| 2004 | } |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2005 | |
| 2006 | if (res != 1) { |
| 2007 | printleader(tcp); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2008 | if (scno_good != 1) |
Denys Vlasenko | b7a6dae | 2012-03-20 16:48:35 +0100 | [diff] [blame] | 2009 | tprints("????" /* anti-trigraph gap */ "("); |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2010 | else if (tcp->qual_flg & UNDEFINED_SCNO) |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 2011 | tprintf("%s(", undefined_scno_name(tcp)); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2012 | else |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2013 | tprintf("%s(", tcp->s_ent->sys_name); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2014 | /* |
| 2015 | * " <unavailable>" will be added later by the code which |
| 2016 | * detects ptrace errors. |
| 2017 | */ |
| 2018 | goto ret; |
| 2019 | } |
| 2020 | |
Denys Vlasenko | 2a3d275 | 2013-05-14 16:07:46 +0200 | [diff] [blame] | 2021 | if ( sys_execve == tcp->s_ent->sys_func |
| 2022 | # if defined(SPARC) || defined(SPARC64) |
| 2023 | || sys_execv == tcp->s_ent->sys_func |
| 2024 | # endif |
| 2025 | ) { |
| 2026 | hide_log_until_execve = 0; |
| 2027 | } |
| 2028 | |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 2029 | #if defined(SYS_socket_subcall) || defined(SYS_ipc_subcall) |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2030 | while (1) { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2031 | # ifdef SYS_socket_subcall |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2032 | if (tcp->s_ent->sys_func == sys_socketcall) { |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 2033 | decode_socket_subcall(tcp); |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 2034 | break; |
| 2035 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2036 | # endif |
| 2037 | # ifdef SYS_ipc_subcall |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2038 | if (tcp->s_ent->sys_func == sys_ipc) { |
Dmitry V. Levin | 648c22c | 2012-03-15 22:08:55 +0000 | [diff] [blame] | 2039 | decode_ipc_subcall(tcp); |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 2040 | break; |
| 2041 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2042 | # endif |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 2043 | break; |
| 2044 | } |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2045 | #endif |
Dmitry V. Levin | b5e88d4 | 2012-02-20 17:02:38 +0000 | [diff] [blame] | 2046 | |
Denys Vlasenko | 8d4ca0c | 2013-02-06 13:18:42 +0100 | [diff] [blame] | 2047 | if (need_fork_exec_workarounds) |
| 2048 | syscall_fixup_for_fork_exec(tcp); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2049 | |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2050 | if (!(tcp->qual_flg & QUAL_TRACE) |
| 2051 | || (tracing_paths && !pathtrace_match(tcp)) |
| 2052 | ) { |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2053 | tcp->flags |= TCB_INSYSCALL | TCB_FILTERED; |
| 2054 | return 0; |
| 2055 | } |
| 2056 | |
| 2057 | tcp->flags &= ~TCB_FILTERED; |
| 2058 | |
Denys Vlasenko | 2a3d275 | 2013-05-14 16:07:46 +0200 | [diff] [blame] | 2059 | if (cflag == CFLAG_ONLY_STATS || hide_log_until_execve) { |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2060 | res = 0; |
| 2061 | goto ret; |
| 2062 | } |
| 2063 | |
| 2064 | printleader(tcp); |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2065 | if (tcp->qual_flg & UNDEFINED_SCNO) |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 2066 | tprintf("%s(", undefined_scno_name(tcp)); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2067 | else |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2068 | tprintf("%s(", tcp->s_ent->sys_name); |
| 2069 | if ((tcp->qual_flg & QUAL_RAW) && tcp->s_ent->sys_func != sys_exit) |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2070 | res = printargs(tcp); |
| 2071 | else |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2072 | res = tcp->s_ent->sys_func(tcp); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2073 | |
Dmitry V. Levin | b742d8c | 2012-09-17 22:40:12 +0000 | [diff] [blame] | 2074 | fflush(tcp->outf); |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2075 | ret: |
| 2076 | tcp->flags |= TCB_INSYSCALL; |
| 2077 | /* Measure the entrance time as late as possible to avoid errors. */ |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 2078 | if (Tflag || cflag) |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2079 | gettimeofday(&tcp->etime, NULL); |
| 2080 | return res; |
| 2081 | } |
| 2082 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2083 | /* Returns: |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 2084 | * 1: ok, continue in trace_syscall_exiting(). |
| 2085 | * -1: error, trace_syscall_exiting() should print error indicator |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2086 | * ("????" etc) and bail out. |
| 2087 | */ |
| 2088 | static int |
| 2089 | get_syscall_result(struct tcb *tcp) |
| 2090 | { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2091 | #if defined(S390) || defined(S390X) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2092 | if (upeek(tcp->pid, PT_GPR2, &gpr2) < 0) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 2093 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2094 | #elif defined(POWERPC) |
Denys Vlasenko | 44a6d04 | 2013-06-28 16:47:38 +0200 | [diff] [blame^] | 2095 | /* already done by get_regs */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2096 | #elif defined(AVR32) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 2097 | /* already done by get_regs */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2098 | #elif defined(BFIN) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2099 | if (upeek(tcp->pid, PT_R0, &bfin_r0) < 0) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 2100 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2101 | #elif defined(I386) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 2102 | /* already done by get_regs */ |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 2103 | #elif defined(X86_64) || defined(X32) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 2104 | /* already done by get_regs */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2105 | #elif defined(IA64) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2106 | # define IA64_PSR_IS ((long)1 << 34) |
Denys Vlasenko | 4bdb6bb | 2013-02-06 18:09:31 +0100 | [diff] [blame] | 2107 | long psr; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2108 | if (upeek(tcp->pid, PT_CR_IPSR, &psr) >= 0) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2109 | ia32 = (psr & IA64_PSR_IS) != 0; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2110 | if (upeek(tcp->pid, PT_R8, &ia64_r8) < 0) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2111 | return -1; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2112 | if (upeek(tcp->pid, PT_R10, &ia64_r10) < 0) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2113 | return -1; |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 2114 | #elif defined(ARM) |
| 2115 | /* already done by get_regs */ |
Steve McIntyre | d8d3bd3 | 2012-10-24 17:58:16 +0100 | [diff] [blame] | 2116 | #elif defined(AARCH64) |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 2117 | /* register reading already done by get_regs */ |
| 2118 | |
| 2119 | /* Used to do this, but we did it on syscall entry already: */ |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 2120 | /* We are in 64-bit mode (personality 1) if register struct is aarch64_regs, |
| 2121 | * else it's personality 0. |
| 2122 | */ |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 2123 | /*update_personality(tcp, aarch64_io.iov_len == sizeof(aarch64_regs));*/ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2124 | #elif defined(M68K) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2125 | if (upeek(tcp->pid, 4*PT_D0, &m68k_d0) < 0) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 2126 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2127 | #elif defined(LINUX_MIPSN32) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2128 | unsigned long long regs[38]; |
| 2129 | |
| 2130 | if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0) |
| 2131 | return -1; |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2132 | mips_a3 = regs[REG_A3]; |
| 2133 | mips_r2 = regs[REG_V0]; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2134 | #elif defined(MIPS) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2135 | if (upeek(tcp->pid, REG_A3, &mips_a3) < 0) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2136 | return -1; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2137 | if (upeek(tcp->pid, REG_V0, &mips_r2) < 0) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2138 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2139 | #elif defined(ALPHA) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2140 | if (upeek(tcp->pid, REG_A3, &alpha_a3) < 0) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2141 | return -1; |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2142 | if (upeek(tcp->pid, REG_R0, &alpha_r0) < 0) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2143 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2144 | #elif defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 2145 | /* already done by get_regs */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2146 | #elif defined(HPPA) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2147 | if (upeek(tcp->pid, PT_GR28, &hppa_r28) < 0) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 2148 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2149 | #elif defined(SH) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 2150 | /* new syscall ABI returns result in R0 */ |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2151 | if (upeek(tcp->pid, 4*REG_REG0, (long *)&sh_r0) < 0) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 2152 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2153 | #elif defined(SH64) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 2154 | /* ABI defines result returned in r9 */ |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2155 | if (upeek(tcp->pid, REG_GENERAL(9), (long *)&sh64_r9) < 0) |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 2156 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2157 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2158 | if (upeek(tcp->pid, 4*PT_R10, &cris_r10) < 0) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 2159 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2160 | #elif defined(TILE) |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 2161 | /* already done by get_regs */ |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2162 | #elif defined(MICROBLAZE) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2163 | if (upeek(tcp->pid, 3 * 4, µblaze_r3) < 0) |
Denys Vlasenko | f20bff6 | 2011-08-25 10:31:24 +0200 | [diff] [blame] | 2164 | return -1; |
Christian Svensson | 492f81f | 2013-02-14 13:26:27 +0100 | [diff] [blame] | 2165 | #elif defined(OR1K) |
| 2166 | /* already done by get_regs */ |
James Hogan | 5f999a8 | 2013-02-22 14:44:10 +0000 | [diff] [blame] | 2167 | #elif defined(METAG) |
| 2168 | /* already done by get_regs */ |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 2169 | #elif defined(XTENSA) |
Denys Vlasenko | 752e5a0 | 2013-06-28 14:35:47 +0200 | [diff] [blame] | 2170 | if (upeek(tcp->pid, REG_A_BASE + 2, &xtensa_a2) < 0) |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 2171 | return -1; |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2172 | #endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2173 | return 1; |
| 2174 | } |
| 2175 | |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 2176 | /* Called at each syscall exit */ |
| 2177 | static void |
Denys Vlasenko | 20c41fd | 2011-08-25 10:23:00 +0200 | [diff] [blame] | 2178 | syscall_fixup_on_sysexit(struct tcb *tcp) |
| 2179 | { |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2180 | #if defined(S390) || defined(S390X) |
Denys Vlasenko | 20c41fd | 2011-08-25 10:23:00 +0200 | [diff] [blame] | 2181 | if (syscall_mode != -ENOSYS) |
| 2182 | syscall_mode = tcp->scno; |
Denys Vlasenko | ece9879 | 2011-08-25 10:25:35 +0200 | [diff] [blame] | 2183 | if ((tcp->flags & TCB_WAITEXECVE) |
Denys Vlasenko | 20c41fd | 2011-08-25 10:23:00 +0200 | [diff] [blame] | 2184 | && (gpr2 == -ENOSYS || gpr2 == tcp->scno)) { |
| 2185 | /* |
| 2186 | * Return from execve. |
| 2187 | * Fake a return value of zero. We leave the TCB_WAITEXECVE |
| 2188 | * flag set for the post-execve SIGTRAP to see and reset. |
| 2189 | */ |
| 2190 | gpr2 = 0; |
| 2191 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2192 | #endif |
Denys Vlasenko | 20c41fd | 2011-08-25 10:23:00 +0200 | [diff] [blame] | 2193 | } |
| 2194 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2195 | /* |
| 2196 | * Check the syscall return value register value for whether it is |
| 2197 | * a negated errno code indicating an error, or a success return value. |
| 2198 | */ |
| 2199 | static inline int |
| 2200 | is_negated_errno(unsigned long int val) |
| 2201 | { |
| 2202 | unsigned long int max = -(long int) nerrnos; |
Denys Vlasenko | 2544f98 | 2013-02-19 17:39:56 +0100 | [diff] [blame] | 2203 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 2204 | if (current_wordsize < sizeof(val)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2205 | val = (unsigned int) val; |
| 2206 | max = (unsigned int) max; |
| 2207 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2208 | #endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2209 | return val > max; |
| 2210 | } |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2211 | |
Denys Vlasenko | afea7dd | 2013-02-12 11:52:35 +0100 | [diff] [blame] | 2212 | #if defined(X32) |
| 2213 | static inline int |
| 2214 | is_negated_errno_x32(unsigned long long val) |
| 2215 | { |
| 2216 | unsigned long long max = -(long long) nerrnos; |
| 2217 | /* |
| 2218 | * current_wordsize is 4 even in personality 0 (native X32) |
| 2219 | * but truncation _must not_ be done in it. |
| 2220 | * can't check current_wordsize here! |
| 2221 | */ |
| 2222 | if (current_personality != 0) { |
| 2223 | val = (uint32_t) val; |
| 2224 | max = (uint32_t) max; |
| 2225 | } |
| 2226 | return val > max; |
| 2227 | } |
| 2228 | #endif |
| 2229 | |
Denys Vlasenko | 907735a | 2012-03-21 00:23:16 +0100 | [diff] [blame] | 2230 | /* Returns: |
| 2231 | * 1: ok, continue in trace_syscall_exiting(). |
| 2232 | * -1: error, trace_syscall_exiting() should print error indicator |
| 2233 | * ("????" etc) and bail out. |
| 2234 | */ |
Denys Vlasenko | c956ef0 | 2013-02-16 14:25:56 +0100 | [diff] [blame] | 2235 | static void |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2236 | get_error(struct tcb *tcp) |
| 2237 | { |
| 2238 | int u_error = 0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2239 | int check_errno = 1; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2240 | if (tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2241 | check_errno = 0; |
| 2242 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2243 | #if defined(S390) || defined(S390X) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2244 | if (check_errno && is_negated_errno(gpr2)) { |
| 2245 | tcp->u_rval = -1; |
| 2246 | u_error = -gpr2; |
| 2247 | } |
| 2248 | else { |
| 2249 | tcp->u_rval = gpr2; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2250 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2251 | #elif defined(I386) |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 2252 | if (check_errno && is_negated_errno(i386_regs.eax)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2253 | tcp->u_rval = -1; |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 2254 | u_error = -i386_regs.eax; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2255 | } |
| 2256 | else { |
Denys Vlasenko | eb0e3e8 | 2011-08-30 18:53:49 +0200 | [diff] [blame] | 2257 | tcp->u_rval = i386_regs.eax; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2258 | } |
Denys Vlasenko | afea7dd | 2013-02-12 11:52:35 +0100 | [diff] [blame] | 2259 | #elif defined(X86_64) |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 2260 | long rax; |
| 2261 | if (x86_io.iov_len == sizeof(i386_regs)) { |
| 2262 | /* Sign extend from 32 bits */ |
| 2263 | rax = (int32_t)i386_regs.eax; |
| 2264 | } else { |
| 2265 | rax = x86_64_regs.rax; |
| 2266 | } |
| 2267 | if (check_errno && is_negated_errno(rax)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2268 | tcp->u_rval = -1; |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 2269 | u_error = -rax; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2270 | } |
| 2271 | else { |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 2272 | tcp->u_rval = rax; |
Denys Vlasenko | afea7dd | 2013-02-12 11:52:35 +0100 | [diff] [blame] | 2273 | } |
| 2274 | #elif defined(X32) |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 2275 | /* In X32, return value is 64-bit (llseek uses one). |
| 2276 | * Using merely "long rax" would not work. |
| 2277 | */ |
| 2278 | long long rax; |
| 2279 | if (x86_io.iov_len == sizeof(i386_regs)) { |
| 2280 | /* Sign extend from 32 bits */ |
| 2281 | rax = (int32_t)i386_regs.eax; |
| 2282 | } else { |
| 2283 | rax = x86_64_regs.rax; |
| 2284 | } |
Denys Vlasenko | afea7dd | 2013-02-12 11:52:35 +0100 | [diff] [blame] | 2285 | /* Careful: is_negated_errno() works only on longs */ |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 2286 | if (check_errno && is_negated_errno_x32(rax)) { |
Denys Vlasenko | afea7dd | 2013-02-12 11:52:35 +0100 | [diff] [blame] | 2287 | tcp->u_rval = -1; |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 2288 | u_error = -rax; |
Denys Vlasenko | afea7dd | 2013-02-12 11:52:35 +0100 | [diff] [blame] | 2289 | } |
| 2290 | else { |
Denys Vlasenko | eec8d5d | 2013-02-14 03:29:48 +0100 | [diff] [blame] | 2291 | tcp->u_rval = rax; /* truncating */ |
| 2292 | tcp->u_lrval = rax; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2293 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2294 | #elif defined(IA64) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2295 | if (ia32) { |
| 2296 | int err; |
| 2297 | |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2298 | err = (int)ia64_r8; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2299 | if (check_errno && is_negated_errno(err)) { |
| 2300 | tcp->u_rval = -1; |
| 2301 | u_error = -err; |
| 2302 | } |
| 2303 | else { |
| 2304 | tcp->u_rval = err; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2305 | } |
| 2306 | } else { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2307 | if (check_errno && ia64_r10) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2308 | tcp->u_rval = -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2309 | u_error = ia64_r8; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2310 | } else { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2311 | tcp->u_rval = ia64_r8; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2312 | } |
| 2313 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2314 | #elif defined(MIPS) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2315 | if (check_errno && mips_a3) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2316 | tcp->u_rval = -1; |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2317 | u_error = mips_r2; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2318 | } else { |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2319 | tcp->u_rval = mips_r2; |
H.J. Lu | dd0130b | 2012-04-16 12:16:45 +0200 | [diff] [blame] | 2320 | # if defined(LINUX_MIPSN32) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2321 | tcp->u_lrval = mips_r2; |
H.J. Lu | dd0130b | 2012-04-16 12:16:45 +0200 | [diff] [blame] | 2322 | # endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2323 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2324 | #elif defined(POWERPC) |
Denys Vlasenko | 44a6d04 | 2013-06-28 16:47:38 +0200 | [diff] [blame^] | 2325 | if (check_errno && (ppc_regs.ccr & 0x10000000)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2326 | tcp->u_rval = -1; |
Denys Vlasenko | 44a6d04 | 2013-06-28 16:47:38 +0200 | [diff] [blame^] | 2327 | u_error = ppc_regs.gpr[3]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2328 | } |
| 2329 | else { |
Denys Vlasenko | 44a6d04 | 2013-06-28 16:47:38 +0200 | [diff] [blame^] | 2330 | tcp->u_rval = ppc_regs.gpr[3]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2331 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2332 | #elif defined(M68K) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2333 | if (check_errno && is_negated_errno(m68k_d0)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2334 | tcp->u_rval = -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2335 | u_error = -m68k_d0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2336 | } |
| 2337 | else { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2338 | tcp->u_rval = m68k_d0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2339 | } |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 2340 | #elif defined(ARM) || defined(AARCH64) |
| 2341 | # if defined(AARCH64) |
| 2342 | if (tcp->currpers == 1) { |
| 2343 | if (check_errno && is_negated_errno(aarch64_regs.regs[0])) { |
| 2344 | tcp->u_rval = -1; |
| 2345 | u_error = -aarch64_regs.regs[0]; |
| 2346 | } |
| 2347 | else { |
| 2348 | tcp->u_rval = aarch64_regs.regs[0]; |
| 2349 | } |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2350 | } |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 2351 | else |
Denys Vlasenko | 28ac68f | 2013-02-08 12:38:51 +0100 | [diff] [blame] | 2352 | # endif |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 2353 | { |
Denys Vlasenko | 401374e | 2013-02-06 18:24:39 +0100 | [diff] [blame] | 2354 | if (check_errno && is_negated_errno(arm_regs.ARM_r0)) { |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 2355 | tcp->u_rval = -1; |
Denys Vlasenko | 401374e | 2013-02-06 18:24:39 +0100 | [diff] [blame] | 2356 | u_error = -arm_regs.ARM_r0; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 2357 | } |
| 2358 | else { |
Denys Vlasenko | 401374e | 2013-02-06 18:24:39 +0100 | [diff] [blame] | 2359 | tcp->u_rval = arm_regs.ARM_r0; |
Steve McIntyre | 890a5ca | 2012-11-10 11:24:48 +0000 | [diff] [blame] | 2360 | } |
Steve McIntyre | d8d3bd3 | 2012-10-24 17:58:16 +0100 | [diff] [blame] | 2361 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2362 | #elif defined(AVR32) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2363 | if (check_errno && avr32_regs.r12 && (unsigned) -avr32_regs.r12 < nerrnos) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2364 | tcp->u_rval = -1; |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2365 | u_error = -avr32_regs.r12; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2366 | } |
| 2367 | else { |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2368 | tcp->u_rval = avr32_regs.r12; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2369 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2370 | #elif defined(BFIN) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2371 | if (check_errno && is_negated_errno(bfin_r0)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2372 | tcp->u_rval = -1; |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2373 | u_error = -bfin_r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2374 | } else { |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2375 | tcp->u_rval = bfin_r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2376 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2377 | #elif defined(ALPHA) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2378 | if (check_errno && alpha_a3) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2379 | tcp->u_rval = -1; |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2380 | u_error = alpha_r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2381 | } |
| 2382 | else { |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2383 | tcp->u_rval = alpha_r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2384 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2385 | #elif defined(SPARC) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2386 | if (check_errno && sparc_regs.psr & PSR_C) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2387 | tcp->u_rval = -1; |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2388 | u_error = sparc_regs.u_regs[U_REG_O0]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2389 | } |
| 2390 | else { |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2391 | tcp->u_rval = sparc_regs.u_regs[U_REG_O0]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2392 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2393 | #elif defined(SPARC64) |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2394 | if (check_errno && sparc_regs.tstate & 0x1100000000UL) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2395 | tcp->u_rval = -1; |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2396 | u_error = sparc_regs.u_regs[U_REG_O0]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2397 | } |
| 2398 | else { |
Denys Vlasenko | 48e4c1b | 2013-02-16 08:23:40 +0100 | [diff] [blame] | 2399 | tcp->u_rval = sparc_regs.u_regs[U_REG_O0]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2400 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2401 | #elif defined(HPPA) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2402 | if (check_errno && is_negated_errno(hppa_r28)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2403 | tcp->u_rval = -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2404 | u_error = -hppa_r28; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2405 | } |
| 2406 | else { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2407 | tcp->u_rval = hppa_r28; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2408 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2409 | #elif defined(SH) |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2410 | if (check_errno && is_negated_errno(sh_r0)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2411 | tcp->u_rval = -1; |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2412 | u_error = -sh_r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2413 | } |
| 2414 | else { |
Denys Vlasenko | d22213a | 2013-02-13 17:52:31 +0100 | [diff] [blame] | 2415 | tcp->u_rval = sh_r0; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2416 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2417 | #elif defined(SH64) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2418 | if (check_errno && is_negated_errno(sh64_r9)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2419 | tcp->u_rval = -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2420 | u_error = -sh64_r9; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2421 | } |
| 2422 | else { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2423 | tcp->u_rval = sh64_r9; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2424 | } |
James Hogan | 5f999a8 | 2013-02-22 14:44:10 +0000 | [diff] [blame] | 2425 | #elif defined(METAG) |
| 2426 | /* result pointer in D0Re0 (D0.0) */ |
| 2427 | if (check_errno && is_negated_errno(metag_regs.dx[0][0])) { |
| 2428 | tcp->u_rval = -1; |
| 2429 | u_error = -metag_regs.dx[0][0]; |
| 2430 | } |
| 2431 | else { |
| 2432 | tcp->u_rval = metag_regs.dx[0][0]; |
| 2433 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2434 | #elif defined(CRISV10) || defined(CRISV32) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2435 | if (check_errno && cris_r10 && (unsigned) -cris_r10 < nerrnos) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2436 | tcp->u_rval = -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2437 | u_error = -cris_r10; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2438 | } |
| 2439 | else { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2440 | tcp->u_rval = cris_r10; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2441 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2442 | #elif defined(TILE) |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 2443 | /* |
| 2444 | * The standard tile calling convention returns the value (or negative |
| 2445 | * errno) in r0, and zero (or positive errno) in r1. |
| 2446 | * Until at least kernel 3.8, however, the r1 value is not reflected |
| 2447 | * in ptregs at this point, so we use r0 here. |
| 2448 | */ |
| 2449 | if (check_errno && is_negated_errno(tile_regs.regs[0])) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2450 | tcp->u_rval = -1; |
Chris Metcalf | 0b99a8a | 2013-02-05 17:48:33 +0100 | [diff] [blame] | 2451 | u_error = -tile_regs.regs[0]; |
| 2452 | } else { |
| 2453 | tcp->u_rval = tile_regs.regs[0]; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2454 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2455 | #elif defined(MICROBLAZE) |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2456 | if (check_errno && is_negated_errno(microblaze_r3)) { |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2457 | tcp->u_rval = -1; |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2458 | u_error = -microblaze_r3; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2459 | } |
| 2460 | else { |
Denys Vlasenko | 89804ec | 2013-02-07 13:14:48 +0100 | [diff] [blame] | 2461 | tcp->u_rval = microblaze_r3; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2462 | } |
Christian Svensson | 492f81f | 2013-02-14 13:26:27 +0100 | [diff] [blame] | 2463 | #elif defined(OR1K) |
| 2464 | if (check_errno && is_negated_errno(or1k_regs.gpr[11])) { |
| 2465 | tcp->u_rval = -1; |
| 2466 | u_error = -or1k_regs.gpr[11]; |
| 2467 | } |
| 2468 | else { |
| 2469 | tcp->u_rval = or1k_regs.gpr[11]; |
| 2470 | } |
Chris Zankel | 8f636ed | 2013-03-25 10:22:07 -0700 | [diff] [blame] | 2471 | #elif defined(XTENSA) |
| 2472 | if (check_errno && is_negated_errno(xtensa_a2)) { |
| 2473 | tcp->u_rval = -1; |
| 2474 | u_error = -xtensa_a2; |
| 2475 | } |
| 2476 | else { |
| 2477 | tcp->u_rval = xtensa_a2; |
| 2478 | } |
Denys Vlasenko | 523635f | 2012-02-25 02:44:25 +0100 | [diff] [blame] | 2479 | #endif |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2480 | tcp->u_error = u_error; |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | static void |
| 2484 | dumpio(struct tcb *tcp) |
| 2485 | { |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2486 | int (*func)(); |
| 2487 | |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2488 | if (syserror(tcp)) |
| 2489 | return; |
Denys Vlasenko | 9cbc15b | 2013-02-22 13:37:36 +0100 | [diff] [blame] | 2490 | if ((unsigned long) tcp->u_arg[0] >= num_quals) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2491 | return; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2492 | func = tcp->s_ent->sys_func; |
| 2493 | if (func == printargs) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2494 | return; |
| 2495 | if (qual_flags[tcp->u_arg[0]] & QUAL_READ) { |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2496 | if (func == sys_read || |
| 2497 | func == sys_pread || |
| 2498 | func == sys_recv || |
| 2499 | func == sys_recvfrom) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2500 | dumpstr(tcp, tcp->u_arg[1], tcp->u_rval); |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2501 | else if (func == sys_readv) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2502 | dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
| 2503 | return; |
| 2504 | } |
| 2505 | if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) { |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2506 | if (func == sys_write || |
| 2507 | func == sys_pwrite || |
| 2508 | func == sys_send || |
| 2509 | func == sys_sendto) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2510 | dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2511 | else if (func == sys_writev) |
Denys Vlasenko | a614692 | 2011-08-24 18:07:22 +0200 | [diff] [blame] | 2512 | dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
| 2513 | return; |
| 2514 | } |
| 2515 | } |
| 2516 | |
Denys Vlasenko | ed4f4f0 | 2011-08-22 11:54:06 +0200 | [diff] [blame] | 2517 | static int |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2518 | trace_syscall_exiting(struct tcb *tcp) |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 2519 | { |
| 2520 | int sys_res; |
| 2521 | struct timeval tv; |
Denys Vlasenko | 1a5b5a7 | 2011-08-25 00:29:56 +0200 | [diff] [blame] | 2522 | int res; |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2523 | long u_error; |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 2524 | |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2525 | /* Measure the exit time as early as possible to avoid errors. */ |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 2526 | if (Tflag || cflag) |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2527 | gettimeofday(&tv, NULL); |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 2528 | |
Dmitry V. Levin | a5a839a | 2011-12-23 00:50:49 +0000 | [diff] [blame] | 2529 | #if SUPPORTED_PERSONALITIES > 1 |
| 2530 | update_personality(tcp, tcp->currpers); |
| 2531 | #endif |
Denys Vlasenko | ce7d953 | 2013-02-05 16:36:13 +0100 | [diff] [blame] | 2532 | res = (get_regs_error ? -1 : get_syscall_result(tcp)); |
Denys Vlasenko | bb6bb5c | 2012-03-20 17:10:35 +0100 | [diff] [blame] | 2533 | if (res == 1) { |
| 2534 | syscall_fixup_on_sysexit(tcp); /* never fails */ |
Denys Vlasenko | c956ef0 | 2013-02-16 14:25:56 +0100 | [diff] [blame] | 2535 | get_error(tcp); /* never fails */ |
| 2536 | if (need_fork_exec_workarounds) |
| 2537 | syscall_fixup_for_fork_exec(tcp); |
Denys Vlasenko | 2a3d275 | 2013-05-14 16:07:46 +0200 | [diff] [blame] | 2538 | if (filtered(tcp) || hide_log_until_execve) |
Denys Vlasenko | c956ef0 | 2013-02-16 14:25:56 +0100 | [diff] [blame] | 2539 | goto ret; |
Pavel Machek | 4dc3b14 | 2000-02-01 17:58:41 +0000 | [diff] [blame] | 2540 | } |
| 2541 | |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2542 | if (cflag) { |
| 2543 | struct timeval t = tv; |
Denys Vlasenko | c95a88f | 2011-08-21 17:47:40 +0200 | [diff] [blame] | 2544 | count_syscall(tcp, &t); |
Denys Vlasenko | 7b609d5 | 2011-06-22 14:32:43 +0200 | [diff] [blame] | 2545 | if (cflag == CFLAG_ONLY_STATS) { |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2546 | goto ret; |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2547 | } |
| 2548 | } |
| 2549 | |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2550 | /* If not in -ff mode, and printing_tcp != tcp, |
| 2551 | * then the log currently does not end with output |
| 2552 | * of _our syscall entry_, but with something else. |
| 2553 | * We need to say which syscall's return is this. |
| 2554 | * |
| 2555 | * Forced reprinting via TCB_REPRINT is used only by |
| 2556 | * "strace -ff -oLOG test/threaded_execve" corner case. |
| 2557 | * It's the only case when -ff mode needs reprinting. |
| 2558 | */ |
| 2559 | if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) { |
| 2560 | tcp->flags &= ~TCB_REPRINT; |
| 2561 | printleader(tcp); |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2562 | if (tcp->qual_flg & UNDEFINED_SCNO) |
Denys Vlasenko | 7270de5 | 2013-02-21 15:46:34 +0100 | [diff] [blame] | 2563 | tprintf("<... %s resumed> ", undefined_scno_name(tcp)); |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2564 | else |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2565 | tprintf("<... %s resumed> ", tcp->s_ent->sys_name); |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2566 | } |
| 2567 | printing_tcp = tcp; |
| 2568 | |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2569 | if (res != 1) { |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2570 | /* There was error in one of prior ptrace ops */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 2571 | tprints(") "); |
Denys Vlasenko | 102ec49 | 2011-08-25 01:27:59 +0200 | [diff] [blame] | 2572 | tabto(); |
Denys Vlasenko | 000b601 | 2012-01-28 01:25:03 +0100 | [diff] [blame] | 2573 | tprints("= ? <unavailable>\n"); |
Denys Vlasenko | 7de265d | 2012-03-13 11:44:31 +0100 | [diff] [blame] | 2574 | line_ended(); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2575 | tcp->flags &= ~TCB_INSYSCALL; |
| 2576 | return res; |
| 2577 | } |
| 2578 | |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2579 | sys_res = 0; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2580 | if (tcp->qual_flg & QUAL_RAW) { |
Denys Vlasenko | a44f969 | 2012-03-21 11:06:20 +0100 | [diff] [blame] | 2581 | /* sys_res = printargs(tcp); - but it's nop on sysexit */ |
Denys Vlasenko | 7de265d | 2012-03-13 11:44:31 +0100 | [diff] [blame] | 2582 | } else { |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2583 | /* FIXME: not_failing_only (IOW, option -z) is broken: |
| 2584 | * failure of syscall is known only after syscall return. |
| 2585 | * Thus we end up with something like this on, say, ENOENT: |
| 2586 | * open("doesnt_exist", O_RDONLY <unfinished ...> |
| 2587 | * {next syscall decode} |
| 2588 | * whereas the intended result is that open(...) line |
| 2589 | * is not shown at all. |
| 2590 | */ |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2591 | if (not_failing_only && tcp->u_error) |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2592 | goto ret; /* ignore failed syscalls */ |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2593 | sys_res = tcp->s_ent->sys_func(tcp); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2594 | } |
| 2595 | |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 2596 | tprints(") "); |
Denys Vlasenko | 102ec49 | 2011-08-25 01:27:59 +0200 | [diff] [blame] | 2597 | tabto(); |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2598 | u_error = tcp->u_error; |
Denys Vlasenko | 74ec14f | 2013-02-21 16:13:47 +0100 | [diff] [blame] | 2599 | if (tcp->qual_flg & QUAL_RAW) { |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2600 | if (u_error) |
| 2601 | tprintf("= -1 (errno %ld)", u_error); |
| 2602 | else |
| 2603 | tprintf("= %#lx", tcp->u_rval); |
| 2604 | } |
| 2605 | else if (!(sys_res & RVAL_NONE) && u_error) { |
| 2606 | switch (u_error) { |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2607 | /* Blocked signals do not interrupt any syscalls. |
| 2608 | * In this case syscalls don't return ERESTARTfoo codes. |
| 2609 | * |
| 2610 | * Deadly signals set to SIG_DFL interrupt syscalls |
| 2611 | * and kill the process regardless of which of the codes below |
| 2612 | * is returned by the interrupted syscall. |
| 2613 | * In some cases, kernel forces a kernel-generated deadly |
| 2614 | * signal to be unblocked and set to SIG_DFL (and thus cause |
| 2615 | * death) if it is blocked or SIG_IGNed: for example, SIGSEGV |
| 2616 | * or SIGILL. (The alternative is to leave process spinning |
| 2617 | * forever on the faulty instruction - not useful). |
| 2618 | * |
| 2619 | * SIG_IGNed signals and non-deadly signals set to SIG_DFL |
| 2620 | * (for example, SIGCHLD, SIGWINCH) interrupt syscalls, |
| 2621 | * but kernel will always restart them. |
| 2622 | */ |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2623 | case ERESTARTSYS: |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2624 | /* Most common type of signal-interrupted syscall exit code. |
| 2625 | * The system call will be restarted with the same arguments |
| 2626 | * if SA_RESTART is set; otherwise, it will fail with EINTR. |
| 2627 | */ |
| 2628 | tprints("= ? ERESTARTSYS (To be restarted if SA_RESTART is set)"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2629 | break; |
| 2630 | case ERESTARTNOINTR: |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2631 | /* Rare. For example, fork() returns this if interrupted. |
| 2632 | * SA_RESTART is ignored (assumed set): the restart is unconditional. |
| 2633 | */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 2634 | tprints("= ? ERESTARTNOINTR (To be restarted)"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2635 | break; |
| 2636 | case ERESTARTNOHAND: |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2637 | /* pause(), rt_sigsuspend() etc use this code. |
| 2638 | * SA_RESTART is ignored (assumed not set): |
| 2639 | * syscall won't restart (will return EINTR instead) |
Denys Vlasenko | 30c0323 | 2013-02-19 16:59:26 +0100 | [diff] [blame] | 2640 | * even after signal with SA_RESTART set. However, |
| 2641 | * after SIG_IGN or SIG_DFL signal it will restart |
| 2642 | * (thus the name "restart only if has no handler"). |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2643 | */ |
Denys Vlasenko | aba6292 | 2013-03-05 16:56:35 +0100 | [diff] [blame] | 2644 | tprints("= ? ERESTARTNOHAND (To be restarted if no handler)"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2645 | break; |
| 2646 | case ERESTART_RESTARTBLOCK: |
Denys Vlasenko | fe58565 | 2012-01-12 11:26:34 +0100 | [diff] [blame] | 2647 | /* Syscalls like nanosleep(), poll() which can't be |
| 2648 | * restarted with their original arguments use this |
| 2649 | * code. Kernel will execute restart_syscall() instead, |
| 2650 | * which changes arguments before restarting syscall. |
| 2651 | * SA_RESTART is ignored (assumed not set) similarly |
| 2652 | * to ERESTARTNOHAND. (Kernel can't honor SA_RESTART |
| 2653 | * since restart data is saved in "restart block" |
| 2654 | * in task struct, and if signal handler uses a syscall |
| 2655 | * which in turn saves another such restart block, |
| 2656 | * old data is lost and restart becomes impossible) |
| 2657 | */ |
| 2658 | tprints("= ? ERESTART_RESTARTBLOCK (Interrupted by signal)"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2659 | break; |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2660 | default: |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2661 | if (u_error < 0) |
Denys Vlasenko | a794974 | 2011-08-21 17:26:55 +0200 | [diff] [blame] | 2662 | tprintf("= -1 E??? (errno %ld)", u_error); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2663 | else if (u_error < nerrnos) |
Denys Vlasenko | a794974 | 2011-08-21 17:26:55 +0200 | [diff] [blame] | 2664 | tprintf("= -1 %s (%s)", errnoent[u_error], |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2665 | strerror(u_error)); |
| 2666 | else |
Denys Vlasenko | a794974 | 2011-08-21 17:26:55 +0200 | [diff] [blame] | 2667 | tprintf("= -1 ERRNO_%ld (%s)", u_error, |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2668 | strerror(u_error)); |
| 2669 | break; |
| 2670 | } |
| 2671 | if ((sys_res & RVAL_STR) && tcp->auxstr) |
| 2672 | tprintf(" (%s)", tcp->auxstr); |
| 2673 | } |
| 2674 | else { |
| 2675 | if (sys_res & RVAL_NONE) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 2676 | tprints("= ?"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2677 | else { |
| 2678 | switch (sys_res & RVAL_MASK) { |
| 2679 | case RVAL_HEX: |
| 2680 | tprintf("= %#lx", tcp->u_rval); |
| 2681 | break; |
| 2682 | case RVAL_OCTAL: |
| 2683 | tprintf("= %#lo", tcp->u_rval); |
| 2684 | break; |
| 2685 | case RVAL_UDECIMAL: |
| 2686 | tprintf("= %lu", tcp->u_rval); |
| 2687 | break; |
| 2688 | case RVAL_DECIMAL: |
| 2689 | tprintf("= %ld", tcp->u_rval); |
| 2690 | break; |
H.J. Lu | dd0130b | 2012-04-16 12:16:45 +0200 | [diff] [blame] | 2691 | #if defined(LINUX_MIPSN32) || defined(X32) |
| 2692 | /* |
| 2693 | case RVAL_LHEX: |
| 2694 | tprintf("= %#llx", tcp->u_lrval); |
| 2695 | break; |
| 2696 | case RVAL_LOCTAL: |
| 2697 | tprintf("= %#llo", tcp->u_lrval); |
| 2698 | break; |
| 2699 | */ |
| 2700 | case RVAL_LUDECIMAL: |
| 2701 | tprintf("= %llu", tcp->u_lrval); |
| 2702 | break; |
| 2703 | /* |
| 2704 | case RVAL_LDECIMAL: |
| 2705 | tprintf("= %lld", tcp->u_lrval); |
| 2706 | break; |
| 2707 | */ |
| 2708 | #endif |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2709 | default: |
| 2710 | fprintf(stderr, |
| 2711 | "invalid rval format\n"); |
| 2712 | break; |
| 2713 | } |
| 2714 | } |
| 2715 | if ((sys_res & RVAL_STR) && tcp->auxstr) |
| 2716 | tprintf(" (%s)", tcp->auxstr); |
| 2717 | } |
Denys Vlasenko | a50d2a8 | 2012-03-15 12:49:52 +0100 | [diff] [blame] | 2718 | if (Tflag) { |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2719 | tv_sub(&tv, &tv, &tcp->etime); |
| 2720 | tprintf(" <%ld.%06ld>", |
| 2721 | (long) tv.tv_sec, (long) tv.tv_usec); |
| 2722 | } |
Denys Vlasenko | 000b601 | 2012-01-28 01:25:03 +0100 | [diff] [blame] | 2723 | tprints("\n"); |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2724 | dumpio(tcp); |
Denys Vlasenko | 7de265d | 2012-03-13 11:44:31 +0100 | [diff] [blame] | 2725 | line_ended(); |
| 2726 | |
Denys Vlasenko | 3b73881 | 2011-08-22 02:06:35 +0200 | [diff] [blame] | 2727 | ret: |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2728 | tcp->flags &= ~TCB_INSYSCALL; |
| 2729 | return 0; |
| 2730 | } |
| 2731 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 2732 | int |
Dmitry V. Levin | 7d7c963 | 2010-03-29 17:51:02 +0000 | [diff] [blame] | 2733 | trace_syscall(struct tcb *tcp) |
| 2734 | { |
| 2735 | return exiting(tcp) ? |
| 2736 | trace_syscall_exiting(tcp) : trace_syscall_entering(tcp); |
| 2737 | } |