blob: b8f9f82a7ae7ebee66960254a1e19c2cde087d2e [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 Khabirova140ecf82015-07-10 22:24:48 +030084#define SEN(syscall_name) SYS_FUNC_NAME(syscall_name)
85
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +010086const struct_sysent sysent0[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000087#include "syscallent.h"
88};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000089
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010090#if SUPPORTED_PERSONALITIES > 1
91static const struct_sysent sysent1[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +010092# include "syscallent1.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000093};
Denys Vlasenko39fca622011-08-20 02:12:33 +020094#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000095
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010096#if SUPPORTED_PERSONALITIES > 2
97static const struct_sysent sysent2[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +010098# include "syscallent2.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000099};
Denys Vlasenko39fca622011-08-20 02:12:33 +0200100#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000101
102/* Now undef them since short defines cause wicked namespace pollution. */
Elvira Khabirova140ecf82015-07-10 22:24:48 +0300103#undef SEN
Roland McGrath2fe7b132005-07-05 03:25:35 +0000104#undef TD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000105#undef TF
106#undef TI
107#undef TN
108#undef TP
109#undef TS
Namhyung Kim96792962012-10-24 11:41:57 +0900110#undef TM
Dmitry V. Levin50a218d2011-01-18 17:36:20 +0000111#undef NF
Denys Vlasenkoac1ce772011-08-23 13:24:17 +0200112#undef MA
Masatake YAMATO1d78d222014-04-16 15:33:11 +0900113#undef SI
114#undef SE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000115
Denys Vlasenko39fca622011-08-20 02:12:33 +0200116/*
Dmitry V. Levindf7aa2b2015-01-19 17:02:16 +0000117 * `ioctlent[012].h' files are automatically generated by the auxiliary
Denys Vlasenko39fca622011-08-20 02:12:33 +0200118 * program `ioctlsort', such that the list is sorted by the `code' field.
119 * This has the side-effect of resolving the _IO.. macros into
120 * plain integers, eliminating the need to include here everything
121 * in "/usr/include".
122 */
123
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100124const char *const errnoent0[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000125#include "errnoent.h"
126};
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100127const char *const signalent0[] = {
Denys Vlasenko39fca622011-08-20 02:12:33 +0200128#include "signalent.h"
129};
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100130const struct_ioctlent ioctlent0[] = {
Dmitry V. Levindf7aa2b2015-01-19 17:02:16 +0000131#include "ioctlent0.h"
Denys Vlasenko39fca622011-08-20 02:12:33 +0200132};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100134#if SUPPORTED_PERSONALITIES > 1
Roland McGrathee36ce12004-09-04 03:53:10 +0000135static const char *const errnoent1[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +0100136# include "errnoent1.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000137};
Denys Vlasenko39fca622011-08-20 02:12:33 +0200138static const char *const signalent1[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +0100139# include "signalent1.h"
Denys Vlasenko39fca622011-08-20 02:12:33 +0200140};
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100141static const struct_ioctlent ioctlent1[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +0100142# include "ioctlent1.h"
Denys Vlasenko39fca622011-08-20 02:12:33 +0200143};
Denys Vlasenko39fca622011-08-20 02:12:33 +0200144#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000145
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100146#if SUPPORTED_PERSONALITIES > 2
Roland McGrathee36ce12004-09-04 03:53:10 +0000147static const char *const errnoent2[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +0100148# include "errnoent2.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000149};
Denys Vlasenko39fca622011-08-20 02:12:33 +0200150static const char *const signalent2[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +0100151# include "signalent2.h"
Denys Vlasenko39fca622011-08-20 02:12:33 +0200152};
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100153static const struct_ioctlent ioctlent2[] = {
Denys Vlasenko523635f2012-02-25 02:44:25 +0100154# include "ioctlent2.h"
Denys Vlasenko39fca622011-08-20 02:12:33 +0200155};
Denys Vlasenko39fca622011-08-20 02:12:33 +0200156#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157
Dmitry V. Levine6f55242013-02-26 22:02:30 +0000158enum {
159 nsyscalls0 = ARRAY_SIZE(sysent0)
160#if SUPPORTED_PERSONALITIES > 1
161 , nsyscalls1 = ARRAY_SIZE(sysent1)
162# if SUPPORTED_PERSONALITIES > 2
163 , nsyscalls2 = ARRAY_SIZE(sysent2)
164# endif
165#endif
166};
167
168enum {
169 nerrnos0 = ARRAY_SIZE(errnoent0)
170#if SUPPORTED_PERSONALITIES > 1
171 , nerrnos1 = ARRAY_SIZE(errnoent1)
172# if SUPPORTED_PERSONALITIES > 2
173 , nerrnos2 = ARRAY_SIZE(errnoent2)
174# endif
175#endif
176};
177
178enum {
179 nsignals0 = ARRAY_SIZE(signalent0)
180#if SUPPORTED_PERSONALITIES > 1
181 , nsignals1 = ARRAY_SIZE(signalent1)
182# if SUPPORTED_PERSONALITIES > 2
183 , nsignals2 = ARRAY_SIZE(signalent2)
184# endif
185#endif
186};
187
188enum {
189 nioctlents0 = ARRAY_SIZE(ioctlent0)
190#if SUPPORTED_PERSONALITIES > 1
191 , nioctlents1 = ARRAY_SIZE(ioctlent1)
192# if SUPPORTED_PERSONALITIES > 2
193 , nioctlents2 = ARRAY_SIZE(ioctlent2)
194# endif
195#endif
196};
197
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100198#if SUPPORTED_PERSONALITIES > 1
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100199const struct_sysent *sysent = sysent0;
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100200const char *const *errnoent = errnoent0;
201const char *const *signalent = signalent0;
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100202const struct_ioctlent *ioctlent = ioctlent0;
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100203#endif
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100204unsigned nsyscalls = nsyscalls0;
205unsigned nerrnos = nerrnos0;
206unsigned nsignals = nsignals0;
207unsigned nioctlents = nioctlents0;
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100208
209unsigned num_quals;
210qualbits_t *qual_vec[SUPPORTED_PERSONALITIES];
211
212static const unsigned nsyscall_vec[SUPPORTED_PERSONALITIES] = {
213 nsyscalls0,
214#if SUPPORTED_PERSONALITIES > 1
215 nsyscalls1,
216#endif
217#if SUPPORTED_PERSONALITIES > 2
218 nsyscalls2,
219#endif
220};
221static const struct_sysent *const sysent_vec[SUPPORTED_PERSONALITIES] = {
222 sysent0,
223#if SUPPORTED_PERSONALITIES > 1
224 sysent1,
225#endif
226#if SUPPORTED_PERSONALITIES > 2
227 sysent2,
228#endif
229};
230
231enum {
232 MAX_NSYSCALLS1 = (nsyscalls0
233#if SUPPORTED_PERSONALITIES > 1
234 > nsyscalls1 ? nsyscalls0 : nsyscalls1
235#endif
236 ),
237 MAX_NSYSCALLS2 = (MAX_NSYSCALLS1
238#if SUPPORTED_PERSONALITIES > 2
239 > nsyscalls2 ? MAX_NSYSCALLS1 : nsyscalls2
240#endif
241 ),
242 MAX_NSYSCALLS = MAX_NSYSCALLS2,
243 /* We are ready for arches with up to 255 signals,
244 * even though the largest known signo is on MIPS and it is 128.
245 * The number of existing syscalls on all arches is
246 * larger that 255 anyway, so it is just a pedantic matter.
247 */
248 MIN_QUALS = MAX_NSYSCALLS > 255 ? MAX_NSYSCALLS : 255
249};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000250
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100251#if SUPPORTED_PERSONALITIES > 1
Denys Vlasenkoae8643e2013-02-15 14:55:14 +0100252unsigned current_personality;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000253
Denys Vlasenkoae8643e2013-02-15 14:55:14 +0100254# ifndef current_wordsize
255unsigned current_wordsize;
256static const int personality_wordsize[SUPPORTED_PERSONALITIES] = {
Roland McGrath4b2dcca2006-01-12 10:18:53 +0000257 PERSONALITY0_WORDSIZE,
Roland McGrath4b2dcca2006-01-12 10:18:53 +0000258 PERSONALITY1_WORDSIZE,
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100259# if SUPPORTED_PERSONALITIES > 2
Roland McGrath4b2dcca2006-01-12 10:18:53 +0000260 PERSONALITY2_WORDSIZE,
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100261# endif
Denys Vlasenko5c774b22011-08-20 01:50:09 +0200262};
Denys Vlasenkoae8643e2013-02-15 14:55:14 +0100263# endif
Roland McGrath4b2dcca2006-01-12 10:18:53 +0000264
Denys Vlasenko5c774b22011-08-20 01:50:09 +0200265void
Dmitry V. Levin3abe8b22006-12-20 22:37:21 +0000266set_personality(int personality)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000267{
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100268 nsyscalls = nsyscall_vec[personality];
269 sysent = sysent_vec[personality];
270
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000271 switch (personality) {
272 case 0:
273 errnoent = errnoent0;
274 nerrnos = nerrnos0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275 ioctlent = ioctlent0;
276 nioctlents = nioctlents0;
277 signalent = signalent0;
278 nsignals = nsignals0;
279 break;
280
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281 case 1:
282 errnoent = errnoent1;
283 nerrnos = nerrnos1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000284 ioctlent = ioctlent1;
285 nioctlents = nioctlents1;
286 signalent = signalent1;
287 nsignals = nsignals1;
288 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000289
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +0100290# if SUPPORTED_PERSONALITIES > 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291 case 2:
292 errnoent = errnoent2;
293 nerrnos = nerrnos2;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000294 ioctlent = ioctlent2;
295 nioctlents = nioctlents2;
296 signalent = signalent2;
297 nsignals = nsignals2;
298 break;
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100299# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000300 }
301
302 current_personality = personality;
Denys Vlasenkoae8643e2013-02-15 14:55:14 +0100303# ifndef current_wordsize
304 current_wordsize = personality_wordsize[personality];
305# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000306}
307
Dmitry V. Levina5a839a2011-12-23 00:50:49 +0000308static void
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000309update_personality(struct tcb *tcp, unsigned int personality)
Dmitry V. Levina5a839a2011-12-23 00:50:49 +0000310{
311 if (personality == current_personality)
312 return;
313 set_personality(personality);
314
315 if (personality == tcp->currpers)
316 return;
317 tcp->currpers = personality;
318
Dmitry V. Levin6c8ef052015-05-25 22:51:19 +0000319# undef PERSONALITY_NAMES
320# if defined POWERPC64
321# define PERSONALITY_NAMES {"64 bit", "32 bit"}
322# elif defined X86_64
323# define PERSONALITY_NAMES {"64 bit", "32 bit", "x32"}
324# elif defined X32
325# define PERSONALITY_NAMES {"x32", "32 bit"}
326# elif defined AARCH64
327# define PERSONALITY_NAMES {"32-bit", "AArch64"}
328# elif defined TILE
329# define PERSONALITY_NAMES {"64-bit", "32-bit"}
330# endif
331# ifdef PERSONALITY_NAMES
Dmitry V. Levina5a839a2011-12-23 00:50:49 +0000332 if (!qflag) {
Dmitry V. Levin6c8ef052015-05-25 22:51:19 +0000333 static const char *const names[] = PERSONALITY_NAMES;
334 error_msg("[ Process PID=%d runs in %s mode. ]",
335 tcp->pid, names[personality]);
Chris Metcalf0b99a8a2013-02-05 17:48:33 +0100336 }
Denys Vlasenko523635f2012-02-25 02:44:25 +0100337# endif
Dmitry V. Levina5a839a2011-12-23 00:50:49 +0000338}
339#endif
Roland McGrathe10e62a2004-09-04 04:20:43 +0000340
Denys Vlasenkoc1540fe2013-02-21 16:17:08 +0100341static int qual_syscall(), qual_signal(), qual_desc();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000342
Roland McGrathe10e62a2004-09-04 04:20:43 +0000343static const struct qual_options {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000344 unsigned int bitflag;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000345 const char *option_name;
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000346 int (*qualify)(const char *, int, int);
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000347 const char *argument_name;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000348} qual_options[] = {
Roland McGrath9797ceb2002-12-30 10:23:00 +0000349 { QUAL_TRACE, "trace", qual_syscall, "system call" },
350 { QUAL_TRACE, "t", qual_syscall, "system call" },
351 { QUAL_ABBREV, "abbrev", qual_syscall, "system call" },
352 { QUAL_ABBREV, "a", qual_syscall, "system call" },
353 { QUAL_VERBOSE, "verbose", qual_syscall, "system call" },
354 { QUAL_VERBOSE, "v", qual_syscall, "system call" },
355 { QUAL_RAW, "raw", qual_syscall, "system call" },
356 { QUAL_RAW, "x", qual_syscall, "system call" },
357 { QUAL_SIGNAL, "signal", qual_signal, "signal" },
358 { QUAL_SIGNAL, "signals", qual_signal, "signal" },
359 { QUAL_SIGNAL, "s", qual_signal, "signal" },
Roland McGrath9797ceb2002-12-30 10:23:00 +0000360 { QUAL_READ, "read", qual_desc, "descriptor" },
361 { QUAL_READ, "reads", qual_desc, "descriptor" },
362 { QUAL_READ, "r", qual_desc, "descriptor" },
363 { QUAL_WRITE, "write", qual_desc, "descriptor" },
364 { QUAL_WRITE, "writes", qual_desc, "descriptor" },
365 { QUAL_WRITE, "w", qual_desc, "descriptor" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366 { 0, NULL, NULL, NULL },
367};
368
Roland McGrath9797ceb2002-12-30 10:23:00 +0000369static void
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000370reallocate_qual(const unsigned int n)
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100371{
372 unsigned p;
373 qualbits_t *qp;
374 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
Dmitry V. Levin3e9d71f2015-05-25 20:41:02 +0000375 qp = qual_vec[p] = xreallocarray(qual_vec[p], n,
376 sizeof(qualbits_t));
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100377 memset(&qp[num_quals], 0, (n - num_quals) * sizeof(qualbits_t));
378 }
379 num_quals = n;
380}
381
382static void
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000383qualify_one(const unsigned int n, unsigned int bitflag, const int not, const int pers)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000385 int p;
Roland McGrath138c6a32006-01-12 09:50:49 +0000386
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100387 if (num_quals <= n)
388 reallocate_qual(n + 1);
Roland McGrath138c6a32006-01-12 09:50:49 +0000389
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100390 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
391 if (pers == p || pers < 0) {
392 if (not)
393 qual_vec[p][n] &= ~bitflag;
394 else
395 qual_vec[p][n] |= bitflag;
396 }
Roland McGrath138c6a32006-01-12 09:50:49 +0000397 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000398}
399
400static int
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000401qual_syscall(const char *s, const unsigned int bitflag, const int not)
Roland McGrath9797ceb2002-12-30 10:23:00 +0000402{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000403 int p;
404 unsigned int i;
Roland McGrathfe6b3522005-02-02 04:40:11 +0000405 int rc = -1;
Roland McGrath9797ceb2002-12-30 10:23:00 +0000406
Denys Vlasenkoe4cc7c52012-03-23 11:29:01 +0100407 if (*s >= '0' && *s <= '9') {
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100408 i = string_to_uint(s);
Denys Vlasenkob43dacd2013-02-23 18:19:28 +0100409 if (i >= MAX_NSYSCALLS)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000410 return -1;
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000411 qualify_one(i, bitflag, not, -1);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000412 return 0;
Roland McGrath48a035f2006-01-12 09:45:56 +0000413 }
Roland McGrath138c6a32006-01-12 09:50:49 +0000414
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100415 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
416 for (i = 0; i < nsyscall_vec[p]; i++) {
417 if (sysent_vec[p][i].sys_name
418 && strcmp(s, sysent_vec[p][i].sys_name) == 0
419 ) {
Dmitry V. Levin7b9e45e2013-03-01 15:50:22 +0000420 qualify_one(i, bitflag, not, p);
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100421 rc = 0;
422 }
Roland McGrath138c6a32006-01-12 09:50:49 +0000423 }
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100424 }
Dmitry V. Levinc18c7032007-08-22 21:43:30 +0000425
Roland McGrathfe6b3522005-02-02 04:40:11 +0000426 return rc;
Roland McGrath9797ceb2002-12-30 10:23:00 +0000427}
428
429static int
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000430qual_signal(const char *s, const unsigned int bitflag, const int not)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000431{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000432 unsigned int i;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433
Denys Vlasenkoe4cc7c52012-03-23 11:29:01 +0100434 if (*s >= '0' && *s <= '9') {
Dmitry V. Levinccee1692012-03-25 21:49:48 +0000435 int signo = string_to_uint(s);
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100436 if (signo < 0 || signo > 255)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000437 return -1;
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000438 qualify_one(signo, bitflag, not, -1);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000439 return 0;
Roland McGrath9797ceb2002-12-30 10:23:00 +0000440 }
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000441 if (strncasecmp(s, "SIG", 3) == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442 s += 3;
Denys Vlasenkoe4cc7c52012-03-23 11:29:01 +0100443 for (i = 0; i <= NSIG; i++) {
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000444 if (strcasecmp(s, signame(i) + 3) == 0) {
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000445 qualify_one(i, bitflag, not, -1);
Roland McGrath76421df2005-02-02 03:51:18 +0000446 return 0;
Roland McGrath9797ceb2002-12-30 10:23:00 +0000447 }
Denys Vlasenkoe4cc7c52012-03-23 11:29:01 +0100448 }
Roland McGrath76421df2005-02-02 03:51:18 +0000449 return -1;
Roland McGrath9797ceb2002-12-30 10:23:00 +0000450}
451
452static int
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000453qual_desc(const char *s, const unsigned int bitflag, const int not)
Roland McGrath9797ceb2002-12-30 10:23:00 +0000454{
Denys Vlasenkoe4cc7c52012-03-23 11:29:01 +0100455 if (*s >= '0' && *s <= '9') {
Dmitry V. Levinccee1692012-03-25 21:49:48 +0000456 int desc = string_to_uint(s);
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100457 if (desc < 0 || desc > 0x7fff) /* paranoia */
Roland McGrathfe6b3522005-02-02 04:40:11 +0000458 return -1;
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000459 qualify_one(desc, bitflag, not, -1);
Roland McGrath2b619022003-04-10 18:58:20 +0000460 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461 }
462 return -1;
463}
464
465static int
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000466lookup_class(const char *s)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000467{
468 if (strcmp(s, "file") == 0)
469 return TRACE_FILE;
470 if (strcmp(s, "ipc") == 0)
471 return TRACE_IPC;
472 if (strcmp(s, "network") == 0)
473 return TRACE_NETWORK;
474 if (strcmp(s, "process") == 0)
475 return TRACE_PROCESS;
476 if (strcmp(s, "signal") == 0)
477 return TRACE_SIGNAL;
Roland McGrath2fe7b132005-07-05 03:25:35 +0000478 if (strcmp(s, "desc") == 0)
479 return TRACE_DESC;
Namhyung Kim96792962012-10-24 11:41:57 +0900480 if (strcmp(s, "memory") == 0)
481 return TRACE_MEMORY;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000482 return -1;
483}
484
485void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000486qualify(const char *s)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000487{
Roland McGrathe10e62a2004-09-04 04:20:43 +0000488 const struct qual_options *opt;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000489 char *copy;
490 const char *p;
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000491 int not;
492 unsigned int i;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000493
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100494 if (num_quals == 0)
495 reallocate_qual(MIN_QUALS);
496
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000497 opt = &qual_options[0];
498 for (i = 0; (p = qual_options[i].option_name); i++) {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000499 unsigned int len = strlen(p);
500 if (strncmp(s, p, len) == 0 && s[len] == '=') {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501 opt = &qual_options[i];
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000502 s += len + 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000503 break;
504 }
505 }
506 not = 0;
507 if (*s == '!') {
508 not = 1;
509 s++;
510 }
511 if (strcmp(s, "none") == 0) {
512 not = 1 - not;
513 s = "all";
514 }
515 if (strcmp(s, "all") == 0) {
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100516 for (i = 0; i < num_quals; i++) {
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000517 qualify_one(i, opt->bitflag, not, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000518 }
519 return;
520 }
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100521 for (i = 0; i < num_quals; i++) {
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000522 qualify_one(i, opt->bitflag, !not, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000523 }
Dmitry V. Levin3e9d71f2015-05-25 20:41:02 +0000524 copy = xstrdup(s);
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000525 for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000526 int n;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527 if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) {
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100528 unsigned pers;
529 for (pers = 0; pers < SUPPORTED_PERSONALITIES; pers++) {
530 for (i = 0; i < nsyscall_vec[pers]; i++)
531 if (sysent_vec[pers][i].sys_flags & n)
Dmitry V. Levin7b9e45e2013-03-01 15:50:22 +0000532 qualify_one(i, opt->bitflag, not, pers);
Denys Vlasenko9cbc15b2013-02-22 13:37:36 +0100533 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000534 continue;
535 }
Dmitry V. Levin35d05722010-09-15 16:18:20 +0000536 if (opt->qualify(p, opt->bitflag, not)) {
Denys Vlasenko4c65c442012-03-08 11:54:10 +0100537 error_msg_and_die("invalid %s '%s'",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538 opt->argument_name, p);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000540 }
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000541 free(copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542 return;
543}
544
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000545#ifdef SYS_socket_subcall
Roland McGratha4d48532005-06-08 20:45:28 +0000546static void
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000547decode_socket_subcall(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548{
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000549 unsigned long addr;
Dmitry V. Levinc2155692015-03-22 15:52:40 +0000550 unsigned int n;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000551
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000552 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_socket_nsubcalls)
553 return;
554
555 tcp->scno = SYS_socket_subcall + tcp->u_arg[0];
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100556 tcp->qual_flg = qual_flags[tcp->scno];
557 tcp->s_ent = &sysent[tcp->scno];
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000558 addr = tcp->u_arg[1];
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100559 n = tcp->s_ent->nargs;
Dmitry V. Levinc2155692015-03-22 15:52:40 +0000560 if (sizeof(tcp->u_arg[0]) == current_wordsize) {
561 memset(tcp->u_arg, 0, n * sizeof(tcp->u_arg[0]));
562 (void) umoven(tcp, addr, n * sizeof(tcp->u_arg[0]), tcp->u_arg);
563 } else {
564 unsigned int args[n];
565 unsigned int i;
566
567 memset(args, 0, sizeof(args));
568 (void) umove(tcp, addr, &args);
569 for (i = 0; i < n; ++i)
570 tcp->u_arg[i] = args[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571 }
572}
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000573#endif
Mike Frysinger3362e892012-03-15 01:09:19 -0400574
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000575#ifdef SYS_ipc_subcall
576static void
577decode_ipc_subcall(struct tcb *tcp)
578{
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100579 unsigned int i, n;
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000580
581 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_ipc_nsubcalls)
582 return;
583
584 tcp->scno = SYS_ipc_subcall + tcp->u_arg[0];
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100585 tcp->qual_flg = qual_flags[tcp->scno];
586 tcp->s_ent = &sysent[tcp->scno];
587 n = tcp->s_ent->nargs;
588 for (i = 0; i < n; i++)
Dmitry V. Levin648c22c2012-03-15 22:08:55 +0000589 tcp->u_arg[i] = tcp->u_arg[i + 1];
590}
591#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592
Dmitry V. Levinf34b97f2015-04-17 09:14:19 +0000593#ifdef LINUX_MIPSO32
594static void
595decode_mips_subcall(struct tcb *tcp)
596{
597 if (!SCNO_IS_VALID(tcp->u_arg[0]))
598 return;
599 tcp->scno = tcp->u_arg[0];
600 tcp->qual_flg = qual_flags[tcp->scno];
601 tcp->s_ent = &sysent[tcp->scno];
602 memmove(&tcp->u_arg[0], &tcp->u_arg[1],
603 sizeof(tcp->u_arg) - sizeof(tcp->u_arg[0]));
604 /*
605 * Fetching the last arg of 7-arg syscalls (fadvise64_64
606 * and sync_file_range) would require additional code,
607 * see linux/mips/get_syscall_args.c
608 */
609}
610
611SYS_FUNC(syscall)
612{
613 return printargs(tcp);
614}
615#endif
616
Denys Vlasenkoa6146922011-08-24 18:07:22 +0200617int
618printargs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000619{
Denys Vlasenkoa6146922011-08-24 18:07:22 +0200620 if (entering(tcp)) {
621 int i;
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100622 int n = tcp->s_ent->nargs;
623 for (i = 0; i < n; i++)
Denys Vlasenkoa6146922011-08-24 18:07:22 +0200624 tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]);
625 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626 return 0;
627}
628
Denys Vlasenko72879c62012-02-27 14:18:02 +0100629int
630printargs_lu(struct tcb *tcp)
631{
632 if (entering(tcp)) {
633 int i;
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100634 int n = tcp->s_ent->nargs;
635 for (i = 0; i < n; i++)
Denys Vlasenko72879c62012-02-27 14:18:02 +0100636 tprintf("%s%lu", i ? ", " : "", tcp->u_arg[i]);
637 }
638 return 0;
639}
640
641int
642printargs_ld(struct tcb *tcp)
643{
644 if (entering(tcp)) {
645 int i;
Denys Vlasenko74ec14f2013-02-21 16:13:47 +0100646 int n = tcp->s_ent->nargs;
647 for (i = 0; i < n; i++)
Denys Vlasenko72879c62012-02-27 14:18:02 +0100648 tprintf("%s%ld", i ? ", " : "", tcp->u_arg[i]);
649 }
650 return 0;
651}
652
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000653static void
654dumpio(struct tcb *tcp)
655{
656 int (*func)();
657
658 if (syserror(tcp))
659 return;
660 if ((unsigned long) tcp->u_arg[0] >= num_quals)
661 return;
662 func = tcp->s_ent->sys_func;
663 if (func == printargs)
664 return;
665 if (qual_flags[tcp->u_arg[0]] & QUAL_READ) {
666 if (func == sys_read ||
667 func == sys_pread ||
668 func == sys_recv ||
669 func == sys_recvfrom) {
670 dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
671 return;
672 } else if (func == sys_readv) {
673 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
674 return;
Dmitry V. Levind93c4e82015-06-17 20:09:13 +0000675#ifdef HAVE_SENDMSG
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000676 } else if (func == sys_recvmsg) {
677 dumpiov_in_msghdr(tcp, tcp->u_arg[1]);
678 return;
679 } else if (func == sys_recvmmsg) {
680 dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]);
681 return;
682#endif
683 }
684 }
685 if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) {
686 if (func == sys_write ||
687 func == sys_pwrite ||
688 func == sys_send ||
689 func == sys_sendto)
690 dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
691 else if (func == sys_writev)
692 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
Dmitry V. Levind93c4e82015-06-17 20:09:13 +0000693#ifdef HAVE_SENDMSG
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000694 else if (func == sys_sendmsg)
695 dumpiov_in_msghdr(tcp, tcp->u_arg[1]);
696 else if (func == sys_sendmmsg)
697 dumpiov_in_mmsghdr(tcp, tcp->u_arg[1]);
698#endif
699 }
700}
701
702/*
703 * Shuffle syscall numbers so that we don't have huge gaps in syscall table.
704 * The shuffling should be an involution: shuffle_scno(shuffle_scno(n)) == n.
705 */
706#if defined(ARM) || defined(AARCH64) /* So far only 32-bit ARM needs this */
707static long
708shuffle_scno(unsigned long scno)
709{
710 if (scno < ARM_FIRST_SHUFFLED_SYSCALL)
711 return scno;
712
713 /* __ARM_NR_cmpxchg? Swap with LAST_ORDINARY+1 */
714 if (scno == ARM_FIRST_SHUFFLED_SYSCALL)
715 return 0x000ffff0;
716 if (scno == 0x000ffff0)
717 return ARM_FIRST_SHUFFLED_SYSCALL;
718
719#define ARM_SECOND_SHUFFLED_SYSCALL (ARM_FIRST_SHUFFLED_SYSCALL + 1)
720 /*
721 * Is it ARM specific syscall?
722 * Swap [0x000f0000, 0x000f0000 + LAST_SPECIAL] range
723 * with [SECOND_SHUFFLED, SECOND_SHUFFLED + LAST_SPECIAL] range.
724 */
725 if (scno >= 0x000f0000 &&
726 scno <= 0x000f0000 + ARM_LAST_SPECIAL_SYSCALL) {
727 return scno - 0x000f0000 + ARM_SECOND_SHUFFLED_SYSCALL;
728 }
729 if (scno <= ARM_SECOND_SHUFFLED_SYSCALL + ARM_LAST_SPECIAL_SYSCALL) {
730 return scno + 0x000f0000 - ARM_SECOND_SHUFFLED_SYSCALL;
731 }
732
733 return scno;
734}
735#else
736# define shuffle_scno(scno) ((long)(scno))
737#endif
738
739static char*
740undefined_scno_name(struct tcb *tcp)
741{
742 static char buf[sizeof("syscall_%lu") + sizeof(long)*3];
743
744 sprintf(buf, "syscall_%lu", shuffle_scno(tcp->scno));
745 return buf;
746}
747
748static long get_regs_error;
749
750void
751clear_regs(void)
752{
753 get_regs_error = -1;
754}
755
756static int get_syscall_args(struct tcb *);
757static int get_syscall_result(struct tcb *);
758
759static int
760trace_syscall_entering(struct tcb *tcp)
761{
762 int res, scno_good;
763
764 scno_good = res = get_scno(tcp);
765 if (res == 0)
766 return res;
767 if (res == 1)
768 res = get_syscall_args(tcp);
769
770 if (res != 1) {
771 printleader(tcp);
772 if (scno_good != 1)
773 tprints("????" /* anti-trigraph gap */ "(");
774 else if (tcp->qual_flg & UNDEFINED_SCNO)
775 tprintf("%s(", undefined_scno_name(tcp));
776 else
777 tprintf("%s(", tcp->s_ent->sys_name);
778 /*
779 * " <unavailable>" will be added later by the code which
780 * detects ptrace errors.
781 */
782 goto ret;
783 }
784
Dmitry V. Levinf34b97f2015-04-17 09:14:19 +0000785#ifdef LINUX_MIPSO32
786 if (sys_syscall == tcp->s_ent->sys_func)
787 decode_mips_subcall(tcp);
788#endif
789
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000790 if ( sys_execve == tcp->s_ent->sys_func
791# if defined(SPARC) || defined(SPARC64)
792 || sys_execv == tcp->s_ent->sys_func
793# endif
794 ) {
795 hide_log_until_execve = 0;
796 }
797
798#if defined(SYS_socket_subcall) || defined(SYS_ipc_subcall)
799 while (1) {
800# ifdef SYS_socket_subcall
801 if (tcp->s_ent->sys_func == sys_socketcall) {
802 decode_socket_subcall(tcp);
803 break;
804 }
805# endif
806# ifdef SYS_ipc_subcall
807 if (tcp->s_ent->sys_func == sys_ipc) {
808 decode_ipc_subcall(tcp);
809 break;
810 }
811# endif
812 break;
813 }
814#endif
815
816 if (!(tcp->qual_flg & QUAL_TRACE)
817 || (tracing_paths && !pathtrace_match(tcp))
818 ) {
819 tcp->flags |= TCB_INSYSCALL | TCB_FILTERED;
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000820 tcp->sys_func_rval = 0;
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000821 return 0;
822 }
823
824 tcp->flags &= ~TCB_FILTERED;
825
826 if (cflag == CFLAG_ONLY_STATS || hide_log_until_execve) {
827 res = 0;
828 goto ret;
829 }
830
831#ifdef USE_LIBUNWIND
832 if (stack_trace_enabled) {
833 if (tcp->s_ent->sys_flags & STACKTRACE_CAPTURE_ON_ENTER)
834 unwind_capture_stacktrace(tcp);
835 }
836#endif
837
838 printleader(tcp);
839 if (tcp->qual_flg & UNDEFINED_SCNO)
840 tprintf("%s(", undefined_scno_name(tcp));
841 else
842 tprintf("%s(", tcp->s_ent->sys_name);
843 if ((tcp->qual_flg & QUAL_RAW) && tcp->s_ent->sys_func != sys_exit)
844 res = printargs(tcp);
845 else
846 res = tcp->s_ent->sys_func(tcp);
847
848 fflush(tcp->outf);
849 ret:
850 tcp->flags |= TCB_INSYSCALL;
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000851 tcp->sys_func_rval = res;
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000852 /* Measure the entrance time as late as possible to avoid errors. */
853 if (Tflag || cflag)
854 gettimeofday(&tcp->etime, NULL);
855 return res;
856}
857
858static int
859trace_syscall_exiting(struct tcb *tcp)
860{
861 int sys_res;
862 struct timeval tv;
863 int res;
864 long u_error;
865
866 /* Measure the exit time as early as possible to avoid errors. */
867 if (Tflag || cflag)
868 gettimeofday(&tv, NULL);
869
870#ifdef USE_LIBUNWIND
871 if (stack_trace_enabled) {
872 if (tcp->s_ent->sys_flags & STACKTRACE_INVALIDATE_CACHE)
873 unwind_cache_invalidate(tcp);
874 }
875#endif
876
877#if SUPPORTED_PERSONALITIES > 1
878 update_personality(tcp, tcp->currpers);
879#endif
880 res = (get_regs_error ? -1 : get_syscall_result(tcp));
Dmitry V. Levin4b80f342015-06-29 11:57:44 +0000881 if (filtered(tcp) || hide_log_until_execve)
882 goto ret;
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000883
884 if (cflag) {
885 count_syscall(tcp, &tv);
886 if (cflag == CFLAG_ONLY_STATS) {
887 goto ret;
888 }
889 }
890
891 /* If not in -ff mode, and printing_tcp != tcp,
892 * then the log currently does not end with output
893 * of _our syscall entry_, but with something else.
894 * We need to say which syscall's return is this.
895 *
896 * Forced reprinting via TCB_REPRINT is used only by
897 * "strace -ff -oLOG test/threaded_execve" corner case.
898 * It's the only case when -ff mode needs reprinting.
899 */
900 if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) {
901 tcp->flags &= ~TCB_REPRINT;
902 printleader(tcp);
903 if (tcp->qual_flg & UNDEFINED_SCNO)
904 tprintf("<... %s resumed> ", undefined_scno_name(tcp));
905 else
906 tprintf("<... %s resumed> ", tcp->s_ent->sys_name);
907 }
908 printing_tcp = tcp;
909
910 tcp->s_prev_ent = NULL;
911 if (res != 1) {
912 /* There was error in one of prior ptrace ops */
913 tprints(") ");
914 tabto();
915 tprints("= ? <unavailable>\n");
916 line_ended();
917 tcp->flags &= ~TCB_INSYSCALL;
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000918 tcp->sys_func_rval = 0;
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000919 return res;
920 }
921 tcp->s_prev_ent = tcp->s_ent;
922
923 sys_res = 0;
924 if (tcp->qual_flg & QUAL_RAW) {
925 /* sys_res = printargs(tcp); - but it's nop on sysexit */
926 } else {
927 /* FIXME: not_failing_only (IOW, option -z) is broken:
928 * failure of syscall is known only after syscall return.
929 * Thus we end up with something like this on, say, ENOENT:
930 * open("doesnt_exist", O_RDONLY <unfinished ...>
931 * {next syscall decode}
932 * whereas the intended result is that open(...) line
933 * is not shown at all.
934 */
935 if (not_failing_only && tcp->u_error)
936 goto ret; /* ignore failed syscalls */
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000937 if (tcp->sys_func_rval & RVAL_DECODED)
938 sys_res = tcp->sys_func_rval;
939 else
940 sys_res = tcp->s_ent->sys_func(tcp);
Dmitry V. Levin1b786072015-03-22 18:09:55 +0000941 }
942
943 tprints(") ");
944 tabto();
945 u_error = tcp->u_error;
946 if (tcp->qual_flg & QUAL_RAW) {
947 if (u_error)
948 tprintf("= -1 (errno %ld)", u_error);
949 else
950 tprintf("= %#lx", tcp->u_rval);
951 }
952 else if (!(sys_res & RVAL_NONE) && u_error) {
953 switch (u_error) {
954 /* Blocked signals do not interrupt any syscalls.
955 * In this case syscalls don't return ERESTARTfoo codes.
956 *
957 * Deadly signals set to SIG_DFL interrupt syscalls
958 * and kill the process regardless of which of the codes below
959 * is returned by the interrupted syscall.
960 * In some cases, kernel forces a kernel-generated deadly
961 * signal to be unblocked and set to SIG_DFL (and thus cause
962 * death) if it is blocked or SIG_IGNed: for example, SIGSEGV
963 * or SIGILL. (The alternative is to leave process spinning
964 * forever on the faulty instruction - not useful).
965 *
966 * SIG_IGNed signals and non-deadly signals set to SIG_DFL
967 * (for example, SIGCHLD, SIGWINCH) interrupt syscalls,
968 * but kernel will always restart them.
969 */
970 case ERESTARTSYS:
971 /* Most common type of signal-interrupted syscall exit code.
972 * The system call will be restarted with the same arguments
973 * if SA_RESTART is set; otherwise, it will fail with EINTR.
974 */
975 tprints("= ? ERESTARTSYS (To be restarted if SA_RESTART is set)");
976 break;
977 case ERESTARTNOINTR:
978 /* Rare. For example, fork() returns this if interrupted.
979 * SA_RESTART is ignored (assumed set): the restart is unconditional.
980 */
981 tprints("= ? ERESTARTNOINTR (To be restarted)");
982 break;
983 case ERESTARTNOHAND:
984 /* pause(), rt_sigsuspend() etc use this code.
985 * SA_RESTART is ignored (assumed not set):
986 * syscall won't restart (will return EINTR instead)
987 * even after signal with SA_RESTART set. However,
988 * after SIG_IGN or SIG_DFL signal it will restart
989 * (thus the name "restart only if has no handler").
990 */
991 tprints("= ? ERESTARTNOHAND (To be restarted if no handler)");
992 break;
993 case ERESTART_RESTARTBLOCK:
994 /* Syscalls like nanosleep(), poll() which can't be
995 * restarted with their original arguments use this
996 * code. Kernel will execute restart_syscall() instead,
997 * which changes arguments before restarting syscall.
998 * SA_RESTART is ignored (assumed not set) similarly
999 * to ERESTARTNOHAND. (Kernel can't honor SA_RESTART
1000 * since restart data is saved in "restart block"
1001 * in task struct, and if signal handler uses a syscall
1002 * which in turn saves another such restart block,
1003 * old data is lost and restart becomes impossible)
1004 */
1005 tprints("= ? ERESTART_RESTARTBLOCK (Interrupted by signal)");
1006 break;
1007 default:
1008 if ((unsigned long) u_error < nerrnos
1009 && errnoent[u_error])
1010 tprintf("= -1 %s (%s)", errnoent[u_error],
1011 strerror(u_error));
1012 else
1013 tprintf("= -1 ERRNO_%lu (%s)", u_error,
1014 strerror(u_error));
1015 break;
1016 }
1017 if ((sys_res & RVAL_STR) && tcp->auxstr)
1018 tprintf(" (%s)", tcp->auxstr);
1019 }
1020 else {
1021 if (sys_res & RVAL_NONE)
1022 tprints("= ?");
1023 else {
1024 switch (sys_res & RVAL_MASK) {
1025 case RVAL_HEX:
1026#if SUPPORTED_PERSONALITIES > 1
1027 if (current_wordsize < sizeof(long))
1028 tprintf("= %#x",
1029 (unsigned int) tcp->u_rval);
1030 else
1031#endif
1032 tprintf("= %#lx", tcp->u_rval);
1033 break;
1034 case RVAL_OCTAL:
1035 tprintf("= %#lo", tcp->u_rval);
1036 break;
1037 case RVAL_UDECIMAL:
1038 tprintf("= %lu", tcp->u_rval);
1039 break;
1040 case RVAL_DECIMAL:
1041 tprintf("= %ld", tcp->u_rval);
1042 break;
1043 case RVAL_FD:
1044 if (show_fd_path) {
1045 tprints("= ");
1046 printfd(tcp, tcp->u_rval);
1047 }
1048 else
1049 tprintf("= %ld", tcp->u_rval);
1050 break;
1051#if defined(LINUX_MIPSN32) || defined(X32)
1052 /*
1053 case RVAL_LHEX:
1054 tprintf("= %#llx", tcp->u_lrval);
1055 break;
1056 case RVAL_LOCTAL:
1057 tprintf("= %#llo", tcp->u_lrval);
1058 break;
1059 */
1060 case RVAL_LUDECIMAL:
1061 tprintf("= %llu", tcp->u_lrval);
1062 break;
1063 /*
1064 case RVAL_LDECIMAL:
1065 tprintf("= %lld", tcp->u_lrval);
1066 break;
1067 */
1068#endif
1069 default:
Dmitry V. Levin6c8ef052015-05-25 22:51:19 +00001070 error_msg("invalid rval format");
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001071 break;
1072 }
1073 }
1074 if ((sys_res & RVAL_STR) && tcp->auxstr)
1075 tprintf(" (%s)", tcp->auxstr);
1076 }
1077 if (Tflag) {
1078 tv_sub(&tv, &tv, &tcp->etime);
1079 tprintf(" <%ld.%06ld>",
1080 (long) tv.tv_sec, (long) tv.tv_usec);
1081 }
1082 tprints("\n");
1083 dumpio(tcp);
1084 line_ended();
1085
1086#ifdef USE_LIBUNWIND
1087 if (stack_trace_enabled)
1088 unwind_print_stacktrace(tcp);
1089#endif
1090
1091 ret:
1092 tcp->flags &= ~TCB_INSYSCALL;
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +00001093 tcp->sys_func_rval = 0;
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001094 return 0;
1095}
1096
1097int
1098trace_syscall(struct tcb *tcp)
1099{
1100 return exiting(tcp) ?
1101 trace_syscall_exiting(tcp) : trace_syscall_entering(tcp);
1102}
1103
1104/*
1105 * Cannot rely on __kernel_[u]long_t being defined,
1106 * it is quite a recent feature of <asm/posix_types.h>.
1107 */
1108#ifdef __kernel_long_t
1109typedef __kernel_long_t kernel_long_t;
1110typedef __kernel_ulong_t kernel_ulong_t;
1111#else
1112# ifdef X32
1113typedef long long kernel_long_t;
1114typedef unsigned long long kernel_ulong_t;
1115# else
1116typedef long kernel_long_t;
1117typedef unsigned long kernel_ulong_t;
1118# endif
1119#endif
1120
1121/*
1122 * Check the syscall return value register value for whether it is
1123 * a negated errno code indicating an error, or a success return value.
1124 */
1125static inline bool
1126is_negated_errno(kernel_ulong_t val)
1127{
1128 /* Linux kernel defines MAX_ERRNO to 4095. */
1129 kernel_ulong_t max = -(kernel_long_t) 4095;
1130
1131#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
1132 if (current_wordsize < sizeof(val)) {
1133 val = (uint32_t) val;
1134 max = (uint32_t) max;
1135 }
1136#elif defined X32
1137 /*
1138 * current_wordsize is 4 even in personality 0 (native X32)
1139 * but truncation _must not_ be done in it.
1140 * can't check current_wordsize here!
1141 */
1142 if (current_personality != 0) {
1143 val = (uint32_t) val;
1144 max = (uint32_t) max;
1145 }
1146#endif
1147
1148 return val >= max;
1149}
1150
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001151#include "arch_regs.c"
Wichert Akkermanc7926982000-04-10 22:22:31 +00001152
Dmitry V. Levin78ed3f32015-03-23 00:04:27 +00001153#ifdef HAVE_GETRVAL2
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001154# include "arch_getrval2.c"
Dmitry V. Levin48f08902015-03-05 23:30:02 +00001155#endif
1156
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001157void
Denys Vlasenko5a2483b2013-07-01 12:49:14 +02001158print_pc(struct tcb *tcp)
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001159{
Dmitry V. Levine96cb622015-02-15 15:52:02 +00001160 const char *fmt;
1161 const char *bad;
1162
Dmitry V. Levinb2d9ff22015-02-23 13:43:20 +00001163#ifdef current_wordsize
Dmitry V. Levine96cb622015-02-15 15:52:02 +00001164# define pc_wordsize current_wordsize
Dmitry V. Levinb2d9ff22015-02-23 13:43:20 +00001165#else
1166# define pc_wordsize personality_wordsize[tcp->currpers]
Dmitry V. Levine96cb622015-02-15 15:52:02 +00001167#endif
1168
1169 if (pc_wordsize == 4) {
1170 fmt = "[%08lx] ";
1171 bad = "[????????] ";
1172 } else {
1173 fmt = "[%016lx] ";
1174 bad = "[????????????????] ";
1175 }
1176
1177#undef pc_wordsize
1178#define PRINTBADPC tprints(bad)
1179
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001180 if (get_regs_error) {
1181 PRINTBADPC;
1182 return;
1183 }
Dmitry V. Levine96cb622015-02-15 15:52:02 +00001184
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001185#include "print_pc.c"
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001186}
1187
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001188#if defined X86_64 || defined POWERPC
1189# include "getregs_old.c"
Anton Blanchard14d51a62013-06-26 14:42:37 +10001190#endif
1191
Dmitry V. Levind6db1db2015-02-13 23:41:04 +00001192#if defined ARCH_REGS_FOR_GETREGSET
1193static long
1194get_regset(pid_t pid)
Dmitry V. Levinfaa177e2013-03-17 23:48:45 +00001195{
Dmitry V. Levind6db1db2015-02-13 23:41:04 +00001196# ifdef ARCH_IOVEC_FOR_GETREGSET
1197 /* variable iovec */
1198 ARCH_IOVEC_FOR_GETREGSET.iov_len = sizeof(ARCH_REGS_FOR_GETREGSET);
1199 return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS,
1200 &ARCH_IOVEC_FOR_GETREGSET);
1201# else
1202 /* constant iovec */
Dmitry V. Levinb787b102013-03-18 10:17:14 +00001203 static struct iovec io = {
1204 .iov_base = &ARCH_REGS_FOR_GETREGSET,
1205 .iov_len = sizeof(ARCH_REGS_FOR_GETREGSET)
Dmitry V. Levinfaa177e2013-03-17 23:48:45 +00001206 };
Dmitry V. Levind6db1db2015-02-13 23:41:04 +00001207 return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &io);
Dmitry V. Levinb787b102013-03-18 10:17:14 +00001208
Dmitry V. Levinfaa177e2013-03-17 23:48:45 +00001209# endif
Dmitry V. Levinb787b102013-03-18 10:17:14 +00001210}
Dmitry V. Levind6db1db2015-02-13 23:41:04 +00001211#endif /* ARCH_REGS_FOR_GETREGSET */
Dmitry V. Levinb787b102013-03-18 10:17:14 +00001212
Denys Vlasenko48e4c1b2013-02-16 08:23:40 +01001213void
1214get_regs(pid_t pid)
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001215{
Dmitry V. Levin7abf2e82015-02-13 23:56:54 +00001216#ifdef ARCH_REGS_FOR_GETREGSET
1217# ifdef X86_64
1218 /* Try PTRACE_GETREGSET first, fallback to PTRACE_GETREGS. */
Dmitry V. Levin27e3ae92013-03-17 23:18:35 +00001219 static int getregset_support;
1220
1221 if (getregset_support >= 0) {
Dmitry V. Levind6db1db2015-02-13 23:41:04 +00001222 get_regs_error = get_regset(pid);
Dmitry V. Levin27e3ae92013-03-17 23:18:35 +00001223 if (getregset_support > 0)
1224 return;
1225 if (get_regs_error >= 0) {
1226 getregset_support = 1;
1227 return;
Denys Vlasenkoeec8d5d2013-02-14 03:29:48 +01001228 }
Dmitry V. Levin27e3ae92013-03-17 23:18:35 +00001229 if (errno == EPERM || errno == ESRCH)
1230 return;
1231 getregset_support = -1;
1232 }
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001233 getregs_old(pid);
Dmitry V. Levin7abf2e82015-02-13 23:56:54 +00001234# else /* !X86_64 */
1235 /* Assume that PTRACE_GETREGSET works. */
1236 get_regs_error = get_regset(pid);
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001237# endif
Dmitry V. Levin7abf2e82015-02-13 23:56:54 +00001238#elif defined ARCH_REGS_FOR_GETREGS
1239# if defined SPARC || defined SPARC64
1240 /* SPARC systems have the meaning of data and addr reversed */
1241 get_regs_error = ptrace(PTRACE_GETREGS, pid, (char *)&ARCH_REGS_FOR_GETREGS, 0);
1242# elif defined POWERPC
1243 static bool old_kernel = 0;
1244 if (old_kernel)
1245 goto old;
1246 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS);
1247 if (get_regs_error && errno == EIO) {
1248 old_kernel = 1;
1249 old:
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001250 get_regs_error = getregs_old(pid);
Dmitry V. Levin7abf2e82015-02-13 23:56:54 +00001251 }
1252# else
1253 /* Assume that PTRACE_GETREGS works. */
1254 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &ARCH_REGS_FOR_GETREGS);
1255# endif
1256
1257#else /* !ARCH_REGS_FOR_GETREGSET && !ARCH_REGS_FOR_GETREGS */
1258# warning get_regs is not implemented for this architecture yet
1259 get_regs_error = 0;
1260#endif
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001261}
Denys Vlasenkoce7d9532013-02-05 16:36:13 +01001262
Denys Vlasenkob88f9612011-08-21 18:03:23 +02001263/* Returns:
Denys Vlasenko907735a2012-03-21 00:23:16 +01001264 * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently.
1265 * 1: ok, continue in trace_syscall_entering().
1266 * other: error, trace_syscall_entering() should print error indicator
Denys Vlasenkob88f9612011-08-21 18:03:23 +02001267 * ("????" etc) and bail out.
1268 */
Denys Vlasenko8497b622015-03-21 17:51:52 +01001269int
Denys Vlasenko06602d92011-08-24 17:53:52 +02001270get_scno(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001271{
Dmitry V. Levin144cda22015-03-23 18:48:32 +00001272 if (get_regs_error)
1273 return -1;
1274
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001275 long scno = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001276
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001277#include "get_scno.c"
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00001278
Denys Vlasenko8cd1acd2011-08-24 16:52:57 +02001279 tcp->scno = scno;
Denys Vlasenko74ec14f2013-02-21 16:13:47 +01001280 if (SCNO_IS_VALID(tcp->scno)) {
1281 tcp->s_ent = &sysent[scno];
1282 tcp->qual_flg = qual_flags[scno];
1283 } else {
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +01001284 static const struct_sysent unknown = {
Denys Vlasenko74ec14f2013-02-21 16:13:47 +01001285 .nargs = MAX_ARGS,
1286 .sys_flags = 0,
1287 .sys_func = printargs,
Denys Vlasenkocc59f142015-04-07 12:46:59 +02001288 .sys_name = "system call",
Denys Vlasenko74ec14f2013-02-21 16:13:47 +01001289 };
1290 tcp->s_ent = &unknown;
1291 tcp->qual_flg = UNDEFINED_SCNO | QUAL_RAW | DEFAULT_QUAL_FLAGS;
Dmitry V. Levinea009002015-03-24 01:59:07 +00001292 if (debug_flag)
Dmitry V. Levin6c8ef052015-05-25 22:51:19 +00001293 error_msg("pid %d invalid syscall %ld", tcp->pid, scno);
Denys Vlasenko74ec14f2013-02-21 16:13:47 +01001294 }
Pavel Machek4dc3b142000-02-01 17:58:41 +00001295 return 1;
1296}
1297
Denys Vlasenkobb6bb5c2012-03-20 17:10:35 +01001298/* Return -1 on error or 1 on success (never 0!) */
Roland McGratha4d48532005-06-08 20:45:28 +00001299static int
Denys Vlasenkobb6bb5c2012-03-20 17:10:35 +01001300get_syscall_args(struct tcb *tcp)
Pavel Machek4dc3b142000-02-01 17:58:41 +00001301{
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001302#include "get_syscall_args.c"
Pavel Machek4dc3b142000-02-01 17:58:41 +00001303 return 1;
1304}
1305
Denys Vlasenkoc956ef02013-02-16 14:25:56 +01001306static void
Denys Vlasenkoa6146922011-08-24 18:07:22 +02001307get_error(struct tcb *tcp)
1308{
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001309 const bool check_errno = !(tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS);
1310 tcp->u_error = 0;
Dmitry V. Levinf46ab5f2015-02-05 18:50:24 +00001311
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001312#include "get_error.c"
Denys Vlasenkoa6146922011-08-24 18:07:22 +02001313}
1314
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001315/* Returns:
1316 * 1: ok, continue in trace_syscall_exiting().
1317 * -1: error, trace_syscall_exiting() should print error indicator
1318 * ("????" etc) and bail out.
1319 */
Denys Vlasenkoed4f4f02011-08-22 11:54:06 +02001320static int
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001321get_syscall_result(struct tcb *tcp)
Pavel Machek4dc3b142000-02-01 17:58:41 +00001322{
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001323#if defined ARCH_REGS_FOR_GETREGSET || defined ARCH_REGS_FOR_GETREGS
1324 /* already done by get_regs */
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001325#else
Dmitry V. Levind70d1c42015-03-22 22:13:55 +00001326# include "get_syscall_result.c"
Masatake YAMATOed69fc22014-04-16 15:33:35 +09001327#endif
Dmitry V. Levin1b786072015-03-22 18:09:55 +00001328 get_error(tcp);
1329 return 1;
Dmitry V. Levin7d7c9632010-03-29 17:51:02 +00001330}