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>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
36 #include <sys/param.h>
40 # ifndef PTRACE_PEEKUSR
41 # define PTRACE_PEEKUSR PTRACE_PEEKUSER
43 #elif defined(HAVE_LINUX_PTRACE_H)
44 # undef PTRACE_SYSCALL
45 # ifdef HAVE_STRUCT_IA64_FPREG
46 # define ia64_fpreg XXX_ia64_fpreg
48 # ifdef HAVE_STRUCT_PT_ALL_USER_REGS
49 # define pt_all_user_regs XXX_pt_all_user_regs
51 # include <linux/ptrace.h>
53 # undef pt_all_user_regs
57 # undef PTRACE_GETREGS
58 # define PTRACE_GETREGS PTRACE_GETREGS64
59 # undef PTRACE_SETREGS
60 # define PTRACE_SETREGS PTRACE_SETREGS64
64 # include <asm/ptrace_offsets.h>
68 #if defined(X86_64) || defined(X32)
69 # include <linux/ptrace.h>
75 # include <asm/ptrace.h>
91 # define ERESTARTSYS 512
93 #ifndef ERESTARTNOINTR
94 # define ERESTARTNOINTR 513
96 #ifndef ERESTARTNOHAND
97 # define ERESTARTNOHAND 514 /* restart if no handler */
99 #ifndef ERESTART_RESTARTBLOCK
100 # define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
104 # warning: NSIG is not defined, using 32
108 /* Ugh. Is this really correct? ARM has no RT signals?! */
115 /* Define these shorthand notations to simplify the syscallent files. */
116 #define TD TRACE_DESC
117 #define TF TRACE_FILE
119 #define TN TRACE_NETWORK
120 #define TP TRACE_PROCESS
121 #define TS TRACE_SIGNAL
122 #define TM TRACE_MEMORY
123 #define NF SYSCALL_NEVER_FAILS
126 const struct_sysent sysent0[] = {
127 #include "syscallent.h"
130 #if SUPPORTED_PERSONALITIES > 1
131 static const struct_sysent sysent1[] = {
132 # include "syscallent1.h"
136 #if SUPPORTED_PERSONALITIES > 2
137 static const struct_sysent sysent2[] = {
138 # include "syscallent2.h"
142 /* Now undef them since short defines cause wicked namespace pollution. */
154 * `ioctlent.h' may be generated from `ioctlent.raw' by the auxiliary
155 * program `ioctlsort', such that the list is sorted by the `code' field.
156 * This has the side-effect of resolving the _IO.. macros into
157 * plain integers, eliminating the need to include here everything
161 const char *const errnoent0[] = {
162 #include "errnoent.h"
164 const char *const signalent0[] = {
165 #include "signalent.h"
167 const struct_ioctlent ioctlent0[] = {
168 #include "ioctlent.h"
171 #if SUPPORTED_PERSONALITIES > 1
172 static const char *const errnoent1[] = {
173 # include "errnoent1.h"
175 static const char *const signalent1[] = {
176 # include "signalent1.h"
178 static const struct_ioctlent ioctlent1[] = {
179 # include "ioctlent1.h"
183 #if SUPPORTED_PERSONALITIES > 2
184 static const char *const errnoent2[] = {
185 # include "errnoent2.h"
187 static const char *const signalent2[] = {
188 # include "signalent2.h"
190 static const struct_ioctlent ioctlent2[] = {
191 # include "ioctlent2.h"
196 nsyscalls0 = ARRAY_SIZE(sysent0)
197 #if SUPPORTED_PERSONALITIES > 1
198 , nsyscalls1 = ARRAY_SIZE(sysent1)
199 # if SUPPORTED_PERSONALITIES > 2
200 , nsyscalls2 = ARRAY_SIZE(sysent2)
206 nerrnos0 = ARRAY_SIZE(errnoent0)
207 #if SUPPORTED_PERSONALITIES > 1
208 , nerrnos1 = ARRAY_SIZE(errnoent1)
209 # if SUPPORTED_PERSONALITIES > 2
210 , nerrnos2 = ARRAY_SIZE(errnoent2)
216 nsignals0 = ARRAY_SIZE(signalent0)
217 #if SUPPORTED_PERSONALITIES > 1
218 , nsignals1 = ARRAY_SIZE(signalent1)
219 # if SUPPORTED_PERSONALITIES > 2
220 , nsignals2 = ARRAY_SIZE(signalent2)
226 nioctlents0 = ARRAY_SIZE(ioctlent0)
227 #if SUPPORTED_PERSONALITIES > 1
228 , nioctlents1 = ARRAY_SIZE(ioctlent1)
229 # if SUPPORTED_PERSONALITIES > 2
230 , nioctlents2 = ARRAY_SIZE(ioctlent2)
235 #if SUPPORTED_PERSONALITIES > 1
236 const struct_sysent *sysent = sysent0;
237 const char *const *errnoent = errnoent0;
238 const char *const *signalent = signalent0;
239 const struct_ioctlent *ioctlent = ioctlent0;
241 unsigned nsyscalls = nsyscalls0;
242 unsigned nerrnos = nerrnos0;
243 unsigned nsignals = nsignals0;
244 unsigned nioctlents = nioctlents0;
247 qualbits_t *qual_vec[SUPPORTED_PERSONALITIES];
249 static const unsigned nsyscall_vec[SUPPORTED_PERSONALITIES] = {
251 #if SUPPORTED_PERSONALITIES > 1
254 #if SUPPORTED_PERSONALITIES > 2
258 static const struct_sysent *const sysent_vec[SUPPORTED_PERSONALITIES] = {
260 #if SUPPORTED_PERSONALITIES > 1
263 #if SUPPORTED_PERSONALITIES > 2
269 MAX_NSYSCALLS1 = (nsyscalls0
270 #if SUPPORTED_PERSONALITIES > 1
271 > nsyscalls1 ? nsyscalls0 : nsyscalls1
274 MAX_NSYSCALLS2 = (MAX_NSYSCALLS1
275 #if SUPPORTED_PERSONALITIES > 2
276 > nsyscalls2 ? MAX_NSYSCALLS1 : nsyscalls2
279 MAX_NSYSCALLS = MAX_NSYSCALLS2,
280 /* We are ready for arches with up to 255 signals,
281 * even though the largest known signo is on MIPS and it is 128.
282 * The number of existing syscalls on all arches is
283 * larger that 255 anyway, so it is just a pedantic matter.
285 MIN_QUALS = MAX_NSYSCALLS > 255 ? MAX_NSYSCALLS : 255
288 #if SUPPORTED_PERSONALITIES > 1
289 unsigned current_personality;
291 # ifndef current_wordsize
292 unsigned current_wordsize;
293 static const int personality_wordsize[SUPPORTED_PERSONALITIES] = {
294 PERSONALITY0_WORDSIZE,
295 PERSONALITY1_WORDSIZE,
296 # if SUPPORTED_PERSONALITIES > 2
297 PERSONALITY2_WORDSIZE,
303 set_personality(int personality)
305 nsyscalls = nsyscall_vec[personality];
306 sysent = sysent_vec[personality];
308 switch (personality) {
310 errnoent = errnoent0;
312 ioctlent = ioctlent0;
313 nioctlents = nioctlents0;
314 signalent = signalent0;
315 nsignals = nsignals0;
319 errnoent = errnoent1;
321 ioctlent = ioctlent1;
322 nioctlents = nioctlents1;
323 signalent = signalent1;
324 nsignals = nsignals1;
327 # if SUPPORTED_PERSONALITIES > 2
329 errnoent = errnoent2;
331 ioctlent = ioctlent2;
332 nioctlents = nioctlents2;
333 signalent = signalent2;
334 nsignals = nsignals2;
339 current_personality = personality;
340 # ifndef current_wordsize
341 current_wordsize = personality_wordsize[personality];
346 update_personality(struct tcb *tcp, int personality)
348 if (personality == current_personality)
350 set_personality(personality);
352 if (personality == tcp->currpers)
354 tcp->currpers = personality;
356 # if defined(POWERPC64)
358 static const char *const names[] = {"64 bit", "32 bit"};
359 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
360 tcp->pid, names[personality]);
362 # elif defined(X86_64)
364 static const char *const names[] = {"64 bit", "32 bit", "x32"};
365 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
366 tcp->pid, names[personality]);
370 static const char *const names[] = {"x32", "32 bit"};
371 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
372 tcp->pid, names[personality]);
374 # elif defined(AARCH64)
376 static const char *const names[] = {"32-bit", "AArch64"};
377 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
378 tcp->pid, names[personality]);
382 static const char *const names[] = {"64-bit", "32-bit"};
383 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
384 tcp->pid, names[personality]);
390 static int qual_syscall(), qual_signal(), qual_desc();
392 static const struct qual_options {
394 const char *option_name;
395 int (*qualify)(const char *, int, int);
396 const char *argument_name;
398 { QUAL_TRACE, "trace", qual_syscall, "system call" },
399 { QUAL_TRACE, "t", qual_syscall, "system call" },
400 { QUAL_ABBREV, "abbrev", qual_syscall, "system call" },
401 { QUAL_ABBREV, "a", qual_syscall, "system call" },
402 { QUAL_VERBOSE, "verbose", qual_syscall, "system call" },
403 { QUAL_VERBOSE, "v", qual_syscall, "system call" },
404 { QUAL_RAW, "raw", qual_syscall, "system call" },
405 { QUAL_RAW, "x", qual_syscall, "system call" },
406 { QUAL_SIGNAL, "signal", qual_signal, "signal" },
407 { QUAL_SIGNAL, "signals", qual_signal, "signal" },
408 { QUAL_SIGNAL, "s", qual_signal, "signal" },
409 { QUAL_READ, "read", qual_desc, "descriptor" },
410 { QUAL_READ, "reads", qual_desc, "descriptor" },
411 { QUAL_READ, "r", qual_desc, "descriptor" },
412 { QUAL_WRITE, "write", qual_desc, "descriptor" },
413 { QUAL_WRITE, "writes", qual_desc, "descriptor" },
414 { QUAL_WRITE, "w", qual_desc, "descriptor" },
415 { 0, NULL, NULL, NULL },
419 reallocate_qual(int n)
423 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
424 qp = qual_vec[p] = realloc(qual_vec[p], n * sizeof(qualbits_t));
427 memset(&qp[num_quals], 0, (n - num_quals) * sizeof(qualbits_t));
433 qualify_one(int n, int bitflag, int not, int pers)
438 reallocate_qual(n + 1);
440 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
441 if (pers == p || pers < 0) {
443 qual_vec[p][n] &= ~bitflag;
445 qual_vec[p][n] |= bitflag;
451 qual_syscall(const char *s, int bitflag, int not)
457 if (*s >= '0' && *s <= '9') {
458 i = string_to_uint(s);
459 if (i >= MAX_NSYSCALLS)
461 qualify_one(i, bitflag, not, -1);
465 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
466 for (i = 0; i < nsyscall_vec[p]; i++) {
467 if (sysent_vec[p][i].sys_name
468 && strcmp(s, sysent_vec[p][i].sys_name) == 0
470 qualify_one(i, bitflag, not, p);
480 qual_signal(const char *s, int bitflag, int not)
484 if (*s >= '0' && *s <= '9') {
485 int signo = string_to_uint(s);
486 if (signo < 0 || signo > 255)
488 qualify_one(signo, bitflag, not, -1);
491 if (strncasecmp(s, "SIG", 3) == 0)
493 for (i = 0; i <= NSIG; i++) {
494 if (strcasecmp(s, signame(i) + 3) == 0) {
495 qualify_one(i, bitflag, not, -1);
503 qual_desc(const char *s, int bitflag, int not)
505 if (*s >= '0' && *s <= '9') {
506 int desc = string_to_uint(s);
507 if (desc < 0 || desc > 0x7fff) /* paranoia */
509 qualify_one(desc, bitflag, not, -1);
516 lookup_class(const char *s)
518 if (strcmp(s, "file") == 0)
520 if (strcmp(s, "ipc") == 0)
522 if (strcmp(s, "network") == 0)
523 return TRACE_NETWORK;
524 if (strcmp(s, "process") == 0)
525 return TRACE_PROCESS;
526 if (strcmp(s, "signal") == 0)
528 if (strcmp(s, "desc") == 0)
530 if (strcmp(s, "memory") == 0)
536 qualify(const char *s)
538 const struct qual_options *opt;
545 reallocate_qual(MIN_QUALS);
547 opt = &qual_options[0];
548 for (i = 0; (p = qual_options[i].option_name); i++) {
550 if (strncmp(s, p, n) == 0 && s[n] == '=') {
551 opt = &qual_options[i];
561 if (strcmp(s, "none") == 0) {
565 if (strcmp(s, "all") == 0) {
566 for (i = 0; i < num_quals; i++) {
567 qualify_one(i, opt->bitflag, not, -1);
571 for (i = 0; i < num_quals; i++) {
572 qualify_one(i, opt->bitflag, !not, -1);
577 for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) {
578 if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) {
580 for (pers = 0; pers < SUPPORTED_PERSONALITIES; pers++) {
581 for (i = 0; i < nsyscall_vec[pers]; i++)
582 if (sysent_vec[pers][i].sys_flags & n)
583 qualify_one(i, opt->bitflag, not, pers);
587 if (opt->qualify(p, opt->bitflag, not)) {
588 error_msg_and_die("invalid %s '%s'",
589 opt->argument_name, p);
596 #ifdef SYS_socket_subcall
598 decode_socket_subcall(struct tcb *tcp)
601 unsigned int i, n, size;
603 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_socket_nsubcalls)
606 tcp->scno = SYS_socket_subcall + tcp->u_arg[0];
607 tcp->qual_flg = qual_flags[tcp->scno];
608 tcp->s_ent = &sysent[tcp->scno];
609 addr = tcp->u_arg[1];
610 size = current_wordsize;
611 n = tcp->s_ent->nargs;
612 for (i = 0; i < n; ++i) {
613 if (size == sizeof(int)) {
615 if (umove(tcp, addr, &arg) < 0)
621 if (umove(tcp, addr, &arg) < 0)
630 #ifdef SYS_ipc_subcall
632 decode_ipc_subcall(struct tcb *tcp)
636 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_ipc_nsubcalls)
639 tcp->scno = SYS_ipc_subcall + tcp->u_arg[0];
640 tcp->qual_flg = qual_flags[tcp->scno];
641 tcp->s_ent = &sysent[tcp->scno];
642 n = tcp->s_ent->nargs;
643 for (i = 0; i < n; i++)
644 tcp->u_arg[i] = tcp->u_arg[i + 1];
649 printargs(struct tcb *tcp)
653 int n = tcp->s_ent->nargs;
654 for (i = 0; i < n; i++)
655 tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]);
661 printargs_lu(struct tcb *tcp)
665 int n = tcp->s_ent->nargs;
666 for (i = 0; i < n; i++)
667 tprintf("%s%lu", i ? ", " : "", tcp->u_arg[i]);
673 printargs_ld(struct tcb *tcp)
677 int n = tcp->s_ent->nargs;
678 for (i = 0; i < n; i++)
679 tprintf("%s%ld", i ? ", " : "", tcp->u_arg[i]);
684 #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH)
686 getrval2(struct tcb *tcp)
690 # if defined(SPARC) || defined(SPARC64)
691 val = sparc_regs.u_regs[U_REG_O1];
693 if (upeek(tcp, 4*(REG_REG0+1), &val) < 0)
696 if (upeek(tcp, PT_R9, &val) < 0)
705 is_restart_error(struct tcb *tcp)
707 switch (tcp->u_error) {
711 case ERESTART_RESTARTBLOCK:
720 struct user_regs_struct i386_regs;
721 #elif defined(X86_64) || defined(X32)
723 * On i386, pt_regs and user_regs_struct are the same,
724 * but on 64 bit x86, user_regs_struct has six more fields:
725 * fs_base, gs_base, ds, es, fs, gs.
726 * PTRACE_GETREGS fills them too, so struct pt_regs would overflow.
728 struct i386_user_regs_struct {
748 struct user_regs_struct x86_64_r;
749 struct i386_user_regs_struct i386_r;
751 # define x86_64_regs x86_regs_union.x86_64_r
752 # define i386_regs x86_regs_union.i386_r
753 static struct iovec x86_io = {
754 .iov_base = &x86_regs_union
757 long ia32 = 0; /* not static */
758 static long ia64_r8, ia64_r10;
759 #elif defined(POWERPC)
760 static long ppc_result;
766 struct pt_regs arm_regs; /* not static */
767 #elif defined(AARCH64)
769 struct user_pt_regs aarch64_r;
770 struct arm_pt_regs arm_r;
772 # define aarch64_regs arm_regs_union.aarch64_r
773 # define arm_regs arm_regs_union.arm_r
774 static struct iovec aarch64_io = {
775 .iov_base = &arm_regs_union
778 static long alpha_r0;
779 static long alpha_a3;
781 static struct pt_regs avr32_regs;
782 #elif defined(SPARC) || defined(SPARC64)
783 struct pt_regs sparc_regs; /* not static */
784 #elif defined(LINUX_MIPSN32)
785 static long long mips_a3;
786 static long long mips_r2;
790 #elif defined(S390) || defined(S390X)
792 static long syscall_mode;
794 static long hppa_r28;
799 #elif defined(CRISV10) || defined(CRISV32)
800 static long cris_r10;
802 struct pt_regs tile_regs;
803 #elif defined(MICROBLAZE)
804 static long microblaze_r3;
806 static struct user_regs_struct or1k_regs;
807 static struct iovec or1k_io = {
808 .iov_base = &or1k_regs
811 static struct user_gp_regs metag_regs;
812 static struct iovec metag_io = {
813 .iov_base = &metag_regs
818 printcall(struct tcb *tcp)
820 #define PRINTBADPC tprintf(sizeof(long) == 4 ? "[????????] " : \
821 sizeof(long) == 8 ? "[????????????????] " : \
823 if (get_regs_error) {
828 tprintf("[%08lx] ", i386_regs.eip);
829 #elif defined(S390) || defined(S390X)
831 if (upeek(tcp, PT_PSWADDR, &psw) < 0) {
836 tprintf("[%08lx] ", psw);
838 tprintf("[%016lx] ", psw);
840 #elif defined(X86_64) || defined(X32)
841 if (x86_io.iov_len == sizeof(i386_regs)) {
842 tprintf("[%08x] ", (unsigned) i386_regs.eip);
845 tprintf("[%016lx] ", (unsigned long) x86_64_regs.rip);
847 /* Note: this truncates 64-bit rip to 32 bits */
848 tprintf("[%08lx] ", (unsigned long) x86_64_regs.rip);
853 if (upeek(tcp, PT_B0, &ip) < 0) {
857 tprintf("[%08lx] ", ip);
858 #elif defined(POWERPC)
860 if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &pc) < 0) {
865 tprintf("[%016lx] ", pc);
867 tprintf("[%08lx] ", pc);
871 if (upeek(tcp, 4*PT_PC, &pc) < 0) {
872 tprints("[????????] ");
875 tprintf("[%08lx] ", pc);
878 if (upeek(tcp, REG_PC, &pc) < 0) {
879 tprints("[????????????????] ");
882 tprintf("[%08lx] ", pc);
884 tprintf("[%08lx] ", sparc_regs.pc);
885 #elif defined(SPARC64)
886 tprintf("[%08lx] ", sparc_regs.tpc);
889 if (upeek(tcp, PT_IAOQ0, &pc) < 0) {
890 tprints("[????????] ");
893 tprintf("[%08lx] ", pc);
896 if (upeek(tcp, REG_EPC, &pc) < 0) {
897 tprints("[????????] ");
900 tprintf("[%08lx] ", pc);
903 if (upeek(tcp, 4*REG_PC, &pc) < 0) {
904 tprints("[????????] ");
907 tprintf("[%08lx] ", pc);
910 if (upeek(tcp, REG_PC, &pc) < 0) {
911 tprints("[????????????????] ");
914 tprintf("[%08lx] ", pc);
916 tprintf("[%08lx] ", arm_regs.ARM_pc);
917 #elif defined(AARCH64)
918 /* tprintf("[%016lx] ", aarch64_regs.regs[???]); */
920 tprintf("[%08lx] ", avr32_regs.pc);
923 if (upeek(tcp, PT_PC, &pc) < 0) {
927 tprintf("[%08lx] ", pc);
928 #elif defined(CRISV10)
930 if (upeek(tcp, 4*PT_IRP, &pc) < 0) {
934 tprintf("[%08lx] ", pc);
935 #elif defined(CRISV32)
937 if (upeek(tcp, 4*PT_ERP, &pc) < 0) {
941 tprintf("[%08lx] ", pc);
944 tprintf("[%016lx] ", (unsigned long) tile_regs.pc);
946 tprintf("[%08lx] ", (unsigned long) tile_regs.pc);
949 tprintf("[%08lx] ", or1k_regs.pc);
951 tprintf("[%08lx] ", metag_regs.pc);
952 #endif /* architecture */
955 /* Shuffle syscall numbers so that we don't have huge gaps in syscall table.
956 * The shuffling should be reversible: shuffle_scno(shuffle_scno(n)) == n.
958 #if defined(ARM) /* So far only ARM needs this */
960 shuffle_scno(unsigned long scno)
962 if (scno <= ARM_LAST_ORDINARY_SYSCALL)
965 /* __ARM_NR_cmpxchg? Swap with LAST_ORDINARY+1 */
966 if (scno == 0x000ffff0)
967 return ARM_LAST_ORDINARY_SYSCALL+1;
968 if (scno == ARM_LAST_ORDINARY_SYSCALL+1)
971 /* Is it ARM specific syscall?
972 * Swap with [LAST_ORDINARY+2, LAST_ORDINARY+2 + LAST_SPECIAL] range.
974 if (scno >= 0x000f0000
975 && scno <= 0x000f0000 + ARM_LAST_SPECIAL_SYSCALL
977 return scno - 0x000f0000 + (ARM_LAST_ORDINARY_SYSCALL+2);
979 if (/* scno >= ARM_LAST_ORDINARY_SYSCALL+2 - always true */ 1
980 && scno <= (ARM_LAST_ORDINARY_SYSCALL+2) + ARM_LAST_SPECIAL_SYSCALL
982 return scno + 0x000f0000 - (ARM_LAST_ORDINARY_SYSCALL+2);
988 # define shuffle_scno(scno) ((long)(scno))
992 undefined_scno_name(struct tcb *tcp)
994 static char buf[sizeof("syscall_%lu") + sizeof(long)*3];
996 sprintf(buf, "syscall_%lu", shuffle_scno(tcp->scno));
1001 long get_regs_error;
1006 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &avr32_regs);
1007 # elif defined(I386)
1008 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &i386_regs);
1009 # elif defined(X86_64) || defined(X32)
1011 * PTRACE_GETREGSET was introduced in 2.6.33.
1012 * Let's be paranoid and require a bit later kernel.
1014 if (os_release >= KERNEL_VERSION(2,6,35)) {
1015 /*x86_io.iov_base = &x86_regs_union; - already is */
1016 x86_io.iov_len = sizeof(x86_regs_union);
1017 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, (long) &x86_io);
1019 /* Use old method, with heuristical detection of 32-bitness */
1020 x86_io.iov_len = sizeof(x86_64_regs);
1021 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &x86_64_regs);
1022 if (!get_regs_error && x86_64_regs.cs == 0x23) {
1023 x86_io.iov_len = sizeof(i386_regs);
1025 * The order is important: i386_regs and x86_64_regs
1026 * are overlaid in memory!
1028 i386_regs.ebx = x86_64_regs.rbx;
1029 i386_regs.ecx = x86_64_regs.rcx;
1030 i386_regs.edx = x86_64_regs.rdx;
1031 i386_regs.esi = x86_64_regs.rsi;
1032 i386_regs.edi = x86_64_regs.rdi;
1033 i386_regs.ebp = x86_64_regs.rbp;
1034 i386_regs.eax = x86_64_regs.rax;
1035 /*i386_regs.xds = x86_64_regs.ds; unused by strace */
1036 /*i386_regs.xes = x86_64_regs.es; ditto... */
1037 /*i386_regs.xfs = x86_64_regs.fs;*/
1038 /*i386_regs.xgs = x86_64_regs.gs;*/
1039 i386_regs.orig_eax = x86_64_regs.orig_rax;
1040 i386_regs.eip = x86_64_regs.rip;
1041 /*i386_regs.xcs = x86_64_regs.cs;*/
1042 /*i386_regs.eflags = x86_64_regs.eflags;*/
1043 i386_regs.esp = x86_64_regs.rsp;
1044 /*i386_regs.xss = x86_64_regs.ss;*/
1048 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (void *)&arm_regs);
1049 # elif defined(AARCH64)
1050 /*aarch64_io.iov_base = &arm_regs_union; - already is */
1051 aarch64_io.iov_len = sizeof(arm_regs_union);
1052 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, (void *)&aarch64_io);
1054 /* Paranoia checks */
1057 switch (aarch64_io.iov_len) {
1058 case sizeof(aarch64_regs):
1059 /* We are in 64-bit mode */
1061 case sizeof(arm_regs):
1062 /* We are in 32-bit mode */
1065 get_regs_error = -1;
1069 # elif defined(SPARC) || defined(SPARC64)
1070 get_regs_error = ptrace(PTRACE_GETREGS, pid, (char *)&sparc_regs, 0);
1071 # elif defined(TILE)
1072 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &tile_regs);
1073 # elif defined(OR1K)
1074 or1k_io.iov_len = sizeof(or1k_regs);
1075 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &or1k_io);
1076 # elif defined(METAG)
1077 metag_io.iov_len = sizeof(metag_regs);
1078 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &metag_io);
1084 * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently.
1085 * 1: ok, continue in trace_syscall_entering().
1086 * other: error, trace_syscall_entering() should print error indicator
1087 * ("????" etc) and bail out.
1090 get_scno(struct tcb *tcp)
1094 #if defined(S390) || defined(S390X)
1095 if (upeek(tcp, PT_GPR2, &syscall_mode) < 0)
1098 if (syscall_mode != -ENOSYS) {
1100 * Since kernel version 2.5.44 the scno gets passed in gpr2.
1102 scno = syscall_mode;
1105 * Old style of "passing" the scno via the SVC instruction.
1108 long opcode, offset_reg, tmp;
1110 static const int gpr_offset[16] = {
1111 PT_GPR0, PT_GPR1, PT_ORIGGPR2, PT_GPR3,
1112 PT_GPR4, PT_GPR5, PT_GPR6, PT_GPR7,
1113 PT_GPR8, PT_GPR9, PT_GPR10, PT_GPR11,
1114 PT_GPR12, PT_GPR13, PT_GPR14, PT_GPR15
1117 if (upeek(tcp, PT_PSWADDR, &psw) < 0)
1120 opcode = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(psw - sizeof(long)), 0);
1122 perror_msg("peektext(psw-oneword)");
1127 * We have to check if the SVC got executed directly or via an
1128 * EXECUTE instruction. In case of EXECUTE it is necessary to do
1129 * instruction decoding to derive the system call number.
1130 * Unfortunately the opcode sizes of EXECUTE and SVC are differently,
1131 * so that this doesn't work if a SVC opcode is part of an EXECUTE
1132 * opcode. Since there is no way to find out the opcode size this
1133 * is the best we can do...
1135 if ((opcode & 0xff00) == 0x0a00) {
1137 scno = opcode & 0xff;
1140 /* SVC got executed by EXECUTE instruction */
1143 * Do instruction decoding of EXECUTE. If you really want to
1144 * understand this, read the Principles of Operations.
1146 svc_addr = (void *) (opcode & 0xfff);
1149 offset_reg = (opcode & 0x000f0000) >> 16;
1150 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1155 offset_reg = (opcode & 0x0000f000) >> 12;
1156 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1160 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, svc_addr, 0);
1169 offset_reg = (opcode & 0x00f00000) >> 20;
1170 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1173 scno = (scno | tmp) & 0xff;
1176 #elif defined(POWERPC)
1177 if (upeek(tcp, sizeof(unsigned long)*PT_R0, &scno) < 0)
1180 /* TODO: speed up strace by not doing this at every syscall.
1181 * We only need to do it after execve.
1186 /* Check for 64/32 bit mode. */
1187 if (upeek(tcp, sizeof(unsigned long)*PT_MSR, &val) < 0)
1189 /* SF is bit 0 of MSR */
1194 update_personality(tcp, currpers);
1196 #elif defined(AVR32)
1197 scno = avr32_regs.r8;
1199 if (upeek(tcp, PT_ORIG_P0, &scno))
1202 scno = i386_regs.orig_eax;
1203 #elif defined(X86_64) || defined(X32)
1204 # ifndef __X32_SYSCALL_BIT
1205 # define __X32_SYSCALL_BIT 0x40000000
1209 /* GETREGSET of NT_PRSTATUS tells us regset size,
1210 * which unambiguously detects i386.
1212 * Linux kernel distinguishes x86-64 and x32 processes
1213 * solely by looking at __X32_SYSCALL_BIT:
1214 * arch/x86/include/asm/compat.h::is_x32_task():
1215 * if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
1218 if (x86_io.iov_len == sizeof(i386_regs)) {
1219 scno = i386_regs.orig_eax;
1222 scno = x86_64_regs.orig_rax;
1224 if (scno & __X32_SYSCALL_BIT) {
1225 scno -= __X32_SYSCALL_BIT;
1230 /* cs = 0x33 for long mode (native 64 bit and x32)
1231 * cs = 0x23 for compatibility mode (32 bit)
1232 * ds = 0x2b for x32 mode (x86-64 in 32 bit)
1234 scno = x86_64_regs.orig_rax;
1235 switch (x86_64_regs.cs) {
1236 case 0x23: currpers = 1; break;
1238 if (x86_64_regs.ds == 0x2b) {
1240 scno &= ~__X32_SYSCALL_BIT;
1245 fprintf(stderr, "Unknown value CS=0x%08X while "
1246 "detecting personality of process "
1247 "PID=%d\n", (int)x86_64_regs.cs, tcp->pid);
1248 currpers = current_personality;
1252 /* This version analyzes the opcode of a syscall instruction.
1253 * (int 0x80 on i386 vs. syscall on x86-64)
1254 * It works, but is too complicated, and strictly speaking, unreliable.
1256 unsigned long call, rip = x86_64_regs.rip;
1257 /* sizeof(syscall) == sizeof(int 0x80) == 2 */
1260 call = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)rip, (char *)0);
1262 fprintf(stderr, "ptrace_peektext failed: %s\n",
1264 switch (call & 0xffff) {
1265 /* x86-64: syscall = 0x0f 0x05 */
1266 case 0x050f: currpers = 0; break;
1267 /* i386: int 0x80 = 0xcd 0x80 */
1268 case 0x80cd: currpers = 1; break;
1270 currpers = current_personality;
1272 "Unknown syscall opcode (0x%04X) while "
1273 "detecting personality of process "
1274 "PID=%d\n", (int)call, tcp->pid);
1280 /* If we are built for a x32 system, then personality 0 is x32
1281 * (not x86_64), and stracing of x86_64 apps is not supported.
1282 * Stracing of i386 apps is still supported.
1284 if (currpers == 0) {
1285 fprintf(stderr, "syscall_%lu(...) in unsupported "
1286 "64-bit mode of process PID=%d\n",
1290 currpers &= ~2; /* map 2,1 to 0,1 */
1292 update_personality(tcp, currpers);
1294 # define IA64_PSR_IS ((long)1 << 34)
1296 if (upeek(tcp, PT_CR_IPSR, &psr) >= 0)
1297 ia32 = (psr & IA64_PSR_IS) != 0;
1299 if (upeek(tcp, PT_R1, &scno) < 0)
1302 if (upeek(tcp, PT_R15, &scno) < 0)
1305 #elif defined(AARCH64)
1306 switch (aarch64_io.iov_len) {
1307 case sizeof(aarch64_regs):
1308 /* We are in 64-bit mode */
1309 scno = aarch64_regs.regs[8];
1310 update_personality(tcp, 1);
1312 case sizeof(arm_regs):
1313 /* We are in 32-bit mode */
1314 scno = arm_regs.ARM_r7;
1315 update_personality(tcp, 0);
1319 if (arm_regs.ARM_ip != 0) {
1320 /* It is not a syscall entry */
1321 fprintf(stderr, "pid %d stray syscall exit\n", tcp->pid);
1322 tcp->flags |= TCB_INSYSCALL;
1325 /* Note: we support only 32-bit CPUs, not 26-bit */
1327 if (arm_regs.ARM_cpsr & 0x20) {
1329 scno = arm_regs.ARM_r7;
1333 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(arm_regs.ARM_pc - 4), NULL);
1337 /* EABI syscall convention? */
1338 if (scno == 0xef000000) {
1339 scno = arm_regs.ARM_r7; /* yes */
1341 if ((scno & 0x0ff00000) != 0x0f900000) {
1342 fprintf(stderr, "pid %d unknown syscall trap 0x%08lx\n",
1346 /* Fixup the syscall number */
1351 scno = shuffle_scno(scno);
1353 if (upeek(tcp, 4*PT_ORIG_D0, &scno) < 0)
1355 #elif defined(LINUX_MIPSN32)
1356 unsigned long long regs[38];
1358 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
1360 mips_a3 = regs[REG_A3];
1361 mips_r2 = regs[REG_V0];
1364 if (!SCNO_IN_RANGE(scno)) {
1365 if (mips_a3 == 0 || mips_a3 == -1) {
1367 fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
1372 if (upeek(tcp, REG_A3, &mips_a3) < 0)
1374 if (upeek(tcp, REG_V0, &scno) < 0)
1377 if (!SCNO_IN_RANGE(scno)) {
1378 if (mips_a3 == 0 || mips_a3 == -1) {
1380 fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
1384 #elif defined(ALPHA)
1385 if (upeek(tcp, REG_A3, &alpha_a3) < 0)
1387 if (upeek(tcp, REG_R0, &scno) < 0)
1391 * Do some sanity checks to figure out if it's
1392 * really a syscall entry
1394 if (!SCNO_IN_RANGE(scno)) {
1395 if (alpha_a3 == 0 || alpha_a3 == -1) {
1397 fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno);
1401 #elif defined(SPARC) || defined(SPARC64)
1402 /* Disassemble the syscall trap. */
1403 /* Retrieve the syscall trap instruction. */
1406 # if defined(SPARC64)
1407 trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.tpc, 0);
1410 trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.pc, 0);
1415 /* Disassemble the trap to see what personality to use. */
1418 /* Linux/SPARC syscall trap. */
1419 update_personality(tcp, 0);
1422 /* Linux/SPARC64 syscall trap. */
1423 update_personality(tcp, 2);
1426 /* SunOS syscall trap. (pers 1) */
1427 fprintf(stderr, "syscall: SunOS no support\n");
1430 /* Solaris 2.x syscall trap. (per 2) */
1431 update_personality(tcp, 1);
1434 /* NetBSD/FreeBSD syscall trap. */
1435 fprintf(stderr, "syscall: NetBSD/FreeBSD not supported\n");
1438 /* Solaris 2.x gettimeofday */
1439 update_personality(tcp, 1);
1442 # if defined(SPARC64)
1443 fprintf(stderr, "syscall: unknown syscall trap %08lx %016lx\n", trap, sparc_regs.tpc);
1445 fprintf(stderr, "syscall: unknown syscall trap %08lx %08lx\n", trap, sparc_regs.pc);
1450 /* Extract the system call number from the registers. */
1451 if (trap == 0x91d02027)
1454 scno = sparc_regs.u_regs[U_REG_G1];
1456 scno = sparc_regs.u_regs[U_REG_O0];
1457 memmove(&sparc_regs.u_regs[U_REG_O0], &sparc_regs.u_regs[U_REG_O1], 7*sizeof(sparc_regs.u_regs[0]));
1460 if (upeek(tcp, PT_GR20, &scno) < 0)
1464 * In the new syscall ABI, the system call number is in R3.
1466 if (upeek(tcp, 4*(REG_REG0+3), &scno) < 0)
1470 /* Odd as it may seem, a glibc bug has been known to cause
1471 glibc to issue bogus negative syscall numbers. So for
1472 our purposes, make strace print what it *should* have been */
1473 long correct_scno = (scno & 0xff);
1476 "Detected glibc bug: bogus system call"
1477 " number = %ld, correcting to %ld\n",
1480 scno = correct_scno;
1483 if (upeek(tcp, REG_SYSCALL, &scno) < 0)
1486 #elif defined(CRISV10) || defined(CRISV32)
1487 if (upeek(tcp, 4*PT_R9, &scno) < 0)
1491 scno = tile_regs.regs[10];
1495 # ifndef PT_FLAGS_COMPAT
1496 # define PT_FLAGS_COMPAT 0x10000 /* from Linux 3.8 on */
1498 if (tile_regs.flags & PT_FLAGS_COMPAT)
1503 update_personality(tcp, currpers);
1504 #elif defined(MICROBLAZE)
1505 if (upeek(tcp, 0, &scno) < 0)
1508 scno = or1k_regs.gpr[11];
1509 #elif defined(METAG)
1510 scno = metag_regs.dx[0][1]; /* syscall number in D1Re0 (D1.0) */
1514 if (SCNO_IS_VALID(tcp->scno)) {
1515 tcp->s_ent = &sysent[scno];
1516 tcp->qual_flg = qual_flags[scno];
1518 static const struct_sysent unknown = {
1521 .sys_func = printargs,
1522 .sys_name = "unknown", /* not used */
1524 tcp->s_ent = &unknown;
1525 tcp->qual_flg = UNDEFINED_SCNO | QUAL_RAW | DEFAULT_QUAL_FLAGS;
1530 /* Called at each syscall entry.
1532 * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently.
1533 * 1: ok, continue in trace_syscall_entering().
1534 * other: error, trace_syscall_entering() should print error indicator
1535 * ("????" etc) and bail out.
1538 syscall_fixup_on_sysenter(struct tcb *tcp)
1540 /* A common case of "not a syscall entry" is post-execve SIGTRAP */
1542 if (i386_regs.eax != -ENOSYS) {
1544 fprintf(stderr, "not a syscall entry (eax = %ld)\n", i386_regs.eax);
1547 #elif defined(X86_64) || defined(X32)
1550 if (x86_io.iov_len == sizeof(i386_regs)) {
1551 /* Sign extend from 32 bits */
1552 rax = (int32_t)i386_regs.eax;
1554 /* Note: in X32 build, this truncates 64 to 32 bits */
1555 rax = x86_64_regs.rax;
1557 if (rax != -ENOSYS) {
1559 fprintf(stderr, "not a syscall entry (rax = %ld)\n", rax);
1563 #elif defined(S390) || defined(S390X)
1564 /* TODO: we already fetched PT_GPR2 in get_scno
1565 * and stored it in syscall_mode, reuse it here
1566 * instead of re-fetching?
1568 if (upeek(tcp, PT_GPR2, &gpr2) < 0)
1570 if (syscall_mode != -ENOSYS)
1571 syscall_mode = tcp->scno;
1572 if (gpr2 != syscall_mode) {
1574 fprintf(stderr, "not a syscall entry (gpr2 = %ld)\n", gpr2);
1578 /* TODO? Eliminate upeek's in arches below like we did in x86 */
1579 if (upeek(tcp, 4*PT_D0, &m68k_d0) < 0)
1581 if (m68k_d0 != -ENOSYS) {
1583 fprintf(stderr, "not a syscall entry (d0 = %ld)\n", m68k_d0);
1587 if (upeek(tcp, PT_R10, &ia64_r10) < 0)
1589 if (upeek(tcp, PT_R8, &ia64_r8) < 0)
1591 if (ia32 && ia64_r8 != -ENOSYS) {
1593 fprintf(stderr, "not a syscall entry (r8 = %ld)\n", ia64_r8);
1596 #elif defined(CRISV10) || defined(CRISV32)
1597 if (upeek(tcp, 4*PT_R10, &cris_r10) < 0)
1599 if (cris_r10 != -ENOSYS) {
1601 fprintf(stderr, "not a syscall entry (r10 = %ld)\n", cris_r10);
1604 #elif defined(MICROBLAZE)
1605 if (upeek(tcp, 3 * 4, µblaze_r3) < 0)
1607 if (microblaze_r3 != -ENOSYS) {
1609 fprintf(stderr, "not a syscall entry (r3 = %ld)\n", microblaze_r3);
1617 internal_fork(struct tcb *tcp)
1619 #if defined S390 || defined S390X || defined CRISV10 || defined CRISV32
1620 # define ARG_FLAGS 1
1622 # define ARG_FLAGS 0
1624 #ifndef CLONE_UNTRACED
1625 # define CLONE_UNTRACED 0x00800000
1627 if ((ptrace_setoptions
1628 & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
1629 == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
1635 if (entering(tcp)) {
1637 * We won't see the new child if clone is called with
1638 * CLONE_UNTRACED, so we keep the same logic with that option
1639 * and don't trace it.
1641 if ((tcp->s_ent->sys_func == sys_clone)
1642 && (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED)
1647 if (tcp->flags & TCB_BPTSET)
1652 #if defined(TCB_WAITEXECVE)
1654 internal_exec(struct tcb *tcp)
1656 /* Maybe we have post-execve SIGTRAP suppressed? */
1657 if (ptrace_setoptions & PTRACE_O_TRACEEXEC)
1658 return; /* yes, no need to do anything */
1660 if (exiting(tcp) && syserror(tcp))
1661 /* Error in execve, no post-execve SIGTRAP expected */
1662 tcp->flags &= ~TCB_WAITEXECVE;
1664 tcp->flags |= TCB_WAITEXECVE;
1669 syscall_fixup_for_fork_exec(struct tcb *tcp)
1672 * We must always trace a few critical system calls in order to
1673 * correctly support following forks in the presence of tracing
1678 func = tcp->s_ent->sys_func;
1680 if ( sys_fork == func
1681 || sys_vfork == func
1682 || sys_clone == func
1688 #if defined(TCB_WAITEXECVE)
1689 if ( sys_execve == func
1690 # if defined(SPARC) || defined(SPARC64)
1691 || sys_execv == func
1700 /* Return -1 on error or 1 on success (never 0!) */
1702 get_syscall_args(struct tcb *tcp)
1706 nargs = tcp->s_ent->nargs;
1708 #if defined(S390) || defined(S390X)
1709 for (i = 0; i < nargs; ++i)
1710 if (upeek(tcp, i==0 ? PT_ORIGGPR2 : PT_GPR2 + i*sizeof(long), &tcp->u_arg[i]) < 0)
1712 #elif defined(ALPHA)
1713 for (i = 0; i < nargs; ++i)
1714 if (upeek(tcp, REG_A0+i, &tcp->u_arg[i]) < 0)
1718 unsigned long *out0, cfm, sof, sol;
1720 /* be backwards compatible with kernel < 2.4.4... */
1722 # define PT_RBS_END PT_AR_BSP
1725 if (upeek(tcp, PT_RBS_END, &rbs_end) < 0)
1727 if (upeek(tcp, PT_CFM, (long *) &cfm) < 0)
1730 sof = (cfm >> 0) & 0x7f;
1731 sol = (cfm >> 7) & 0x7f;
1732 out0 = ia64_rse_skip_regs((unsigned long *) rbs_end, -sof + sol);
1734 for (i = 0; i < nargs; ++i) {
1735 if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i),
1736 sizeof(long), (char *) &tcp->u_arg[i]) < 0)
1740 static const int argreg[MAX_ARGS] = { PT_R11 /* EBX = out0 */,
1741 PT_R9 /* ECX = out1 */,
1742 PT_R10 /* EDX = out2 */,
1743 PT_R14 /* ESI = out3 */,
1744 PT_R15 /* EDI = out4 */,
1745 PT_R13 /* EBP = out5 */};
1747 for (i = 0; i < nargs; ++i) {
1748 if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
1750 /* truncate away IVE sign-extension */
1751 tcp->u_arg[i] &= 0xffffffff;
1754 #elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
1755 /* N32 and N64 both use up to six registers. */
1756 unsigned long long regs[38];
1758 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
1761 for (i = 0; i < nargs; ++i) {
1762 tcp->u_arg[i] = regs[REG_A0 + i];
1763 # if defined(LINUX_MIPSN32)
1764 tcp->ext_arg[i] = regs[REG_A0 + i];
1771 if (upeek(tcp, REG_SP, &sp) < 0)
1773 for (i = 0; i < 4; ++i)
1774 if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
1776 umoven(tcp, sp + 16, (nargs - 4) * sizeof(tcp->u_arg[0]),
1777 (char *)(tcp->u_arg + 4));
1779 for (i = 0; i < nargs; ++i)
1780 if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
1783 #elif defined(POWERPC)
1785 # define PT_ORIG_R3 34
1787 for (i = 0; i < nargs; ++i) {
1788 if (upeek(tcp, (i==0) ?
1789 (sizeof(unsigned long) * PT_ORIG_R3) :
1790 ((i+PT_R3) * sizeof(unsigned long)),
1791 &tcp->u_arg[i]) < 0)
1794 #elif defined(SPARC) || defined(SPARC64)
1795 for (i = 0; i < nargs; ++i)
1796 tcp->u_arg[i] = sparc_regs.u_regs[U_REG_O0 + i];
1798 for (i = 0; i < nargs; ++i)
1799 if (upeek(tcp, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
1801 #elif defined(ARM) || defined(AARCH64)
1802 # if defined(AARCH64)
1803 if (tcp->currpers == 1)
1804 for (i = 0; i < nargs; ++i)
1805 tcp->u_arg[i] = aarch64_regs.regs[i];
1808 for (i = 0; i < nargs; ++i)
1809 tcp->u_arg[i] = arm_regs.uregs[i];
1810 #elif defined(AVR32)
1813 tcp->u_arg[0] = avr32_regs.r12;
1814 tcp->u_arg[1] = avr32_regs.r11;
1815 tcp->u_arg[2] = avr32_regs.r10;
1816 tcp->u_arg[3] = avr32_regs.r9;
1817 tcp->u_arg[4] = avr32_regs.r5;
1818 tcp->u_arg[5] = avr32_regs.r3;
1820 static const int argreg[MAX_ARGS] = { PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5 };
1822 for (i = 0; i < nargs; ++i)
1823 if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
1826 static const int syscall_regs[MAX_ARGS] = {
1827 4 * (REG_REG0+4), 4 * (REG_REG0+5), 4 * (REG_REG0+6),
1828 4 * (REG_REG0+7), 4 * (REG_REG0 ), 4 * (REG_REG0+1)
1831 for (i = 0; i < nargs; ++i)
1832 if (upeek(tcp, syscall_regs[i], &tcp->u_arg[i]) < 0)
1836 /* Registers used by SH5 Linux system calls for parameters */
1837 static const int syscall_regs[MAX_ARGS] = { 2, 3, 4, 5, 6, 7 };
1839 for (i = 0; i < nargs; ++i)
1840 if (upeek(tcp, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0)
1845 tcp->u_arg[0] = i386_regs.ebx;
1846 tcp->u_arg[1] = i386_regs.ecx;
1847 tcp->u_arg[2] = i386_regs.edx;
1848 tcp->u_arg[3] = i386_regs.esi;
1849 tcp->u_arg[4] = i386_regs.edi;
1850 tcp->u_arg[5] = i386_regs.ebp;
1851 #elif defined(X86_64) || defined(X32)
1854 if (x86_io.iov_len != sizeof(i386_regs)) {
1855 /* x86-64 or x32 ABI */
1856 tcp->u_arg[0] = x86_64_regs.rdi;
1857 tcp->u_arg[1] = x86_64_regs.rsi;
1858 tcp->u_arg[2] = x86_64_regs.rdx;
1859 tcp->u_arg[3] = x86_64_regs.r10;
1860 tcp->u_arg[4] = x86_64_regs.r8;
1861 tcp->u_arg[5] = x86_64_regs.r9;
1863 tcp->ext_arg[0] = x86_64_regs.rdi;
1864 tcp->ext_arg[1] = x86_64_regs.rsi;
1865 tcp->ext_arg[2] = x86_64_regs.rdx;
1866 tcp->ext_arg[3] = x86_64_regs.r10;
1867 tcp->ext_arg[4] = x86_64_regs.r8;
1868 tcp->ext_arg[5] = x86_64_regs.r9;
1872 /* Zero-extend from 32 bits */
1873 /* Use widen_to_long(tcp->u_arg[N]) in syscall handlers
1874 * if you need to use *sign-extended* parameter.
1876 tcp->u_arg[0] = (long)(uint32_t)i386_regs.ebx;
1877 tcp->u_arg[1] = (long)(uint32_t)i386_regs.ecx;
1878 tcp->u_arg[2] = (long)(uint32_t)i386_regs.edx;
1879 tcp->u_arg[3] = (long)(uint32_t)i386_regs.esi;
1880 tcp->u_arg[4] = (long)(uint32_t)i386_regs.edi;
1881 tcp->u_arg[5] = (long)(uint32_t)i386_regs.ebp;
1883 #elif defined(MICROBLAZE)
1884 for (i = 0; i < nargs; ++i)
1885 if (upeek(tcp, (5 + i) * 4, &tcp->u_arg[i]) < 0)
1887 #elif defined(CRISV10) || defined(CRISV32)
1888 static const int crisregs[MAX_ARGS] = {
1889 4*PT_ORIG_R10, 4*PT_R11, 4*PT_R12,
1890 4*PT_R13 , 4*PT_MOF, 4*PT_SRP
1893 for (i = 0; i < nargs; ++i)
1894 if (upeek(tcp, crisregs[i], &tcp->u_arg[i]) < 0)
1897 for (i = 0; i < nargs; ++i)
1898 tcp->u_arg[i] = tile_regs.regs[i];
1900 for (i = 0; i < nargs; ++i)
1901 if (upeek(tcp, (i < 5 ? i : i + 2)*4, &tcp->u_arg[i]) < 0)
1905 for (i = 0; i < 6; ++i)
1906 tcp->u_arg[i] = or1k_regs.gpr[3 + i];
1907 #elif defined(METAG)
1908 for (i = 0; i < nargs; i++)
1909 /* arguments go backwards from D1Ar1 (D1.3) */
1910 tcp->u_arg[i] = ((unsigned long *)&metag_regs.dx[3][1])[-i];
1911 #else /* Other architecture (32bits specific) */
1912 for (i = 0; i < nargs; ++i)
1913 if (upeek(tcp, i*4, &tcp->u_arg[i]) < 0)
1920 trace_syscall_entering(struct tcb *tcp)
1924 #if defined TCB_WAITEXECVE
1925 if (tcp->flags & TCB_WAITEXECVE) {
1926 /* This is the post-execve SIGTRAP. */
1927 tcp->flags &= ~TCB_WAITEXECVE;
1932 scno_good = res = (get_regs_error ? -1 : get_scno(tcp));
1936 res = syscall_fixup_on_sysenter(tcp);
1940 res = get_syscall_args(tcp);
1946 tprints("????" /* anti-trigraph gap */ "(");
1947 else if (tcp->qual_flg & UNDEFINED_SCNO)
1948 tprintf("%s(", undefined_scno_name(tcp));
1950 tprintf("%s(", tcp->s_ent->sys_name);
1952 * " <unavailable>" will be added later by the code which
1953 * detects ptrace errors.
1958 #if defined(SYS_socket_subcall) || defined(SYS_ipc_subcall)
1960 # ifdef SYS_socket_subcall
1961 if (tcp->s_ent->sys_func == sys_socketcall) {
1962 decode_socket_subcall(tcp);
1966 # ifdef SYS_ipc_subcall
1967 if (tcp->s_ent->sys_func == sys_ipc) {
1968 decode_ipc_subcall(tcp);
1976 if (need_fork_exec_workarounds)
1977 syscall_fixup_for_fork_exec(tcp);
1979 if (!(tcp->qual_flg & QUAL_TRACE)
1980 || (tracing_paths && !pathtrace_match(tcp))
1982 tcp->flags |= TCB_INSYSCALL | TCB_FILTERED;
1986 tcp->flags &= ~TCB_FILTERED;
1988 if (cflag == CFLAG_ONLY_STATS) {
1994 if (tcp->qual_flg & UNDEFINED_SCNO)
1995 tprintf("%s(", undefined_scno_name(tcp));
1997 tprintf("%s(", tcp->s_ent->sys_name);
1998 if ((tcp->qual_flg & QUAL_RAW) && tcp->s_ent->sys_func != sys_exit)
1999 res = printargs(tcp);
2001 res = tcp->s_ent->sys_func(tcp);
2005 tcp->flags |= TCB_INSYSCALL;
2006 /* Measure the entrance time as late as possible to avoid errors. */
2008 gettimeofday(&tcp->etime, NULL);
2013 * 1: ok, continue in trace_syscall_exiting().
2014 * -1: error, trace_syscall_exiting() should print error indicator
2015 * ("????" etc) and bail out.
2018 get_syscall_result(struct tcb *tcp)
2020 #if defined(S390) || defined(S390X)
2021 if (upeek(tcp, PT_GPR2, &gpr2) < 0)
2023 #elif defined(POWERPC)
2024 # define SO_MASK 0x10000000
2027 if (upeek(tcp, sizeof(unsigned long)*PT_CCR, &flags) < 0)
2029 if (upeek(tcp, sizeof(unsigned long)*PT_R3, &ppc_result) < 0)
2031 if (flags & SO_MASK)
2032 ppc_result = -ppc_result;
2034 #elif defined(AVR32)
2035 /* already done by get_regs */
2037 if (upeek(tcp, PT_R0, &bfin_r0) < 0)
2040 /* already done by get_regs */
2041 #elif defined(X86_64) || defined(X32)
2042 /* already done by get_regs */
2044 # define IA64_PSR_IS ((long)1 << 34)
2046 if (upeek(tcp, PT_CR_IPSR, &psr) >= 0)
2047 ia32 = (psr & IA64_PSR_IS) != 0;
2048 if (upeek(tcp, PT_R8, &ia64_r8) < 0)
2050 if (upeek(tcp, PT_R10, &ia64_r10) < 0)
2053 /* already done by get_regs */
2054 #elif defined(AARCH64)
2055 /* register reading already done by get_regs */
2057 /* Used to do this, but we did it on syscall entry already: */
2058 /* We are in 64-bit mode (personality 1) if register struct is aarch64_regs,
2059 * else it's personality 0.
2061 /*update_personality(tcp, aarch64_io.iov_len == sizeof(aarch64_regs));*/
2063 if (upeek(tcp, 4*PT_D0, &m68k_d0) < 0)
2065 #elif defined(LINUX_MIPSN32)
2066 unsigned long long regs[38];
2068 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
2070 mips_a3 = regs[REG_A3];
2071 mips_r2 = regs[REG_V0];
2073 if (upeek(tcp, REG_A3, &mips_a3) < 0)
2075 if (upeek(tcp, REG_V0, &mips_r2) < 0)
2077 #elif defined(ALPHA)
2078 if (upeek(tcp, REG_A3, &alpha_a3) < 0)
2080 if (upeek(tcp, REG_R0, &alpha_r0) < 0)
2082 #elif defined(SPARC) || defined(SPARC64)
2083 /* already done by get_regs */
2085 if (upeek(tcp, PT_GR28, &hppa_r28) < 0)
2088 /* new syscall ABI returns result in R0 */
2089 if (upeek(tcp, 4*REG_REG0, (long *)&sh_r0) < 0)
2092 /* ABI defines result returned in r9 */
2093 if (upeek(tcp, REG_GENERAL(9), (long *)&sh64_r9) < 0)
2095 #elif defined(CRISV10) || defined(CRISV32)
2096 if (upeek(tcp, 4*PT_R10, &cris_r10) < 0)
2099 /* already done by get_regs */
2100 #elif defined(MICROBLAZE)
2101 if (upeek(tcp, 3 * 4, µblaze_r3) < 0)
2104 /* already done by get_regs */
2105 #elif defined(METAG)
2106 /* already done by get_regs */
2111 /* Called at each syscall exit */
2113 syscall_fixup_on_sysexit(struct tcb *tcp)
2115 #if defined(S390) || defined(S390X)
2116 if (syscall_mode != -ENOSYS)
2117 syscall_mode = tcp->scno;
2118 if ((tcp->flags & TCB_WAITEXECVE)
2119 && (gpr2 == -ENOSYS || gpr2 == tcp->scno)) {
2121 * Return from execve.
2122 * Fake a return value of zero. We leave the TCB_WAITEXECVE
2123 * flag set for the post-execve SIGTRAP to see and reset.
2131 * Check the syscall return value register value for whether it is
2132 * a negated errno code indicating an error, or a success return value.
2135 is_negated_errno(unsigned long int val)
2137 unsigned long int max = -(long int) nerrnos;
2138 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
2139 if (current_wordsize < sizeof(val)) {
2140 val = (unsigned int) val;
2141 max = (unsigned int) max;
2149 is_negated_errno_x32(unsigned long long val)
2151 unsigned long long max = -(long long) nerrnos;
2153 * current_wordsize is 4 even in personality 0 (native X32)
2154 * but truncation _must not_ be done in it.
2155 * can't check current_wordsize here!
2157 if (current_personality != 0) {
2158 val = (uint32_t) val;
2159 max = (uint32_t) max;
2166 * 1: ok, continue in trace_syscall_exiting().
2167 * -1: error, trace_syscall_exiting() should print error indicator
2168 * ("????" etc) and bail out.
2171 get_error(struct tcb *tcp)
2174 int check_errno = 1;
2175 if (tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS) {
2178 #if defined(S390) || defined(S390X)
2179 if (check_errno && is_negated_errno(gpr2)) {
2187 if (check_errno && is_negated_errno(i386_regs.eax)) {
2189 u_error = -i386_regs.eax;
2192 tcp->u_rval = i386_regs.eax;
2194 #elif defined(X86_64)
2196 if (x86_io.iov_len == sizeof(i386_regs)) {
2197 /* Sign extend from 32 bits */
2198 rax = (int32_t)i386_regs.eax;
2200 rax = x86_64_regs.rax;
2202 if (check_errno && is_negated_errno(rax)) {
2210 /* In X32, return value is 64-bit (llseek uses one).
2211 * Using merely "long rax" would not work.
2214 if (x86_io.iov_len == sizeof(i386_regs)) {
2215 /* Sign extend from 32 bits */
2216 rax = (int32_t)i386_regs.eax;
2218 rax = x86_64_regs.rax;
2220 /* Careful: is_negated_errno() works only on longs */
2221 if (check_errno && is_negated_errno_x32(rax)) {
2226 tcp->u_rval = rax; /* truncating */
2234 if (check_errno && is_negated_errno(err)) {
2242 if (check_errno && ia64_r10) {
2246 tcp->u_rval = ia64_r8;
2250 if (check_errno && mips_a3) {
2254 tcp->u_rval = mips_r2;
2255 # if defined(LINUX_MIPSN32)
2256 tcp->u_lrval = mips_r2;
2259 #elif defined(POWERPC)
2260 if (check_errno && is_negated_errno(ppc_result)) {
2262 u_error = -ppc_result;
2265 tcp->u_rval = ppc_result;
2268 if (check_errno && is_negated_errno(m68k_d0)) {
2273 tcp->u_rval = m68k_d0;
2275 #elif defined(ARM) || defined(AARCH64)
2276 # if defined(AARCH64)
2277 if (tcp->currpers == 1) {
2278 if (check_errno && is_negated_errno(aarch64_regs.regs[0])) {
2280 u_error = -aarch64_regs.regs[0];
2283 tcp->u_rval = aarch64_regs.regs[0];
2289 if (check_errno && is_negated_errno(arm_regs.ARM_r0)) {
2291 u_error = -arm_regs.ARM_r0;
2294 tcp->u_rval = arm_regs.ARM_r0;
2297 #elif defined(AVR32)
2298 if (check_errno && avr32_regs.r12 && (unsigned) -avr32_regs.r12 < nerrnos) {
2300 u_error = -avr32_regs.r12;
2303 tcp->u_rval = avr32_regs.r12;
2306 if (check_errno && is_negated_errno(bfin_r0)) {
2310 tcp->u_rval = bfin_r0;
2312 #elif defined(ALPHA)
2313 if (check_errno && alpha_a3) {
2318 tcp->u_rval = alpha_r0;
2320 #elif defined(SPARC)
2321 if (check_errno && sparc_regs.psr & PSR_C) {
2323 u_error = sparc_regs.u_regs[U_REG_O0];
2326 tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
2328 #elif defined(SPARC64)
2329 if (check_errno && sparc_regs.tstate & 0x1100000000UL) {
2331 u_error = sparc_regs.u_regs[U_REG_O0];
2334 tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
2337 if (check_errno && is_negated_errno(hppa_r28)) {
2339 u_error = -hppa_r28;
2342 tcp->u_rval = hppa_r28;
2345 if (check_errno && is_negated_errno(sh_r0)) {
2350 tcp->u_rval = sh_r0;
2353 if (check_errno && is_negated_errno(sh64_r9)) {
2358 tcp->u_rval = sh64_r9;
2360 #elif defined(METAG)
2361 /* result pointer in D0Re0 (D0.0) */
2362 if (check_errno && is_negated_errno(metag_regs.dx[0][0])) {
2364 u_error = -metag_regs.dx[0][0];
2367 tcp->u_rval = metag_regs.dx[0][0];
2369 #elif defined(CRISV10) || defined(CRISV32)
2370 if (check_errno && cris_r10 && (unsigned) -cris_r10 < nerrnos) {
2372 u_error = -cris_r10;
2375 tcp->u_rval = cris_r10;
2379 * The standard tile calling convention returns the value (or negative
2380 * errno) in r0, and zero (or positive errno) in r1.
2381 * Until at least kernel 3.8, however, the r1 value is not reflected
2382 * in ptregs at this point, so we use r0 here.
2384 if (check_errno && is_negated_errno(tile_regs.regs[0])) {
2386 u_error = -tile_regs.regs[0];
2388 tcp->u_rval = tile_regs.regs[0];
2390 #elif defined(MICROBLAZE)
2391 if (check_errno && is_negated_errno(microblaze_r3)) {
2393 u_error = -microblaze_r3;
2396 tcp->u_rval = microblaze_r3;
2399 if (check_errno && is_negated_errno(or1k_regs.gpr[11])) {
2401 u_error = -or1k_regs.gpr[11];
2404 tcp->u_rval = or1k_regs.gpr[11];
2407 tcp->u_error = u_error;
2411 dumpio(struct tcb *tcp)
2417 if ((unsigned long) tcp->u_arg[0] >= num_quals)
2419 func = tcp->s_ent->sys_func;
2420 if (func == printargs)
2422 if (qual_flags[tcp->u_arg[0]] & QUAL_READ) {
2423 if (func == sys_read ||
2424 func == sys_pread ||
2426 func == sys_recvfrom)
2427 dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
2428 else if (func == sys_readv)
2429 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2432 if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) {
2433 if (func == sys_write ||
2434 func == sys_pwrite ||
2437 dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2438 else if (func == sys_writev)
2439 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2445 trace_syscall_exiting(struct tcb *tcp)
2452 /* Measure the exit time as early as possible to avoid errors. */
2454 gettimeofday(&tv, NULL);
2456 #if SUPPORTED_PERSONALITIES > 1
2457 update_personality(tcp, tcp->currpers);
2459 res = (get_regs_error ? -1 : get_syscall_result(tcp));
2461 syscall_fixup_on_sysexit(tcp); /* never fails */
2462 get_error(tcp); /* never fails */
2463 if (need_fork_exec_workarounds)
2464 syscall_fixup_for_fork_exec(tcp);
2470 struct timeval t = tv;
2471 count_syscall(tcp, &t);
2472 if (cflag == CFLAG_ONLY_STATS) {
2477 /* If not in -ff mode, and printing_tcp != tcp,
2478 * then the log currently does not end with output
2479 * of _our syscall entry_, but with something else.
2480 * We need to say which syscall's return is this.
2482 * Forced reprinting via TCB_REPRINT is used only by
2483 * "strace -ff -oLOG test/threaded_execve" corner case.
2484 * It's the only case when -ff mode needs reprinting.
2486 if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) {
2487 tcp->flags &= ~TCB_REPRINT;
2489 if (tcp->qual_flg & UNDEFINED_SCNO)
2490 tprintf("<... %s resumed> ", undefined_scno_name(tcp));
2492 tprintf("<... %s resumed> ", tcp->s_ent->sys_name);
2497 /* There was error in one of prior ptrace ops */
2500 tprints("= ? <unavailable>\n");
2502 tcp->flags &= ~TCB_INSYSCALL;
2507 if (tcp->qual_flg & QUAL_RAW) {
2508 /* sys_res = printargs(tcp); - but it's nop on sysexit */
2510 /* FIXME: not_failing_only (IOW, option -z) is broken:
2511 * failure of syscall is known only after syscall return.
2512 * Thus we end up with something like this on, say, ENOENT:
2513 * open("doesnt_exist", O_RDONLY <unfinished ...>
2514 * {next syscall decode}
2515 * whereas the intended result is that open(...) line
2516 * is not shown at all.
2518 if (not_failing_only && tcp->u_error)
2519 goto ret; /* ignore failed syscalls */
2520 sys_res = tcp->s_ent->sys_func(tcp);
2525 u_error = tcp->u_error;
2526 if (tcp->qual_flg & QUAL_RAW) {
2528 tprintf("= -1 (errno %ld)", u_error);
2530 tprintf("= %#lx", tcp->u_rval);
2532 else if (!(sys_res & RVAL_NONE) && u_error) {
2534 /* Blocked signals do not interrupt any syscalls.
2535 * In this case syscalls don't return ERESTARTfoo codes.
2537 * Deadly signals set to SIG_DFL interrupt syscalls
2538 * and kill the process regardless of which of the codes below
2539 * is returned by the interrupted syscall.
2540 * In some cases, kernel forces a kernel-generated deadly
2541 * signal to be unblocked and set to SIG_DFL (and thus cause
2542 * death) if it is blocked or SIG_IGNed: for example, SIGSEGV
2543 * or SIGILL. (The alternative is to leave process spinning
2544 * forever on the faulty instruction - not useful).
2546 * SIG_IGNed signals and non-deadly signals set to SIG_DFL
2547 * (for example, SIGCHLD, SIGWINCH) interrupt syscalls,
2548 * but kernel will always restart them.
2551 /* Most common type of signal-interrupted syscall exit code.
2552 * The system call will be restarted with the same arguments
2553 * if SA_RESTART is set; otherwise, it will fail with EINTR.
2555 tprints("= ? ERESTARTSYS (To be restarted if SA_RESTART is set)");
2557 case ERESTARTNOINTR:
2558 /* Rare. For example, fork() returns this if interrupted.
2559 * SA_RESTART is ignored (assumed set): the restart is unconditional.
2561 tprints("= ? ERESTARTNOINTR (To be restarted)");
2563 case ERESTARTNOHAND:
2564 /* pause(), rt_sigsuspend() etc use this code.
2565 * SA_RESTART is ignored (assumed not set):
2566 * syscall won't restart (will return EINTR instead)
2567 * even after signal with SA_RESTART set. However,
2568 * after SIG_IGN or SIG_DFL signal it will restart
2569 * (thus the name "restart only if has no handler").
2571 tprints("= ? ERESTARTNOHAND (Interrupted by signal)");
2573 case ERESTART_RESTARTBLOCK:
2574 /* Syscalls like nanosleep(), poll() which can't be
2575 * restarted with their original arguments use this
2576 * code. Kernel will execute restart_syscall() instead,
2577 * which changes arguments before restarting syscall.
2578 * SA_RESTART is ignored (assumed not set) similarly
2579 * to ERESTARTNOHAND. (Kernel can't honor SA_RESTART
2580 * since restart data is saved in "restart block"
2581 * in task struct, and if signal handler uses a syscall
2582 * which in turn saves another such restart block,
2583 * old data is lost and restart becomes impossible)
2585 tprints("= ? ERESTART_RESTARTBLOCK (Interrupted by signal)");
2589 tprintf("= -1 E??? (errno %ld)", u_error);
2590 else if (u_error < nerrnos)
2591 tprintf("= -1 %s (%s)", errnoent[u_error],
2594 tprintf("= -1 ERRNO_%ld (%s)", u_error,
2598 if ((sys_res & RVAL_STR) && tcp->auxstr)
2599 tprintf(" (%s)", tcp->auxstr);
2602 if (sys_res & RVAL_NONE)
2605 switch (sys_res & RVAL_MASK) {
2607 tprintf("= %#lx", tcp->u_rval);
2610 tprintf("= %#lo", tcp->u_rval);
2613 tprintf("= %lu", tcp->u_rval);
2616 tprintf("= %ld", tcp->u_rval);
2618 #if defined(LINUX_MIPSN32) || defined(X32)
2621 tprintf("= %#llx", tcp->u_lrval);
2624 tprintf("= %#llo", tcp->u_lrval);
2627 case RVAL_LUDECIMAL:
2628 tprintf("= %llu", tcp->u_lrval);
2632 tprintf("= %lld", tcp->u_lrval);
2638 "invalid rval format\n");
2642 if ((sys_res & RVAL_STR) && tcp->auxstr)
2643 tprintf(" (%s)", tcp->auxstr);
2646 tv_sub(&tv, &tv, &tcp->etime);
2647 tprintf(" <%ld.%06ld>",
2648 (long) tv.tv_sec, (long) tv.tv_usec);
2655 tcp->flags &= ~TCB_INSYSCALL;
2660 trace_syscall(struct tcb *tcp)
2662 return exiting(tcp) ?
2663 trace_syscall_exiting(tcp) : trace_syscall_entering(tcp);