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 /* for struct iovec */
76 # include <asm/ptrace.h>
80 # include <asm/ptrace.h>
84 # define ERESTARTSYS 512
86 #ifndef ERESTARTNOINTR
87 # define ERESTARTNOINTR 513
89 #ifndef ERESTARTNOHAND
90 # define ERESTARTNOHAND 514 /* restart if no handler */
92 #ifndef ERESTART_RESTARTBLOCK
93 # define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
97 # warning: NSIG is not defined, using 32
101 /* Ugh. Is this really correct? ARM has no RT signals?! */
108 /* Define these shorthand notations to simplify the syscallent files. */
109 #define TD TRACE_DESC
110 #define TF TRACE_FILE
112 #define TN TRACE_NETWORK
113 #define TP TRACE_PROCESS
114 #define TS TRACE_SIGNAL
115 #define TM TRACE_MEMORY
116 #define NF SYSCALL_NEVER_FAILS
119 const struct_sysent sysent0[] = {
120 #include "syscallent.h"
123 #if SUPPORTED_PERSONALITIES > 1
124 static const struct_sysent sysent1[] = {
125 # include "syscallent1.h"
129 #if SUPPORTED_PERSONALITIES > 2
130 static const struct_sysent sysent2[] = {
131 # include "syscallent2.h"
135 /* Now undef them since short defines cause wicked namespace pollution. */
147 * `ioctlent.h' may be generated from `ioctlent.raw' by the auxiliary
148 * program `ioctlsort', such that the list is sorted by the `code' field.
149 * This has the side-effect of resolving the _IO.. macros into
150 * plain integers, eliminating the need to include here everything
154 const char *const errnoent0[] = {
155 #include "errnoent.h"
157 const char *const signalent0[] = {
158 #include "signalent.h"
160 const struct_ioctlent ioctlent0[] = {
161 #include "ioctlent.h"
164 #if SUPPORTED_PERSONALITIES > 1
165 static const char *const errnoent1[] = {
166 # include "errnoent1.h"
168 static const char *const signalent1[] = {
169 # include "signalent1.h"
171 static const struct_ioctlent ioctlent1[] = {
172 # include "ioctlent1.h"
176 #if SUPPORTED_PERSONALITIES > 2
177 static const char *const errnoent2[] = {
178 # include "errnoent2.h"
180 static const char *const signalent2[] = {
181 # include "signalent2.h"
183 static const struct_ioctlent ioctlent2[] = {
184 # include "ioctlent2.h"
189 nsyscalls0 = ARRAY_SIZE(sysent0)
190 #if SUPPORTED_PERSONALITIES > 1
191 , nsyscalls1 = ARRAY_SIZE(sysent1)
192 # if SUPPORTED_PERSONALITIES > 2
193 , nsyscalls2 = ARRAY_SIZE(sysent2)
199 nerrnos0 = ARRAY_SIZE(errnoent0)
200 #if SUPPORTED_PERSONALITIES > 1
201 , nerrnos1 = ARRAY_SIZE(errnoent1)
202 # if SUPPORTED_PERSONALITIES > 2
203 , nerrnos2 = ARRAY_SIZE(errnoent2)
209 nsignals0 = ARRAY_SIZE(signalent0)
210 #if SUPPORTED_PERSONALITIES > 1
211 , nsignals1 = ARRAY_SIZE(signalent1)
212 # if SUPPORTED_PERSONALITIES > 2
213 , nsignals2 = ARRAY_SIZE(signalent2)
219 nioctlents0 = ARRAY_SIZE(ioctlent0)
220 #if SUPPORTED_PERSONALITIES > 1
221 , nioctlents1 = ARRAY_SIZE(ioctlent1)
222 # if SUPPORTED_PERSONALITIES > 2
223 , nioctlents2 = ARRAY_SIZE(ioctlent2)
228 #if SUPPORTED_PERSONALITIES > 1
229 const struct_sysent *sysent = sysent0;
230 const char *const *errnoent = errnoent0;
231 const char *const *signalent = signalent0;
232 const struct_ioctlent *ioctlent = ioctlent0;
234 unsigned nsyscalls = nsyscalls0;
235 unsigned nerrnos = nerrnos0;
236 unsigned nsignals = nsignals0;
237 unsigned nioctlents = nioctlents0;
240 qualbits_t *qual_vec[SUPPORTED_PERSONALITIES];
242 static const unsigned nsyscall_vec[SUPPORTED_PERSONALITIES] = {
244 #if SUPPORTED_PERSONALITIES > 1
247 #if SUPPORTED_PERSONALITIES > 2
251 static const struct_sysent *const sysent_vec[SUPPORTED_PERSONALITIES] = {
253 #if SUPPORTED_PERSONALITIES > 1
256 #if SUPPORTED_PERSONALITIES > 2
262 MAX_NSYSCALLS1 = (nsyscalls0
263 #if SUPPORTED_PERSONALITIES > 1
264 > nsyscalls1 ? nsyscalls0 : nsyscalls1
267 MAX_NSYSCALLS2 = (MAX_NSYSCALLS1
268 #if SUPPORTED_PERSONALITIES > 2
269 > nsyscalls2 ? MAX_NSYSCALLS1 : nsyscalls2
272 MAX_NSYSCALLS = MAX_NSYSCALLS2,
273 /* We are ready for arches with up to 255 signals,
274 * even though the largest known signo is on MIPS and it is 128.
275 * The number of existing syscalls on all arches is
276 * larger that 255 anyway, so it is just a pedantic matter.
278 MIN_QUALS = MAX_NSYSCALLS > 255 ? MAX_NSYSCALLS : 255
281 #if SUPPORTED_PERSONALITIES > 1
282 unsigned current_personality;
284 # ifndef current_wordsize
285 unsigned current_wordsize;
286 static const int personality_wordsize[SUPPORTED_PERSONALITIES] = {
287 PERSONALITY0_WORDSIZE,
288 PERSONALITY1_WORDSIZE,
289 # if SUPPORTED_PERSONALITIES > 2
290 PERSONALITY2_WORDSIZE,
296 set_personality(int personality)
298 nsyscalls = nsyscall_vec[personality];
299 sysent = sysent_vec[personality];
301 switch (personality) {
303 errnoent = errnoent0;
305 ioctlent = ioctlent0;
306 nioctlents = nioctlents0;
307 signalent = signalent0;
308 nsignals = nsignals0;
312 errnoent = errnoent1;
314 ioctlent = ioctlent1;
315 nioctlents = nioctlents1;
316 signalent = signalent1;
317 nsignals = nsignals1;
320 # if SUPPORTED_PERSONALITIES > 2
322 errnoent = errnoent2;
324 ioctlent = ioctlent2;
325 nioctlents = nioctlents2;
326 signalent = signalent2;
327 nsignals = nsignals2;
332 current_personality = personality;
333 # ifndef current_wordsize
334 current_wordsize = personality_wordsize[personality];
339 update_personality(struct tcb *tcp, int personality)
341 if (personality == current_personality)
343 set_personality(personality);
345 if (personality == tcp->currpers)
347 tcp->currpers = personality;
349 # if defined(POWERPC64)
351 static const char *const names[] = {"64 bit", "32 bit"};
352 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
353 tcp->pid, names[personality]);
355 # elif defined(X86_64)
357 static const char *const names[] = {"64 bit", "32 bit", "x32"};
358 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
359 tcp->pid, names[personality]);
363 static const char *const names[] = {"x32", "32 bit"};
364 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
365 tcp->pid, names[personality]);
367 # elif defined(AARCH64)
369 static const char *const names[] = {"32-bit", "AArch64"};
370 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
371 tcp->pid, names[personality]);
375 static const char *const names[] = {"64-bit", "32-bit"};
376 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
377 tcp->pid, names[personality]);
383 static int qual_syscall(), qual_signal(), qual_desc();
385 static const struct qual_options {
387 const char *option_name;
388 int (*qualify)(const char *, int, int);
389 const char *argument_name;
391 { QUAL_TRACE, "trace", qual_syscall, "system call" },
392 { QUAL_TRACE, "t", qual_syscall, "system call" },
393 { QUAL_ABBREV, "abbrev", qual_syscall, "system call" },
394 { QUAL_ABBREV, "a", qual_syscall, "system call" },
395 { QUAL_VERBOSE, "verbose", qual_syscall, "system call" },
396 { QUAL_VERBOSE, "v", qual_syscall, "system call" },
397 { QUAL_RAW, "raw", qual_syscall, "system call" },
398 { QUAL_RAW, "x", qual_syscall, "system call" },
399 { QUAL_SIGNAL, "signal", qual_signal, "signal" },
400 { QUAL_SIGNAL, "signals", qual_signal, "signal" },
401 { QUAL_SIGNAL, "s", qual_signal, "signal" },
402 { QUAL_READ, "read", qual_desc, "descriptor" },
403 { QUAL_READ, "reads", qual_desc, "descriptor" },
404 { QUAL_READ, "r", qual_desc, "descriptor" },
405 { QUAL_WRITE, "write", qual_desc, "descriptor" },
406 { QUAL_WRITE, "writes", qual_desc, "descriptor" },
407 { QUAL_WRITE, "w", qual_desc, "descriptor" },
408 { 0, NULL, NULL, NULL },
412 reallocate_qual(int n)
416 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
417 qp = qual_vec[p] = realloc(qual_vec[p], n * sizeof(qualbits_t));
420 memset(&qp[num_quals], 0, (n - num_quals) * sizeof(qualbits_t));
426 qualify_one(int n, int bitflag, int not, int pers)
431 reallocate_qual(n + 1);
433 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
434 if (pers == p || pers < 0) {
436 qual_vec[p][n] &= ~bitflag;
438 qual_vec[p][n] |= bitflag;
444 qual_syscall(const char *s, int bitflag, int not)
450 if (*s >= '0' && *s <= '9') {
451 i = string_to_uint(s);
452 if (i >= MAX_NSYSCALLS)
454 qualify_one(i, bitflag, not, -1);
458 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
459 for (i = 0; i < nsyscall_vec[p]; i++) {
460 if (sysent_vec[p][i].sys_name
461 && strcmp(s, sysent_vec[p][i].sys_name) == 0
463 qualify_one(i, bitflag, not, p);
473 qual_signal(const char *s, int bitflag, int not)
477 if (*s >= '0' && *s <= '9') {
478 int signo = string_to_uint(s);
479 if (signo < 0 || signo > 255)
481 qualify_one(signo, bitflag, not, -1);
484 if (strncasecmp(s, "SIG", 3) == 0)
486 for (i = 0; i <= NSIG; i++) {
487 if (strcasecmp(s, signame(i) + 3) == 0) {
488 qualify_one(i, bitflag, not, -1);
496 qual_desc(const char *s, int bitflag, int not)
498 if (*s >= '0' && *s <= '9') {
499 int desc = string_to_uint(s);
500 if (desc < 0 || desc > 0x7fff) /* paranoia */
502 qualify_one(desc, bitflag, not, -1);
509 lookup_class(const char *s)
511 if (strcmp(s, "file") == 0)
513 if (strcmp(s, "ipc") == 0)
515 if (strcmp(s, "network") == 0)
516 return TRACE_NETWORK;
517 if (strcmp(s, "process") == 0)
518 return TRACE_PROCESS;
519 if (strcmp(s, "signal") == 0)
521 if (strcmp(s, "desc") == 0)
523 if (strcmp(s, "memory") == 0)
529 qualify(const char *s)
531 const struct qual_options *opt;
538 reallocate_qual(MIN_QUALS);
540 opt = &qual_options[0];
541 for (i = 0; (p = qual_options[i].option_name); i++) {
543 if (strncmp(s, p, n) == 0 && s[n] == '=') {
544 opt = &qual_options[i];
554 if (strcmp(s, "none") == 0) {
558 if (strcmp(s, "all") == 0) {
559 for (i = 0; i < num_quals; i++) {
560 qualify_one(i, opt->bitflag, not, -1);
564 for (i = 0; i < num_quals; i++) {
565 qualify_one(i, opt->bitflag, !not, -1);
570 for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) {
571 if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) {
573 for (pers = 0; pers < SUPPORTED_PERSONALITIES; pers++) {
574 for (i = 0; i < nsyscall_vec[pers]; i++)
575 if (sysent_vec[pers][i].sys_flags & n)
576 qualify_one(i, opt->bitflag, not, pers);
580 if (opt->qualify(p, opt->bitflag, not)) {
581 error_msg_and_die("invalid %s '%s'",
582 opt->argument_name, p);
589 #ifdef SYS_socket_subcall
591 decode_socket_subcall(struct tcb *tcp)
594 unsigned int i, n, size;
596 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_socket_nsubcalls)
599 tcp->scno = SYS_socket_subcall + tcp->u_arg[0];
600 tcp->qual_flg = qual_flags[tcp->scno];
601 tcp->s_ent = &sysent[tcp->scno];
602 addr = tcp->u_arg[1];
603 size = current_wordsize;
604 n = tcp->s_ent->nargs;
605 for (i = 0; i < n; ++i) {
606 if (size == sizeof(int)) {
608 if (umove(tcp, addr, &arg) < 0)
614 if (umove(tcp, addr, &arg) < 0)
623 #ifdef SYS_ipc_subcall
625 decode_ipc_subcall(struct tcb *tcp)
629 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_ipc_nsubcalls)
632 tcp->scno = SYS_ipc_subcall + tcp->u_arg[0];
633 tcp->qual_flg = qual_flags[tcp->scno];
634 tcp->s_ent = &sysent[tcp->scno];
635 n = tcp->s_ent->nargs;
636 for (i = 0; i < n; i++)
637 tcp->u_arg[i] = tcp->u_arg[i + 1];
642 printargs(struct tcb *tcp)
646 int n = tcp->s_ent->nargs;
647 for (i = 0; i < n; i++)
648 tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]);
654 printargs_lu(struct tcb *tcp)
658 int n = tcp->s_ent->nargs;
659 for (i = 0; i < n; i++)
660 tprintf("%s%lu", i ? ", " : "", tcp->u_arg[i]);
666 printargs_ld(struct tcb *tcp)
670 int n = tcp->s_ent->nargs;
671 for (i = 0; i < n; i++)
672 tprintf("%s%ld", i ? ", " : "", tcp->u_arg[i]);
677 #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH)
679 getrval2(struct tcb *tcp)
683 # if defined(SPARC) || defined(SPARC64)
684 val = sparc_regs.u_regs[U_REG_O1];
686 if (upeek(tcp, 4*(REG_REG0+1), &val) < 0)
689 if (upeek(tcp, PT_R9, &val) < 0)
698 is_restart_error(struct tcb *tcp)
700 switch (tcp->u_error) {
704 case ERESTART_RESTARTBLOCK:
713 struct user_regs_struct i386_regs;
714 # define ARCH_REGS_FOR_GETREGSET i386_regs
715 #elif defined(X86_64) || defined(X32)
717 * On i386, pt_regs and user_regs_struct are the same,
718 * but on 64 bit x86, user_regs_struct has six more fields:
719 * fs_base, gs_base, ds, es, fs, gs.
720 * PTRACE_GETREGS fills them too, so struct pt_regs would overflow.
722 struct i386_user_regs_struct {
742 struct user_regs_struct x86_64_r;
743 struct i386_user_regs_struct i386_r;
745 # define x86_64_regs x86_regs_union.x86_64_r
746 # define i386_regs x86_regs_union.i386_r
747 static struct iovec x86_io = {
748 .iov_base = &x86_regs_union
751 long ia32 = 0; /* not static */
752 static long ia64_r8, ia64_r10;
753 #elif defined(POWERPC)
754 struct pt_regs ppc_regs;
755 static long ppc_result;
761 struct pt_regs arm_regs; /* not static */
762 # define ARCH_REGS_FOR_GETREGSET arm_regs
763 #elif defined(AARCH64)
765 struct user_pt_regs aarch64_r;
766 struct arm_pt_regs arm_r;
768 # define aarch64_regs arm_regs_union.aarch64_r
769 # define arm_regs arm_regs_union.arm_r
770 static struct iovec aarch64_io = {
771 .iov_base = &arm_regs_union
774 static long alpha_r0;
775 static long alpha_a3;
777 static struct pt_regs avr32_regs;
778 #elif defined(SPARC) || defined(SPARC64)
779 struct pt_regs sparc_regs; /* not static */
780 #elif defined(LINUX_MIPSN32)
781 static long long mips_a3;
782 static long long mips_r2;
786 #elif defined(S390) || defined(S390X)
788 static long syscall_mode;
790 static long hppa_r28;
795 #elif defined(CRISV10) || defined(CRISV32)
796 static long cris_r10;
798 struct pt_regs tile_regs;
799 #elif defined(MICROBLAZE)
800 static long microblaze_r3;
802 static struct user_regs_struct or1k_regs;
803 # define ARCH_REGS_FOR_GETREGSET or1k_regs
805 static struct user_gp_regs metag_regs;
806 # define ARCH_REGS_FOR_GETREGSET metag_regs
807 #elif defined(XTENSA)
808 static long xtensa_a2;
812 printcall(struct tcb *tcp)
814 #define PRINTBADPC tprintf(sizeof(long) == 4 ? "[????????] " : \
815 sizeof(long) == 8 ? "[????????????????] " : \
817 if (get_regs_error) {
822 tprintf("[%08lx] ", i386_regs.eip);
823 #elif defined(S390) || defined(S390X)
825 if (upeek(tcp, PT_PSWADDR, &psw) < 0) {
830 tprintf("[%08lx] ", psw);
832 tprintf("[%016lx] ", psw);
834 #elif defined(X86_64) || defined(X32)
835 if (x86_io.iov_len == sizeof(i386_regs)) {
836 tprintf("[%08x] ", (unsigned) i386_regs.eip);
839 tprintf("[%016lx] ", (unsigned long) x86_64_regs.rip);
841 /* Note: this truncates 64-bit rip to 32 bits */
842 tprintf("[%08lx] ", (unsigned long) x86_64_regs.rip);
847 if (upeek(tcp, PT_B0, &ip) < 0) {
851 tprintf("[%08lx] ", ip);
852 #elif defined(POWERPC)
853 long pc = ppc_regs.nip;
855 tprintf("[%016lx] ", pc);
857 tprintf("[%08lx] ", pc);
861 if (upeek(tcp, 4*PT_PC, &pc) < 0) {
862 tprints("[????????] ");
865 tprintf("[%08lx] ", pc);
868 if (upeek(tcp, REG_PC, &pc) < 0) {
869 tprints("[????????????????] ");
872 tprintf("[%08lx] ", pc);
874 tprintf("[%08lx] ", sparc_regs.pc);
875 #elif defined(SPARC64)
876 tprintf("[%08lx] ", sparc_regs.tpc);
879 if (upeek(tcp, PT_IAOQ0, &pc) < 0) {
880 tprints("[????????] ");
883 tprintf("[%08lx] ", pc);
886 if (upeek(tcp, REG_EPC, &pc) < 0) {
887 tprints("[????????] ");
890 tprintf("[%08lx] ", pc);
893 if (upeek(tcp, 4*REG_PC, &pc) < 0) {
894 tprints("[????????] ");
897 tprintf("[%08lx] ", pc);
900 if (upeek(tcp, REG_PC, &pc) < 0) {
901 tprints("[????????????????] ");
904 tprintf("[%08lx] ", pc);
906 tprintf("[%08lx] ", arm_regs.ARM_pc);
907 #elif defined(AARCH64)
908 /* tprintf("[%016lx] ", aarch64_regs.regs[???]); */
910 tprintf("[%08lx] ", avr32_regs.pc);
913 if (upeek(tcp, PT_PC, &pc) < 0) {
917 tprintf("[%08lx] ", pc);
918 #elif defined(CRISV10)
920 if (upeek(tcp, 4*PT_IRP, &pc) < 0) {
924 tprintf("[%08lx] ", pc);
925 #elif defined(CRISV32)
927 if (upeek(tcp, 4*PT_ERP, &pc) < 0) {
931 tprintf("[%08lx] ", pc);
934 tprintf("[%016lx] ", (unsigned long) tile_regs.pc);
936 tprintf("[%08lx] ", (unsigned long) tile_regs.pc);
939 tprintf("[%08lx] ", or1k_regs.pc);
941 tprintf("[%08lx] ", metag_regs.pc);
942 #elif defined(XTENSA)
944 if (upeek(tcp, REG_PC, &pc) < 0) {
948 tprintf("[%08lx] ", pc);
949 #endif /* architecture */
952 /* Shuffle syscall numbers so that we don't have huge gaps in syscall table.
953 * The shuffling should be reversible: shuffle_scno(shuffle_scno(n)) == n.
955 #if defined(ARM) /* So far only ARM needs this */
957 shuffle_scno(unsigned long scno)
959 if (scno <= ARM_LAST_ORDINARY_SYSCALL)
962 /* __ARM_NR_cmpxchg? Swap with LAST_ORDINARY+1 */
963 if (scno == 0x000ffff0)
964 return ARM_LAST_ORDINARY_SYSCALL+1;
965 if (scno == ARM_LAST_ORDINARY_SYSCALL+1)
968 /* Is it ARM specific syscall?
969 * Swap with [LAST_ORDINARY+2, LAST_ORDINARY+2 + LAST_SPECIAL] range.
971 if (scno >= 0x000f0000
972 && scno <= 0x000f0000 + ARM_LAST_SPECIAL_SYSCALL
974 return scno - 0x000f0000 + (ARM_LAST_ORDINARY_SYSCALL+2);
976 if (/* scno >= ARM_LAST_ORDINARY_SYSCALL+2 - always true */ 1
977 && scno <= (ARM_LAST_ORDINARY_SYSCALL+2) + ARM_LAST_SPECIAL_SYSCALL
979 return scno + 0x000f0000 - (ARM_LAST_ORDINARY_SYSCALL+2);
985 # define shuffle_scno(scno) ((long)(scno))
989 undefined_scno_name(struct tcb *tcp)
991 static char buf[sizeof("syscall_%lu") + sizeof(long)*3];
993 sprintf(buf, "syscall_%lu", shuffle_scno(tcp->scno));
999 * PTRACE_GETREGS was added to the PowerPC kernel in v2.6.23, so we
1000 * provide a slow fallback for very old kernels.
1003 static long powerpc_getreg(pid_t pid, unsigned long offset, unsigned long *p)
1008 val = ptrace(PTRACE_PEEKUSER, pid, (char *)offset, 0);
1009 if (val == -1 && errno)
1016 static long powerpc_getregs_old(pid_t pid)
1021 r = powerpc_getreg(pid, sizeof(unsigned long) * PT_MSR, &ppc_regs.msr);
1025 r = powerpc_getreg(pid, sizeof(unsigned long) * PT_CCR, &ppc_regs.ccr);
1029 r = powerpc_getreg(pid, sizeof(unsigned long) * PT_ORIG_R3,
1030 &ppc_regs.orig_gpr3);
1034 for (i = 0; i <= 8; i++) {
1035 r = powerpc_getreg(pid, sizeof(unsigned long) * (PT_R0 + i),
1047 long get_regs_error;
1049 #if defined(PTRACE_GETREGSET) && defined(NT_PRSTATUS)
1050 static void get_regset(pid_t pid)
1052 /* constant iovec */
1057 static struct iovec io = {
1058 .iov_base = &ARCH_REGS_FOR_GETREGSET,
1059 .iov_len = sizeof(ARCH_REGS_FOR_GETREGSET)
1061 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &io);
1063 /* variable iovec */
1064 # elif defined(X86_64) || defined(X32)
1065 /* x86_io.iov_base = &x86_regs_union; - already is */
1066 x86_io.iov_len = sizeof(x86_regs_union);
1067 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &x86_io);
1068 # elif defined(AARCH64)
1069 /* aarch64_io.iov_base = &arm_regs_union; - already is */
1070 aarch64_io.iov_len = sizeof(arm_regs_union);
1071 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &aarch64_io);
1073 # warning both PTRACE_GETREGSET and NT_PRSTATUS are available but not yet used
1076 #endif /* PTRACE_GETREGSET && NT_PRSTATUS */
1081 /* PTRACE_GETREGSET only */
1082 # if defined(METAG) || defined(OR1K) || defined(X32) || defined(AARCH64)
1085 /* PTRACE_GETREGS only */
1086 # elif defined(AVR32)
1087 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &avr32_regs);
1088 # elif defined(TILE)
1089 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &tile_regs);
1090 # elif defined(SPARC) || defined(SPARC64)
1091 get_regs_error = ptrace(PTRACE_GETREGS, pid, (char *)&sparc_regs, 0);
1092 # elif defined(POWERPC)
1093 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &ppc_regs);
1094 if (get_regs_error && errno == EIO)
1095 get_regs_error = powerpc_getregs_old(pid);
1097 /* try PTRACE_GETREGSET first, fallback to PTRACE_GETREGS */
1099 # if defined(PTRACE_GETREGSET) && defined(NT_PRSTATUS)
1100 static int getregset_support;
1102 if (getregset_support >= 0) {
1104 if (getregset_support > 0)
1106 if (get_regs_error >= 0) {
1107 getregset_support = 1;
1110 if (errno == EPERM || errno == ESRCH)
1112 getregset_support = -1;
1114 # endif /* PTRACE_GETREGSET && NT_PRSTATUS */
1116 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &arm_regs);
1117 # elif defined(I386)
1118 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &i386_regs);
1119 # elif defined(X86_64)
1120 /* Use old method, with unreliable heuristical detection of 32-bitness. */
1121 x86_io.iov_len = sizeof(x86_64_regs);
1122 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &x86_64_regs);
1123 if (!get_regs_error && x86_64_regs.cs == 0x23) {
1124 x86_io.iov_len = sizeof(i386_regs);
1126 * The order is important: i386_regs and x86_64_regs
1127 * are overlaid in memory!
1129 i386_regs.ebx = x86_64_regs.rbx;
1130 i386_regs.ecx = x86_64_regs.rcx;
1131 i386_regs.edx = x86_64_regs.rdx;
1132 i386_regs.esi = x86_64_regs.rsi;
1133 i386_regs.edi = x86_64_regs.rdi;
1134 i386_regs.ebp = x86_64_regs.rbp;
1135 i386_regs.eax = x86_64_regs.rax;
1136 /* i386_regs.xds = x86_64_regs.ds; unused by strace */
1137 /* i386_regs.xes = x86_64_regs.es; ditto... */
1138 /* i386_regs.xfs = x86_64_regs.fs; */
1139 /* i386_regs.xgs = x86_64_regs.gs; */
1140 i386_regs.orig_eax = x86_64_regs.orig_rax;
1141 i386_regs.eip = x86_64_regs.rip;
1142 /* i386_regs.xcs = x86_64_regs.cs; */
1143 /* i386_regs.eflags = x86_64_regs.eflags; */
1144 i386_regs.esp = x86_64_regs.rsp;
1145 /* i386_regs.xss = x86_64_regs.ss; */
1148 # error unhandled architecture
1149 # endif /* ARM || I386 || X86_64 */
1152 #endif /* !get_regs */
1155 * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently.
1156 * 1: ok, continue in trace_syscall_entering().
1157 * other: error, trace_syscall_entering() should print error indicator
1158 * ("????" etc) and bail out.
1161 get_scno(struct tcb *tcp)
1165 #if defined(S390) || defined(S390X)
1166 if (upeek(tcp, PT_GPR2, &syscall_mode) < 0)
1169 if (syscall_mode != -ENOSYS) {
1171 * Since kernel version 2.5.44 the scno gets passed in gpr2.
1173 scno = syscall_mode;
1176 * Old style of "passing" the scno via the SVC instruction.
1179 long opcode, offset_reg, tmp;
1181 static const int gpr_offset[16] = {
1182 PT_GPR0, PT_GPR1, PT_ORIGGPR2, PT_GPR3,
1183 PT_GPR4, PT_GPR5, PT_GPR6, PT_GPR7,
1184 PT_GPR8, PT_GPR9, PT_GPR10, PT_GPR11,
1185 PT_GPR12, PT_GPR13, PT_GPR14, PT_GPR15
1188 if (upeek(tcp, PT_PSWADDR, &psw) < 0)
1191 opcode = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(psw - sizeof(long)), 0);
1193 perror_msg("peektext(psw-oneword)");
1198 * We have to check if the SVC got executed directly or via an
1199 * EXECUTE instruction. In case of EXECUTE it is necessary to do
1200 * instruction decoding to derive the system call number.
1201 * Unfortunately the opcode sizes of EXECUTE and SVC are differently,
1202 * so that this doesn't work if a SVC opcode is part of an EXECUTE
1203 * opcode. Since there is no way to find out the opcode size this
1204 * is the best we can do...
1206 if ((opcode & 0xff00) == 0x0a00) {
1208 scno = opcode & 0xff;
1211 /* SVC got executed by EXECUTE instruction */
1214 * Do instruction decoding of EXECUTE. If you really want to
1215 * understand this, read the Principles of Operations.
1217 svc_addr = (void *) (opcode & 0xfff);
1220 offset_reg = (opcode & 0x000f0000) >> 16;
1221 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1226 offset_reg = (opcode & 0x0000f000) >> 12;
1227 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1231 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, svc_addr, 0);
1240 offset_reg = (opcode & 0x00f00000) >> 20;
1241 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1244 scno = (scno | tmp) & 0xff;
1247 #elif defined(POWERPC)
1248 scno = ppc_regs.gpr[0];
1252 /* Check for 64/32 bit mode. */
1253 /* SF is bit 0 of MSR */
1254 if ((ppc_regs.msr >> 63) & 1)
1258 update_personality(tcp, currpers);
1260 #elif defined(AVR32)
1261 scno = avr32_regs.r8;
1263 if (upeek(tcp, PT_ORIG_P0, &scno))
1266 scno = i386_regs.orig_eax;
1267 #elif defined(X86_64) || defined(X32)
1268 # ifndef __X32_SYSCALL_BIT
1269 # define __X32_SYSCALL_BIT 0x40000000
1273 /* GETREGSET of NT_PRSTATUS tells us regset size,
1274 * which unambiguously detects i386.
1276 * Linux kernel distinguishes x86-64 and x32 processes
1277 * solely by looking at __X32_SYSCALL_BIT:
1278 * arch/x86/include/asm/compat.h::is_x32_task():
1279 * if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
1282 if (x86_io.iov_len == sizeof(i386_regs)) {
1283 scno = i386_regs.orig_eax;
1286 scno = x86_64_regs.orig_rax;
1288 if (scno & __X32_SYSCALL_BIT) {
1289 scno -= __X32_SYSCALL_BIT;
1294 /* cs = 0x33 for long mode (native 64 bit and x32)
1295 * cs = 0x23 for compatibility mode (32 bit)
1296 * ds = 0x2b for x32 mode (x86-64 in 32 bit)
1298 scno = x86_64_regs.orig_rax;
1299 switch (x86_64_regs.cs) {
1300 case 0x23: currpers = 1; break;
1302 if (x86_64_regs.ds == 0x2b) {
1304 scno &= ~__X32_SYSCALL_BIT;
1309 fprintf(stderr, "Unknown value CS=0x%08X while "
1310 "detecting personality of process "
1311 "PID=%d\n", (int)x86_64_regs.cs, tcp->pid);
1312 currpers = current_personality;
1316 /* This version analyzes the opcode of a syscall instruction.
1317 * (int 0x80 on i386 vs. syscall on x86-64)
1318 * It works, but is too complicated, and strictly speaking, unreliable.
1320 unsigned long call, rip = x86_64_regs.rip;
1321 /* sizeof(syscall) == sizeof(int 0x80) == 2 */
1324 call = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)rip, (char *)0);
1326 fprintf(stderr, "ptrace_peektext failed: %s\n",
1328 switch (call & 0xffff) {
1329 /* x86-64: syscall = 0x0f 0x05 */
1330 case 0x050f: currpers = 0; break;
1331 /* i386: int 0x80 = 0xcd 0x80 */
1332 case 0x80cd: currpers = 1; break;
1334 currpers = current_personality;
1336 "Unknown syscall opcode (0x%04X) while "
1337 "detecting personality of process "
1338 "PID=%d\n", (int)call, tcp->pid);
1344 /* If we are built for a x32 system, then personality 0 is x32
1345 * (not x86_64), and stracing of x86_64 apps is not supported.
1346 * Stracing of i386 apps is still supported.
1348 if (currpers == 0) {
1349 fprintf(stderr, "syscall_%lu(...) in unsupported "
1350 "64-bit mode of process PID=%d\n",
1354 currpers &= ~2; /* map 2,1 to 0,1 */
1356 update_personality(tcp, currpers);
1358 # define IA64_PSR_IS ((long)1 << 34)
1360 if (upeek(tcp, PT_CR_IPSR, &psr) >= 0)
1361 ia32 = (psr & IA64_PSR_IS) != 0;
1363 if (upeek(tcp, PT_R1, &scno) < 0)
1366 if (upeek(tcp, PT_R15, &scno) < 0)
1369 #elif defined(AARCH64)
1370 switch (aarch64_io.iov_len) {
1371 case sizeof(aarch64_regs):
1372 /* We are in 64-bit mode */
1373 scno = aarch64_regs.regs[8];
1374 update_personality(tcp, 1);
1376 case sizeof(arm_regs):
1377 /* We are in 32-bit mode */
1378 scno = arm_regs.ARM_r7;
1379 update_personality(tcp, 0);
1383 if (arm_regs.ARM_ip != 0) {
1384 /* It is not a syscall entry */
1385 fprintf(stderr, "pid %d stray syscall exit\n", tcp->pid);
1386 tcp->flags |= TCB_INSYSCALL;
1389 /* Note: we support only 32-bit CPUs, not 26-bit */
1391 if (arm_regs.ARM_cpsr & 0x20) {
1393 scno = arm_regs.ARM_r7;
1397 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(arm_regs.ARM_pc - 4), NULL);
1401 /* EABI syscall convention? */
1402 if (scno == 0xef000000) {
1403 scno = arm_regs.ARM_r7; /* yes */
1405 if ((scno & 0x0ff00000) != 0x0f900000) {
1406 fprintf(stderr, "pid %d unknown syscall trap 0x%08lx\n",
1410 /* Fixup the syscall number */
1415 scno = shuffle_scno(scno);
1417 if (upeek(tcp, 4*PT_ORIG_D0, &scno) < 0)
1419 #elif defined(LINUX_MIPSN32)
1420 unsigned long long regs[38];
1422 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
1424 mips_a3 = regs[REG_A3];
1425 mips_r2 = regs[REG_V0];
1428 if (!SCNO_IN_RANGE(scno)) {
1429 if (mips_a3 == 0 || mips_a3 == -1) {
1431 fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
1436 if (upeek(tcp, REG_A3, &mips_a3) < 0)
1438 if (upeek(tcp, REG_V0, &scno) < 0)
1441 if (!SCNO_IN_RANGE(scno)) {
1442 if (mips_a3 == 0 || mips_a3 == -1) {
1444 fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
1448 #elif defined(ALPHA)
1449 if (upeek(tcp, REG_A3, &alpha_a3) < 0)
1451 if (upeek(tcp, REG_R0, &scno) < 0)
1455 * Do some sanity checks to figure out if it's
1456 * really a syscall entry
1458 if (!SCNO_IN_RANGE(scno)) {
1459 if (alpha_a3 == 0 || alpha_a3 == -1) {
1461 fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno);
1465 #elif defined(SPARC) || defined(SPARC64)
1466 /* Disassemble the syscall trap. */
1467 /* Retrieve the syscall trap instruction. */
1470 # if defined(SPARC64)
1471 trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.tpc, 0);
1474 trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.pc, 0);
1479 /* Disassemble the trap to see what personality to use. */
1482 /* Linux/SPARC syscall trap. */
1483 update_personality(tcp, 0);
1486 /* Linux/SPARC64 syscall trap. */
1487 update_personality(tcp, 2);
1490 /* SunOS syscall trap. (pers 1) */
1491 fprintf(stderr, "syscall: SunOS no support\n");
1494 /* Solaris 2.x syscall trap. (per 2) */
1495 update_personality(tcp, 1);
1498 /* NetBSD/FreeBSD syscall trap. */
1499 fprintf(stderr, "syscall: NetBSD/FreeBSD not supported\n");
1502 /* Solaris 2.x gettimeofday */
1503 update_personality(tcp, 1);
1506 # if defined(SPARC64)
1507 fprintf(stderr, "syscall: unknown syscall trap %08lx %016lx\n", trap, sparc_regs.tpc);
1509 fprintf(stderr, "syscall: unknown syscall trap %08lx %08lx\n", trap, sparc_regs.pc);
1514 /* Extract the system call number from the registers. */
1515 if (trap == 0x91d02027)
1518 scno = sparc_regs.u_regs[U_REG_G1];
1520 scno = sparc_regs.u_regs[U_REG_O0];
1521 memmove(&sparc_regs.u_regs[U_REG_O0], &sparc_regs.u_regs[U_REG_O1], 7*sizeof(sparc_regs.u_regs[0]));
1524 if (upeek(tcp, PT_GR20, &scno) < 0)
1528 * In the new syscall ABI, the system call number is in R3.
1530 if (upeek(tcp, 4*(REG_REG0+3), &scno) < 0)
1534 /* Odd as it may seem, a glibc bug has been known to cause
1535 glibc to issue bogus negative syscall numbers. So for
1536 our purposes, make strace print what it *should* have been */
1537 long correct_scno = (scno & 0xff);
1540 "Detected glibc bug: bogus system call"
1541 " number = %ld, correcting to %ld\n",
1544 scno = correct_scno;
1547 if (upeek(tcp, REG_SYSCALL, &scno) < 0)
1550 #elif defined(CRISV10) || defined(CRISV32)
1551 if (upeek(tcp, 4*PT_R9, &scno) < 0)
1555 scno = tile_regs.regs[10];
1559 # ifndef PT_FLAGS_COMPAT
1560 # define PT_FLAGS_COMPAT 0x10000 /* from Linux 3.8 on */
1562 if (tile_regs.flags & PT_FLAGS_COMPAT)
1567 update_personality(tcp, currpers);
1568 #elif defined(MICROBLAZE)
1569 if (upeek(tcp, 0, &scno) < 0)
1572 scno = or1k_regs.gpr[11];
1573 #elif defined(METAG)
1574 scno = metag_regs.dx[0][1]; /* syscall number in D1Re0 (D1.0) */
1575 #elif defined(XTENSA)
1576 if (upeek(tcp, SYSCALL_NR, &scno) < 0)
1581 if (SCNO_IS_VALID(tcp->scno)) {
1582 tcp->s_ent = &sysent[scno];
1583 tcp->qual_flg = qual_flags[scno];
1585 static const struct_sysent unknown = {
1588 .sys_func = printargs,
1589 .sys_name = "unknown", /* not used */
1591 tcp->s_ent = &unknown;
1592 tcp->qual_flg = UNDEFINED_SCNO | QUAL_RAW | DEFAULT_QUAL_FLAGS;
1597 /* Called at each syscall entry.
1599 * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently.
1600 * 1: ok, continue in trace_syscall_entering().
1601 * other: error, trace_syscall_entering() should print error indicator
1602 * ("????" etc) and bail out.
1605 syscall_fixup_on_sysenter(struct tcb *tcp)
1607 /* A common case of "not a syscall entry" is post-execve SIGTRAP */
1609 if (i386_regs.eax != -ENOSYS) {
1611 fprintf(stderr, "not a syscall entry (eax = %ld)\n", i386_regs.eax);
1614 #elif defined(X86_64) || defined(X32)
1617 if (x86_io.iov_len == sizeof(i386_regs)) {
1618 /* Sign extend from 32 bits */
1619 rax = (int32_t)i386_regs.eax;
1621 /* Note: in X32 build, this truncates 64 to 32 bits */
1622 rax = x86_64_regs.rax;
1624 if (rax != -ENOSYS) {
1626 fprintf(stderr, "not a syscall entry (rax = %ld)\n", rax);
1630 #elif defined(S390) || defined(S390X)
1631 /* TODO: we already fetched PT_GPR2 in get_scno
1632 * and stored it in syscall_mode, reuse it here
1633 * instead of re-fetching?
1635 if (upeek(tcp, PT_GPR2, &gpr2) < 0)
1637 if (syscall_mode != -ENOSYS)
1638 syscall_mode = tcp->scno;
1639 if (gpr2 != syscall_mode) {
1641 fprintf(stderr, "not a syscall entry (gpr2 = %ld)\n", gpr2);
1645 /* TODO? Eliminate upeek's in arches below like we did in x86 */
1646 if (upeek(tcp, 4*PT_D0, &m68k_d0) < 0)
1648 if (m68k_d0 != -ENOSYS) {
1650 fprintf(stderr, "not a syscall entry (d0 = %ld)\n", m68k_d0);
1654 if (upeek(tcp, PT_R10, &ia64_r10) < 0)
1656 if (upeek(tcp, PT_R8, &ia64_r8) < 0)
1658 if (ia32 && ia64_r8 != -ENOSYS) {
1660 fprintf(stderr, "not a syscall entry (r8 = %ld)\n", ia64_r8);
1663 #elif defined(CRISV10) || defined(CRISV32)
1664 if (upeek(tcp, 4*PT_R10, &cris_r10) < 0)
1666 if (cris_r10 != -ENOSYS) {
1668 fprintf(stderr, "not a syscall entry (r10 = %ld)\n", cris_r10);
1671 #elif defined(MICROBLAZE)
1672 if (upeek(tcp, 3 * 4, µblaze_r3) < 0)
1674 if (microblaze_r3 != -ENOSYS) {
1676 fprintf(stderr, "not a syscall entry (r3 = %ld)\n", microblaze_r3);
1684 internal_fork(struct tcb *tcp)
1686 #if defined S390 || defined S390X || defined CRISV10 || defined CRISV32
1687 # define ARG_FLAGS 1
1689 # define ARG_FLAGS 0
1691 #ifndef CLONE_UNTRACED
1692 # define CLONE_UNTRACED 0x00800000
1694 if ((ptrace_setoptions
1695 & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
1696 == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
1702 if (entering(tcp)) {
1704 * We won't see the new child if clone is called with
1705 * CLONE_UNTRACED, so we keep the same logic with that option
1706 * and don't trace it.
1708 if ((tcp->s_ent->sys_func == sys_clone)
1709 && (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED)
1714 if (tcp->flags & TCB_BPTSET)
1719 #if defined(TCB_WAITEXECVE)
1721 internal_exec(struct tcb *tcp)
1723 /* Maybe we have post-execve SIGTRAP suppressed? */
1724 if (ptrace_setoptions & PTRACE_O_TRACEEXEC)
1725 return; /* yes, no need to do anything */
1727 if (exiting(tcp) && syserror(tcp))
1728 /* Error in execve, no post-execve SIGTRAP expected */
1729 tcp->flags &= ~TCB_WAITEXECVE;
1731 tcp->flags |= TCB_WAITEXECVE;
1736 syscall_fixup_for_fork_exec(struct tcb *tcp)
1739 * We must always trace a few critical system calls in order to
1740 * correctly support following forks in the presence of tracing
1745 func = tcp->s_ent->sys_func;
1747 if ( sys_fork == func
1748 || sys_vfork == func
1749 || sys_clone == func
1755 #if defined(TCB_WAITEXECVE)
1756 if ( sys_execve == func
1757 # if defined(SPARC) || defined(SPARC64)
1758 || sys_execv == func
1767 /* Return -1 on error or 1 on success (never 0!) */
1769 get_syscall_args(struct tcb *tcp)
1773 nargs = tcp->s_ent->nargs;
1775 #if defined(S390) || defined(S390X)
1776 for (i = 0; i < nargs; ++i)
1777 if (upeek(tcp, i==0 ? PT_ORIGGPR2 : PT_GPR2 + i*sizeof(long), &tcp->u_arg[i]) < 0)
1779 #elif defined(ALPHA)
1780 for (i = 0; i < nargs; ++i)
1781 if (upeek(tcp, REG_A0+i, &tcp->u_arg[i]) < 0)
1785 unsigned long *out0, cfm, sof, sol;
1787 /* be backwards compatible with kernel < 2.4.4... */
1789 # define PT_RBS_END PT_AR_BSP
1792 if (upeek(tcp, PT_RBS_END, &rbs_end) < 0)
1794 if (upeek(tcp, PT_CFM, (long *) &cfm) < 0)
1797 sof = (cfm >> 0) & 0x7f;
1798 sol = (cfm >> 7) & 0x7f;
1799 out0 = ia64_rse_skip_regs((unsigned long *) rbs_end, -sof + sol);
1801 for (i = 0; i < nargs; ++i) {
1802 if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i),
1803 sizeof(long), (char *) &tcp->u_arg[i]) < 0)
1807 static const int argreg[MAX_ARGS] = { PT_R11 /* EBX = out0 */,
1808 PT_R9 /* ECX = out1 */,
1809 PT_R10 /* EDX = out2 */,
1810 PT_R14 /* ESI = out3 */,
1811 PT_R15 /* EDI = out4 */,
1812 PT_R13 /* EBP = out5 */};
1814 for (i = 0; i < nargs; ++i) {
1815 if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
1817 /* truncate away IVE sign-extension */
1818 tcp->u_arg[i] &= 0xffffffff;
1821 #elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
1822 /* N32 and N64 both use up to six registers. */
1823 unsigned long long regs[38];
1825 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
1828 for (i = 0; i < nargs; ++i) {
1829 tcp->u_arg[i] = regs[REG_A0 + i];
1830 # if defined(LINUX_MIPSN32)
1831 tcp->ext_arg[i] = regs[REG_A0 + i];
1838 if (upeek(tcp, REG_SP, &sp) < 0)
1840 for (i = 0; i < 4; ++i)
1841 if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
1843 umoven(tcp, sp + 16, (nargs - 4) * sizeof(tcp->u_arg[0]),
1844 (char *)(tcp->u_arg + 4));
1846 for (i = 0; i < nargs; ++i)
1847 if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
1850 #elif defined(POWERPC)
1853 tcp->u_arg[0] = ppc_regs.orig_gpr3;
1854 tcp->u_arg[1] = ppc_regs.gpr[4];
1855 tcp->u_arg[2] = ppc_regs.gpr[5];
1856 tcp->u_arg[3] = ppc_regs.gpr[6];
1857 tcp->u_arg[4] = ppc_regs.gpr[7];
1858 tcp->u_arg[5] = ppc_regs.gpr[8];
1859 #elif defined(SPARC) || defined(SPARC64)
1860 for (i = 0; i < nargs; ++i)
1861 tcp->u_arg[i] = sparc_regs.u_regs[U_REG_O0 + i];
1863 for (i = 0; i < nargs; ++i)
1864 if (upeek(tcp, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
1866 #elif defined(ARM) || defined(AARCH64)
1867 # if defined(AARCH64)
1868 if (tcp->currpers == 1)
1869 for (i = 0; i < nargs; ++i)
1870 tcp->u_arg[i] = aarch64_regs.regs[i];
1873 for (i = 0; i < nargs; ++i)
1874 tcp->u_arg[i] = arm_regs.uregs[i];
1875 #elif defined(AVR32)
1878 tcp->u_arg[0] = avr32_regs.r12;
1879 tcp->u_arg[1] = avr32_regs.r11;
1880 tcp->u_arg[2] = avr32_regs.r10;
1881 tcp->u_arg[3] = avr32_regs.r9;
1882 tcp->u_arg[4] = avr32_regs.r5;
1883 tcp->u_arg[5] = avr32_regs.r3;
1885 static const int argreg[MAX_ARGS] = { PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5 };
1887 for (i = 0; i < nargs; ++i)
1888 if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
1891 static const int syscall_regs[MAX_ARGS] = {
1892 4 * (REG_REG0+4), 4 * (REG_REG0+5), 4 * (REG_REG0+6),
1893 4 * (REG_REG0+7), 4 * (REG_REG0 ), 4 * (REG_REG0+1)
1896 for (i = 0; i < nargs; ++i)
1897 if (upeek(tcp, syscall_regs[i], &tcp->u_arg[i]) < 0)
1901 /* Registers used by SH5 Linux system calls for parameters */
1902 static const int syscall_regs[MAX_ARGS] = { 2, 3, 4, 5, 6, 7 };
1904 for (i = 0; i < nargs; ++i)
1905 if (upeek(tcp, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0)
1910 tcp->u_arg[0] = i386_regs.ebx;
1911 tcp->u_arg[1] = i386_regs.ecx;
1912 tcp->u_arg[2] = i386_regs.edx;
1913 tcp->u_arg[3] = i386_regs.esi;
1914 tcp->u_arg[4] = i386_regs.edi;
1915 tcp->u_arg[5] = i386_regs.ebp;
1916 #elif defined(X86_64) || defined(X32)
1919 if (x86_io.iov_len != sizeof(i386_regs)) {
1920 /* x86-64 or x32 ABI */
1921 tcp->u_arg[0] = x86_64_regs.rdi;
1922 tcp->u_arg[1] = x86_64_regs.rsi;
1923 tcp->u_arg[2] = x86_64_regs.rdx;
1924 tcp->u_arg[3] = x86_64_regs.r10;
1925 tcp->u_arg[4] = x86_64_regs.r8;
1926 tcp->u_arg[5] = x86_64_regs.r9;
1928 tcp->ext_arg[0] = x86_64_regs.rdi;
1929 tcp->ext_arg[1] = x86_64_regs.rsi;
1930 tcp->ext_arg[2] = x86_64_regs.rdx;
1931 tcp->ext_arg[3] = x86_64_regs.r10;
1932 tcp->ext_arg[4] = x86_64_regs.r8;
1933 tcp->ext_arg[5] = x86_64_regs.r9;
1937 /* Zero-extend from 32 bits */
1938 /* Use widen_to_long(tcp->u_arg[N]) in syscall handlers
1939 * if you need to use *sign-extended* parameter.
1941 tcp->u_arg[0] = (long)(uint32_t)i386_regs.ebx;
1942 tcp->u_arg[1] = (long)(uint32_t)i386_regs.ecx;
1943 tcp->u_arg[2] = (long)(uint32_t)i386_regs.edx;
1944 tcp->u_arg[3] = (long)(uint32_t)i386_regs.esi;
1945 tcp->u_arg[4] = (long)(uint32_t)i386_regs.edi;
1946 tcp->u_arg[5] = (long)(uint32_t)i386_regs.ebp;
1948 #elif defined(MICROBLAZE)
1949 for (i = 0; i < nargs; ++i)
1950 if (upeek(tcp, (5 + i) * 4, &tcp->u_arg[i]) < 0)
1952 #elif defined(CRISV10) || defined(CRISV32)
1953 static const int crisregs[MAX_ARGS] = {
1954 4*PT_ORIG_R10, 4*PT_R11, 4*PT_R12,
1955 4*PT_R13 , 4*PT_MOF, 4*PT_SRP
1958 for (i = 0; i < nargs; ++i)
1959 if (upeek(tcp, crisregs[i], &tcp->u_arg[i]) < 0)
1962 for (i = 0; i < nargs; ++i)
1963 tcp->u_arg[i] = tile_regs.regs[i];
1965 for (i = 0; i < nargs; ++i)
1966 if (upeek(tcp, (i < 5 ? i : i + 2)*4, &tcp->u_arg[i]) < 0)
1970 for (i = 0; i < 6; ++i)
1971 tcp->u_arg[i] = or1k_regs.gpr[3 + i];
1972 #elif defined(METAG)
1973 for (i = 0; i < nargs; i++)
1974 /* arguments go backwards from D1Ar1 (D1.3) */
1975 tcp->u_arg[i] = ((unsigned long *)&metag_regs.dx[3][1])[-i];
1976 #elif defined(XTENSA)
1977 /* arg0: a6, arg1: a3, arg2: a4, arg3: a5, arg4: a8, arg5: a9 */
1978 static const int xtensaregs[MAX_ARGS] = { 6, 3, 4, 5, 8, 9 };
1979 for (i = 0; i < nargs; ++i)
1980 if (upeek(tcp, REG_A_BASE + xtensaregs[i], &tcp->u_arg[i]) < 0)
1982 #else /* Other architecture (32bits specific) */
1983 for (i = 0; i < nargs; ++i)
1984 if (upeek(tcp, i*4, &tcp->u_arg[i]) < 0)
1991 trace_syscall_entering(struct tcb *tcp)
1995 #if defined TCB_WAITEXECVE
1996 if (tcp->flags & TCB_WAITEXECVE) {
1997 /* This is the post-execve SIGTRAP. */
1998 tcp->flags &= ~TCB_WAITEXECVE;
2003 scno_good = res = (get_regs_error ? -1 : get_scno(tcp));
2007 res = syscall_fixup_on_sysenter(tcp);
2011 res = get_syscall_args(tcp);
2017 tprints("????" /* anti-trigraph gap */ "(");
2018 else if (tcp->qual_flg & UNDEFINED_SCNO)
2019 tprintf("%s(", undefined_scno_name(tcp));
2021 tprintf("%s(", tcp->s_ent->sys_name);
2023 * " <unavailable>" will be added later by the code which
2024 * detects ptrace errors.
2029 if ( sys_execve == tcp->s_ent->sys_func
2030 # if defined(SPARC) || defined(SPARC64)
2031 || sys_execv == tcp->s_ent->sys_func
2034 hide_log_until_execve = 0;
2037 #if defined(SYS_socket_subcall) || defined(SYS_ipc_subcall)
2039 # ifdef SYS_socket_subcall
2040 if (tcp->s_ent->sys_func == sys_socketcall) {
2041 decode_socket_subcall(tcp);
2045 # ifdef SYS_ipc_subcall
2046 if (tcp->s_ent->sys_func == sys_ipc) {
2047 decode_ipc_subcall(tcp);
2055 if (need_fork_exec_workarounds)
2056 syscall_fixup_for_fork_exec(tcp);
2058 if (!(tcp->qual_flg & QUAL_TRACE)
2059 || (tracing_paths && !pathtrace_match(tcp))
2061 tcp->flags |= TCB_INSYSCALL | TCB_FILTERED;
2065 tcp->flags &= ~TCB_FILTERED;
2067 if (cflag == CFLAG_ONLY_STATS || hide_log_until_execve) {
2073 if (tcp->qual_flg & UNDEFINED_SCNO)
2074 tprintf("%s(", undefined_scno_name(tcp));
2076 tprintf("%s(", tcp->s_ent->sys_name);
2077 if ((tcp->qual_flg & QUAL_RAW) && tcp->s_ent->sys_func != sys_exit)
2078 res = printargs(tcp);
2080 res = tcp->s_ent->sys_func(tcp);
2084 tcp->flags |= TCB_INSYSCALL;
2085 /* Measure the entrance time as late as possible to avoid errors. */
2087 gettimeofday(&tcp->etime, NULL);
2092 * 1: ok, continue in trace_syscall_exiting().
2093 * -1: error, trace_syscall_exiting() should print error indicator
2094 * ("????" etc) and bail out.
2097 get_syscall_result(struct tcb *tcp)
2099 #if defined(S390) || defined(S390X)
2100 if (upeek(tcp, PT_GPR2, &gpr2) < 0)
2102 #elif defined(POWERPC)
2103 # define SO_MASK 0x10000000
2104 ppc_result = ppc_regs.gpr[3];
2105 if (ppc_regs.ccr & SO_MASK)
2106 ppc_result = -ppc_result;
2107 #elif defined(AVR32)
2108 /* already done by get_regs */
2110 if (upeek(tcp, PT_R0, &bfin_r0) < 0)
2113 /* already done by get_regs */
2114 #elif defined(X86_64) || defined(X32)
2115 /* already done by get_regs */
2117 # define IA64_PSR_IS ((long)1 << 34)
2119 if (upeek(tcp, PT_CR_IPSR, &psr) >= 0)
2120 ia32 = (psr & IA64_PSR_IS) != 0;
2121 if (upeek(tcp, PT_R8, &ia64_r8) < 0)
2123 if (upeek(tcp, PT_R10, &ia64_r10) < 0)
2126 /* already done by get_regs */
2127 #elif defined(AARCH64)
2128 /* register reading already done by get_regs */
2130 /* Used to do this, but we did it on syscall entry already: */
2131 /* We are in 64-bit mode (personality 1) if register struct is aarch64_regs,
2132 * else it's personality 0.
2134 /*update_personality(tcp, aarch64_io.iov_len == sizeof(aarch64_regs));*/
2136 if (upeek(tcp, 4*PT_D0, &m68k_d0) < 0)
2138 #elif defined(LINUX_MIPSN32)
2139 unsigned long long regs[38];
2141 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
2143 mips_a3 = regs[REG_A3];
2144 mips_r2 = regs[REG_V0];
2146 if (upeek(tcp, REG_A3, &mips_a3) < 0)
2148 if (upeek(tcp, REG_V0, &mips_r2) < 0)
2150 #elif defined(ALPHA)
2151 if (upeek(tcp, REG_A3, &alpha_a3) < 0)
2153 if (upeek(tcp, REG_R0, &alpha_r0) < 0)
2155 #elif defined(SPARC) || defined(SPARC64)
2156 /* already done by get_regs */
2158 if (upeek(tcp, PT_GR28, &hppa_r28) < 0)
2161 /* new syscall ABI returns result in R0 */
2162 if (upeek(tcp, 4*REG_REG0, (long *)&sh_r0) < 0)
2165 /* ABI defines result returned in r9 */
2166 if (upeek(tcp, REG_GENERAL(9), (long *)&sh64_r9) < 0)
2168 #elif defined(CRISV10) || defined(CRISV32)
2169 if (upeek(tcp, 4*PT_R10, &cris_r10) < 0)
2172 /* already done by get_regs */
2173 #elif defined(MICROBLAZE)
2174 if (upeek(tcp, 3 * 4, µblaze_r3) < 0)
2177 /* already done by get_regs */
2178 #elif defined(METAG)
2179 /* already done by get_regs */
2180 #elif defined(XTENSA)
2181 if (upeek(tcp, REG_A_BASE + 2, &xtensa_a2) < 0)
2187 /* Called at each syscall exit */
2189 syscall_fixup_on_sysexit(struct tcb *tcp)
2191 #if defined(S390) || defined(S390X)
2192 if (syscall_mode != -ENOSYS)
2193 syscall_mode = tcp->scno;
2194 if ((tcp->flags & TCB_WAITEXECVE)
2195 && (gpr2 == -ENOSYS || gpr2 == tcp->scno)) {
2197 * Return from execve.
2198 * Fake a return value of zero. We leave the TCB_WAITEXECVE
2199 * flag set for the post-execve SIGTRAP to see and reset.
2207 * Check the syscall return value register value for whether it is
2208 * a negated errno code indicating an error, or a success return value.
2211 is_negated_errno(unsigned long int val)
2213 unsigned long int max = -(long int) nerrnos;
2214 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
2215 if (current_wordsize < sizeof(val)) {
2216 val = (unsigned int) val;
2217 max = (unsigned int) max;
2225 is_negated_errno_x32(unsigned long long val)
2227 unsigned long long max = -(long long) nerrnos;
2229 * current_wordsize is 4 even in personality 0 (native X32)
2230 * but truncation _must not_ be done in it.
2231 * can't check current_wordsize here!
2233 if (current_personality != 0) {
2234 val = (uint32_t) val;
2235 max = (uint32_t) max;
2242 * 1: ok, continue in trace_syscall_exiting().
2243 * -1: error, trace_syscall_exiting() should print error indicator
2244 * ("????" etc) and bail out.
2247 get_error(struct tcb *tcp)
2250 int check_errno = 1;
2251 if (tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS) {
2254 #if defined(S390) || defined(S390X)
2255 if (check_errno && is_negated_errno(gpr2)) {
2263 if (check_errno && is_negated_errno(i386_regs.eax)) {
2265 u_error = -i386_regs.eax;
2268 tcp->u_rval = i386_regs.eax;
2270 #elif defined(X86_64)
2272 if (x86_io.iov_len == sizeof(i386_regs)) {
2273 /* Sign extend from 32 bits */
2274 rax = (int32_t)i386_regs.eax;
2276 rax = x86_64_regs.rax;
2278 if (check_errno && is_negated_errno(rax)) {
2286 /* In X32, return value is 64-bit (llseek uses one).
2287 * Using merely "long rax" would not work.
2290 if (x86_io.iov_len == sizeof(i386_regs)) {
2291 /* Sign extend from 32 bits */
2292 rax = (int32_t)i386_regs.eax;
2294 rax = x86_64_regs.rax;
2296 /* Careful: is_negated_errno() works only on longs */
2297 if (check_errno && is_negated_errno_x32(rax)) {
2302 tcp->u_rval = rax; /* truncating */
2310 if (check_errno && is_negated_errno(err)) {
2318 if (check_errno && ia64_r10) {
2322 tcp->u_rval = ia64_r8;
2326 if (check_errno && mips_a3) {
2330 tcp->u_rval = mips_r2;
2331 # if defined(LINUX_MIPSN32)
2332 tcp->u_lrval = mips_r2;
2335 #elif defined(POWERPC)
2336 if (check_errno && is_negated_errno(ppc_result)) {
2338 u_error = -ppc_result;
2341 tcp->u_rval = ppc_result;
2344 if (check_errno && is_negated_errno(m68k_d0)) {
2349 tcp->u_rval = m68k_d0;
2351 #elif defined(ARM) || defined(AARCH64)
2352 # if defined(AARCH64)
2353 if (tcp->currpers == 1) {
2354 if (check_errno && is_negated_errno(aarch64_regs.regs[0])) {
2356 u_error = -aarch64_regs.regs[0];
2359 tcp->u_rval = aarch64_regs.regs[0];
2365 if (check_errno && is_negated_errno(arm_regs.ARM_r0)) {
2367 u_error = -arm_regs.ARM_r0;
2370 tcp->u_rval = arm_regs.ARM_r0;
2373 #elif defined(AVR32)
2374 if (check_errno && avr32_regs.r12 && (unsigned) -avr32_regs.r12 < nerrnos) {
2376 u_error = -avr32_regs.r12;
2379 tcp->u_rval = avr32_regs.r12;
2382 if (check_errno && is_negated_errno(bfin_r0)) {
2386 tcp->u_rval = bfin_r0;
2388 #elif defined(ALPHA)
2389 if (check_errno && alpha_a3) {
2394 tcp->u_rval = alpha_r0;
2396 #elif defined(SPARC)
2397 if (check_errno && sparc_regs.psr & PSR_C) {
2399 u_error = sparc_regs.u_regs[U_REG_O0];
2402 tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
2404 #elif defined(SPARC64)
2405 if (check_errno && sparc_regs.tstate & 0x1100000000UL) {
2407 u_error = sparc_regs.u_regs[U_REG_O0];
2410 tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
2413 if (check_errno && is_negated_errno(hppa_r28)) {
2415 u_error = -hppa_r28;
2418 tcp->u_rval = hppa_r28;
2421 if (check_errno && is_negated_errno(sh_r0)) {
2426 tcp->u_rval = sh_r0;
2429 if (check_errno && is_negated_errno(sh64_r9)) {
2434 tcp->u_rval = sh64_r9;
2436 #elif defined(METAG)
2437 /* result pointer in D0Re0 (D0.0) */
2438 if (check_errno && is_negated_errno(metag_regs.dx[0][0])) {
2440 u_error = -metag_regs.dx[0][0];
2443 tcp->u_rval = metag_regs.dx[0][0];
2445 #elif defined(CRISV10) || defined(CRISV32)
2446 if (check_errno && cris_r10 && (unsigned) -cris_r10 < nerrnos) {
2448 u_error = -cris_r10;
2451 tcp->u_rval = cris_r10;
2455 * The standard tile calling convention returns the value (or negative
2456 * errno) in r0, and zero (or positive errno) in r1.
2457 * Until at least kernel 3.8, however, the r1 value is not reflected
2458 * in ptregs at this point, so we use r0 here.
2460 if (check_errno && is_negated_errno(tile_regs.regs[0])) {
2462 u_error = -tile_regs.regs[0];
2464 tcp->u_rval = tile_regs.regs[0];
2466 #elif defined(MICROBLAZE)
2467 if (check_errno && is_negated_errno(microblaze_r3)) {
2469 u_error = -microblaze_r3;
2472 tcp->u_rval = microblaze_r3;
2475 if (check_errno && is_negated_errno(or1k_regs.gpr[11])) {
2477 u_error = -or1k_regs.gpr[11];
2480 tcp->u_rval = or1k_regs.gpr[11];
2482 #elif defined(XTENSA)
2483 if (check_errno && is_negated_errno(xtensa_a2)) {
2485 u_error = -xtensa_a2;
2488 tcp->u_rval = xtensa_a2;
2491 tcp->u_error = u_error;
2495 dumpio(struct tcb *tcp)
2501 if ((unsigned long) tcp->u_arg[0] >= num_quals)
2503 func = tcp->s_ent->sys_func;
2504 if (func == printargs)
2506 if (qual_flags[tcp->u_arg[0]] & QUAL_READ) {
2507 if (func == sys_read ||
2508 func == sys_pread ||
2510 func == sys_recvfrom)
2511 dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
2512 else if (func == sys_readv)
2513 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2516 if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) {
2517 if (func == sys_write ||
2518 func == sys_pwrite ||
2521 dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2522 else if (func == sys_writev)
2523 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2529 trace_syscall_exiting(struct tcb *tcp)
2536 /* Measure the exit time as early as possible to avoid errors. */
2538 gettimeofday(&tv, NULL);
2540 #if SUPPORTED_PERSONALITIES > 1
2541 update_personality(tcp, tcp->currpers);
2543 res = (get_regs_error ? -1 : get_syscall_result(tcp));
2545 syscall_fixup_on_sysexit(tcp); /* never fails */
2546 get_error(tcp); /* never fails */
2547 if (need_fork_exec_workarounds)
2548 syscall_fixup_for_fork_exec(tcp);
2549 if (filtered(tcp) || hide_log_until_execve)
2554 struct timeval t = tv;
2555 count_syscall(tcp, &t);
2556 if (cflag == CFLAG_ONLY_STATS) {
2561 /* If not in -ff mode, and printing_tcp != tcp,
2562 * then the log currently does not end with output
2563 * of _our syscall entry_, but with something else.
2564 * We need to say which syscall's return is this.
2566 * Forced reprinting via TCB_REPRINT is used only by
2567 * "strace -ff -oLOG test/threaded_execve" corner case.
2568 * It's the only case when -ff mode needs reprinting.
2570 if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) {
2571 tcp->flags &= ~TCB_REPRINT;
2573 if (tcp->qual_flg & UNDEFINED_SCNO)
2574 tprintf("<... %s resumed> ", undefined_scno_name(tcp));
2576 tprintf("<... %s resumed> ", tcp->s_ent->sys_name);
2581 /* There was error in one of prior ptrace ops */
2584 tprints("= ? <unavailable>\n");
2586 tcp->flags &= ~TCB_INSYSCALL;
2591 if (tcp->qual_flg & QUAL_RAW) {
2592 /* sys_res = printargs(tcp); - but it's nop on sysexit */
2594 /* FIXME: not_failing_only (IOW, option -z) is broken:
2595 * failure of syscall is known only after syscall return.
2596 * Thus we end up with something like this on, say, ENOENT:
2597 * open("doesnt_exist", O_RDONLY <unfinished ...>
2598 * {next syscall decode}
2599 * whereas the intended result is that open(...) line
2600 * is not shown at all.
2602 if (not_failing_only && tcp->u_error)
2603 goto ret; /* ignore failed syscalls */
2604 sys_res = tcp->s_ent->sys_func(tcp);
2609 u_error = tcp->u_error;
2610 if (tcp->qual_flg & QUAL_RAW) {
2612 tprintf("= -1 (errno %ld)", u_error);
2614 tprintf("= %#lx", tcp->u_rval);
2616 else if (!(sys_res & RVAL_NONE) && u_error) {
2618 /* Blocked signals do not interrupt any syscalls.
2619 * In this case syscalls don't return ERESTARTfoo codes.
2621 * Deadly signals set to SIG_DFL interrupt syscalls
2622 * and kill the process regardless of which of the codes below
2623 * is returned by the interrupted syscall.
2624 * In some cases, kernel forces a kernel-generated deadly
2625 * signal to be unblocked and set to SIG_DFL (and thus cause
2626 * death) if it is blocked or SIG_IGNed: for example, SIGSEGV
2627 * or SIGILL. (The alternative is to leave process spinning
2628 * forever on the faulty instruction - not useful).
2630 * SIG_IGNed signals and non-deadly signals set to SIG_DFL
2631 * (for example, SIGCHLD, SIGWINCH) interrupt syscalls,
2632 * but kernel will always restart them.
2635 /* Most common type of signal-interrupted syscall exit code.
2636 * The system call will be restarted with the same arguments
2637 * if SA_RESTART is set; otherwise, it will fail with EINTR.
2639 tprints("= ? ERESTARTSYS (To be restarted if SA_RESTART is set)");
2641 case ERESTARTNOINTR:
2642 /* Rare. For example, fork() returns this if interrupted.
2643 * SA_RESTART is ignored (assumed set): the restart is unconditional.
2645 tprints("= ? ERESTARTNOINTR (To be restarted)");
2647 case ERESTARTNOHAND:
2648 /* pause(), rt_sigsuspend() etc use this code.
2649 * SA_RESTART is ignored (assumed not set):
2650 * syscall won't restart (will return EINTR instead)
2651 * even after signal with SA_RESTART set. However,
2652 * after SIG_IGN or SIG_DFL signal it will restart
2653 * (thus the name "restart only if has no handler").
2655 tprints("= ? ERESTARTNOHAND (To be restarted if no handler)");
2657 case ERESTART_RESTARTBLOCK:
2658 /* Syscalls like nanosleep(), poll() which can't be
2659 * restarted with their original arguments use this
2660 * code. Kernel will execute restart_syscall() instead,
2661 * which changes arguments before restarting syscall.
2662 * SA_RESTART is ignored (assumed not set) similarly
2663 * to ERESTARTNOHAND. (Kernel can't honor SA_RESTART
2664 * since restart data is saved in "restart block"
2665 * in task struct, and if signal handler uses a syscall
2666 * which in turn saves another such restart block,
2667 * old data is lost and restart becomes impossible)
2669 tprints("= ? ERESTART_RESTARTBLOCK (Interrupted by signal)");
2673 tprintf("= -1 E??? (errno %ld)", u_error);
2674 else if (u_error < nerrnos)
2675 tprintf("= -1 %s (%s)", errnoent[u_error],
2678 tprintf("= -1 ERRNO_%ld (%s)", u_error,
2682 if ((sys_res & RVAL_STR) && tcp->auxstr)
2683 tprintf(" (%s)", tcp->auxstr);
2686 if (sys_res & RVAL_NONE)
2689 switch (sys_res & RVAL_MASK) {
2691 tprintf("= %#lx", tcp->u_rval);
2694 tprintf("= %#lo", tcp->u_rval);
2697 tprintf("= %lu", tcp->u_rval);
2700 tprintf("= %ld", tcp->u_rval);
2702 #if defined(LINUX_MIPSN32) || defined(X32)
2705 tprintf("= %#llx", tcp->u_lrval);
2708 tprintf("= %#llo", tcp->u_lrval);
2711 case RVAL_LUDECIMAL:
2712 tprintf("= %llu", tcp->u_lrval);
2716 tprintf("= %lld", tcp->u_lrval);
2722 "invalid rval format\n");
2726 if ((sys_res & RVAL_STR) && tcp->auxstr)
2727 tprintf(" (%s)", tcp->auxstr);
2730 tv_sub(&tv, &tv, &tcp->etime);
2731 tprintf(" <%ld.%06ld>",
2732 (long) tv.tv_sec, (long) tv.tv_usec);
2739 tcp->flags &= ~TCB_INSYSCALL;
2744 trace_syscall(struct tcb *tcp)
2746 return exiting(tcp) ?
2747 trace_syscall_exiting(tcp) : trace_syscall_entering(tcp);