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