blob: 6753f2dea12d2e3ad7964dcec9468cc848179f7e [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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 Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * 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 Akkerman76baf7c1999-02-19 00:21:36 +00009 * 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 Akkerman76baf7c1999-02-19 00:21:36 +000032 */
33
34#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035#include <sys/param.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036
Dmitry V. Levin5503dd22015-02-13 02:12:14 +000037/* for struct iovec */
38#include <sys/uio.h>
Maarten ter Huurne40c174b2014-10-20 01:02:48 +020039
Dmitry V. Levin7211dbc2015-02-28 12:20:21 +000040#include "regs.h"
Dmitry V. Levinfadf3792015-02-13 00:26:38 +000041#include "ptrace.h"
Wichert Akkerman15dea971999-10-06 13:06:34 +000042
Denys Vlasenko84703742012-02-25 02:38:52 +010043#if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000044# undef PTRACE_GETREGS
45# define PTRACE_GETREGS PTRACE_GETREGS64
46# undef PTRACE_SETREGS
47# define PTRACE_SETREGS PTRACE_SETREGS64
Denys Vlasenko84703742012-02-25 02:38:52 +010048#endif
Roland McGrath6d1a65c2004-07-12 07:44:08 +000049
Dmitry V. Levin5503dd22015-02-13 02:12:14 +000050#if defined SPARC64
51# include <asm/psrcompat.h>
52#elif defined SPARC
53# include <asm/psr.h>
Denys Vlasenkoeec8d5d2013-02-14 03:29:48 +010054#endif
55
Dmitry V. Levin48f08902015-03-05 23:30:02 +000056#ifdef IA64
57# include <asm/rse.h>
58#endif
59
Dmitry V. Levin4c3f2ae2015-02-13 22:53:00 +000060#ifndef NT_PRSTATUS
61# define NT_PRSTATUS 1
62#endif
63
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000064#ifndef NSIG
Denys Vlasenko523635f2012-02-25 02:44:25 +010065# warning: NSIG is not defined, using 32
66# define NSIG 32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000067#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000068
69#include "syscall.h"
70
71/* Define these shorthand notations to simplify the syscallent files. */
Roland McGrath2fe7b132005-07-05 03:25:35 +000072#define TD TRACE_DESC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073#define TF TRACE_FILE
74#define TI TRACE_IPC
75#define TN TRACE_NETWORK
76#define TP TRACE_PROCESS
77#define TS TRACE_SIGNAL
Namhyung Kim96792962012-10-24 11:41:57 +090078#define TM TRACE_MEMORY
Dmitry V. Levin50a218d2011-01-18 17:36:20 +000079#define NF SYSCALL_NEVER_FAILS
Denys Vlasenkoac1ce772011-08-23 13:24:17 +020080#define MA MAX_ARGS
Masatake YAMATO1d78d222014-04-16 15:33:11 +090081#define SI STACKTRACE_INVALIDATE_CACHE
82#define SE STACKTRACE_CAPTURE_ON_ENTER
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000083
Elvira Khabirova28e32df2015-07-10 22:24:54 +030084#define SEN_NAME(syscall_name) SEN_ ## syscall_name
85#define SEN(syscall_name) SEN_NAME(syscall_name), SYS_FUNC_NAME(syscall_name)
Elvira Khabirova140ecf82015-07-10 22:24:48 +030086
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +010087const struct_sysent sysent0[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000088#include "syscallent.h"
89};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000090
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010091#if SUPPORTED_PERSONALITIES > 1
92static const struct_sysent sysent1[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +010093# include "syscallent1.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000094};
Denys Vlasenko39fca622011-08-20 02:12:33 +020095#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000096
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010097#if SUPPORTED_PERSONALITIES > 2
98static const struct_sysent sysent2[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +010099# include "syscallent2.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000100};
Denys Vlasenko39fca622011-08-20 02:12:33 +0200101#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000102
103/* Now undef them since short defines cause wicked namespace pollution. */
Elvira Khabirova140ecf82015-07-10 22:24:48 +0300104#undef SEN
Elvira Khabirova28e32df2015-07-10 22:24:54 +0300105#undef SEN_NAME
Roland McGrath2fe7b132005-07-05 03:25:35 +0000106#undef TD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000107#undef TF
108#undef TI
109#undef TN
110#undef TP
111#undef TS
Namhyung Kim96792962012-10-24 11:41:57 +0900112#undef TM
Dmitry V. Levin50a218d2011-01-18 17:36:20 +0000113#undef NF
Denys Vlasenkoac1ce772011-08-23 13:24:17 +0200114#undef MA
Masatake YAMATO1d78d222014-04-16 15:33:11 +0900115#undef SI
116#undef SE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000117
Denys Vlasenko39fca622011-08-20 02:12:33 +0200118/*
Dmitry V. Levindf7aa2b2015-01-19 17:02:16 +0000119 * `ioctlent[012].h' files are automatically generated by the auxiliary
Denys Vlasenko39fca622011-08-20 02:12:33 +0200120 * program `ioctlsort', such that the list is sorted by the `code' field.
121 * This has the side-effect of resolving the _IO.. macros into
122 * plain integers, eliminating the need to include here everything
123 * in "/usr/include".
124 */
125
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100126const char *const errnoent0[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000127#include "errnoent.h"
128};
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100129const char *const signalent0[] = {
Denys Vlasenko39fca622011-08-20 02:12:33 +0200130#include "signalent.h"
131};
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100132const struct_ioctlent ioctlent0[] = {
Dmitry V. Levindf7aa2b2015-01-19 17:02:16 +0000133#include "ioctlent0.h"
Denys Vlasenko39fca622011-08-20 02:12:33 +0200134};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000135
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100136#if SUPPORTED_PERSONALITIES > 1
Roland McGrathee36ce12004-09-04 03:53:10 +0000137static const char *const errnoent1[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +0100138# include "errnoent1.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000139};
Denys Vlasenko39fca622011-08-20 02:12:33 +0200140static const char *const signalent1[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +0100141# include "signalent1.h"
Denys Vlasenko39fca622011-08-20 02:12:33 +0200142};
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100143static const struct_ioctlent ioctlent1[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +0100144# include "ioctlent1.h"
Denys Vlasenko39fca622011-08-20 02:12:33 +0200145};
Denys Vlasenko39fca622011-08-20 02:12:33 +0200146#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000147
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100148#if SUPPORTED_PERSONALITIES > 2
Roland McGrathee36ce12004-09-04 03:53:10 +0000149static const char *const errnoent2[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +0100150# include "errnoent2.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151};
Denys Vlasenko39fca622011-08-20 02:12:33 +0200152static const char *const signalent2[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +0100153# include "signalent2.h"
Denys Vlasenko39fca622011-08-20 02:12:33 +0200154};
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100155static const struct_ioctlent ioctlent2[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +0100156# include "ioctlent2.h"
Denys Vlasenko39fca622011-08-20 02:12:33 +0200157};
Denys Vlasenko39fca622011-08-20 02:12:33 +0200158#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159
Dmitry V. Levine6f55242013-02-26 22:02:30 +0000160enum {
161 nsyscalls0 = ARRAY_SIZE(sysent0)
162#if SUPPORTED_PERSONALITIES > 1
163 , nsyscalls1 = ARRAY_SIZE(sysent1)
164# if SUPPORTED_PERSONALITIES > 2
165 , nsyscalls2 = ARRAY_SIZE(sysent2)
166# endif
167#endif
168};
169
170enum {
171 nerrnos0 = ARRAY_SIZE(errnoent0)
172#if SUPPORTED_PERSONALITIES > 1
173 , nerrnos1 = ARRAY_SIZE(errnoent1)
174# if SUPPORTED_PERSONALITIES > 2
175 , nerrnos2 = ARRAY_SIZE(errnoent2)
176# endif
177#endif
178};
179
180enum {
181 nsignals0 = ARRAY_SIZE(signalent0)
182#if SUPPORTED_PERSONALITIES > 1
183 , nsignals1 = ARRAY_SIZE(signalent1)
184# if SUPPORTED_PERSONALITIES > 2
185 , nsignals2 = ARRAY_SIZE(signalent2)
186# endif
187#endif
188};
189
190enum {
191 nioctlents0 = ARRAY_SIZE(ioctlent0)
192#if SUPPORTED_PERSONALITIES > 1
193 , nioctlents1 = ARRAY_SIZE(ioctlent1)
194# if SUPPORTED_PERSONALITIES > 2
195 , nioctlents2 = ARRAY_SIZE(ioctlent2)
196# endif
197#endif
198};
199
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100200#if SUPPORTED_PERSONALITIES > 1
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100201const struct_sysent *sysent = sysent0;
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100202const char *const *errnoent = errnoent0;
203const char *const *signalent = signalent0;
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100204const struct_ioctlent *ioctlent = ioctlent0;
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100205#endif
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100206unsigned nsyscalls = nsyscalls0;
207unsigned nerrnos = nerrnos0;
208unsigned nsignals = nsignals0;
209unsigned nioctlents = nioctlents0;
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100210
211unsigned num_quals;
212qualbits_t *qual_vec[SUPPORTED_PERSONALITIES];
213
214static const unsigned nsyscall_vec[SUPPORTED_PERSONALITIES] = {
215 nsyscalls0,
216#if SUPPORTED_PERSONALITIES > 1
217 nsyscalls1,
218#endif
219#if SUPPORTED_PERSONALITIES > 2
220 nsyscalls2,
221#endif
222};
223static const struct_sysent *const sysent_vec[SUPPORTED_PERSONALITIES] = {
224 sysent0,
225#if SUPPORTED_PERSONALITIES > 1
226 sysent1,
227#endif
228#if SUPPORTED_PERSONALITIES > 2
229 sysent2,
230#endif
231};
232
233enum {
234 MAX_NSYSCALLS1 = (nsyscalls0
235#if SUPPORTED_PERSONALITIES > 1
236 > nsyscalls1 ? nsyscalls0 : nsyscalls1
237#endif
238 ),
239 MAX_NSYSCALLS2 = (MAX_NSYSCALLS1
240#if SUPPORTED_PERSONALITIES > 2
241 > nsyscalls2 ? MAX_NSYSCALLS1 : nsyscalls2
242#endif
243 ),
244 MAX_NSYSCALLS = MAX_NSYSCALLS2,
245 /* We are ready for arches with up to 255 signals,
246 * even though the largest known signo is on MIPS and it is 128.
247 * The number of existing syscalls on all arches is
248 * larger that 255 anyway, so it is just a pedantic matter.
249 */
250 MIN_QUALS = MAX_NSYSCALLS > 255 ? MAX_NSYSCALLS : 255
251};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000252
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100253#if SUPPORTED_PERSONALITIES > 1
Denys Vlasenkoae8643e2013-02-15 14:55:14 +0100254unsigned current_personality;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255
Denys Vlasenkoae8643e2013-02-15 14:55:14 +0100256# ifndef current_wordsize
257unsigned current_wordsize;
258static const int personality_wordsize[SUPPORTED_PERSONALITIES] = {
Roland McGrath4b2dcca2006-01-12 10:18:53 +0000259 PERSONALITY0_WORDSIZE,
Roland McGrath4b2dcca2006-01-12 10:18:53 +0000260 PERSONALITY1_WORDSIZE,
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100261# if SUPPORTED_PERSONALITIES > 2
Roland McGrath4b2dcca2006-01-12 10:18:53 +0000262 PERSONALITY2_WORDSIZE,
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100263# endif
Denys Vlasenko5c774b22011-08-20 01:50:09 +0200264};
Denys Vlasenkoae8643e2013-02-15 14:55:14 +0100265# endif
Roland McGrath4b2dcca2006-01-12 10:18:53 +0000266
Denys Vlasenko5c774b22011-08-20 01:50:09 +0200267void
Dmitry V. Levin3abe8b22006-12-20 22:37:21 +0000268set_personality(int personality)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000269{
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100270 nsyscalls = nsyscall_vec[personality];
271 sysent = sysent_vec[personality];
272
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000273 switch (personality) {
274 case 0:
275 errnoent = errnoent0;
276 nerrnos = nerrnos0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277 ioctlent = ioctlent0;
278 nioctlents = nioctlents0;
279 signalent = signalent0;
280 nsignals = nsignals0;
281 break;
282
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000283 case 1:
284 errnoent = errnoent1;
285 nerrnos = nerrnos1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000286 ioctlent = ioctlent1;
287 nioctlents = nioctlents1;
288 signalent = signalent1;
289 nsignals = nsignals1;
290 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100292# if SUPPORTED_PERSONALITIES > 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000293 case 2:
294 errnoent = errnoent2;
295 nerrnos = nerrnos2;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000296 ioctlent = ioctlent2;
297 nioctlents = nioctlents2;
298 signalent = signalent2;
299 nsignals = nsignals2;
300 break;
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100301# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000302 }
303
304 current_personality = personality;
Denys Vlasenkoae8643e2013-02-15 14:55:14 +0100305# ifndef current_wordsize
306 current_wordsize = personality_wordsize[personality];
307# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000308}
309
Dmitry V. Levina5a839a2011-12-23 00:50:49 +0000310static void
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000311update_personality(struct tcb *tcp, unsigned int personality)
Dmitry V. Levina5a839a2011-12-23 00:50:49 +0000312{
313 if (personality == current_personality)
314 return;
315 set_personality(personality);
316
317 if (personality == tcp->currpers)
318 return;
319 tcp->currpers = personality;
320
Dmitry V. Levin6c8ef052015-05-25 22:51:19 +0000321# undef PERSONALITY_NAMES
322# if defined POWERPC64
323# define PERSONALITY_NAMES {"64 bit", "32 bit"}
324# elif defined X86_64
325# define PERSONALITY_NAMES {"64 bit", "32 bit", "x32"}
326# elif defined X32
327# define PERSONALITY_NAMES {"x32", "32 bit"}
328# elif defined AARCH64
329# define PERSONALITY_NAMES {"32-bit", "AArch64"}
330# elif defined TILE
331# define PERSONALITY_NAMES {"64-bit", "32-bit"}
332# endif
333# ifdef PERSONALITY_NAMES
Dmitry V. Levina5a839a2011-12-23 00:50:49 +0000334 if (!qflag) {
Dmitry V. Levin6c8ef052015-05-25 22:51:19 +0000335 static const char *const names[] = PERSONALITY_NAMES;
336 error_msg("[ Process PID=%d runs in %s mode. ]",
337 tcp->pid, names[personality]);
Chris Metcalf0b99a8a2013-02-05 17:48:33 +0100338 }
Denys Vlasenko523635f2012-02-25 02:44:25 +0100339# endif
Dmitry V. Levina5a839a2011-12-23 00:50:49 +0000340}
341#endif
Roland McGrathe10e62a2004-09-04 04:20:43 +0000342
Denys Vlasenkoc1540fe2013-02-21 16:17:08 +0100343static int qual_syscall(), qual_signal(), qual_desc();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344
Roland McGrathe10e62a2004-09-04 04:20:43 +0000345static const struct qual_options {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000346 unsigned int bitflag;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000347 const char *option_name;
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000348 int (*qualify)(const char *, int, int);
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000349 const char *argument_name;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000350} qual_options[] = {
Roland McGrath9797ceb2002-12-30 10:23:00 +0000351 { QUAL_TRACE, "trace", qual_syscall, "system call" },
352 { QUAL_TRACE, "t", qual_syscall, "system call" },
353 { QUAL_ABBREV, "abbrev", qual_syscall, "system call" },
354 { QUAL_ABBREV, "a", qual_syscall, "system call" },
355 { QUAL_VERBOSE, "verbose", qual_syscall, "system call" },
356 { QUAL_VERBOSE, "v", qual_syscall, "system call" },
357 { QUAL_RAW, "raw", qual_syscall, "system call" },
358 { QUAL_RAW, "x", qual_syscall, "system call" },
359 { QUAL_SIGNAL, "signal", qual_signal, "signal" },
360 { QUAL_SIGNAL, "signals", qual_signal, "signal" },
361 { QUAL_SIGNAL, "s", qual_signal, "signal" },
Roland McGrath9797ceb2002-12-30 10:23:00 +0000362 { QUAL_READ, "read", qual_desc, "descriptor" },
363 { QUAL_READ, "reads", qual_desc, "descriptor" },
364 { QUAL_READ, "r", qual_desc, "descriptor" },
365 { QUAL_WRITE, "write", qual_desc, "descriptor" },
366 { QUAL_WRITE, "writes", qual_desc, "descriptor" },
367 { QUAL_WRITE, "w", qual_desc, "descriptor" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000368 { 0, NULL, NULL, NULL },
369};
370
Roland McGrath9797ceb2002-12-30 10:23:00 +0000371static void
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000372reallocate_qual(const unsigned int n)
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100373{
374 unsigned p;
375 qualbits_t *qp;
376 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
Dmitry V. Levin3e9d71f2015-05-25 20:41:02 +0000377 qp = qual_vec[p] = xreallocarray(qual_vec[p], n,
378 sizeof(qualbits_t));
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100379 memset(&qp[num_quals], 0, (n - num_quals) * sizeof(qualbits_t));
380 }
381 num_quals = n;
382}
383
384static void
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000385qualify_one(const unsigned int n, unsigned int bitflag, const int not, const int pers)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000386{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000387 int p;
Roland McGrath138c6a32006-01-12 09:50:49 +0000388
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100389 if (num_quals <= n)
390 reallocate_qual(n + 1);
Roland McGrath138c6a32006-01-12 09:50:49 +0000391
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100392 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
393 if (pers == p || pers < 0) {
394 if (not)
395 qual_vec[p][n] &= ~bitflag;
396 else
397 qual_vec[p][n] |= bitflag;
398 }
Roland McGrath138c6a32006-01-12 09:50:49 +0000399 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400}
401
402static int
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000403qual_syscall(const char *s, const unsigned int bitflag, const int not)
Roland McGrath9797ceb2002-12-30 10:23:00 +0000404{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000405 int p;
406 unsigned int i;
Roland McGrathfe6b3522005-02-02 04:40:11 +0000407 int rc = -1;
Roland McGrath9797ceb2002-12-30 10:23:00 +0000408
Denys Vlasenkoe4cc7c52012-03-23 11:29:01 +0100409 if (*s >= '0' && *s <= '9') {
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100410 i = string_to_uint(s);
Denys Vlasenkob43dacd2013-02-23 18:19:28 +0100411 if (i >= MAX_NSYSCALLS)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000412 return -1;
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000413 qualify_one(i, bitflag, not, -1);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000414 return 0;
Roland McGrath48a035f2006-01-12 09:45:56 +0000415 }
Roland McGrath138c6a32006-01-12 09:50:49 +0000416
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100417 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
418 for (i = 0; i < nsyscall_vec[p]; i++) {
419 if (sysent_vec[p][i].sys_name
420 && strcmp(s, sysent_vec[p][i].sys_name) == 0
421 ) {
Dmitry V. Levin7b9e45e2013-03-01 15:50:22 +0000422 qualify_one(i, bitflag, not, p);
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100423 rc = 0;
424 }
Roland McGrath138c6a32006-01-12 09:50:49 +0000425 }
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100426 }
Dmitry V. Levinc18c7032007-08-22 21:43:30 +0000427
Roland McGrathfe6b3522005-02-02 04:40:11 +0000428 return rc;
Roland McGrath9797ceb2002-12-30 10:23:00 +0000429}
430
431static int
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000432qual_signal(const char *s, const unsigned int bitflag, const int not)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000434 unsigned int i;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000435
Denys Vlasenkoe4cc7c52012-03-23 11:29:01 +0100436 if (*s >= '0' && *s <= '9') {
Dmitry V. Levinccee1692012-03-25 21:49:48 +0000437 int signo = string_to_uint(s);
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100438 if (signo < 0 || signo > 255)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000439 return -1;
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000440 qualify_one(signo, bitflag, not, -1);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000441 return 0;
Roland McGrath9797ceb2002-12-30 10:23:00 +0000442 }
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000443 if (strncasecmp(s, "SIG", 3) == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444 s += 3;
Denys Vlasenkoe4cc7c52012-03-23 11:29:01 +0100445 for (i = 0; i <= NSIG; i++) {
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000446 if (strcasecmp(s, signame(i) + 3) == 0) {
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000447 qualify_one(i, bitflag, not, -1);
Roland McGrath76421df2005-02-02 03:51:18 +0000448 return 0;
Roland McGrath9797ceb2002-12-30 10:23:00 +0000449 }
Denys Vlasenkoe4cc7c52012-03-23 11:29:01 +0100450 }
Roland McGrath76421df2005-02-02 03:51:18 +0000451 return -1;
Roland McGrath9797ceb2002-12-30 10:23:00 +0000452}
453
454static int
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000455qual_desc(const char *s, const unsigned int bitflag, const int not)
Roland McGrath9797ceb2002-12-30 10:23:00 +0000456{
Denys Vlasenkoe4cc7c52012-03-23 11:29:01 +0100457 if (*s >= '0' && *s <= '9') {
Dmitry V. Levinccee1692012-03-25 21:49:48 +0000458 int desc = string_to_uint(s);
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100459 if (desc < 0 || desc > 0x7fff) /* paranoia */
Roland McGrathfe6b3522005-02-02 04:40:11 +0000460 return -1;
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000461 qualify_one(desc, bitflag, not, -1);
Roland McGrath2b619022003-04-10 18:58:20 +0000462 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463 }
464 return -1;
465}
466
467static int
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000468lookup_class(const char *s)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000469{
470 if (strcmp(s, "file") == 0)
471 return TRACE_FILE;
472 if (strcmp(s, "ipc") == 0)
473 return TRACE_IPC;
474 if (strcmp(s, "network") == 0)
475 return TRACE_NETWORK;
476 if (strcmp(s, "process") == 0)
477 return TRACE_PROCESS;
478 if (strcmp(s, "signal") == 0)
479 return TRACE_SIGNAL;
Roland McGrath2fe7b132005-07-05 03:25:35 +0000480 if (strcmp(s, "desc") == 0)
481 return TRACE_DESC;
Namhyung Kim96792962012-10-24 11:41:57 +0900482 if (strcmp(s, "memory") == 0)
483 return TRACE_MEMORY;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000484 return -1;
485}
486
487void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000488qualify(const char *s)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489{
Roland McGrathe10e62a2004-09-04 04:20:43 +0000490 const struct qual_options *opt;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000491 char *copy;
492 const char *p;
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000493 int not;
494 unsigned int i;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000495
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100496 if (num_quals == 0)
497 reallocate_qual(MIN_QUALS);
498
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000499 opt = &qual_options[0];
500 for (i = 0; (p = qual_options[i].option_name); i++) {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000501 unsigned int len = strlen(p);
502 if (strncmp(s, p, len) == 0 && s[len] == '=') {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000503 opt = &qual_options[i];
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000504 s += len + 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000505 break;
506 }
507 }
508 not = 0;
509 if (*s == '!') {
510 not = 1;
511 s++;
512 }
513 if (strcmp(s, "none") == 0) {
514 not = 1 - not;
515 s = "all";
516 }
517 if (strcmp(s, "all") == 0) {
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100518 for (i = 0; i < num_quals; i++) {
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000519 qualify_one(i, opt->bitflag, not, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520 }
521 return;
522 }
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100523 for (i = 0; i < num_quals; i++) {
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000524 qualify_one(i, opt->bitflag, !not, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525 }
Dmitry V. Levin3e9d71f2015-05-25 20:41:02 +0000526 copy = xstrdup(s);
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000527 for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000528 int n;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529 if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) {
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100530 unsigned pers;
531 for (pers = 0; pers < SUPPORTED_PERSONALITIES; pers++) {
532 for (i = 0; i < nsyscall_vec[pers]; i++)
533 if (sysent_vec[pers][i].sys_flags & n)
Dmitry V. Levin7b9e45e2013-03-01 15:50:22 +0000534 qualify_one(i, opt->bitflag, not, pers);
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100535 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536 continue;
537 }
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000538 if (opt->qualify(p, opt->bitflag, not)) {
Denys Vlasenko4c65c442012-03-08 11:54:10 +0100539 error_msg_and_die("invalid %s '%s'",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000540 opt->argument_name, p);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542 }
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000543 free(copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544 return;
545}
546
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000547#ifdef SYS_socket_subcall
Roland McGratha4d48532005-06-08 20:45:28 +0000548static void
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000549decode_socket_subcall(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550{
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000551 unsigned long addr;
Dmitry V. Levinc2155692015-03-22 15:52:40 +0000552 unsigned int n;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000553
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000554 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_socket_nsubcalls)
555 return;
556
557 tcp->scno = SYS_socket_subcall + tcp->u_arg[0];
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100558 tcp->qual_flg = qual_flags[tcp->scno];
559 tcp->s_ent = &sysent[tcp->scno];
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000560 addr = tcp->u_arg[1];
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100561 n = tcp->s_ent->nargs;
Dmitry V. Levinc2155692015-03-22 15:52:40 +0000562 if (sizeof(tcp->u_arg[0]) == current_wordsize) {
563 memset(tcp->u_arg, 0, n * sizeof(tcp->u_arg[0]));
564 (void) umoven(tcp, addr, n * sizeof(tcp->u_arg[0]), tcp->u_arg);
565 } else {
566 unsigned int args[n];
567 unsigned int i;
568
569 memset(args, 0, sizeof(args));
570 (void) umove(tcp, addr, &args);
571 for (i = 0; i < n; ++i)
572 tcp->u_arg[i] = args[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573 }
574}
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000575#endif
Mike Frysinger3362e892012-03-15 01:09:19 -0400576
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000577#ifdef SYS_ipc_subcall
578static void
579decode_ipc_subcall(struct tcb *tcp)
580{
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100581 unsigned int i, n;
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000582
583 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_ipc_nsubcalls)
584 return;
585
586 tcp->scno = SYS_ipc_subcall + tcp->u_arg[0];
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100587 tcp->qual_flg = qual_flags[tcp->scno];
588 tcp->s_ent = &sysent[tcp->scno];
589 n = tcp->s_ent->nargs;
590 for (i = 0; i < n; i++)
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000591 tcp->u_arg[i] = tcp->u_arg[i + 1];
592}
593#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000594
Dmitry V. Levinf34b97f2015-04-17 09:14:19 +0000595#ifdef LINUX_MIPSO32
596static void
597decode_mips_subcall(struct tcb *tcp)
598{
599 if (!SCNO_IS_VALID(tcp->u_arg[0]))
600 return;
601 tcp->scno = tcp->u_arg[0];
602 tcp->qual_flg = qual_flags[tcp->scno];
603 tcp->s_ent = &sysent[tcp->scno];
604 memmove(&tcp->u_arg[0], &tcp->u_arg[1],
605 sizeof(tcp->u_arg) - sizeof(tcp->u_arg[0]));
606 /*
607 * Fetching the last arg of 7-arg syscalls (fadvise64_64
608 * and sync_file_range) would require additional code,
609 * see linux/mips/get_syscall_args.c
610 */
611}
612
613SYS_FUNC(syscall)
614{
615 return printargs(tcp);
616}
617#endif
618
Denys Vlasenkoa6146922011-08-24 18:07:22 +0200619int
620printargs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000621{
Denys Vlasenkoa6146922011-08-24 18:07:22 +0200622 if (entering(tcp)) {
623 int i;
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100624 int n = tcp->s_ent->nargs;
625 for (i = 0; i < n; i++)
Denys Vlasenkoa6146922011-08-24 18:07:22 +0200626 tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]);
627 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000628 return 0;
629}
630
Denys Vlasenko72879c62012-02-27 14:18:02 +0100631int
632printargs_lu(struct tcb *tcp)
633{
634 if (entering(tcp)) {
635 int i;
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100636 int n = tcp->s_ent->nargs;
637 for (i = 0; i < n; i++)
Denys Vlasenko72879c62012-02-27 14:18:02 +0100638 tprintf("%s%lu", i ? ", " : "", tcp->u_arg[i]);
639 }
640 return 0;
641}
642
643int
644printargs_ld(struct tcb *tcp)
645{
646 if (entering(tcp)) {
647 int i;
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100648 int n = tcp->s_ent->nargs;
649 for (i = 0; i < n; i++)
Denys Vlasenko72879c62012-02-27 14:18:02 +0100650 tprintf("%s%ld", i ? ", " : "", tcp->u_arg[i]);
651 }
652 return 0;
653}
654
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000655static void
656dumpio(struct tcb *tcp)
657{
658 int (*func)();
659
660 if (syserror(tcp))
661 return;
662 if ((unsigned long) tcp->u_arg[0] >= num_quals)
663 return;
664 func = tcp->s_ent->sys_func;
665 if (func == printargs)
666 return;
667 if (qual_flags[tcp->u_arg[0]] & QUAL_READ) {
668 if (func == sys_read ||
669 func == sys_pread ||
670 func == sys_recv ||
671 func == sys_recvfrom) {
672 dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
673 return;
674 } else if (func == sys_readv) {
675 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
676 return;
Dmitry V. Levind93c4e82015-06-17 20:09:13 +0000677#ifdef HAVE_SENDMSG
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000678 } else if (func == sys_recvmsg) {
679 dumpiov_in_msghdr(tcp, tcp->u_arg[1]);
680 return;
681 } else if (func == sys_recvmmsg) {
682 dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]);
683 return;
684#endif
685 }
686 }
687 if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) {
688 if (func == sys_write ||
689 func == sys_pwrite ||
690 func == sys_send ||
691 func == sys_sendto)
692 dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
693 else if (func == sys_writev)
694 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
Dmitry V. Levind93c4e82015-06-17 20:09:13 +0000695#ifdef HAVE_SENDMSG
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000696 else if (func == sys_sendmsg)
697 dumpiov_in_msghdr(tcp, tcp->u_arg[1]);
698 else if (func == sys_sendmmsg)
699 dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]);
700#endif
701 }
702}
703
704/*
705 * Shuffle syscall numbers so that we don't have huge gaps in syscall table.
706 * The shuffling should be an involution: shuffle_scno(shuffle_scno(n)) == n.
707 */
708#if defined(ARM) || defined(AARCH64) /* So far only 32-bit ARM needs this */
709static long
710shuffle_scno(unsigned long scno)
711{
712 if (scno < ARM_FIRST_SHUFFLED_SYSCALL)
713 return scno;
714
715 /* __ARM_NR_cmpxchg? Swap with LAST_ORDINARY+1 */
716 if (scno == ARM_FIRST_SHUFFLED_SYSCALL)
717 return 0x000ffff0;
718 if (scno == 0x000ffff0)
719 return ARM_FIRST_SHUFFLED_SYSCALL;
720
721#define ARM_SECOND_SHUFFLED_SYSCALL (ARM_FIRST_SHUFFLED_SYSCALL + 1)
722 /*
723 * Is it ARM specific syscall?
724 * Swap [0x000f0000, 0x000f0000 + LAST_SPECIAL] range
725 * with [SECOND_SHUFFLED, SECOND_SHUFFLED + LAST_SPECIAL] range.
726 */
727 if (scno >= 0x000f0000 &&
728 scno <= 0x000f0000 + ARM_LAST_SPECIAL_SYSCALL) {
729 return scno - 0x000f0000 + ARM_SECOND_SHUFFLED_SYSCALL;
730 }
731 if (scno <= ARM_SECOND_SHUFFLED_SYSCALL + ARM_LAST_SPECIAL_SYSCALL) {
732 return scno + 0x000f0000 - ARM_SECOND_SHUFFLED_SYSCALL;
733 }
734
735 return scno;
736}
737#else
738# define shuffle_scno(scno) ((long)(scno))
739#endif
740
741static char*
742undefined_scno_name(struct tcb *tcp)
743{
744 static char buf[sizeof("syscall_%lu") + sizeof(long)*3];
745
746 sprintf(buf, "syscall_%lu", shuffle_scno(tcp->scno));
747 return buf;
748}
749
750static long get_regs_error;
751
752void
753clear_regs(void)
754{
755 get_regs_error = -1;
756}
757
758static int get_syscall_args(struct tcb *);
759static int get_syscall_result(struct tcb *);
760
761static int
762trace_syscall_entering(struct tcb *tcp)
763{
764 int res, scno_good;
765
766 scno_good = res = get_scno(tcp);
767 if (res == 0)
768 return res;
769 if (res == 1)
770 res = get_syscall_args(tcp);
771
772 if (res != 1) {
773 printleader(tcp);
774 if (scno_good != 1)
775 tprints("????" /* anti-trigraph gap */ "(");
776 else if (tcp->qual_flg & UNDEFINED_SCNO)
777 tprintf("%s(", undefined_scno_name(tcp));
778 else
779 tprintf("%s(", tcp->s_ent->sys_name);
780 /*
781 * " <unavailable>" will be added later by the code which
782 * detects ptrace errors.
783 */
784 goto ret;
785 }
786
Dmitry V. Levinf34b97f2015-04-17 09:14:19 +0000787#ifdef LINUX_MIPSO32
788 if (sys_syscall == tcp->s_ent->sys_func)
789 decode_mips_subcall(tcp);
790#endif
791
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000792 if ( sys_execve == tcp->s_ent->sys_func
793# if defined(SPARC) || defined(SPARC64)
794 || sys_execv == tcp->s_ent->sys_func
795# endif
796 ) {
797 hide_log_until_execve = 0;
798 }
799
800#if defined(SYS_socket_subcall) || defined(SYS_ipc_subcall)
801 while (1) {
802# ifdef SYS_socket_subcall
803 if (tcp->s_ent->sys_func == sys_socketcall) {
804 decode_socket_subcall(tcp);
805 break;
806 }
807# endif
808# ifdef SYS_ipc_subcall
809 if (tcp->s_ent->sys_func == sys_ipc) {
810 decode_ipc_subcall(tcp);
811 break;
812 }
813# endif
814 break;
815 }
816#endif
817
818 if (!(tcp->qual_flg & QUAL_TRACE)
819 || (tracing_paths && !pathtrace_match(tcp))
820 ) {
821 tcp->flags |= TCB_INSYSCALL | TCB_FILTERED;
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000822 tcp->sys_func_rval = 0;
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000823 return 0;
824 }
825
826 tcp->flags &= ~TCB_FILTERED;
827
828 if (cflag == CFLAG_ONLY_STATS || hide_log_until_execve) {
829 res = 0;
830 goto ret;
831 }
832
833#ifdef USE_LIBUNWIND
834 if (stack_trace_enabled) {
835 if (tcp->s_ent->sys_flags & STACKTRACE_CAPTURE_ON_ENTER)
836 unwind_capture_stacktrace(tcp);
837 }
838#endif
839
840 printleader(tcp);
841 if (tcp->qual_flg & UNDEFINED_SCNO)
842 tprintf("%s(", undefined_scno_name(tcp));
843 else
844 tprintf("%s(", tcp->s_ent->sys_name);
845 if ((tcp->qual_flg & QUAL_RAW) && tcp->s_ent->sys_func != sys_exit)
846 res = printargs(tcp);
847 else
848 res = tcp->s_ent->sys_func(tcp);
849
850 fflush(tcp->outf);
851 ret:
852 tcp->flags |= TCB_INSYSCALL;
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000853 tcp->sys_func_rval = res;
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000854 /* Measure the entrance time as late as possible to avoid errors. */
855 if (Tflag || cflag)
856 gettimeofday(&tcp->etime, NULL);
857 return res;
858}
859
860static int
861trace_syscall_exiting(struct tcb *tcp)
862{
863 int sys_res;
864 struct timeval tv;
865 int res;
866 long u_error;
867
868 /* Measure the exit time as early as possible to avoid errors. */
869 if (Tflag || cflag)
870 gettimeofday(&tv, NULL);
871
872#ifdef USE_LIBUNWIND
873 if (stack_trace_enabled) {
874 if (tcp->s_ent->sys_flags & STACKTRACE_INVALIDATE_CACHE)
875 unwind_cache_invalidate(tcp);
876 }
877#endif
878
879#if SUPPORTED_PERSONALITIES > 1
880 update_personality(tcp, tcp->currpers);
881#endif
882 res = (get_regs_error ? -1 : get_syscall_result(tcp));
Dmitry V. Levin4b80f342015-06-29 11:57:44 +0000883 if (filtered(tcp) || hide_log_until_execve)
884 goto ret;
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000885
886 if (cflag) {
887 count_syscall(tcp, &tv);
888 if (cflag == CFLAG_ONLY_STATS) {
889 goto ret;
890 }
891 }
892
893 /* If not in -ff mode, and printing_tcp != tcp,
894 * then the log currently does not end with output
895 * of _our syscall entry_, but with something else.
896 * We need to say which syscall's return is this.
897 *
898 * Forced reprinting via TCB_REPRINT is used only by
899 * "strace -ff -oLOG test/threaded_execve" corner case.
900 * It's the only case when -ff mode needs reprinting.
901 */
902 if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) {
903 tcp->flags &= ~TCB_REPRINT;
904 printleader(tcp);
905 if (tcp->qual_flg & UNDEFINED_SCNO)
906 tprintf("<... %s resumed> ", undefined_scno_name(tcp));
907 else
908 tprintf("<... %s resumed> ", tcp->s_ent->sys_name);
909 }
910 printing_tcp = tcp;
911
912 tcp->s_prev_ent = NULL;
913 if (res != 1) {
914 /* There was error in one of prior ptrace ops */
915 tprints(") ");
916 tabto();
917 tprints("= ? <unavailable>\n");
918 line_ended();
919 tcp->flags &= ~TCB_INSYSCALL;
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000920 tcp->sys_func_rval = 0;
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000921 return res;
922 }
923 tcp->s_prev_ent = tcp->s_ent;
924
925 sys_res = 0;
926 if (tcp->qual_flg & QUAL_RAW) {
927 /* sys_res = printargs(tcp); - but it's nop on sysexit */
928 } else {
929 /* FIXME: not_failing_only (IOW, option -z) is broken:
930 * failure of syscall is known only after syscall return.
931 * Thus we end up with something like this on, say, ENOENT:
932 * open("doesnt_exist", O_RDONLY <unfinished ...>
933 * {next syscall decode}
934 * whereas the intended result is that open(...) line
935 * is not shown at all.
936 */
937 if (not_failing_only && tcp->u_error)
938 goto ret; /* ignore failed syscalls */
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000939 if (tcp->sys_func_rval & RVAL_DECODED)
940 sys_res = tcp->sys_func_rval;
941 else
942 sys_res = tcp->s_ent->sys_func(tcp);
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000943 }
944
945 tprints(") ");
946 tabto();
947 u_error = tcp->u_error;
948 if (tcp->qual_flg & QUAL_RAW) {
949 if (u_error)
950 tprintf("= -1 (errno %ld)", u_error);
951 else
952 tprintf("= %#lx", tcp->u_rval);
953 }
954 else if (!(sys_res & RVAL_NONE) && u_error) {
955 switch (u_error) {
956 /* Blocked signals do not interrupt any syscalls.
957 * In this case syscalls don't return ERESTARTfoo codes.
958 *
959 * Deadly signals set to SIG_DFL interrupt syscalls
960 * and kill the process regardless of which of the codes below
961 * is returned by the interrupted syscall.
962 * In some cases, kernel forces a kernel-generated deadly
963 * signal to be unblocked and set to SIG_DFL (and thus cause
964 * death) if it is blocked or SIG_IGNed: for example, SIGSEGV
965 * or SIGILL. (The alternative is to leave process spinning
966 * forever on the faulty instruction - not useful).
967 *
968 * SIG_IGNed signals and non-deadly signals set to SIG_DFL
969 * (for example, SIGCHLD, SIGWINCH) interrupt syscalls,
970 * but kernel will always restart them.
971 */
972 case ERESTARTSYS:
973 /* Most common type of signal-interrupted syscall exit code.
974 * The system call will be restarted with the same arguments
975 * if SA_RESTART is set; otherwise, it will fail with EINTR.
976 */
977 tprints("= ? ERESTARTSYS (To be restarted if SA_RESTART is set)");
978 break;
979 case ERESTARTNOINTR:
980 /* Rare. For example, fork() returns this if interrupted.
981 * SA_RESTART is ignored (assumed set): the restart is unconditional.
982 */
983 tprints("= ? ERESTARTNOINTR (To be restarted)");
984 break;
985 case ERESTARTNOHAND:
986 /* pause(), rt_sigsuspend() etc use this code.
987 * SA_RESTART is ignored (assumed not set):
988 * syscall won't restart (will return EINTR instead)
989 * even after signal with SA_RESTART set. However,
990 * after SIG_IGN or SIG_DFL signal it will restart
991 * (thus the name "restart only if has no handler").
992 */
993 tprints("= ? ERESTARTNOHAND (To be restarted if no handler)");
994 break;
995 case ERESTART_RESTARTBLOCK:
996 /* Syscalls like nanosleep(), poll() which can't be
997 * restarted with their original arguments use this
998 * code. Kernel will execute restart_syscall() instead,
999 * which changes arguments before restarting syscall.
1000 * SA_RESTART is ignored (assumed not set) similarly
1001 * to ERESTARTNOHAND. (Kernel can't honor SA_RESTART
1002 * since restart data is saved in "restart block"
1003 * in task struct, and if signal handler uses a syscall
1004 * which in turn saves another such restart block,
1005 * old data is lost and restart becomes impossible)
1006 */
1007 tprints("= ? ERESTART_RESTARTBLOCK (Interrupted by signal)");
1008 break;
1009 default:
1010 if ((unsigned long) u_error < nerrnos
1011 && errnoent[u_error])
1012 tprintf("= -1 %s (%s)", errnoent[u_error],
1013 strerror(u_error));
1014 else
1015 tprintf("= -1 ERRNO_%lu (%s)", u_error,
1016 strerror(u_error));
1017 break;
1018 }
1019 if ((sys_res & RVAL_STR) && tcp->auxstr)
1020 tprintf(" (%s)", tcp->auxstr);
1021 }
1022 else {
1023 if (sys_res & RVAL_NONE)
1024 tprints("= ?");
1025 else {
1026 switch (sys_res & RVAL_MASK) {
1027 case RVAL_HEX:
1028#if SUPPORTED_PERSONALITIES > 1
1029 if (current_wordsize < sizeof(long))
1030 tprintf("= %#x",
1031 (unsigned int) tcp->u_rval);
1032 else
1033#endif
1034 tprintf("= %#lx", tcp->u_rval);
1035 break;
1036 case RVAL_OCTAL:
1037 tprintf("= %#lo", tcp->u_rval);
1038 break;
1039 case RVAL_UDECIMAL:
1040 tprintf("= %lu", tcp->u_rval);
1041 break;
1042 case RVAL_DECIMAL:
1043 tprintf("= %ld", tcp->u_rval);
1044 break;
1045 case RVAL_FD:
1046 if (show_fd_path) {
1047 tprints("= ");
1048 printfd(tcp, tcp->u_rval);
1049 }
1050 else
1051 tprintf("= %ld", tcp->u_rval);
1052 break;
1053#if defined(LINUX_MIPSN32) || defined(X32)
1054 /*
1055 case RVAL_LHEX:
1056 tprintf("= %#llx", tcp->u_lrval);
1057 break;
1058 case RVAL_LOCTAL:
1059 tprintf("= %#llo", tcp->u_lrval);
1060 break;
1061 */
1062 case RVAL_LUDECIMAL:
1063 tprintf("= %llu", tcp->u_lrval);
1064 break;
1065 /*
1066 case RVAL_LDECIMAL:
1067 tprintf("= %lld", tcp->u_lrval);
1068 break;
1069 */
1070#endif
1071 default:
Dmitry V. Levin6c8ef052015-05-25 22:51:19 +00001072 error_msg("invalid rval format");
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001073 break;
1074 }
1075 }
1076 if ((sys_res & RVAL_STR) && tcp->auxstr)
1077 tprintf(" (%s)", tcp->auxstr);
1078 }
1079 if (Tflag) {
1080 tv_sub(&tv, &tv, &tcp->etime);
1081 tprintf(" <%ld.%06ld>",
1082 (long) tv.tv_sec, (long) tv.tv_usec);
1083 }
1084 tprints("\n");
1085 dumpio(tcp);
1086 line_ended();
1087
1088#ifdef USE_LIBUNWIND
1089 if (stack_trace_enabled)
1090 unwind_print_stacktrace(tcp);
1091#endif
1092
1093 ret:
1094 tcp->flags &= ~TCB_INSYSCALL;
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +00001095 tcp->sys_func_rval = 0;
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001096 return 0;
1097}
1098
1099int
1100trace_syscall(struct tcb *tcp)
1101{
1102 return exiting(tcp) ?
1103 trace_syscall_exiting(tcp) : trace_syscall_entering(tcp);
1104}
1105
1106/*
1107 * Cannot rely on __kernel_[u]long_t being defined,
1108 * it is quite a recent feature of <asm/posix_types.h>.
1109 */
1110#ifdef __kernel_long_t
1111typedef __kernel_long_t kernel_long_t;
1112typedef __kernel_ulong_t kernel_ulong_t;
1113#else
1114# ifdef X32
1115typedef long long kernel_long_t;
1116typedef unsigned long long kernel_ulong_t;
1117# else
1118typedef long kernel_long_t;
1119typedef unsigned long kernel_ulong_t;
1120# endif
1121#endif
1122
1123/*
1124 * Check the syscall return value register value for whether it is
1125 * a negated errno code indicating an error, or a success return value.
1126 */
1127static inline bool
1128is_negated_errno(kernel_ulong_t val)
1129{
1130 /* Linux kernel defines MAX_ERRNO to 4095. */
1131 kernel_ulong_t max = -(kernel_long_t) 4095;
1132
1133#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1134 if (current_wordsize < sizeof(val)) {
1135 val = (uint32_t) val;
1136 max = (uint32_t) max;
1137 }
1138#elif defined X32
1139 /*
1140 * current_wordsize is 4 even in personality 0 (native X32)
1141 * but truncation _must not_ be done in it.
1142 * can't check current_wordsize here!
1143 */
1144 if (current_personality != 0) {
1145 val = (uint32_t) val;
1146 max = (uint32_t) max;
1147 }
1148#endif
1149
1150 return val >= max;
1151}
1152
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001153#include "arch_regs.c"
Wichert Akkermanc7926982000-04-10 22:22:31 +00001154
Dmitry V. Levin78ed3f32015-03-23 00:04:27 +00001155#ifdef HAVE_GETRVAL2
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001156# include "arch_getrval2.c"
Dmitry V. Levin48f08902015-03-05 23:30:02 +00001157#endif
1158
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001159void
Denys Vlasenko5a2483b2013-07-01 12:49:14 +02001160print_pc(struct tcb *tcp)
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001161{
Dmitry V. Levine96cb622015-02-15 15:52:02 +00001162 const char *fmt;
1163 const char *bad;
1164
Dmitry V. Levinb2d9ff22015-02-23 13:43:20 +00001165#ifdef current_wordsize
Dmitry V. Levine96cb622015-02-15 15:52:02 +00001166# define pc_wordsize current_wordsize
Dmitry V. Levinb2d9ff22015-02-23 13:43:20 +00001167#else
1168# define pc_wordsize personality_wordsize[tcp->currpers]
Dmitry V. Levine96cb622015-02-15 15:52:02 +00001169#endif
1170
1171 if (pc_wordsize == 4) {
1172 fmt = "[%08lx] ";
1173 bad = "[????????] ";
1174 } else {
1175 fmt = "[%016lx] ";
1176 bad = "[????????????????] ";
1177 }
1178
1179#undef pc_wordsize
1180#define PRINTBADPC tprints(bad)
1181
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001182 if (get_regs_error) {
1183 PRINTBADPC;
1184 return;
1185 }
Dmitry V. Levine96cb622015-02-15 15:52:02 +00001186
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001187#include "print_pc.c"
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001188}
1189
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001190#if defined X86_64 || defined POWERPC
1191# include "getregs_old.c"
Anton Blanchard14d51a62013-06-26 14:42:37 +10001192#endif
1193
Dmitry V. Levind6db1db2015-02-13 23:41:04 +00001194#if defined ARCH_REGS_FOR_GETREGSET
1195static long
1196get_regset(pid_t pid)
Dmitry V. Levinfaa177e2013-03-17 23:48:45 +00001197{
Dmitry V. Levind6db1db2015-02-13 23:41:04 +00001198# ifdef ARCH_IOVEC_FOR_GETREGSET
1199 /* variable iovec */
1200 ARCH_IOVEC_FOR_GETREGSET.iov_len = sizeof(ARCH_REGS_FOR_GETREGSET);
1201 return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS,
1202 &ARCH_IOVEC_FOR_GETREGSET);
1203# else
1204 /* constant iovec */
Dmitry V. Levinb787b102013-03-18 10:17:14 +00001205 static struct iovec io = {
1206 .iov_base = &ARCH_REGS_FOR_GETREGSET,
1207 .iov_len = sizeof(ARCH_REGS_FOR_GETREGSET)
Dmitry V. Levinfaa177e2013-03-17 23:48:45 +00001208 };
Dmitry V. Levind6db1db2015-02-13 23:41:04 +00001209 return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &io);
Dmitry V. Levinb787b102013-03-18 10:17:14 +00001210
Dmitry V. Levinfaa177e2013-03-17 23:48:45 +00001211# endif
Dmitry V. Levinb787b102013-03-18 10:17:14 +00001212}
Dmitry V. Levind6db1db2015-02-13 23:41:04 +00001213#endif /* ARCH_REGS_FOR_GETREGSET */
Dmitry V. Levinb787b102013-03-18 10:17:14 +00001214
Denys Vlasenko48e4c1b2013-02-16 08:23:40 +01001215void
1216get_regs(pid_t pid)
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001217{
Dmitry V. Levin7abf2e82015-02-13 23:56:54 +00001218#ifdef ARCH_REGS_FOR_GETREGSET
1219# ifdef X86_64
1220 /* Try PTRACE_GETREGSET first, fallback to PTRACE_GETREGS. */
Dmitry V. Levin27e3ae92013-03-17 23:18:35 +00001221 static int getregset_support;
1222
1223 if (getregset_support >= 0) {
Dmitry V. Levind6db1db2015-02-13 23:41:04 +00001224 get_regs_error = get_regset(pid);
Dmitry V. Levin27e3ae92013-03-17 23:18:35 +00001225 if (getregset_support > 0)
1226 return;
1227 if (get_regs_error >= 0) {
1228 getregset_support = 1;
1229 return;
Denys Vlasenkoeec8d5d2013-02-14 03:29:48 +01001230 }
Dmitry V. Levin27e3ae92013-03-17 23:18:35 +00001231 if (errno == EPERM || errno == ESRCH)
1232 return;
1233 getregset_support = -1;
1234 }
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001235 getregs_old(pid);
Dmitry V. Levin7abf2e82015-02-13 23:56:54 +00001236# else /* !X86_64 */
1237 /* Assume that PTRACE_GETREGSET works. */
1238 get_regs_error = get_regset(pid);
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001239# endif
Dmitry V. Levin7abf2e82015-02-13 23:56:54 +00001240#elif defined ARCH_REGS_FOR_GETREGS
1241# if defined SPARC || defined SPARC64
1242 /* SPARC systems have the meaning of data and addr reversed */
1243 get_regs_error = ptrace(PTRACE_GETREGS, pid, (char *)&ARCH_REGS_FOR_GETREGS, 0);
1244# elif defined POWERPC
1245 static bool old_kernel = 0;
1246 if (old_kernel)
1247 goto old;
1248 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS);
1249 if (get_regs_error && errno == EIO) {
1250 old_kernel = 1;
1251 old:
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001252 get_regs_error = getregs_old(pid);
Dmitry V. Levin7abf2e82015-02-13 23:56:54 +00001253 }
1254# else
1255 /* Assume that PTRACE_GETREGS works. */
1256 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS);
1257# endif
1258
1259#else /* !ARCH_REGS_FOR_GETREGSET && !ARCH_REGS_FOR_GETREGS */
1260# warning get_regs is not implemented for this architecture yet
1261 get_regs_error = 0;
1262#endif
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001263}
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001264
Denys Vlasenkob88f9612011-08-21 18:03:23 +02001265/* Returns:
Denys Vlasenko907735a2012-03-21 00:23:16 +01001266 * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently.
1267 * 1: ok, continue in trace_syscall_entering().
1268 * other: error, trace_syscall_entering() should print error indicator
Denys Vlasenkob88f9612011-08-21 18:03:23 +02001269 * ("????" etc) and bail out.
1270 */
Denys Vlasenko8497b622015-03-21 17:51:52 +01001271int
Denys Vlasenko06602d92011-08-24 17:53:52 +02001272get_scno(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001273{
Dmitry V. Levin144cda22015-03-23 18:48:32 +00001274 if (get_regs_error)
1275 return -1;
1276
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001277 long scno = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001278
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001279#include "get_scno.c"
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001280
Denys Vlasenko8cd1acd2011-08-24 16:52:57 +02001281 tcp->scno = scno;
Denys Vlasenko74ec14f2013-02-21 16:13:47 +01001282 if (SCNO_IS_VALID(tcp->scno)) {
1283 tcp->s_ent = &sysent[scno];
1284 tcp->qual_flg = qual_flags[scno];
1285 } else {
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +01001286 static const struct_sysent unknown = {
Denys Vlasenko74ec14f2013-02-21 16:13:47 +01001287 .nargs = MAX_ARGS,
1288 .sys_flags = 0,
1289 .sys_func = printargs,
Denys Vlasenkocc59f142015-04-07 12:46:59 +02001290 .sys_name = "system call",
Denys Vlasenko74ec14f2013-02-21 16:13:47 +01001291 };
1292 tcp->s_ent = &unknown;
1293 tcp->qual_flg = UNDEFINED_SCNO | QUAL_RAW | DEFAULT_QUAL_FLAGS;
Dmitry V. Levinea009002015-03-24 01:59:07 +00001294 if (debug_flag)
Dmitry V. Levin6c8ef052015-05-25 22:51:19 +00001295 error_msg("pid %d invalid syscall %ld", tcp->pid, scno);
Denys Vlasenko74ec14f2013-02-21 16:13:47 +01001296 }
Pavel Machek4dc3b142000-02-01 17:58:41 +00001297 return 1;
1298}
1299
Denys Vlasenkobb6bb5c2012-03-20 17:10:35 +01001300/* Return -1 on error or 1 on success (never 0!) */
Roland McGratha4d48532005-06-08 20:45:28 +00001301static int
Denys Vlasenkobb6bb5c2012-03-20 17:10:35 +01001302get_syscall_args(struct tcb *tcp)
Pavel Machek4dc3b142000-02-01 17:58:41 +00001303{
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001304#include "get_syscall_args.c"
Pavel Machek4dc3b142000-02-01 17:58:41 +00001305 return 1;
1306}
1307
Denys Vlasenkoc956ef02013-02-16 14:25:56 +01001308static void
Denys Vlasenkoa6146922011-08-24 18:07:22 +02001309get_error(struct tcb *tcp)
1310{
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001311 const bool check_errno = !(tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS);
1312 tcp->u_error = 0;
Dmitry V. Levinf46ab5f2015-02-05 18:50:24 +00001313
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001314#include "get_error.c"
Denys Vlasenkoa6146922011-08-24 18:07:22 +02001315}
1316
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001317/* Returns:
1318 * 1: ok, continue in trace_syscall_exiting().
1319 * -1: error, trace_syscall_exiting() should print error indicator
1320 * ("????" etc) and bail out.
1321 */
Denys Vlasenkoed4f4f02011-08-22 11:54:06 +02001322static int
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001323get_syscall_result(struct tcb *tcp)
Pavel Machek4dc3b142000-02-01 17:58:41 +00001324{
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001325#if defined ARCH_REGS_FOR_GETREGSET || defined ARCH_REGS_FOR_GETREGS
1326 /* already done by get_regs */
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001327#else
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001328# include "get_syscall_result.c"
Masatake YAMATOed69fc22014-04-16 15:33:35 +09001329#endif
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001330 get_error(tcp);
1331 return 1;
Dmitry V. Levin7d7c9632010-03-29 17:51:02 +00001332}