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>
86 # define ERESTARTSYS 512
88 #ifndef ERESTARTNOINTR
89 # define ERESTARTNOINTR 513
91 #ifndef ERESTARTNOHAND
92 # define ERESTARTNOHAND 514 /* restart if no handler */
94 #ifndef ERESTART_RESTARTBLOCK
95 # define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
99 # warning: NSIG is not defined, using 32
103 /* Ugh. Is this really correct? ARM has no RT signals?! */
110 /* Define these shorthand notations to simplify the syscallent files. */
111 #define TD TRACE_DESC
112 #define TF TRACE_FILE
114 #define TN TRACE_NETWORK
115 #define TP TRACE_PROCESS
116 #define TS TRACE_SIGNAL
117 #define TM TRACE_MEMORY
118 #define NF SYSCALL_NEVER_FAILS
121 const struct_sysent sysent0[] = {
122 #include "syscallent.h"
125 #if SUPPORTED_PERSONALITIES > 1
126 static const struct_sysent sysent1[] = {
127 # include "syscallent1.h"
131 #if SUPPORTED_PERSONALITIES > 2
132 static const struct_sysent sysent2[] = {
133 # include "syscallent2.h"
137 /* Now undef them since short defines cause wicked namespace pollution. */
149 * `ioctlent.h' may be generated from `ioctlent.raw' by the auxiliary
150 * program `ioctlsort', such that the list is sorted by the `code' field.
151 * This has the side-effect of resolving the _IO.. macros into
152 * plain integers, eliminating the need to include here everything
156 const char *const errnoent0[] = {
157 #include "errnoent.h"
159 const char *const signalent0[] = {
160 #include "signalent.h"
162 const struct_ioctlent ioctlent0[] = {
163 #include "ioctlent.h"
166 #if SUPPORTED_PERSONALITIES > 1
167 static const char *const errnoent1[] = {
168 # include "errnoent1.h"
170 static const char *const signalent1[] = {
171 # include "signalent1.h"
173 static const struct_ioctlent ioctlent1[] = {
174 # include "ioctlent1.h"
178 #if SUPPORTED_PERSONALITIES > 2
179 static const char *const errnoent2[] = {
180 # include "errnoent2.h"
182 static const char *const signalent2[] = {
183 # include "signalent2.h"
185 static const struct_ioctlent ioctlent2[] = {
186 # include "ioctlent2.h"
191 nsyscalls0 = ARRAY_SIZE(sysent0)
192 #if SUPPORTED_PERSONALITIES > 1
193 , nsyscalls1 = ARRAY_SIZE(sysent1)
194 # if SUPPORTED_PERSONALITIES > 2
195 , nsyscalls2 = ARRAY_SIZE(sysent2)
201 nerrnos0 = ARRAY_SIZE(errnoent0)
202 #if SUPPORTED_PERSONALITIES > 1
203 , nerrnos1 = ARRAY_SIZE(errnoent1)
204 # if SUPPORTED_PERSONALITIES > 2
205 , nerrnos2 = ARRAY_SIZE(errnoent2)
211 nsignals0 = ARRAY_SIZE(signalent0)
212 #if SUPPORTED_PERSONALITIES > 1
213 , nsignals1 = ARRAY_SIZE(signalent1)
214 # if SUPPORTED_PERSONALITIES > 2
215 , nsignals2 = ARRAY_SIZE(signalent2)
221 nioctlents0 = ARRAY_SIZE(ioctlent0)
222 #if SUPPORTED_PERSONALITIES > 1
223 , nioctlents1 = ARRAY_SIZE(ioctlent1)
224 # if SUPPORTED_PERSONALITIES > 2
225 , nioctlents2 = ARRAY_SIZE(ioctlent2)
230 #if SUPPORTED_PERSONALITIES > 1
231 const struct_sysent *sysent = sysent0;
232 const char *const *errnoent = errnoent0;
233 const char *const *signalent = signalent0;
234 const struct_ioctlent *ioctlent = ioctlent0;
236 unsigned nsyscalls = nsyscalls0;
237 unsigned nerrnos = nerrnos0;
238 unsigned nsignals = nsignals0;
239 unsigned nioctlents = nioctlents0;
242 qualbits_t *qual_vec[SUPPORTED_PERSONALITIES];
244 static const unsigned nsyscall_vec[SUPPORTED_PERSONALITIES] = {
246 #if SUPPORTED_PERSONALITIES > 1
249 #if SUPPORTED_PERSONALITIES > 2
253 static const struct_sysent *const sysent_vec[SUPPORTED_PERSONALITIES] = {
255 #if SUPPORTED_PERSONALITIES > 1
258 #if SUPPORTED_PERSONALITIES > 2
264 MAX_NSYSCALLS1 = (nsyscalls0
265 #if SUPPORTED_PERSONALITIES > 1
266 > nsyscalls1 ? nsyscalls0 : nsyscalls1
269 MAX_NSYSCALLS2 = (MAX_NSYSCALLS1
270 #if SUPPORTED_PERSONALITIES > 2
271 > nsyscalls2 ? MAX_NSYSCALLS1 : nsyscalls2
274 MAX_NSYSCALLS = MAX_NSYSCALLS2,
275 /* We are ready for arches with up to 255 signals,
276 * even though the largest known signo is on MIPS and it is 128.
277 * The number of existing syscalls on all arches is
278 * larger that 255 anyway, so it is just a pedantic matter.
280 MIN_QUALS = MAX_NSYSCALLS > 255 ? MAX_NSYSCALLS : 255
283 #if SUPPORTED_PERSONALITIES > 1
284 unsigned current_personality;
286 # ifndef current_wordsize
287 unsigned current_wordsize;
288 static const int personality_wordsize[SUPPORTED_PERSONALITIES] = {
289 PERSONALITY0_WORDSIZE,
290 PERSONALITY1_WORDSIZE,
291 # if SUPPORTED_PERSONALITIES > 2
292 PERSONALITY2_WORDSIZE,
298 set_personality(int personality)
300 nsyscalls = nsyscall_vec[personality];
301 sysent = sysent_vec[personality];
303 switch (personality) {
305 errnoent = errnoent0;
307 ioctlent = ioctlent0;
308 nioctlents = nioctlents0;
309 signalent = signalent0;
310 nsignals = nsignals0;
314 errnoent = errnoent1;
316 ioctlent = ioctlent1;
317 nioctlents = nioctlents1;
318 signalent = signalent1;
319 nsignals = nsignals1;
322 # if SUPPORTED_PERSONALITIES > 2
324 errnoent = errnoent2;
326 ioctlent = ioctlent2;
327 nioctlents = nioctlents2;
328 signalent = signalent2;
329 nsignals = nsignals2;
334 current_personality = personality;
335 # ifndef current_wordsize
336 current_wordsize = personality_wordsize[personality];
341 update_personality(struct tcb *tcp, int personality)
343 if (personality == current_personality)
345 set_personality(personality);
347 if (personality == tcp->currpers)
349 tcp->currpers = personality;
351 # if defined(POWERPC64)
353 static const char *const names[] = {"64 bit", "32 bit"};
354 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
355 tcp->pid, names[personality]);
357 # elif defined(X86_64)
359 static const char *const names[] = {"64 bit", "32 bit", "x32"};
360 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
361 tcp->pid, names[personality]);
365 static const char *const names[] = {"x32", "32 bit"};
366 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
367 tcp->pid, names[personality]);
369 # elif defined(AARCH64)
371 static const char *const names[] = {"32-bit", "AArch64"};
372 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
373 tcp->pid, names[personality]);
377 static const char *const names[] = {"64-bit", "32-bit"};
378 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
379 tcp->pid, names[personality]);
385 static int qual_syscall(), qual_signal(), qual_desc();
387 static const struct qual_options {
389 const char *option_name;
390 int (*qualify)(const char *, int, int);
391 const char *argument_name;
393 { QUAL_TRACE, "trace", qual_syscall, "system call" },
394 { QUAL_TRACE, "t", qual_syscall, "system call" },
395 { QUAL_ABBREV, "abbrev", qual_syscall, "system call" },
396 { QUAL_ABBREV, "a", qual_syscall, "system call" },
397 { QUAL_VERBOSE, "verbose", qual_syscall, "system call" },
398 { QUAL_VERBOSE, "v", qual_syscall, "system call" },
399 { QUAL_RAW, "raw", qual_syscall, "system call" },
400 { QUAL_RAW, "x", qual_syscall, "system call" },
401 { QUAL_SIGNAL, "signal", qual_signal, "signal" },
402 { QUAL_SIGNAL, "signals", qual_signal, "signal" },
403 { QUAL_SIGNAL, "s", qual_signal, "signal" },
404 { QUAL_READ, "read", qual_desc, "descriptor" },
405 { QUAL_READ, "reads", qual_desc, "descriptor" },
406 { QUAL_READ, "r", qual_desc, "descriptor" },
407 { QUAL_WRITE, "write", qual_desc, "descriptor" },
408 { QUAL_WRITE, "writes", qual_desc, "descriptor" },
409 { QUAL_WRITE, "w", qual_desc, "descriptor" },
410 { 0, NULL, NULL, NULL },
414 reallocate_qual(int n)
418 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
419 qp = qual_vec[p] = realloc(qual_vec[p], n * sizeof(qualbits_t));
422 memset(&qp[num_quals], 0, (n - num_quals) * sizeof(qualbits_t));
428 qualify_one(int n, int bitflag, int not, int pers)
433 reallocate_qual(n + 1);
435 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
436 if (pers == p || pers < 0) {
438 qual_vec[p][n] &= ~bitflag;
440 qual_vec[p][n] |= bitflag;
446 qual_syscall(const char *s, int bitflag, int not)
452 if (*s >= '0' && *s <= '9') {
453 i = string_to_uint(s);
454 if (i >= MAX_NSYSCALLS)
456 qualify_one(i, bitflag, not, -1);
460 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
461 for (i = 0; i < nsyscall_vec[p]; i++) {
462 if (sysent_vec[p][i].sys_name
463 && strcmp(s, sysent_vec[p][i].sys_name) == 0
465 qualify_one(i, bitflag, not, 0);
475 qual_signal(const char *s, int bitflag, int not)
479 if (*s >= '0' && *s <= '9') {
480 int signo = string_to_uint(s);
481 if (signo < 0 || signo > 255)
483 qualify_one(signo, bitflag, not, -1);
486 if (strncasecmp(s, "SIG", 3) == 0)
488 for (i = 0; i <= NSIG; i++) {
489 if (strcasecmp(s, signame(i) + 3) == 0) {
490 qualify_one(i, bitflag, not, -1);
498 qual_desc(const char *s, int bitflag, int not)
500 if (*s >= '0' && *s <= '9') {
501 int desc = string_to_uint(s);
502 if (desc < 0 || desc > 0x7fff) /* paranoia */
504 qualify_one(desc, bitflag, not, -1);
511 lookup_class(const char *s)
513 if (strcmp(s, "file") == 0)
515 if (strcmp(s, "ipc") == 0)
517 if (strcmp(s, "network") == 0)
518 return TRACE_NETWORK;
519 if (strcmp(s, "process") == 0)
520 return TRACE_PROCESS;
521 if (strcmp(s, "signal") == 0)
523 if (strcmp(s, "desc") == 0)
525 if (strcmp(s, "memory") == 0)
531 qualify(const char *s)
533 const struct qual_options *opt;
540 reallocate_qual(MIN_QUALS);
542 opt = &qual_options[0];
543 for (i = 0; (p = qual_options[i].option_name); i++) {
545 if (strncmp(s, p, n) == 0 && s[n] == '=') {
546 opt = &qual_options[i];
556 if (strcmp(s, "none") == 0) {
560 if (strcmp(s, "all") == 0) {
561 for (i = 0; i < num_quals; i++) {
562 qualify_one(i, opt->bitflag, not, -1);
566 for (i = 0; i < num_quals; i++) {
567 qualify_one(i, opt->bitflag, !not, -1);
572 for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) {
573 if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) {
575 for (pers = 0; pers < SUPPORTED_PERSONALITIES; pers++) {
576 for (i = 0; i < nsyscall_vec[pers]; i++)
577 if (sysent_vec[pers][i].sys_flags & n)
578 qualify_one(i, opt->bitflag, not, 0);
582 if (opt->qualify(p, opt->bitflag, not)) {
583 error_msg_and_die("invalid %s '%s'",
584 opt->argument_name, p);
591 #ifdef SYS_socket_subcall
593 decode_socket_subcall(struct tcb *tcp)
596 unsigned int i, n, size;
598 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_socket_nsubcalls)
601 tcp->scno = SYS_socket_subcall + tcp->u_arg[0];
602 tcp->qual_flg = qual_flags[tcp->scno];
603 tcp->s_ent = &sysent[tcp->scno];
604 addr = tcp->u_arg[1];
605 size = current_wordsize;
606 n = tcp->s_ent->nargs;
607 for (i = 0; i < n; ++i) {
608 if (size == sizeof(int)) {
610 if (umove(tcp, addr, &arg) < 0)
616 if (umove(tcp, addr, &arg) < 0)
625 #ifdef SYS_ipc_subcall
627 decode_ipc_subcall(struct tcb *tcp)
631 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_ipc_nsubcalls)
634 tcp->scno = SYS_ipc_subcall + tcp->u_arg[0];
635 tcp->qual_flg = qual_flags[tcp->scno];
636 tcp->s_ent = &sysent[tcp->scno];
637 n = tcp->s_ent->nargs;
638 for (i = 0; i < n; i++)
639 tcp->u_arg[i] = tcp->u_arg[i + 1];
644 printargs(struct tcb *tcp)
648 int n = tcp->s_ent->nargs;
649 for (i = 0; i < n; i++)
650 tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]);
656 printargs_lu(struct tcb *tcp)
660 int n = tcp->s_ent->nargs;
661 for (i = 0; i < n; i++)
662 tprintf("%s%lu", i ? ", " : "", tcp->u_arg[i]);
668 printargs_ld(struct tcb *tcp)
672 int n = tcp->s_ent->nargs;
673 for (i = 0; i < n; i++)
674 tprintf("%s%ld", i ? ", " : "", tcp->u_arg[i]);
679 #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH)
681 getrval2(struct tcb *tcp)
685 # if defined(SPARC) || defined(SPARC64)
686 val = sparc_regs.u_regs[U_REG_O1];
688 if (upeek(tcp, 4*(REG_REG0+1), &val) < 0)
691 if (upeek(tcp, PT_R9, &val) < 0)
700 is_restart_error(struct tcb *tcp)
702 switch (tcp->u_error) {
706 case ERESTART_RESTARTBLOCK:
715 struct user_regs_struct i386_regs;
716 #elif defined(X86_64) || defined(X32)
718 * On i386, pt_regs and user_regs_struct are the same,
719 * but on 64 bit x86, user_regs_struct has six more fields:
720 * fs_base, gs_base, ds, es, fs, gs.
721 * PTRACE_GETREGS fills them too, so struct pt_regs would overflow.
723 struct i386_user_regs_struct {
743 struct user_regs_struct x86_64_r;
744 struct i386_user_regs_struct i386_r;
746 # define x86_64_regs x86_regs_union.x86_64_r
747 # define i386_regs x86_regs_union.i386_r
748 static struct iovec x86_io = {
749 .iov_base = &x86_regs_union
752 long ia32 = 0; /* not static */
753 static long ia64_r8, ia64_r10;
754 #elif defined(POWERPC)
755 static long ppc_result;
761 struct pt_regs arm_regs; /* not static */
762 #elif defined(AARCH64)
764 struct user_pt_regs aarch64_r;
765 struct arm_pt_regs arm_r;
767 # define aarch64_regs arm_regs_union.aarch64_r
768 # define arm_regs arm_regs_union.arm_r
769 static struct iovec aarch64_io = {
770 .iov_base = &arm_regs_union
773 static long alpha_r0;
774 static long alpha_a3;
776 static struct pt_regs avr32_regs;
777 #elif defined(SPARC) || defined(SPARC64)
778 struct pt_regs sparc_regs; /* not static */
779 #elif defined(LINUX_MIPSN32)
780 static long long mips_a3;
781 static long long mips_r2;
785 #elif defined(S390) || defined(S390X)
787 static long syscall_mode;
789 static long hppa_r28;
794 #elif defined(CRISV10) || defined(CRISV32)
795 static long cris_r10;
797 struct pt_regs tile_regs;
798 #elif defined(MICROBLAZE)
799 static long microblaze_r3;
801 static struct user_regs_struct or1k_regs;
802 static struct iovec or1k_io = {
803 .iov_base = &or1k_regs
808 printcall(struct tcb *tcp)
810 #define PRINTBADPC tprintf(sizeof(long) == 4 ? "[????????] " : \
811 sizeof(long) == 8 ? "[????????????????] " : \
813 if (get_regs_error) {
818 tprintf("[%08lx] ", i386_regs.eip);
819 #elif defined(S390) || defined(S390X)
821 if (upeek(tcp, PT_PSWADDR, &psw) < 0) {
826 tprintf("[%08lx] ", psw);
828 tprintf("[%016lx] ", psw);
830 #elif defined(X86_64) || defined(X32)
831 if (x86_io.iov_len == sizeof(i386_regs)) {
832 tprintf("[%08x] ", (unsigned) i386_regs.eip);
835 tprintf("[%016lx] ", (unsigned long) x86_64_regs.rip);
837 /* Note: this truncates 64-bit rip to 32 bits */
838 tprintf("[%08lx] ", (unsigned long) x86_64_regs.rip);
843 if (upeek(tcp, PT_B0, &ip) < 0) {
847 tprintf("[%08lx] ", ip);
848 #elif defined(POWERPC)
850 if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &pc) < 0) {
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);
940 #endif /* architecture */
943 /* Shuffle syscall numbers so that we don't have huge gaps in syscall table.
944 * The shuffling should be reversible: shuffle_scno(shuffle_scno(n)) == n.
946 #if defined(ARM) /* So far only ARM needs this */
948 shuffle_scno(unsigned long scno)
950 if (scno <= ARM_LAST_ORDINARY_SYSCALL)
953 /* __ARM_NR_cmpxchg? Swap with LAST_ORDINARY+1 */
954 if (scno == 0x000ffff0)
955 return ARM_LAST_ORDINARY_SYSCALL+1;
956 if (scno == ARM_LAST_ORDINARY_SYSCALL+1)
959 /* Is it ARM specific syscall?
960 * Swap with [LAST_ORDINARY+2, LAST_ORDINARY+2 + LAST_SPECIAL] range.
962 if (scno >= 0x000f0000
963 && scno <= 0x000f0000 + ARM_LAST_SPECIAL_SYSCALL
965 return scno - 0x000f0000 + (ARM_LAST_ORDINARY_SYSCALL+2);
967 if (/* scno >= ARM_LAST_ORDINARY_SYSCALL+2 - always true */ 1
968 && scno <= (ARM_LAST_ORDINARY_SYSCALL+2) + ARM_LAST_SPECIAL_SYSCALL
970 return scno + 0x000f0000 - (ARM_LAST_ORDINARY_SYSCALL+2);
976 # define shuffle_scno(scno) ((long)(scno))
980 undefined_scno_name(struct tcb *tcp)
982 static char buf[sizeof("syscall_%lu") + sizeof(long)*3];
984 sprintf(buf, "syscall_%lu", shuffle_scno(tcp->scno));
994 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &avr32_regs);
996 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &i386_regs);
997 # elif defined(X86_64) || defined(X32)
999 * PTRACE_GETREGSET was introduced in 2.6.33.
1000 * Let's be paranoid and require a bit later kernel.
1002 if (os_release >= KERNEL_VERSION(2,6,35)) {
1003 /*x86_io.iov_base = &x86_regs_union; - already is */
1004 x86_io.iov_len = sizeof(x86_regs_union);
1005 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, (long) &x86_io);
1007 /* Use old method, with heuristical detection of 32-bitness */
1008 x86_io.iov_len = sizeof(x86_64_regs);
1009 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &x86_64_regs);
1010 if (!get_regs_error && x86_64_regs.cs == 0x23) {
1011 x86_io.iov_len = sizeof(i386_regs);
1013 * The order is important: i386_regs and x86_64_regs
1014 * are overlaid in memory!
1016 i386_regs.ebx = x86_64_regs.rbx;
1017 i386_regs.ecx = x86_64_regs.rcx;
1018 i386_regs.edx = x86_64_regs.rdx;
1019 i386_regs.esi = x86_64_regs.rsi;
1020 i386_regs.edi = x86_64_regs.rdi;
1021 i386_regs.ebp = x86_64_regs.rbp;
1022 i386_regs.eax = x86_64_regs.rax;
1023 /*i386_regs.xds = x86_64_regs.ds; unused by strace */
1024 /*i386_regs.xes = x86_64_regs.es; ditto... */
1025 /*i386_regs.xfs = x86_64_regs.fs;*/
1026 /*i386_regs.xgs = x86_64_regs.gs;*/
1027 i386_regs.orig_eax = x86_64_regs.orig_rax;
1028 i386_regs.eip = x86_64_regs.rip;
1029 /*i386_regs.xcs = x86_64_regs.cs;*/
1030 /*i386_regs.eflags = x86_64_regs.eflags;*/
1031 i386_regs.esp = x86_64_regs.rsp;
1032 /*i386_regs.xss = x86_64_regs.ss;*/
1036 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (void *)&arm_regs);
1037 # elif defined(AARCH64)
1038 /*aarch64_io.iov_base = &arm_regs_union; - already is */
1039 aarch64_io.iov_len = sizeof(arm_regs_union);
1040 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, (void *)&aarch64_io);
1042 /* Paranoia checks */
1045 switch (aarch64_io.iov_len) {
1046 case sizeof(aarch64_regs):
1047 /* We are in 64-bit mode */
1049 case sizeof(arm_regs):
1050 /* We are in 32-bit mode */
1053 get_regs_error = -1;
1057 # elif defined(SPARC) || defined(SPARC64)
1058 get_regs_error = ptrace(PTRACE_GETREGS, pid, (char *)&sparc_regs, 0);
1059 # elif defined(TILE)
1060 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &tile_regs);
1061 # elif defined(OR1K)
1062 or1k_io.iov_len = sizeof(or1k_regs);
1063 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &or1k_io);
1069 * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently.
1070 * 1: ok, continue in trace_syscall_entering().
1071 * other: error, trace_syscall_entering() should print error indicator
1072 * ("????" etc) and bail out.
1075 get_scno(struct tcb *tcp)
1079 #if defined(S390) || defined(S390X)
1080 if (upeek(tcp, PT_GPR2, &syscall_mode) < 0)
1083 if (syscall_mode != -ENOSYS) {
1085 * Since kernel version 2.5.44 the scno gets passed in gpr2.
1087 scno = syscall_mode;
1090 * Old style of "passing" the scno via the SVC instruction.
1093 long opcode, offset_reg, tmp;
1095 static const int gpr_offset[16] = {
1096 PT_GPR0, PT_GPR1, PT_ORIGGPR2, PT_GPR3,
1097 PT_GPR4, PT_GPR5, PT_GPR6, PT_GPR7,
1098 PT_GPR8, PT_GPR9, PT_GPR10, PT_GPR11,
1099 PT_GPR12, PT_GPR13, PT_GPR14, PT_GPR15
1102 if (upeek(tcp, PT_PSWADDR, &psw) < 0)
1105 opcode = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(psw - sizeof(long)), 0);
1107 perror_msg("peektext(psw-oneword)");
1112 * We have to check if the SVC got executed directly or via an
1113 * EXECUTE instruction. In case of EXECUTE it is necessary to do
1114 * instruction decoding to derive the system call number.
1115 * Unfortunately the opcode sizes of EXECUTE and SVC are differently,
1116 * so that this doesn't work if a SVC opcode is part of an EXECUTE
1117 * opcode. Since there is no way to find out the opcode size this
1118 * is the best we can do...
1120 if ((opcode & 0xff00) == 0x0a00) {
1122 scno = opcode & 0xff;
1125 /* SVC got executed by EXECUTE instruction */
1128 * Do instruction decoding of EXECUTE. If you really want to
1129 * understand this, read the Principles of Operations.
1131 svc_addr = (void *) (opcode & 0xfff);
1134 offset_reg = (opcode & 0x000f0000) >> 16;
1135 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1140 offset_reg = (opcode & 0x0000f000) >> 12;
1141 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1145 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, svc_addr, 0);
1154 offset_reg = (opcode & 0x00f00000) >> 20;
1155 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1158 scno = (scno | tmp) & 0xff;
1161 #elif defined(POWERPC)
1162 if (upeek(tcp, sizeof(unsigned long)*PT_R0, &scno) < 0)
1165 /* TODO: speed up strace by not doing this at every syscall.
1166 * We only need to do it after execve.
1171 /* Check for 64/32 bit mode. */
1172 if (upeek(tcp, sizeof(unsigned long)*PT_MSR, &val) < 0)
1174 /* SF is bit 0 of MSR */
1179 update_personality(tcp, currpers);
1181 #elif defined(AVR32)
1182 scno = avr32_regs.r8;
1184 if (upeek(tcp, PT_ORIG_P0, &scno))
1187 scno = i386_regs.orig_eax;
1188 #elif defined(X86_64) || defined(X32)
1189 # ifndef __X32_SYSCALL_BIT
1190 # define __X32_SYSCALL_BIT 0x40000000
1194 /* GETREGSET of NT_PRSTATUS tells us regset size,
1195 * which unambiguously detects i386.
1197 * Linux kernel distinguishes x86-64 and x32 processes
1198 * solely by looking at __X32_SYSCALL_BIT:
1199 * arch/x86/include/asm/compat.h::is_x32_task():
1200 * if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
1203 if (x86_io.iov_len == sizeof(i386_regs)) {
1204 scno = i386_regs.orig_eax;
1207 scno = x86_64_regs.orig_rax;
1209 if (scno & __X32_SYSCALL_BIT) {
1210 scno -= __X32_SYSCALL_BIT;
1215 /* cs = 0x33 for long mode (native 64 bit and x32)
1216 * cs = 0x23 for compatibility mode (32 bit)
1217 * ds = 0x2b for x32 mode (x86-64 in 32 bit)
1219 scno = x86_64_regs.orig_rax;
1220 switch (x86_64_regs.cs) {
1221 case 0x23: currpers = 1; break;
1223 if (x86_64_regs.ds == 0x2b) {
1225 scno &= ~__X32_SYSCALL_BIT;
1230 fprintf(stderr, "Unknown value CS=0x%08X while "
1231 "detecting personality of process "
1232 "PID=%d\n", (int)x86_64_regs.cs, tcp->pid);
1233 currpers = current_personality;
1237 /* This version analyzes the opcode of a syscall instruction.
1238 * (int 0x80 on i386 vs. syscall on x86-64)
1239 * It works, but is too complicated, and strictly speaking, unreliable.
1241 unsigned long call, rip = x86_64_regs.rip;
1242 /* sizeof(syscall) == sizeof(int 0x80) == 2 */
1245 call = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)rip, (char *)0);
1247 fprintf(stderr, "ptrace_peektext failed: %s\n",
1249 switch (call & 0xffff) {
1250 /* x86-64: syscall = 0x0f 0x05 */
1251 case 0x050f: currpers = 0; break;
1252 /* i386: int 0x80 = 0xcd 0x80 */
1253 case 0x80cd: currpers = 1; break;
1255 currpers = current_personality;
1257 "Unknown syscall opcode (0x%04X) while "
1258 "detecting personality of process "
1259 "PID=%d\n", (int)call, tcp->pid);
1265 /* If we are built for a x32 system, then personality 0 is x32
1266 * (not x86_64), and stracing of x86_64 apps is not supported.
1267 * Stracing of i386 apps is still supported.
1269 if (currpers == 0) {
1270 fprintf(stderr, "syscall_%lu(...) in unsupported "
1271 "64-bit mode of process PID=%d\n",
1275 currpers &= ~2; /* map 2,1 to 0,1 */
1277 update_personality(tcp, currpers);
1279 # define IA64_PSR_IS ((long)1 << 34)
1281 if (upeek(tcp, PT_CR_IPSR, &psr) >= 0)
1282 ia32 = (psr & IA64_PSR_IS) != 0;
1284 if (upeek(tcp, PT_R1, &scno) < 0)
1287 if (upeek(tcp, PT_R15, &scno) < 0)
1290 #elif defined(AARCH64)
1291 switch (aarch64_io.iov_len) {
1292 case sizeof(aarch64_regs):
1293 /* We are in 64-bit mode */
1294 scno = aarch64_regs.regs[8];
1295 update_personality(tcp, 1);
1297 case sizeof(arm_regs):
1298 /* We are in 32-bit mode */
1299 scno = arm_regs.ARM_r7;
1300 update_personality(tcp, 0);
1304 if (arm_regs.ARM_ip != 0) {
1305 /* It is not a syscall entry */
1306 fprintf(stderr, "pid %d stray syscall exit\n", tcp->pid);
1307 tcp->flags |= TCB_INSYSCALL;
1310 /* Note: we support only 32-bit CPUs, not 26-bit */
1312 if (arm_regs.ARM_cpsr & 0x20) {
1314 scno = arm_regs.ARM_r7;
1318 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(arm_regs.ARM_pc - 4), NULL);
1322 /* EABI syscall convention? */
1323 if (scno == 0xef000000) {
1324 scno = arm_regs.ARM_r7; /* yes */
1326 if ((scno & 0x0ff00000) != 0x0f900000) {
1327 fprintf(stderr, "pid %d unknown syscall trap 0x%08lx\n",
1331 /* Fixup the syscall number */
1336 scno = shuffle_scno(scno);
1338 if (upeek(tcp, 4*PT_ORIG_D0, &scno) < 0)
1340 #elif defined(LINUX_MIPSN32)
1341 unsigned long long regs[38];
1343 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
1345 mips_a3 = regs[REG_A3];
1346 mips_r2 = regs[REG_V0];
1349 if (!SCNO_IN_RANGE(scno)) {
1350 if (mips_a3 == 0 || mips_a3 == -1) {
1352 fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
1357 if (upeek(tcp, REG_A3, &mips_a3) < 0)
1359 if (upeek(tcp, REG_V0, &scno) < 0)
1362 if (!SCNO_IN_RANGE(scno)) {
1363 if (mips_a3 == 0 || mips_a3 == -1) {
1365 fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
1369 #elif defined(ALPHA)
1370 if (upeek(tcp, REG_A3, &alpha_a3) < 0)
1372 if (upeek(tcp, REG_R0, &scno) < 0)
1376 * Do some sanity checks to figure out if it's
1377 * really a syscall entry
1379 if (!SCNO_IN_RANGE(scno)) {
1380 if (alpha_a3 == 0 || alpha_a3 == -1) {
1382 fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno);
1386 #elif defined(SPARC) || defined(SPARC64)
1387 /* Disassemble the syscall trap. */
1388 /* Retrieve the syscall trap instruction. */
1391 # if defined(SPARC64)
1392 trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.tpc, 0);
1395 trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.pc, 0);
1400 /* Disassemble the trap to see what personality to use. */
1403 /* Linux/SPARC syscall trap. */
1404 update_personality(tcp, 0);
1407 /* Linux/SPARC64 syscall trap. */
1408 update_personality(tcp, 2);
1411 /* SunOS syscall trap. (pers 1) */
1412 fprintf(stderr, "syscall: SunOS no support\n");
1415 /* Solaris 2.x syscall trap. (per 2) */
1416 update_personality(tcp, 1);
1419 /* NetBSD/FreeBSD syscall trap. */
1420 fprintf(stderr, "syscall: NetBSD/FreeBSD not supported\n");
1423 /* Solaris 2.x gettimeofday */
1424 update_personality(tcp, 1);
1427 # if defined(SPARC64)
1428 fprintf(stderr, "syscall: unknown syscall trap %08lx %016lx\n", trap, sparc_regs.tpc);
1430 fprintf(stderr, "syscall: unknown syscall trap %08lx %08lx\n", trap, sparc_regs.pc);
1435 /* Extract the system call number from the registers. */
1436 if (trap == 0x91d02027)
1439 scno = sparc_regs.u_regs[U_REG_G1];
1441 scno = sparc_regs.u_regs[U_REG_O0];
1442 memmove(&sparc_regs.u_regs[U_REG_O0], &sparc_regs.u_regs[U_REG_O1], 7*sizeof(sparc_regs.u_regs[0]));
1445 if (upeek(tcp, PT_GR20, &scno) < 0)
1449 * In the new syscall ABI, the system call number is in R3.
1451 if (upeek(tcp, 4*(REG_REG0+3), &scno) < 0)
1455 /* Odd as it may seem, a glibc bug has been known to cause
1456 glibc to issue bogus negative syscall numbers. So for
1457 our purposes, make strace print what it *should* have been */
1458 long correct_scno = (scno & 0xff);
1461 "Detected glibc bug: bogus system call"
1462 " number = %ld, correcting to %ld\n",
1465 scno = correct_scno;
1468 if (upeek(tcp, REG_SYSCALL, &scno) < 0)
1471 #elif defined(CRISV10) || defined(CRISV32)
1472 if (upeek(tcp, 4*PT_R9, &scno) < 0)
1476 scno = tile_regs.regs[10];
1480 # ifndef PT_FLAGS_COMPAT
1481 # define PT_FLAGS_COMPAT 0x10000 /* from Linux 3.8 on */
1483 if (tile_regs.flags & PT_FLAGS_COMPAT)
1488 update_personality(tcp, currpers);
1489 #elif defined(MICROBLAZE)
1490 if (upeek(tcp, 0, &scno) < 0)
1493 scno = or1k_regs.gpr[11];
1497 if (SCNO_IS_VALID(tcp->scno)) {
1498 tcp->s_ent = &sysent[scno];
1499 tcp->qual_flg = qual_flags[scno];
1501 static const struct_sysent unknown = {
1504 .sys_func = printargs,
1505 .sys_name = "unknown", /* not used */
1507 tcp->s_ent = &unknown;
1508 tcp->qual_flg = UNDEFINED_SCNO | QUAL_RAW | DEFAULT_QUAL_FLAGS;
1513 /* Called at each syscall entry.
1515 * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently.
1516 * 1: ok, continue in trace_syscall_entering().
1517 * other: error, trace_syscall_entering() should print error indicator
1518 * ("????" etc) and bail out.
1521 syscall_fixup_on_sysenter(struct tcb *tcp)
1523 /* A common case of "not a syscall entry" is post-execve SIGTRAP */
1525 if (i386_regs.eax != -ENOSYS) {
1527 fprintf(stderr, "not a syscall entry (eax = %ld)\n", i386_regs.eax);
1530 #elif defined(X86_64) || defined(X32)
1533 if (x86_io.iov_len == sizeof(i386_regs)) {
1534 /* Sign extend from 32 bits */
1535 rax = (int32_t)i386_regs.eax;
1537 /* Note: in X32 build, this truncates 64 to 32 bits */
1538 rax = x86_64_regs.rax;
1540 if (rax != -ENOSYS) {
1542 fprintf(stderr, "not a syscall entry (rax = %ld)\n", rax);
1546 #elif defined(S390) || defined(S390X)
1547 /* TODO: we already fetched PT_GPR2 in get_scno
1548 * and stored it in syscall_mode, reuse it here
1549 * instead of re-fetching?
1551 if (upeek(tcp, PT_GPR2, &gpr2) < 0)
1553 if (syscall_mode != -ENOSYS)
1554 syscall_mode = tcp->scno;
1555 if (gpr2 != syscall_mode) {
1557 fprintf(stderr, "not a syscall entry (gpr2 = %ld)\n", gpr2);
1561 /* TODO? Eliminate upeek's in arches below like we did in x86 */
1562 if (upeek(tcp, 4*PT_D0, &m68k_d0) < 0)
1564 if (m68k_d0 != -ENOSYS) {
1566 fprintf(stderr, "not a syscall entry (d0 = %ld)\n", m68k_d0);
1570 if (upeek(tcp, PT_R10, &ia64_r10) < 0)
1572 if (upeek(tcp, PT_R8, &ia64_r8) < 0)
1574 if (ia32 && ia64_r8 != -ENOSYS) {
1576 fprintf(stderr, "not a syscall entry (r8 = %ld)\n", ia64_r8);
1579 #elif defined(CRISV10) || defined(CRISV32)
1580 if (upeek(tcp, 4*PT_R10, &cris_r10) < 0)
1582 if (cris_r10 != -ENOSYS) {
1584 fprintf(stderr, "not a syscall entry (r10 = %ld)\n", cris_r10);
1587 #elif defined(MICROBLAZE)
1588 if (upeek(tcp, 3 * 4, µblaze_r3) < 0)
1590 if (microblaze_r3 != -ENOSYS) {
1592 fprintf(stderr, "not a syscall entry (r3 = %ld)\n", microblaze_r3);
1600 internal_fork(struct tcb *tcp)
1602 #if defined S390 || defined S390X || defined CRISV10 || defined CRISV32
1603 # define ARG_FLAGS 1
1605 # define ARG_FLAGS 0
1607 #ifndef CLONE_UNTRACED
1608 # define CLONE_UNTRACED 0x00800000
1610 if ((ptrace_setoptions
1611 & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
1612 == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
1618 if (entering(tcp)) {
1620 * We won't see the new child if clone is called with
1621 * CLONE_UNTRACED, so we keep the same logic with that option
1622 * and don't trace it.
1624 if ((tcp->s_ent->sys_func == sys_clone)
1625 && (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED)
1630 if (tcp->flags & TCB_BPTSET)
1635 #if defined(TCB_WAITEXECVE)
1637 internal_exec(struct tcb *tcp)
1639 /* Maybe we have post-execve SIGTRAP suppressed? */
1640 if (ptrace_setoptions & PTRACE_O_TRACEEXEC)
1641 return; /* yes, no need to do anything */
1643 if (exiting(tcp) && syserror(tcp))
1644 /* Error in execve, no post-execve SIGTRAP expected */
1645 tcp->flags &= ~TCB_WAITEXECVE;
1647 tcp->flags |= TCB_WAITEXECVE;
1652 syscall_fixup_for_fork_exec(struct tcb *tcp)
1655 * We must always trace a few critical system calls in order to
1656 * correctly support following forks in the presence of tracing
1661 func = tcp->s_ent->sys_func;
1663 if ( sys_fork == func
1664 || sys_vfork == func
1665 || sys_clone == func
1671 #if defined(TCB_WAITEXECVE)
1672 if ( sys_execve == func
1673 # if defined(SPARC) || defined(SPARC64)
1674 || sys_execv == func
1683 /* Return -1 on error or 1 on success (never 0!) */
1685 get_syscall_args(struct tcb *tcp)
1689 nargs = tcp->s_ent->nargs;
1691 #if defined(S390) || defined(S390X)
1692 for (i = 0; i < nargs; ++i)
1693 if (upeek(tcp, i==0 ? PT_ORIGGPR2 : PT_GPR2 + i*sizeof(long), &tcp->u_arg[i]) < 0)
1695 #elif defined(ALPHA)
1696 for (i = 0; i < nargs; ++i)
1697 if (upeek(tcp, REG_A0+i, &tcp->u_arg[i]) < 0)
1701 unsigned long *out0, cfm, sof, sol;
1703 /* be backwards compatible with kernel < 2.4.4... */
1705 # define PT_RBS_END PT_AR_BSP
1708 if (upeek(tcp, PT_RBS_END, &rbs_end) < 0)
1710 if (upeek(tcp, PT_CFM, (long *) &cfm) < 0)
1713 sof = (cfm >> 0) & 0x7f;
1714 sol = (cfm >> 7) & 0x7f;
1715 out0 = ia64_rse_skip_regs((unsigned long *) rbs_end, -sof + sol);
1717 for (i = 0; i < nargs; ++i) {
1718 if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i),
1719 sizeof(long), (char *) &tcp->u_arg[i]) < 0)
1723 static const int argreg[MAX_ARGS] = { PT_R11 /* EBX = out0 */,
1724 PT_R9 /* ECX = out1 */,
1725 PT_R10 /* EDX = out2 */,
1726 PT_R14 /* ESI = out3 */,
1727 PT_R15 /* EDI = out4 */,
1728 PT_R13 /* EBP = out5 */};
1730 for (i = 0; i < nargs; ++i) {
1731 if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
1733 /* truncate away IVE sign-extension */
1734 tcp->u_arg[i] &= 0xffffffff;
1737 #elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
1738 /* N32 and N64 both use up to six registers. */
1739 unsigned long long regs[38];
1741 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
1744 for (i = 0; i < nargs; ++i) {
1745 tcp->u_arg[i] = regs[REG_A0 + i];
1746 # if defined(LINUX_MIPSN32)
1747 tcp->ext_arg[i] = regs[REG_A0 + i];
1754 if (upeek(tcp, REG_SP, &sp) < 0)
1756 for (i = 0; i < 4; ++i)
1757 if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
1759 umoven(tcp, sp + 16, (nargs - 4) * sizeof(tcp->u_arg[0]),
1760 (char *)(tcp->u_arg + 4));
1762 for (i = 0; i < nargs; ++i)
1763 if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
1766 #elif defined(POWERPC)
1768 # define PT_ORIG_R3 34
1770 for (i = 0; i < nargs; ++i) {
1771 if (upeek(tcp, (i==0) ?
1772 (sizeof(unsigned long) * PT_ORIG_R3) :
1773 ((i+PT_R3) * sizeof(unsigned long)),
1774 &tcp->u_arg[i]) < 0)
1777 #elif defined(SPARC) || defined(SPARC64)
1778 for (i = 0; i < nargs; ++i)
1779 tcp->u_arg[i] = sparc_regs.u_regs[U_REG_O0 + i];
1781 for (i = 0; i < nargs; ++i)
1782 if (upeek(tcp, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
1784 #elif defined(ARM) || defined(AARCH64)
1785 # if defined(AARCH64)
1786 if (tcp->currpers == 1)
1787 for (i = 0; i < nargs; ++i)
1788 tcp->u_arg[i] = aarch64_regs.regs[i];
1791 for (i = 0; i < nargs; ++i)
1792 tcp->u_arg[i] = arm_regs.uregs[i];
1793 #elif defined(AVR32)
1796 tcp->u_arg[0] = avr32_regs.r12;
1797 tcp->u_arg[1] = avr32_regs.r11;
1798 tcp->u_arg[2] = avr32_regs.r10;
1799 tcp->u_arg[3] = avr32_regs.r9;
1800 tcp->u_arg[4] = avr32_regs.r5;
1801 tcp->u_arg[5] = avr32_regs.r3;
1803 static const int argreg[MAX_ARGS] = { PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5 };
1805 for (i = 0; i < nargs; ++i)
1806 if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
1809 static const int syscall_regs[MAX_ARGS] = {
1810 4 * (REG_REG0+4), 4 * (REG_REG0+5), 4 * (REG_REG0+6),
1811 4 * (REG_REG0+7), 4 * (REG_REG0 ), 4 * (REG_REG0+1)
1814 for (i = 0; i < nargs; ++i)
1815 if (upeek(tcp, syscall_regs[i], &tcp->u_arg[i]) < 0)
1819 /* Registers used by SH5 Linux system calls for parameters */
1820 static const int syscall_regs[MAX_ARGS] = { 2, 3, 4, 5, 6, 7 };
1822 for (i = 0; i < nargs; ++i)
1823 if (upeek(tcp, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0)
1828 tcp->u_arg[0] = i386_regs.ebx;
1829 tcp->u_arg[1] = i386_regs.ecx;
1830 tcp->u_arg[2] = i386_regs.edx;
1831 tcp->u_arg[3] = i386_regs.esi;
1832 tcp->u_arg[4] = i386_regs.edi;
1833 tcp->u_arg[5] = i386_regs.ebp;
1834 #elif defined(X86_64) || defined(X32)
1837 if (x86_io.iov_len != sizeof(i386_regs)) {
1838 /* x86-64 or x32 ABI */
1839 tcp->u_arg[0] = x86_64_regs.rdi;
1840 tcp->u_arg[1] = x86_64_regs.rsi;
1841 tcp->u_arg[2] = x86_64_regs.rdx;
1842 tcp->u_arg[3] = x86_64_regs.r10;
1843 tcp->u_arg[4] = x86_64_regs.r8;
1844 tcp->u_arg[5] = x86_64_regs.r9;
1846 tcp->ext_arg[0] = x86_64_regs.rdi;
1847 tcp->ext_arg[1] = x86_64_regs.rsi;
1848 tcp->ext_arg[2] = x86_64_regs.rdx;
1849 tcp->ext_arg[3] = x86_64_regs.r10;
1850 tcp->ext_arg[4] = x86_64_regs.r8;
1851 tcp->ext_arg[5] = x86_64_regs.r9;
1855 /* Zero-extend from 32 bits */
1856 /* Use widen_to_long(tcp->u_arg[N]) in syscall handlers
1857 * if you need to use *sign-extended* parameter.
1859 tcp->u_arg[0] = (long)(uint32_t)i386_regs.ebx;
1860 tcp->u_arg[1] = (long)(uint32_t)i386_regs.ecx;
1861 tcp->u_arg[2] = (long)(uint32_t)i386_regs.edx;
1862 tcp->u_arg[3] = (long)(uint32_t)i386_regs.esi;
1863 tcp->u_arg[4] = (long)(uint32_t)i386_regs.edi;
1864 tcp->u_arg[5] = (long)(uint32_t)i386_regs.ebp;
1866 #elif defined(MICROBLAZE)
1867 for (i = 0; i < nargs; ++i)
1868 if (upeek(tcp, (5 + i) * 4, &tcp->u_arg[i]) < 0)
1870 #elif defined(CRISV10) || defined(CRISV32)
1871 static const int crisregs[MAX_ARGS] = {
1872 4*PT_ORIG_R10, 4*PT_R11, 4*PT_R12,
1873 4*PT_R13 , 4*PT_MOF, 4*PT_SRP
1876 for (i = 0; i < nargs; ++i)
1877 if (upeek(tcp, crisregs[i], &tcp->u_arg[i]) < 0)
1880 for (i = 0; i < nargs; ++i)
1881 tcp->u_arg[i] = tile_regs.regs[i];
1883 for (i = 0; i < nargs; ++i)
1884 if (upeek(tcp, (i < 5 ? i : i + 2)*4, &tcp->u_arg[i]) < 0)
1888 for (i = 0; i < 6; ++i)
1889 tcp->u_arg[i] = or1k_regs.gpr[3 + i];
1890 #else /* Other architecture (32bits specific) */
1891 for (i = 0; i < nargs; ++i)
1892 if (upeek(tcp, i*4, &tcp->u_arg[i]) < 0)
1899 trace_syscall_entering(struct tcb *tcp)
1903 #if defined TCB_WAITEXECVE
1904 if (tcp->flags & TCB_WAITEXECVE) {
1905 /* This is the post-execve SIGTRAP. */
1906 tcp->flags &= ~TCB_WAITEXECVE;
1911 scno_good = res = (get_regs_error ? -1 : get_scno(tcp));
1915 res = syscall_fixup_on_sysenter(tcp);
1919 res = get_syscall_args(tcp);
1925 tprints("????" /* anti-trigraph gap */ "(");
1926 else if (tcp->qual_flg & UNDEFINED_SCNO)
1927 tprintf("%s(", undefined_scno_name(tcp));
1929 tprintf("%s(", tcp->s_ent->sys_name);
1931 * " <unavailable>" will be added later by the code which
1932 * detects ptrace errors.
1937 #if defined(SYS_socket_subcall) || defined(SYS_ipc_subcall)
1939 # ifdef SYS_socket_subcall
1940 if (tcp->s_ent->sys_func == sys_socketcall) {
1941 decode_socket_subcall(tcp);
1945 # ifdef SYS_ipc_subcall
1946 if (tcp->s_ent->sys_func == sys_ipc) {
1947 decode_ipc_subcall(tcp);
1955 if (need_fork_exec_workarounds)
1956 syscall_fixup_for_fork_exec(tcp);
1958 if (!(tcp->qual_flg & QUAL_TRACE)
1959 || (tracing_paths && !pathtrace_match(tcp))
1961 tcp->flags |= TCB_INSYSCALL | TCB_FILTERED;
1965 tcp->flags &= ~TCB_FILTERED;
1967 if (cflag == CFLAG_ONLY_STATS) {
1973 if (tcp->qual_flg & UNDEFINED_SCNO)
1974 tprintf("%s(", undefined_scno_name(tcp));
1976 tprintf("%s(", tcp->s_ent->sys_name);
1977 if ((tcp->qual_flg & QUAL_RAW) && tcp->s_ent->sys_func != sys_exit)
1978 res = printargs(tcp);
1980 res = tcp->s_ent->sys_func(tcp);
1984 tcp->flags |= TCB_INSYSCALL;
1985 /* Measure the entrance time as late as possible to avoid errors. */
1987 gettimeofday(&tcp->etime, NULL);
1992 * 1: ok, continue in trace_syscall_exiting().
1993 * -1: error, trace_syscall_exiting() should print error indicator
1994 * ("????" etc) and bail out.
1997 get_syscall_result(struct tcb *tcp)
1999 #if defined(S390) || defined(S390X)
2000 if (upeek(tcp, PT_GPR2, &gpr2) < 0)
2002 #elif defined(POWERPC)
2003 # define SO_MASK 0x10000000
2006 if (upeek(tcp, sizeof(unsigned long)*PT_CCR, &flags) < 0)
2008 if (upeek(tcp, sizeof(unsigned long)*PT_R3, &ppc_result) < 0)
2010 if (flags & SO_MASK)
2011 ppc_result = -ppc_result;
2013 #elif defined(AVR32)
2014 /* already done by get_regs */
2016 if (upeek(tcp, PT_R0, &bfin_r0) < 0)
2019 /* already done by get_regs */
2020 #elif defined(X86_64) || defined(X32)
2021 /* already done by get_regs */
2023 # define IA64_PSR_IS ((long)1 << 34)
2025 if (upeek(tcp, PT_CR_IPSR, &psr) >= 0)
2026 ia32 = (psr & IA64_PSR_IS) != 0;
2027 if (upeek(tcp, PT_R8, &ia64_r8) < 0)
2029 if (upeek(tcp, PT_R10, &ia64_r10) < 0)
2032 /* already done by get_regs */
2033 #elif defined(AARCH64)
2034 /* register reading already done by get_regs */
2036 /* Used to do this, but we did it on syscall entry already: */
2037 /* We are in 64-bit mode (personality 1) if register struct is aarch64_regs,
2038 * else it's personality 0.
2040 /*update_personality(tcp, aarch64_io.iov_len == sizeof(aarch64_regs));*/
2042 if (upeek(tcp, 4*PT_D0, &m68k_d0) < 0)
2044 #elif defined(LINUX_MIPSN32)
2045 unsigned long long regs[38];
2047 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
2049 mips_a3 = regs[REG_A3];
2050 mips_r2 = regs[REG_V0];
2052 if (upeek(tcp, REG_A3, &mips_a3) < 0)
2054 if (upeek(tcp, REG_V0, &mips_r2) < 0)
2056 #elif defined(ALPHA)
2057 if (upeek(tcp, REG_A3, &alpha_a3) < 0)
2059 if (upeek(tcp, REG_R0, &alpha_r0) < 0)
2061 #elif defined(SPARC) || defined(SPARC64)
2062 /* already done by get_regs */
2064 if (upeek(tcp, PT_GR28, &hppa_r28) < 0)
2067 /* new syscall ABI returns result in R0 */
2068 if (upeek(tcp, 4*REG_REG0, (long *)&sh_r0) < 0)
2071 /* ABI defines result returned in r9 */
2072 if (upeek(tcp, REG_GENERAL(9), (long *)&sh64_r9) < 0)
2074 #elif defined(CRISV10) || defined(CRISV32)
2075 if (upeek(tcp, 4*PT_R10, &cris_r10) < 0)
2078 /* already done by get_regs */
2079 #elif defined(MICROBLAZE)
2080 if (upeek(tcp, 3 * 4, µblaze_r3) < 0)
2083 /* already done by get_regs */
2088 /* Called at each syscall exit */
2090 syscall_fixup_on_sysexit(struct tcb *tcp)
2092 #if defined(S390) || defined(S390X)
2093 if (syscall_mode != -ENOSYS)
2094 syscall_mode = tcp->scno;
2095 if ((tcp->flags & TCB_WAITEXECVE)
2096 && (gpr2 == -ENOSYS || gpr2 == tcp->scno)) {
2098 * Return from execve.
2099 * Fake a return value of zero. We leave the TCB_WAITEXECVE
2100 * flag set for the post-execve SIGTRAP to see and reset.
2108 * Check the syscall return value register value for whether it is
2109 * a negated errno code indicating an error, or a success return value.
2112 is_negated_errno(unsigned long int val)
2114 unsigned long int max = -(long int) nerrnos;
2115 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
2116 if (current_wordsize < sizeof(val)) {
2117 val = (unsigned int) val;
2118 max = (unsigned int) max;
2126 is_negated_errno_x32(unsigned long long val)
2128 unsigned long long max = -(long long) nerrnos;
2130 * current_wordsize is 4 even in personality 0 (native X32)
2131 * but truncation _must not_ be done in it.
2132 * can't check current_wordsize here!
2134 if (current_personality != 0) {
2135 val = (uint32_t) val;
2136 max = (uint32_t) max;
2143 * 1: ok, continue in trace_syscall_exiting().
2144 * -1: error, trace_syscall_exiting() should print error indicator
2145 * ("????" etc) and bail out.
2148 get_error(struct tcb *tcp)
2151 int check_errno = 1;
2152 if (tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS) {
2155 #if defined(S390) || defined(S390X)
2156 if (check_errno && is_negated_errno(gpr2)) {
2164 if (check_errno && is_negated_errno(i386_regs.eax)) {
2166 u_error = -i386_regs.eax;
2169 tcp->u_rval = i386_regs.eax;
2171 #elif defined(X86_64)
2173 if (x86_io.iov_len == sizeof(i386_regs)) {
2174 /* Sign extend from 32 bits */
2175 rax = (int32_t)i386_regs.eax;
2177 rax = x86_64_regs.rax;
2179 if (check_errno && is_negated_errno(rax)) {
2187 /* In X32, return value is 64-bit (llseek uses one).
2188 * Using merely "long rax" would not work.
2191 if (x86_io.iov_len == sizeof(i386_regs)) {
2192 /* Sign extend from 32 bits */
2193 rax = (int32_t)i386_regs.eax;
2195 rax = x86_64_regs.rax;
2197 /* Careful: is_negated_errno() works only on longs */
2198 if (check_errno && is_negated_errno_x32(rax)) {
2203 tcp->u_rval = rax; /* truncating */
2211 if (check_errno && is_negated_errno(err)) {
2219 if (check_errno && ia64_r10) {
2223 tcp->u_rval = ia64_r8;
2227 if (check_errno && mips_a3) {
2231 tcp->u_rval = mips_r2;
2232 # if defined(LINUX_MIPSN32)
2233 tcp->u_lrval = mips_r2;
2236 #elif defined(POWERPC)
2237 if (check_errno && is_negated_errno(ppc_result)) {
2239 u_error = -ppc_result;
2242 tcp->u_rval = ppc_result;
2245 if (check_errno && is_negated_errno(m68k_d0)) {
2250 tcp->u_rval = m68k_d0;
2252 #elif defined(ARM) || defined(AARCH64)
2253 # if defined(AARCH64)
2254 if (tcp->currpers == 1) {
2255 if (check_errno && is_negated_errno(aarch64_regs.regs[0])) {
2257 u_error = -aarch64_regs.regs[0];
2260 tcp->u_rval = aarch64_regs.regs[0];
2266 if (check_errno && is_negated_errno(arm_regs.ARM_r0)) {
2268 u_error = -arm_regs.ARM_r0;
2271 tcp->u_rval = arm_regs.ARM_r0;
2274 #elif defined(AVR32)
2275 if (check_errno && avr32_regs.r12 && (unsigned) -avr32_regs.r12 < nerrnos) {
2277 u_error = -avr32_regs.r12;
2280 tcp->u_rval = avr32_regs.r12;
2283 if (check_errno && is_negated_errno(bfin_r0)) {
2287 tcp->u_rval = bfin_r0;
2289 #elif defined(ALPHA)
2290 if (check_errno && alpha_a3) {
2295 tcp->u_rval = alpha_r0;
2297 #elif defined(SPARC)
2298 if (check_errno && sparc_regs.psr & PSR_C) {
2300 u_error = sparc_regs.u_regs[U_REG_O0];
2303 tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
2305 #elif defined(SPARC64)
2306 if (check_errno && sparc_regs.tstate & 0x1100000000UL) {
2308 u_error = sparc_regs.u_regs[U_REG_O0];
2311 tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
2314 if (check_errno && is_negated_errno(hppa_r28)) {
2316 u_error = -hppa_r28;
2319 tcp->u_rval = hppa_r28;
2322 if (check_errno && is_negated_errno(sh_r0)) {
2327 tcp->u_rval = sh_r0;
2330 if (check_errno && is_negated_errno(sh64_r9)) {
2335 tcp->u_rval = sh64_r9;
2337 #elif defined(CRISV10) || defined(CRISV32)
2338 if (check_errno && cris_r10 && (unsigned) -cris_r10 < nerrnos) {
2340 u_error = -cris_r10;
2343 tcp->u_rval = cris_r10;
2347 * The standard tile calling convention returns the value (or negative
2348 * errno) in r0, and zero (or positive errno) in r1.
2349 * Until at least kernel 3.8, however, the r1 value is not reflected
2350 * in ptregs at this point, so we use r0 here.
2352 if (check_errno && is_negated_errno(tile_regs.regs[0])) {
2354 u_error = -tile_regs.regs[0];
2356 tcp->u_rval = tile_regs.regs[0];
2358 #elif defined(MICROBLAZE)
2359 if (check_errno && is_negated_errno(microblaze_r3)) {
2361 u_error = -microblaze_r3;
2364 tcp->u_rval = microblaze_r3;
2367 if (check_errno && is_negated_errno(or1k_regs.gpr[11])) {
2369 u_error = -or1k_regs.gpr[11];
2372 tcp->u_rval = or1k_regs.gpr[11];
2375 tcp->u_error = u_error;
2379 dumpio(struct tcb *tcp)
2385 if ((unsigned long) tcp->u_arg[0] >= num_quals)
2387 func = tcp->s_ent->sys_func;
2388 if (func == printargs)
2390 if (qual_flags[tcp->u_arg[0]] & QUAL_READ) {
2391 if (func == sys_read ||
2392 func == sys_pread ||
2394 func == sys_recvfrom)
2395 dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
2396 else if (func == sys_readv)
2397 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2400 if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) {
2401 if (func == sys_write ||
2402 func == sys_pwrite ||
2405 dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2406 else if (func == sys_writev)
2407 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2413 trace_syscall_exiting(struct tcb *tcp)
2420 /* Measure the exit time as early as possible to avoid errors. */
2422 gettimeofday(&tv, NULL);
2424 #if SUPPORTED_PERSONALITIES > 1
2425 update_personality(tcp, tcp->currpers);
2427 res = (get_regs_error ? -1 : get_syscall_result(tcp));
2429 syscall_fixup_on_sysexit(tcp); /* never fails */
2430 get_error(tcp); /* never fails */
2431 if (need_fork_exec_workarounds)
2432 syscall_fixup_for_fork_exec(tcp);
2438 struct timeval t = tv;
2439 count_syscall(tcp, &t);
2440 if (cflag == CFLAG_ONLY_STATS) {
2445 /* If not in -ff mode, and printing_tcp != tcp,
2446 * then the log currently does not end with output
2447 * of _our syscall entry_, but with something else.
2448 * We need to say which syscall's return is this.
2450 * Forced reprinting via TCB_REPRINT is used only by
2451 * "strace -ff -oLOG test/threaded_execve" corner case.
2452 * It's the only case when -ff mode needs reprinting.
2454 if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) {
2455 tcp->flags &= ~TCB_REPRINT;
2457 if (tcp->qual_flg & UNDEFINED_SCNO)
2458 tprintf("<... %s resumed> ", undefined_scno_name(tcp));
2460 tprintf("<... %s resumed> ", tcp->s_ent->sys_name);
2465 /* There was error in one of prior ptrace ops */
2468 tprints("= ? <unavailable>\n");
2470 tcp->flags &= ~TCB_INSYSCALL;
2475 if (tcp->qual_flg & QUAL_RAW) {
2476 /* sys_res = printargs(tcp); - but it's nop on sysexit */
2478 /* FIXME: not_failing_only (IOW, option -z) is broken:
2479 * failure of syscall is known only after syscall return.
2480 * Thus we end up with something like this on, say, ENOENT:
2481 * open("doesnt_exist", O_RDONLY <unfinished ...>
2482 * {next syscall decode}
2483 * whereas the intended result is that open(...) line
2484 * is not shown at all.
2486 if (not_failing_only && tcp->u_error)
2487 goto ret; /* ignore failed syscalls */
2488 sys_res = tcp->s_ent->sys_func(tcp);
2493 u_error = tcp->u_error;
2494 if (tcp->qual_flg & QUAL_RAW) {
2496 tprintf("= -1 (errno %ld)", u_error);
2498 tprintf("= %#lx", tcp->u_rval);
2500 else if (!(sys_res & RVAL_NONE) && u_error) {
2502 /* Blocked signals do not interrupt any syscalls.
2503 * In this case syscalls don't return ERESTARTfoo codes.
2505 * Deadly signals set to SIG_DFL interrupt syscalls
2506 * and kill the process regardless of which of the codes below
2507 * is returned by the interrupted syscall.
2508 * In some cases, kernel forces a kernel-generated deadly
2509 * signal to be unblocked and set to SIG_DFL (and thus cause
2510 * death) if it is blocked or SIG_IGNed: for example, SIGSEGV
2511 * or SIGILL. (The alternative is to leave process spinning
2512 * forever on the faulty instruction - not useful).
2514 * SIG_IGNed signals and non-deadly signals set to SIG_DFL
2515 * (for example, SIGCHLD, SIGWINCH) interrupt syscalls,
2516 * but kernel will always restart them.
2519 /* Most common type of signal-interrupted syscall exit code.
2520 * The system call will be restarted with the same arguments
2521 * if SA_RESTART is set; otherwise, it will fail with EINTR.
2523 tprints("= ? ERESTARTSYS (To be restarted if SA_RESTART is set)");
2525 case ERESTARTNOINTR:
2526 /* Rare. For example, fork() returns this if interrupted.
2527 * SA_RESTART is ignored (assumed set): the restart is unconditional.
2529 tprints("= ? ERESTARTNOINTR (To be restarted)");
2531 case ERESTARTNOHAND:
2532 /* pause(), rt_sigsuspend() etc use this code.
2533 * SA_RESTART is ignored (assumed not set):
2534 * syscall won't restart (will return EINTR instead)
2535 * even after signal with SA_RESTART set. However,
2536 * after SIG_IGN or SIG_DFL signal it will restart
2537 * (thus the name "restart only if has no handler").
2539 tprints("= ? ERESTARTNOHAND (Interrupted by signal)");
2541 case ERESTART_RESTARTBLOCK:
2542 /* Syscalls like nanosleep(), poll() which can't be
2543 * restarted with their original arguments use this
2544 * code. Kernel will execute restart_syscall() instead,
2545 * which changes arguments before restarting syscall.
2546 * SA_RESTART is ignored (assumed not set) similarly
2547 * to ERESTARTNOHAND. (Kernel can't honor SA_RESTART
2548 * since restart data is saved in "restart block"
2549 * in task struct, and if signal handler uses a syscall
2550 * which in turn saves another such restart block,
2551 * old data is lost and restart becomes impossible)
2553 tprints("= ? ERESTART_RESTARTBLOCK (Interrupted by signal)");
2557 tprintf("= -1 E??? (errno %ld)", u_error);
2558 else if (u_error < nerrnos)
2559 tprintf("= -1 %s (%s)", errnoent[u_error],
2562 tprintf("= -1 ERRNO_%ld (%s)", u_error,
2566 if ((sys_res & RVAL_STR) && tcp->auxstr)
2567 tprintf(" (%s)", tcp->auxstr);
2570 if (sys_res & RVAL_NONE)
2573 switch (sys_res & RVAL_MASK) {
2575 tprintf("= %#lx", tcp->u_rval);
2578 tprintf("= %#lo", tcp->u_rval);
2581 tprintf("= %lu", tcp->u_rval);
2584 tprintf("= %ld", tcp->u_rval);
2586 #if defined(LINUX_MIPSN32) || defined(X32)
2589 tprintf("= %#llx", tcp->u_lrval);
2592 tprintf("= %#llo", tcp->u_lrval);
2595 case RVAL_LUDECIMAL:
2596 tprintf("= %llu", tcp->u_lrval);
2600 tprintf("= %lld", tcp->u_lrval);
2606 "invalid rval format\n");
2610 if ((sys_res & RVAL_STR) && tcp->auxstr)
2611 tprintf(" (%s)", tcp->auxstr);
2614 tv_sub(&tv, &tv, &tcp->etime);
2615 tprintf(" <%ld.%06ld>",
2616 (long) tv.tv_sec, (long) tv.tv_usec);
2623 tcp->flags &= ~TCB_INSYSCALL;
2628 trace_syscall(struct tcb *tcp)
2630 return exiting(tcp) ?
2631 trace_syscall_exiting(tcp) : trace_syscall_entering(tcp);