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"
165 enum { nsyscalls0 = ARRAY_SIZE(sysent0) };
166 enum { nerrnos0 = ARRAY_SIZE(errnoent0) };
167 enum { nsignals0 = ARRAY_SIZE(signalent0) };
168 enum { nioctlents0 = ARRAY_SIZE(ioctlent0) };
170 #if SUPPORTED_PERSONALITIES > 1
171 static const char *const errnoent1[] = {
172 # include "errnoent1.h"
174 static const char *const signalent1[] = {
175 # include "signalent1.h"
177 static const struct_ioctlent ioctlent1[] = {
178 # include "ioctlent1.h"
180 enum { nsyscalls1 = ARRAY_SIZE(sysent1) };
181 enum { nerrnos1 = ARRAY_SIZE(errnoent1) };
182 enum { nsignals1 = ARRAY_SIZE(signalent1) };
183 enum { nioctlents1 = ARRAY_SIZE(ioctlent1) };
186 #if SUPPORTED_PERSONALITIES > 2
187 static const char *const errnoent2[] = {
188 # include "errnoent2.h"
190 static const char *const signalent2[] = {
191 # include "signalent2.h"
193 static const struct_ioctlent ioctlent2[] = {
194 # include "ioctlent2.h"
196 enum { nsyscalls2 = ARRAY_SIZE(sysent2) };
197 enum { nerrnos2 = ARRAY_SIZE(errnoent2) };
198 enum { nsignals2 = ARRAY_SIZE(signalent2) };
199 enum { nioctlents2 = ARRAY_SIZE(ioctlent2) };
202 #if SUPPORTED_PERSONALITIES > 1
203 const struct_sysent *sysent = sysent0;
204 const char *const *errnoent = errnoent0;
205 const char *const *signalent = signalent0;
206 const struct_ioctlent *ioctlent = ioctlent0;
208 unsigned nsyscalls = nsyscalls0;
209 unsigned nerrnos = nerrnos0;
210 unsigned nsignals = nsignals0;
211 unsigned nioctlents = nioctlents0;
214 qualbits_t *qual_vec[SUPPORTED_PERSONALITIES];
216 static const unsigned nsyscall_vec[SUPPORTED_PERSONALITIES] = {
218 #if SUPPORTED_PERSONALITIES > 1
221 #if SUPPORTED_PERSONALITIES > 2
225 static const struct_sysent *const sysent_vec[SUPPORTED_PERSONALITIES] = {
227 #if SUPPORTED_PERSONALITIES > 1
230 #if SUPPORTED_PERSONALITIES > 2
236 MAX_NSYSCALLS1 = (nsyscalls0
237 #if SUPPORTED_PERSONALITIES > 1
238 > nsyscalls1 ? nsyscalls0 : nsyscalls1
241 MAX_NSYSCALLS2 = (MAX_NSYSCALLS1
242 #if SUPPORTED_PERSONALITIES > 2
243 > nsyscalls2 ? MAX_NSYSCALLS1 : nsyscalls2
246 MAX_NSYSCALLS = MAX_NSYSCALLS2,
247 /* We are ready for arches with up to 255 signals,
248 * even though the largest known signo is on MIPS and it is 128.
249 * The number of existing syscalls on all arches is
250 * larger that 255 anyway, so it is just a pedantic matter.
252 MIN_QUALS = MAX_NSYSCALLS > 255 ? MAX_NSYSCALLS : 255
255 #if SUPPORTED_PERSONALITIES > 1
256 unsigned current_personality;
258 # ifndef current_wordsize
259 unsigned current_wordsize;
260 static const int personality_wordsize[SUPPORTED_PERSONALITIES] = {
261 PERSONALITY0_WORDSIZE,
262 PERSONALITY1_WORDSIZE,
263 # if SUPPORTED_PERSONALITIES > 2
264 PERSONALITY2_WORDSIZE,
270 set_personality(int personality)
272 nsyscalls = nsyscall_vec[personality];
273 sysent = sysent_vec[personality];
275 switch (personality) {
277 errnoent = errnoent0;
279 ioctlent = ioctlent0;
280 nioctlents = nioctlents0;
281 signalent = signalent0;
282 nsignals = nsignals0;
286 errnoent = errnoent1;
288 ioctlent = ioctlent1;
289 nioctlents = nioctlents1;
290 signalent = signalent1;
291 nsignals = nsignals1;
294 # if SUPPORTED_PERSONALITIES > 2
296 errnoent = errnoent2;
298 ioctlent = ioctlent2;
299 nioctlents = nioctlents2;
300 signalent = signalent2;
301 nsignals = nsignals2;
306 current_personality = personality;
307 # ifndef current_wordsize
308 current_wordsize = personality_wordsize[personality];
313 update_personality(struct tcb *tcp, int personality)
315 if (personality == current_personality)
317 set_personality(personality);
319 if (personality == tcp->currpers)
321 tcp->currpers = personality;
323 # if defined(POWERPC64)
325 static const char *const names[] = {"64 bit", "32 bit"};
326 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
327 tcp->pid, names[personality]);
329 # elif defined(X86_64)
331 static const char *const names[] = {"64 bit", "32 bit", "x32"};
332 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
333 tcp->pid, names[personality]);
337 static const char *const names[] = {"x32", "32 bit"};
338 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
339 tcp->pid, names[personality]);
341 # elif defined(AARCH64)
343 static const char *const names[] = {"32-bit", "AArch64"};
344 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
345 tcp->pid, names[personality]);
349 static const char *const names[] = {"64-bit", "32-bit"};
350 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
351 tcp->pid, names[personality]);
357 static int qual_syscall(), qual_signal(), qual_desc();
359 static const struct qual_options {
361 const char *option_name;
362 int (*qualify)(const char *, int, int);
363 const char *argument_name;
365 { QUAL_TRACE, "trace", qual_syscall, "system call" },
366 { QUAL_TRACE, "t", qual_syscall, "system call" },
367 { QUAL_ABBREV, "abbrev", qual_syscall, "system call" },
368 { QUAL_ABBREV, "a", qual_syscall, "system call" },
369 { QUAL_VERBOSE, "verbose", qual_syscall, "system call" },
370 { QUAL_VERBOSE, "v", qual_syscall, "system call" },
371 { QUAL_RAW, "raw", qual_syscall, "system call" },
372 { QUAL_RAW, "x", qual_syscall, "system call" },
373 { QUAL_SIGNAL, "signal", qual_signal, "signal" },
374 { QUAL_SIGNAL, "signals", qual_signal, "signal" },
375 { QUAL_SIGNAL, "s", qual_signal, "signal" },
376 { QUAL_READ, "read", qual_desc, "descriptor" },
377 { QUAL_READ, "reads", qual_desc, "descriptor" },
378 { QUAL_READ, "r", qual_desc, "descriptor" },
379 { QUAL_WRITE, "write", qual_desc, "descriptor" },
380 { QUAL_WRITE, "writes", qual_desc, "descriptor" },
381 { QUAL_WRITE, "w", qual_desc, "descriptor" },
382 { 0, NULL, NULL, NULL },
386 reallocate_qual(int n)
390 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
391 qp = qual_vec[p] = realloc(qual_vec[p], n * sizeof(qualbits_t));
394 memset(&qp[num_quals], 0, (n - num_quals) * sizeof(qualbits_t));
400 qualify_one(int n, int bitflag, int not, int pers)
405 reallocate_qual(n + 1);
407 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
408 if (pers == p || pers < 0) {
410 qual_vec[p][n] &= ~bitflag;
412 qual_vec[p][n] |= bitflag;
418 qual_syscall(const char *s, int bitflag, int not)
424 if (*s >= '0' && *s <= '9') {
425 i = string_to_uint(s);
426 if (i > MAX_NSYSCALLS)
428 qualify_one(i, bitflag, not, -1);
432 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
433 for (i = 0; i < nsyscall_vec[p]; i++) {
434 if (sysent_vec[p][i].sys_name
435 && strcmp(s, sysent_vec[p][i].sys_name) == 0
437 qualify_one(i, bitflag, not, 0);
447 qual_signal(const char *s, int bitflag, int not)
451 if (*s >= '0' && *s <= '9') {
452 int signo = string_to_uint(s);
453 if (signo < 0 || signo > 255)
455 qualify_one(signo, bitflag, not, -1);
458 if (strncasecmp(s, "SIG", 3) == 0)
460 for (i = 0; i <= NSIG; i++) {
461 if (strcasecmp(s, signame(i) + 3) == 0) {
462 qualify_one(i, bitflag, not, -1);
470 qual_desc(const char *s, int bitflag, int not)
472 if (*s >= '0' && *s <= '9') {
473 int desc = string_to_uint(s);
474 if (desc < 0 || desc > 0x7fff) /* paranoia */
476 qualify_one(desc, bitflag, not, -1);
483 lookup_class(const char *s)
485 if (strcmp(s, "file") == 0)
487 if (strcmp(s, "ipc") == 0)
489 if (strcmp(s, "network") == 0)
490 return TRACE_NETWORK;
491 if (strcmp(s, "process") == 0)
492 return TRACE_PROCESS;
493 if (strcmp(s, "signal") == 0)
495 if (strcmp(s, "desc") == 0)
497 if (strcmp(s, "memory") == 0)
503 qualify(const char *s)
505 const struct qual_options *opt;
512 reallocate_qual(MIN_QUALS);
514 opt = &qual_options[0];
515 for (i = 0; (p = qual_options[i].option_name); i++) {
517 if (strncmp(s, p, n) == 0 && s[n] == '=') {
518 opt = &qual_options[i];
528 if (strcmp(s, "none") == 0) {
532 if (strcmp(s, "all") == 0) {
533 for (i = 0; i < num_quals; i++) {
534 qualify_one(i, opt->bitflag, not, -1);
538 for (i = 0; i < num_quals; i++) {
539 qualify_one(i, opt->bitflag, !not, -1);
544 for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) {
545 if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) {
547 for (pers = 0; pers < SUPPORTED_PERSONALITIES; pers++) {
548 for (i = 0; i < nsyscall_vec[pers]; i++)
549 if (sysent_vec[pers][i].sys_flags & n)
550 qualify_one(i, opt->bitflag, not, 0);
554 if (opt->qualify(p, opt->bitflag, not)) {
555 error_msg_and_die("invalid %s '%s'",
556 opt->argument_name, p);
563 #ifdef SYS_socket_subcall
565 decode_socket_subcall(struct tcb *tcp)
568 unsigned int i, n, size;
570 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_socket_nsubcalls)
573 tcp->scno = SYS_socket_subcall + tcp->u_arg[0];
574 tcp->qual_flg = qual_flags[tcp->scno];
575 tcp->s_ent = &sysent[tcp->scno];
576 addr = tcp->u_arg[1];
577 size = current_wordsize;
578 n = tcp->s_ent->nargs;
579 for (i = 0; i < n; ++i) {
580 if (size == sizeof(int)) {
582 if (umove(tcp, addr, &arg) < 0)
588 if (umove(tcp, addr, &arg) < 0)
597 #ifdef SYS_ipc_subcall
599 decode_ipc_subcall(struct tcb *tcp)
603 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_ipc_nsubcalls)
606 tcp->scno = SYS_ipc_subcall + tcp->u_arg[0];
607 tcp->qual_flg = qual_flags[tcp->scno];
608 tcp->s_ent = &sysent[tcp->scno];
609 n = tcp->s_ent->nargs;
610 for (i = 0; i < n; i++)
611 tcp->u_arg[i] = tcp->u_arg[i + 1];
616 printargs(struct tcb *tcp)
620 int n = tcp->s_ent->nargs;
621 for (i = 0; i < n; i++)
622 tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]);
628 printargs_lu(struct tcb *tcp)
632 int n = tcp->s_ent->nargs;
633 for (i = 0; i < n; i++)
634 tprintf("%s%lu", i ? ", " : "", tcp->u_arg[i]);
640 printargs_ld(struct tcb *tcp)
644 int n = tcp->s_ent->nargs;
645 for (i = 0; i < n; i++)
646 tprintf("%s%ld", i ? ", " : "", tcp->u_arg[i]);
651 #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH)
653 getrval2(struct tcb *tcp)
657 # if defined(SPARC) || defined(SPARC64)
658 val = sparc_regs.u_regs[U_REG_O1];
660 if (upeek(tcp, 4*(REG_REG0+1), &val) < 0)
663 if (upeek(tcp, PT_R9, &val) < 0)
672 is_restart_error(struct tcb *tcp)
674 switch (tcp->u_error) {
678 case ERESTART_RESTARTBLOCK:
687 struct user_regs_struct i386_regs;
688 #elif defined(X86_64) || defined(X32)
690 * On i386, pt_regs and user_regs_struct are the same,
691 * but on 64 bit x86, user_regs_struct has six more fields:
692 * fs_base, gs_base, ds, es, fs, gs.
693 * PTRACE_GETREGS fills them too, so struct pt_regs would overflow.
695 struct i386_user_regs_struct {
715 struct user_regs_struct x86_64_r;
716 struct i386_user_regs_struct i386_r;
718 # define x86_64_regs x86_regs_union.x86_64_r
719 # define i386_regs x86_regs_union.i386_r
720 static struct iovec x86_io = {
721 .iov_base = &x86_regs_union
724 long ia32 = 0; /* not static */
725 static long ia64_r8, ia64_r10;
726 #elif defined(POWERPC)
727 static long ppc_result;
733 struct pt_regs arm_regs; /* not static */
734 #elif defined(AARCH64)
736 struct user_pt_regs aarch64_r;
737 struct arm_pt_regs arm_r;
739 # define aarch64_regs arm_regs_union.aarch64_r
740 # define arm_regs arm_regs_union.arm_r
741 static struct iovec aarch64_io = {
742 .iov_base = &arm_regs_union
745 static long alpha_r0;
746 static long alpha_a3;
748 static struct pt_regs avr32_regs;
749 #elif defined(SPARC) || defined(SPARC64)
750 struct pt_regs sparc_regs; /* not static */
751 #elif defined(LINUX_MIPSN32)
752 static long long mips_a3;
753 static long long mips_r2;
757 #elif defined(S390) || defined(S390X)
759 static long syscall_mode;
761 static long hppa_r28;
766 #elif defined(CRISV10) || defined(CRISV32)
767 static long cris_r10;
769 struct pt_regs tile_regs;
770 #elif defined(MICROBLAZE)
771 static long microblaze_r3;
773 static struct user_regs_struct or1k_regs;
774 static struct iovec or1k_io = {
775 .iov_base = &or1k_regs
780 printcall(struct tcb *tcp)
782 #define PRINTBADPC tprintf(sizeof(long) == 4 ? "[????????] " : \
783 sizeof(long) == 8 ? "[????????????????] " : \
785 if (get_regs_error) {
790 tprintf("[%08lx] ", i386_regs.eip);
791 #elif defined(S390) || defined(S390X)
793 if (upeek(tcp, PT_PSWADDR, &psw) < 0) {
798 tprintf("[%08lx] ", psw);
800 tprintf("[%016lx] ", psw);
802 #elif defined(X86_64) || defined(X32)
803 if (x86_io.iov_len == sizeof(i386_regs)) {
804 tprintf("[%08x] ", (unsigned) i386_regs.eip);
807 tprintf("[%016lx] ", (unsigned long) x86_64_regs.rip);
809 /* Note: this truncates 64-bit rip to 32 bits */
810 tprintf("[%08lx] ", (unsigned long) x86_64_regs.rip);
815 if (upeek(tcp, PT_B0, &ip) < 0) {
819 tprintf("[%08lx] ", ip);
820 #elif defined(POWERPC)
822 if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &pc) < 0) {
827 tprintf("[%016lx] ", pc);
829 tprintf("[%08lx] ", pc);
833 if (upeek(tcp, 4*PT_PC, &pc) < 0) {
834 tprints("[????????] ");
837 tprintf("[%08lx] ", pc);
840 if (upeek(tcp, REG_PC, &pc) < 0) {
841 tprints("[????????????????] ");
844 tprintf("[%08lx] ", pc);
846 tprintf("[%08lx] ", sparc_regs.pc);
847 #elif defined(SPARC64)
848 tprintf("[%08lx] ", sparc_regs.tpc);
851 if (upeek(tcp, PT_IAOQ0, &pc) < 0) {
852 tprints("[????????] ");
855 tprintf("[%08lx] ", pc);
858 if (upeek(tcp, REG_EPC, &pc) < 0) {
859 tprints("[????????] ");
862 tprintf("[%08lx] ", pc);
865 if (upeek(tcp, 4*REG_PC, &pc) < 0) {
866 tprints("[????????] ");
869 tprintf("[%08lx] ", pc);
872 if (upeek(tcp, REG_PC, &pc) < 0) {
873 tprints("[????????????????] ");
876 tprintf("[%08lx] ", pc);
878 tprintf("[%08lx] ", arm_regs.ARM_pc);
879 #elif defined(AARCH64)
880 /* tprintf("[%016lx] ", aarch64_regs.regs[???]); */
882 tprintf("[%08lx] ", avr32_regs.pc);
885 if (upeek(tcp, PT_PC, &pc) < 0) {
889 tprintf("[%08lx] ", pc);
890 #elif defined(CRISV10)
892 if (upeek(tcp, 4*PT_IRP, &pc) < 0) {
896 tprintf("[%08lx] ", pc);
897 #elif defined(CRISV32)
899 if (upeek(tcp, 4*PT_ERP, &pc) < 0) {
903 tprintf("[%08lx] ", pc);
906 tprintf("[%016lx] ", (unsigned long) tile_regs.pc);
908 tprintf("[%08lx] ", (unsigned long) tile_regs.pc);
911 tprintf("[%08lx] ", or1k_regs.pc);
912 #endif /* architecture */
915 /* Shuffle syscall numbers so that we don't have huge gaps in syscall table.
916 * The shuffling should be reversible: shuffle_scno(shuffle_scno(n)) == n.
918 #if defined(ARM) /* So far only ARM needs this */
920 shuffle_scno(unsigned long scno)
922 if (scno <= ARM_LAST_ORDINARY_SYSCALL)
925 /* __ARM_NR_cmpxchg? Swap with LAST_ORDINARY+1 */
926 if (scno == 0x000ffff0)
927 return ARM_LAST_ORDINARY_SYSCALL+1;
928 if (scno == ARM_LAST_ORDINARY_SYSCALL+1)
931 /* Is it ARM specific syscall?
932 * Swap with [LAST_ORDINARY+2, LAST_ORDINARY+2 + LAST_SPECIAL] range.
934 if (scno >= 0x000f0000
935 && scno <= 0x000f0000 + ARM_LAST_SPECIAL_SYSCALL
937 return scno - 0x000f0000 + (ARM_LAST_ORDINARY_SYSCALL+2);
939 if (/* scno >= ARM_LAST_ORDINARY_SYSCALL+2 - always true */ 1
940 && scno <= (ARM_LAST_ORDINARY_SYSCALL+2) + ARM_LAST_SPECIAL_SYSCALL
942 return scno + 0x000f0000 - (ARM_LAST_ORDINARY_SYSCALL+2);
948 # define shuffle_scno(scno) ((long)(scno))
952 undefined_scno_name(struct tcb *tcp)
954 static char buf[sizeof("syscall_%lu") + sizeof(long)*3];
956 sprintf(buf, "syscall_%lu", shuffle_scno(tcp->scno));
966 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &avr32_regs);
968 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &i386_regs);
969 # elif defined(X86_64) || defined(X32)
971 * PTRACE_GETREGSET was introduced in 2.6.33.
972 * Let's be paranoid and require a bit later kernel.
974 if (os_release >= KERNEL_VERSION(2,6,35)) {
975 /*x86_io.iov_base = &x86_regs_union; - already is */
976 x86_io.iov_len = sizeof(x86_regs_union);
977 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, (long) &x86_io);
979 /* Use old method, with heuristical detection of 32-bitness */
980 x86_io.iov_len = sizeof(x86_64_regs);
981 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &x86_64_regs);
982 if (!get_regs_error && x86_64_regs.cs == 0x23) {
983 x86_io.iov_len = sizeof(i386_regs);
985 * The order is important: i386_regs and x86_64_regs
986 * are overlaid in memory!
988 i386_regs.ebx = x86_64_regs.rbx;
989 i386_regs.ecx = x86_64_regs.rcx;
990 i386_regs.edx = x86_64_regs.rdx;
991 i386_regs.esi = x86_64_regs.rsi;
992 i386_regs.edi = x86_64_regs.rdi;
993 i386_regs.ebp = x86_64_regs.rbp;
994 i386_regs.eax = x86_64_regs.rax;
995 /*i386_regs.xds = x86_64_regs.ds; unused by strace */
996 /*i386_regs.xes = x86_64_regs.es; ditto... */
997 /*i386_regs.xfs = x86_64_regs.fs;*/
998 /*i386_regs.xgs = x86_64_regs.gs;*/
999 i386_regs.orig_eax = x86_64_regs.orig_rax;
1000 i386_regs.eip = x86_64_regs.rip;
1001 /*i386_regs.xcs = x86_64_regs.cs;*/
1002 /*i386_regs.eflags = x86_64_regs.eflags;*/
1003 i386_regs.esp = x86_64_regs.rsp;
1004 /*i386_regs.xss = x86_64_regs.ss;*/
1008 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (void *)&arm_regs);
1009 # elif defined(AARCH64)
1010 /*aarch64_io.iov_base = &arm_regs_union; - already is */
1011 aarch64_io.iov_len = sizeof(arm_regs_union);
1012 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, (void *)&aarch64_io);
1014 /* Paranoia checks */
1017 switch (aarch64_io.iov_len) {
1018 case sizeof(aarch64_regs):
1019 /* We are in 64-bit mode */
1021 case sizeof(arm_regs):
1022 /* We are in 32-bit mode */
1025 get_regs_error = -1;
1029 # elif defined(SPARC) || defined(SPARC64)
1030 get_regs_error = ptrace(PTRACE_GETREGS, pid, (char *)&sparc_regs, 0);
1031 # elif defined(TILE)
1032 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &tile_regs);
1033 # elif defined(OR1K)
1034 or1k_io.iov_len = sizeof(or1k_regs);
1035 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &or1k_io);
1041 * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently.
1042 * 1: ok, continue in trace_syscall_entering().
1043 * other: error, trace_syscall_entering() should print error indicator
1044 * ("????" etc) and bail out.
1047 get_scno(struct tcb *tcp)
1051 #if defined(S390) || defined(S390X)
1052 if (upeek(tcp, PT_GPR2, &syscall_mode) < 0)
1055 if (syscall_mode != -ENOSYS) {
1057 * Since kernel version 2.5.44 the scno gets passed in gpr2.
1059 scno = syscall_mode;
1062 * Old style of "passing" the scno via the SVC instruction.
1065 long opcode, offset_reg, tmp;
1067 static const int gpr_offset[16] = {
1068 PT_GPR0, PT_GPR1, PT_ORIGGPR2, PT_GPR3,
1069 PT_GPR4, PT_GPR5, PT_GPR6, PT_GPR7,
1070 PT_GPR8, PT_GPR9, PT_GPR10, PT_GPR11,
1071 PT_GPR12, PT_GPR13, PT_GPR14, PT_GPR15
1074 if (upeek(tcp, PT_PSWADDR, &psw) < 0)
1077 opcode = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(psw - sizeof(long)), 0);
1079 perror_msg("%s", "peektext(psw-oneword)");
1084 * We have to check if the SVC got executed directly or via an
1085 * EXECUTE instruction. In case of EXECUTE it is necessary to do
1086 * instruction decoding to derive the system call number.
1087 * Unfortunately the opcode sizes of EXECUTE and SVC are differently,
1088 * so that this doesn't work if a SVC opcode is part of an EXECUTE
1089 * opcode. Since there is no way to find out the opcode size this
1090 * is the best we can do...
1092 if ((opcode & 0xff00) == 0x0a00) {
1094 scno = opcode & 0xff;
1097 /* SVC got executed by EXECUTE instruction */
1100 * Do instruction decoding of EXECUTE. If you really want to
1101 * understand this, read the Principles of Operations.
1103 svc_addr = (void *) (opcode & 0xfff);
1106 offset_reg = (opcode & 0x000f0000) >> 16;
1107 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1112 offset_reg = (opcode & 0x0000f000) >> 12;
1113 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1117 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, svc_addr, 0);
1126 offset_reg = (opcode & 0x00f00000) >> 20;
1127 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1130 scno = (scno | tmp) & 0xff;
1133 #elif defined(POWERPC)
1134 if (upeek(tcp, sizeof(unsigned long)*PT_R0, &scno) < 0)
1137 /* TODO: speed up strace by not doing this at every syscall.
1138 * We only need to do it after execve.
1143 /* Check for 64/32 bit mode. */
1144 if (upeek(tcp, sizeof(unsigned long)*PT_MSR, &val) < 0)
1146 /* SF is bit 0 of MSR */
1151 update_personality(tcp, currpers);
1153 #elif defined(AVR32)
1154 scno = avr32_regs.r8;
1156 if (upeek(tcp, PT_ORIG_P0, &scno))
1159 scno = i386_regs.orig_eax;
1160 #elif defined(X86_64) || defined(X32)
1161 # ifndef __X32_SYSCALL_BIT
1162 # define __X32_SYSCALL_BIT 0x40000000
1166 /* GETREGSET of NT_PRSTATUS tells us regset size,
1167 * which unambiguously detects i386.
1169 * Linux kernel distinguishes x86-64 and x32 processes
1170 * solely by looking at __X32_SYSCALL_BIT:
1171 * arch/x86/include/asm/compat.h::is_x32_task():
1172 * if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
1175 if (x86_io.iov_len == sizeof(i386_regs)) {
1176 scno = i386_regs.orig_eax;
1179 scno = x86_64_regs.orig_rax;
1181 if (scno & __X32_SYSCALL_BIT) {
1182 scno -= __X32_SYSCALL_BIT;
1187 /* cs = 0x33 for long mode (native 64 bit and x32)
1188 * cs = 0x23 for compatibility mode (32 bit)
1189 * ds = 0x2b for x32 mode (x86-64 in 32 bit)
1191 scno = x86_64_regs.orig_rax;
1192 switch (x86_64_regs.cs) {
1193 case 0x23: currpers = 1; break;
1195 if (x86_64_regs.ds == 0x2b) {
1197 scno &= ~__X32_SYSCALL_BIT;
1202 fprintf(stderr, "Unknown value CS=0x%08X while "
1203 "detecting personality of process "
1204 "PID=%d\n", (int)x86_64_regs.cs, tcp->pid);
1205 currpers = current_personality;
1209 /* This version analyzes the opcode of a syscall instruction.
1210 * (int 0x80 on i386 vs. syscall on x86-64)
1211 * It works, but is too complicated, and strictly speaking, unreliable.
1213 unsigned long call, rip = x86_64_regs.rip;
1214 /* sizeof(syscall) == sizeof(int 0x80) == 2 */
1217 call = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)rip, (char *)0);
1219 fprintf(stderr, "ptrace_peektext failed: %s\n",
1221 switch (call & 0xffff) {
1222 /* x86-64: syscall = 0x0f 0x05 */
1223 case 0x050f: currpers = 0; break;
1224 /* i386: int 0x80 = 0xcd 0x80 */
1225 case 0x80cd: currpers = 1; break;
1227 currpers = current_personality;
1229 "Unknown syscall opcode (0x%04X) while "
1230 "detecting personality of process "
1231 "PID=%d\n", (int)call, tcp->pid);
1237 /* If we are built for a x32 system, then personality 0 is x32
1238 * (not x86_64), and stracing of x86_64 apps is not supported.
1239 * Stracing of i386 apps is still supported.
1241 if (currpers == 0) {
1242 fprintf(stderr, "syscall_%lu(...) in unsupported "
1243 "64-bit mode of process PID=%d\n",
1247 currpers &= ~2; /* map 2,1 to 0,1 */
1249 update_personality(tcp, currpers);
1251 # define IA64_PSR_IS ((long)1 << 34)
1253 if (upeek(tcp, PT_CR_IPSR, &psr) >= 0)
1254 ia32 = (psr & IA64_PSR_IS) != 0;
1256 if (upeek(tcp, PT_R1, &scno) < 0)
1259 if (upeek(tcp, PT_R15, &scno) < 0)
1262 #elif defined(AARCH64)
1263 switch (aarch64_io.iov_len) {
1264 case sizeof(aarch64_regs):
1265 /* We are in 64-bit mode */
1266 scno = aarch64_regs.regs[8];
1267 update_personality(tcp, 1);
1269 case sizeof(arm_regs):
1270 /* We are in 32-bit mode */
1271 scno = arm_regs.ARM_r7;
1272 update_personality(tcp, 0);
1276 if (arm_regs.ARM_ip != 0) {
1277 /* It is not a syscall entry */
1278 fprintf(stderr, "pid %d stray syscall exit\n", tcp->pid);
1279 tcp->flags |= TCB_INSYSCALL;
1282 /* Note: we support only 32-bit CPUs, not 26-bit */
1284 if (arm_regs.ARM_cpsr & 0x20) {
1286 scno = arm_regs.ARM_r7;
1290 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(arm_regs.ARM_pc - 4), NULL);
1294 /* EABI syscall convention? */
1295 if (scno == 0xef000000) {
1296 scno = arm_regs.ARM_r7; /* yes */
1298 if ((scno & 0x0ff00000) != 0x0f900000) {
1299 fprintf(stderr, "pid %d unknown syscall trap 0x%08lx\n",
1303 /* Fixup the syscall number */
1308 scno = shuffle_scno(scno);
1310 if (upeek(tcp, 4*PT_ORIG_D0, &scno) < 0)
1312 #elif defined(LINUX_MIPSN32)
1313 unsigned long long regs[38];
1315 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
1317 mips_a3 = regs[REG_A3];
1318 mips_r2 = regs[REG_V0];
1321 if (!SCNO_IN_RANGE(scno)) {
1322 if (mips_a3 == 0 || mips_a3 == -1) {
1324 fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
1329 if (upeek(tcp, REG_A3, &mips_a3) < 0)
1331 if (upeek(tcp, REG_V0, &scno) < 0)
1334 if (!SCNO_IN_RANGE(scno)) {
1335 if (mips_a3 == 0 || mips_a3 == -1) {
1337 fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
1341 #elif defined(ALPHA)
1342 if (upeek(tcp, REG_A3, &alpha_a3) < 0)
1344 if (upeek(tcp, REG_R0, &scno) < 0)
1348 * Do some sanity checks to figure out if it's
1349 * really a syscall entry
1351 if (!SCNO_IN_RANGE(scno)) {
1352 if (alpha_a3 == 0 || alpha_a3 == -1) {
1354 fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno);
1358 #elif defined(SPARC) || defined(SPARC64)
1359 /* Disassemble the syscall trap. */
1360 /* Retrieve the syscall trap instruction. */
1363 # if defined(SPARC64)
1364 trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.tpc, 0);
1367 trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.pc, 0);
1372 /* Disassemble the trap to see what personality to use. */
1375 /* Linux/SPARC syscall trap. */
1376 update_personality(tcp, 0);
1379 /* Linux/SPARC64 syscall trap. */
1380 update_personality(tcp, 2);
1383 /* SunOS syscall trap. (pers 1) */
1384 fprintf(stderr, "syscall: SunOS no support\n");
1387 /* Solaris 2.x syscall trap. (per 2) */
1388 update_personality(tcp, 1);
1391 /* NetBSD/FreeBSD syscall trap. */
1392 fprintf(stderr, "syscall: NetBSD/FreeBSD not supported\n");
1395 /* Solaris 2.x gettimeofday */
1396 update_personality(tcp, 1);
1399 # if defined(SPARC64)
1400 fprintf(stderr, "syscall: unknown syscall trap %08lx %016lx\n", trap, sparc_regs.tpc);
1402 fprintf(stderr, "syscall: unknown syscall trap %08lx %08lx\n", trap, sparc_regs.pc);
1407 /* Extract the system call number from the registers. */
1408 if (trap == 0x91d02027)
1411 scno = sparc_regs.u_regs[U_REG_G1];
1413 scno = sparc_regs.u_regs[U_REG_O0];
1414 memmove(&sparc_regs.u_regs[U_REG_O0], &sparc_regs.u_regs[U_REG_O1], 7*sizeof(sparc_regs.u_regs[0]));
1417 if (upeek(tcp, PT_GR20, &scno) < 0)
1421 * In the new syscall ABI, the system call number is in R3.
1423 if (upeek(tcp, 4*(REG_REG0+3), &scno) < 0)
1427 /* Odd as it may seem, a glibc bug has been known to cause
1428 glibc to issue bogus negative syscall numbers. So for
1429 our purposes, make strace print what it *should* have been */
1430 long correct_scno = (scno & 0xff);
1433 "Detected glibc bug: bogus system call"
1434 " number = %ld, correcting to %ld\n",
1437 scno = correct_scno;
1440 if (upeek(tcp, REG_SYSCALL, &scno) < 0)
1443 #elif defined(CRISV10) || defined(CRISV32)
1444 if (upeek(tcp, 4*PT_R9, &scno) < 0)
1448 scno = tile_regs.regs[10];
1452 # ifndef PT_FLAGS_COMPAT
1453 # define PT_FLAGS_COMPAT 0x10000 /* from Linux 3.8 on */
1455 if (tile_regs.flags & PT_FLAGS_COMPAT)
1460 update_personality(tcp, currpers);
1461 #elif defined(MICROBLAZE)
1462 if (upeek(tcp, 0, &scno) < 0)
1465 scno = or1k_regs.gpr[11];
1469 if (SCNO_IS_VALID(tcp->scno)) {
1470 tcp->s_ent = &sysent[scno];
1471 tcp->qual_flg = qual_flags[scno];
1473 static const struct_sysent unknown = {
1476 .sys_func = printargs,
1477 .sys_name = "unknown", /* not used */
1479 tcp->s_ent = &unknown;
1480 tcp->qual_flg = UNDEFINED_SCNO | QUAL_RAW | DEFAULT_QUAL_FLAGS;
1485 /* Called at each syscall entry.
1487 * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently.
1488 * 1: ok, continue in trace_syscall_entering().
1489 * other: error, trace_syscall_entering() should print error indicator
1490 * ("????" etc) and bail out.
1493 syscall_fixup_on_sysenter(struct tcb *tcp)
1495 /* A common case of "not a syscall entry" is post-execve SIGTRAP */
1497 if (i386_regs.eax != -ENOSYS) {
1499 fprintf(stderr, "not a syscall entry (eax = %ld)\n", i386_regs.eax);
1502 #elif defined(X86_64) || defined(X32)
1505 if (x86_io.iov_len == sizeof(i386_regs)) {
1506 /* Sign extend from 32 bits */
1507 rax = (int32_t)i386_regs.eax;
1509 /* Note: in X32 build, this truncates 64 to 32 bits */
1510 rax = x86_64_regs.rax;
1512 if (rax != -ENOSYS) {
1514 fprintf(stderr, "not a syscall entry (rax = %ld)\n", rax);
1518 #elif defined(S390) || defined(S390X)
1519 /* TODO: we already fetched PT_GPR2 in get_scno
1520 * and stored it in syscall_mode, reuse it here
1521 * instead of re-fetching?
1523 if (upeek(tcp, PT_GPR2, &gpr2) < 0)
1525 if (syscall_mode != -ENOSYS)
1526 syscall_mode = tcp->scno;
1527 if (gpr2 != syscall_mode) {
1529 fprintf(stderr, "not a syscall entry (gpr2 = %ld)\n", gpr2);
1533 /* TODO? Eliminate upeek's in arches below like we did in x86 */
1534 if (upeek(tcp, 4*PT_D0, &m68k_d0) < 0)
1536 if (m68k_d0 != -ENOSYS) {
1538 fprintf(stderr, "not a syscall entry (d0 = %ld)\n", m68k_d0);
1542 if (upeek(tcp, PT_R10, &ia64_r10) < 0)
1544 if (upeek(tcp, PT_R8, &ia64_r8) < 0)
1546 if (ia32 && ia64_r8 != -ENOSYS) {
1548 fprintf(stderr, "not a syscall entry (r8 = %ld)\n", ia64_r8);
1551 #elif defined(CRISV10) || defined(CRISV32)
1552 if (upeek(tcp, 4*PT_R10, &cris_r10) < 0)
1554 if (cris_r10 != -ENOSYS) {
1556 fprintf(stderr, "not a syscall entry (r10 = %ld)\n", cris_r10);
1559 #elif defined(MICROBLAZE)
1560 if (upeek(tcp, 3 * 4, µblaze_r3) < 0)
1562 if (microblaze_r3 != -ENOSYS) {
1564 fprintf(stderr, "not a syscall entry (r3 = %ld)\n", microblaze_r3);
1572 internal_fork(struct tcb *tcp)
1574 #if defined S390 || defined S390X || defined CRISV10 || defined CRISV32
1575 # define ARG_FLAGS 1
1577 # define ARG_FLAGS 0
1579 #ifndef CLONE_UNTRACED
1580 # define CLONE_UNTRACED 0x00800000
1582 if ((ptrace_setoptions
1583 & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
1584 == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
1590 if (entering(tcp)) {
1592 * We won't see the new child if clone is called with
1593 * CLONE_UNTRACED, so we keep the same logic with that option
1594 * and don't trace it.
1596 if ((tcp->s_ent->sys_func == sys_clone)
1597 && (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED)
1602 if (tcp->flags & TCB_BPTSET)
1607 #if defined(TCB_WAITEXECVE)
1609 internal_exec(struct tcb *tcp)
1611 /* Maybe we have post-execve SIGTRAP suppressed? */
1612 if (ptrace_setoptions & PTRACE_O_TRACEEXEC)
1613 return; /* yes, no need to do anything */
1615 if (exiting(tcp) && syserror(tcp))
1616 /* Error in execve, no post-execve SIGTRAP expected */
1617 tcp->flags &= ~TCB_WAITEXECVE;
1619 tcp->flags |= TCB_WAITEXECVE;
1624 syscall_fixup_for_fork_exec(struct tcb *tcp)
1627 * We must always trace a few critical system calls in order to
1628 * correctly support following forks in the presence of tracing
1633 func = tcp->s_ent->sys_func;
1635 if ( sys_fork == func
1636 || sys_vfork == func
1637 || sys_clone == func
1643 #if defined(TCB_WAITEXECVE)
1644 if ( sys_execve == func
1645 # if defined(SPARC) || defined(SPARC64)
1646 || sys_execv == func
1655 /* Return -1 on error or 1 on success (never 0!) */
1657 get_syscall_args(struct tcb *tcp)
1661 nargs = tcp->s_ent->nargs;
1663 #if defined(S390) || defined(S390X)
1664 for (i = 0; i < nargs; ++i)
1665 if (upeek(tcp, i==0 ? PT_ORIGGPR2 : PT_GPR2 + i*sizeof(long), &tcp->u_arg[i]) < 0)
1667 #elif defined(ALPHA)
1668 for (i = 0; i < nargs; ++i)
1669 if (upeek(tcp, REG_A0+i, &tcp->u_arg[i]) < 0)
1673 unsigned long *out0, cfm, sof, sol;
1675 /* be backwards compatible with kernel < 2.4.4... */
1677 # define PT_RBS_END PT_AR_BSP
1680 if (upeek(tcp, PT_RBS_END, &rbs_end) < 0)
1682 if (upeek(tcp, PT_CFM, (long *) &cfm) < 0)
1685 sof = (cfm >> 0) & 0x7f;
1686 sol = (cfm >> 7) & 0x7f;
1687 out0 = ia64_rse_skip_regs((unsigned long *) rbs_end, -sof + sol);
1689 for (i = 0; i < nargs; ++i) {
1690 if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i),
1691 sizeof(long), (char *) &tcp->u_arg[i]) < 0)
1695 static const int argreg[MAX_ARGS] = { PT_R11 /* EBX = out0 */,
1696 PT_R9 /* ECX = out1 */,
1697 PT_R10 /* EDX = out2 */,
1698 PT_R14 /* ESI = out3 */,
1699 PT_R15 /* EDI = out4 */,
1700 PT_R13 /* EBP = out5 */};
1702 for (i = 0; i < nargs; ++i) {
1703 if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
1705 /* truncate away IVE sign-extension */
1706 tcp->u_arg[i] &= 0xffffffff;
1709 #elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
1710 /* N32 and N64 both use up to six registers. */
1711 unsigned long long regs[38];
1713 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
1716 for (i = 0; i < nargs; ++i) {
1717 tcp->u_arg[i] = regs[REG_A0 + i];
1718 # if defined(LINUX_MIPSN32)
1719 tcp->ext_arg[i] = regs[REG_A0 + i];
1726 if (upeek(tcp, REG_SP, &sp) < 0)
1728 for (i = 0; i < 4; ++i)
1729 if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
1731 umoven(tcp, sp + 16, (nargs - 4) * sizeof(tcp->u_arg[0]),
1732 (char *)(tcp->u_arg + 4));
1734 for (i = 0; i < nargs; ++i)
1735 if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
1738 #elif defined(POWERPC)
1740 # define PT_ORIG_R3 34
1742 for (i = 0; i < nargs; ++i) {
1743 if (upeek(tcp, (i==0) ?
1744 (sizeof(unsigned long) * PT_ORIG_R3) :
1745 ((i+PT_R3) * sizeof(unsigned long)),
1746 &tcp->u_arg[i]) < 0)
1749 #elif defined(SPARC) || defined(SPARC64)
1750 for (i = 0; i < nargs; ++i)
1751 tcp->u_arg[i] = sparc_regs.u_regs[U_REG_O0 + i];
1753 for (i = 0; i < nargs; ++i)
1754 if (upeek(tcp, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
1756 #elif defined(ARM) || defined(AARCH64)
1757 # if defined(AARCH64)
1758 if (tcp->currpers == 1)
1759 for (i = 0; i < nargs; ++i)
1760 tcp->u_arg[i] = aarch64_regs.regs[i];
1763 for (i = 0; i < nargs; ++i)
1764 tcp->u_arg[i] = arm_regs.uregs[i];
1765 #elif defined(AVR32)
1768 tcp->u_arg[0] = avr32_regs.r12;
1769 tcp->u_arg[1] = avr32_regs.r11;
1770 tcp->u_arg[2] = avr32_regs.r10;
1771 tcp->u_arg[3] = avr32_regs.r9;
1772 tcp->u_arg[4] = avr32_regs.r5;
1773 tcp->u_arg[5] = avr32_regs.r3;
1775 static const int argreg[MAX_ARGS] = { PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5 };
1777 for (i = 0; i < nargs; ++i)
1778 if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
1781 static const int syscall_regs[MAX_ARGS] = {
1782 4 * (REG_REG0+4), 4 * (REG_REG0+5), 4 * (REG_REG0+6),
1783 4 * (REG_REG0+7), 4 * (REG_REG0 ), 4 * (REG_REG0+1)
1786 for (i = 0; i < nargs; ++i)
1787 if (upeek(tcp, syscall_regs[i], &tcp->u_arg[i]) < 0)
1791 /* Registers used by SH5 Linux system calls for parameters */
1792 static const int syscall_regs[MAX_ARGS] = { 2, 3, 4, 5, 6, 7 };
1794 for (i = 0; i < nargs; ++i)
1795 if (upeek(tcp, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0)
1800 tcp->u_arg[0] = i386_regs.ebx;
1801 tcp->u_arg[1] = i386_regs.ecx;
1802 tcp->u_arg[2] = i386_regs.edx;
1803 tcp->u_arg[3] = i386_regs.esi;
1804 tcp->u_arg[4] = i386_regs.edi;
1805 tcp->u_arg[5] = i386_regs.ebp;
1806 #elif defined(X86_64) || defined(X32)
1809 if (x86_io.iov_len != sizeof(i386_regs)) {
1810 /* x86-64 or x32 ABI */
1811 tcp->u_arg[0] = x86_64_regs.rdi;
1812 tcp->u_arg[1] = x86_64_regs.rsi;
1813 tcp->u_arg[2] = x86_64_regs.rdx;
1814 tcp->u_arg[3] = x86_64_regs.r10;
1815 tcp->u_arg[4] = x86_64_regs.r8;
1816 tcp->u_arg[5] = x86_64_regs.r9;
1818 tcp->ext_arg[0] = x86_64_regs.rdi;
1819 tcp->ext_arg[1] = x86_64_regs.rsi;
1820 tcp->ext_arg[2] = x86_64_regs.rdx;
1821 tcp->ext_arg[3] = x86_64_regs.r10;
1822 tcp->ext_arg[4] = x86_64_regs.r8;
1823 tcp->ext_arg[5] = x86_64_regs.r9;
1827 /* Zero-extend from 32 bits */
1828 /* Use widen_to_long(tcp->u_arg[N]) in syscall handlers
1829 * if you need to use *sign-extended* parameter.
1831 tcp->u_arg[0] = (long)(uint32_t)i386_regs.ebx;
1832 tcp->u_arg[1] = (long)(uint32_t)i386_regs.ecx;
1833 tcp->u_arg[2] = (long)(uint32_t)i386_regs.edx;
1834 tcp->u_arg[3] = (long)(uint32_t)i386_regs.esi;
1835 tcp->u_arg[4] = (long)(uint32_t)i386_regs.edi;
1836 tcp->u_arg[5] = (long)(uint32_t)i386_regs.ebp;
1838 #elif defined(MICROBLAZE)
1839 for (i = 0; i < nargs; ++i)
1840 if (upeek(tcp, (5 + i) * 4, &tcp->u_arg[i]) < 0)
1842 #elif defined(CRISV10) || defined(CRISV32)
1843 static const int crisregs[MAX_ARGS] = {
1844 4*PT_ORIG_R10, 4*PT_R11, 4*PT_R12,
1845 4*PT_R13 , 4*PT_MOF, 4*PT_SRP
1848 for (i = 0; i < nargs; ++i)
1849 if (upeek(tcp, crisregs[i], &tcp->u_arg[i]) < 0)
1852 for (i = 0; i < nargs; ++i)
1853 tcp->u_arg[i] = tile_regs.regs[i];
1855 for (i = 0; i < nargs; ++i)
1856 if (upeek(tcp, (i < 5 ? i : i + 2)*4, &tcp->u_arg[i]) < 0)
1860 for (i = 0; i < 6; ++i)
1861 tcp->u_arg[i] = or1k_regs.gpr[3 + i];
1862 #else /* Other architecture (32bits specific) */
1863 for (i = 0; i < nargs; ++i)
1864 if (upeek(tcp, i*4, &tcp->u_arg[i]) < 0)
1871 trace_syscall_entering(struct tcb *tcp)
1875 #if defined TCB_WAITEXECVE
1876 if (tcp->flags & TCB_WAITEXECVE) {
1877 /* This is the post-execve SIGTRAP. */
1878 tcp->flags &= ~TCB_WAITEXECVE;
1883 scno_good = res = (get_regs_error ? -1 : get_scno(tcp));
1887 res = syscall_fixup_on_sysenter(tcp);
1891 res = get_syscall_args(tcp);
1897 tprints("????" /* anti-trigraph gap */ "(");
1898 else if (tcp->qual_flg & UNDEFINED_SCNO)
1899 tprintf("%s(", undefined_scno_name(tcp));
1901 tprintf("%s(", tcp->s_ent->sys_name);
1903 * " <unavailable>" will be added later by the code which
1904 * detects ptrace errors.
1909 #if defined(SYS_socket_subcall) || defined(SYS_ipc_subcall)
1911 # ifdef SYS_socket_subcall
1912 if (tcp->s_ent->sys_func == sys_socketcall) {
1913 decode_socket_subcall(tcp);
1917 # ifdef SYS_ipc_subcall
1918 if (tcp->s_ent->sys_func == sys_ipc) {
1919 decode_ipc_subcall(tcp);
1927 if (need_fork_exec_workarounds)
1928 syscall_fixup_for_fork_exec(tcp);
1930 if (!(tcp->qual_flg & QUAL_TRACE)
1931 || (tracing_paths && !pathtrace_match(tcp))
1933 tcp->flags |= TCB_INSYSCALL | TCB_FILTERED;
1937 tcp->flags &= ~TCB_FILTERED;
1939 if (cflag == CFLAG_ONLY_STATS) {
1945 if (tcp->qual_flg & UNDEFINED_SCNO)
1946 tprintf("%s(", undefined_scno_name(tcp));
1948 tprintf("%s(", tcp->s_ent->sys_name);
1949 if ((tcp->qual_flg & QUAL_RAW) && tcp->s_ent->sys_func != sys_exit)
1950 res = printargs(tcp);
1952 res = tcp->s_ent->sys_func(tcp);
1956 tcp->flags |= TCB_INSYSCALL;
1957 /* Measure the entrance time as late as possible to avoid errors. */
1959 gettimeofday(&tcp->etime, NULL);
1964 * 1: ok, continue in trace_syscall_exiting().
1965 * -1: error, trace_syscall_exiting() should print error indicator
1966 * ("????" etc) and bail out.
1969 get_syscall_result(struct tcb *tcp)
1971 #if defined(S390) || defined(S390X)
1972 if (upeek(tcp, PT_GPR2, &gpr2) < 0)
1974 #elif defined(POWERPC)
1975 # define SO_MASK 0x10000000
1978 if (upeek(tcp, sizeof(unsigned long)*PT_CCR, &flags) < 0)
1980 if (upeek(tcp, sizeof(unsigned long)*PT_R3, &ppc_result) < 0)
1982 if (flags & SO_MASK)
1983 ppc_result = -ppc_result;
1985 #elif defined(AVR32)
1986 /* already done by get_regs */
1988 if (upeek(tcp, PT_R0, &bfin_r0) < 0)
1991 /* already done by get_regs */
1992 #elif defined(X86_64) || defined(X32)
1993 /* already done by get_regs */
1995 # define IA64_PSR_IS ((long)1 << 34)
1997 if (upeek(tcp, PT_CR_IPSR, &psr) >= 0)
1998 ia32 = (psr & IA64_PSR_IS) != 0;
1999 if (upeek(tcp, PT_R8, &ia64_r8) < 0)
2001 if (upeek(tcp, PT_R10, &ia64_r10) < 0)
2004 /* already done by get_regs */
2005 #elif defined(AARCH64)
2006 /* register reading already done by get_regs */
2008 /* Used to do this, but we did it on syscall entry already: */
2009 /* We are in 64-bit mode (personality 1) if register struct is aarch64_regs,
2010 * else it's personality 0.
2012 /*update_personality(tcp, aarch64_io.iov_len == sizeof(aarch64_regs));*/
2014 if (upeek(tcp, 4*PT_D0, &m68k_d0) < 0)
2016 #elif defined(LINUX_MIPSN32)
2017 unsigned long long regs[38];
2019 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
2021 mips_a3 = regs[REG_A3];
2022 mips_r2 = regs[REG_V0];
2024 if (upeek(tcp, REG_A3, &mips_a3) < 0)
2026 if (upeek(tcp, REG_V0, &mips_r2) < 0)
2028 #elif defined(ALPHA)
2029 if (upeek(tcp, REG_A3, &alpha_a3) < 0)
2031 if (upeek(tcp, REG_R0, &alpha_r0) < 0)
2033 #elif defined(SPARC) || defined(SPARC64)
2034 /* already done by get_regs */
2036 if (upeek(tcp, PT_GR28, &hppa_r28) < 0)
2039 /* new syscall ABI returns result in R0 */
2040 if (upeek(tcp, 4*REG_REG0, (long *)&sh_r0) < 0)
2043 /* ABI defines result returned in r9 */
2044 if (upeek(tcp, REG_GENERAL(9), (long *)&sh64_r9) < 0)
2046 #elif defined(CRISV10) || defined(CRISV32)
2047 if (upeek(tcp, 4*PT_R10, &cris_r10) < 0)
2050 /* already done by get_regs */
2051 #elif defined(MICROBLAZE)
2052 if (upeek(tcp, 3 * 4, µblaze_r3) < 0)
2055 /* already done by get_regs */
2060 /* Called at each syscall exit */
2062 syscall_fixup_on_sysexit(struct tcb *tcp)
2064 #if defined(S390) || defined(S390X)
2065 if (syscall_mode != -ENOSYS)
2066 syscall_mode = tcp->scno;
2067 if ((tcp->flags & TCB_WAITEXECVE)
2068 && (gpr2 == -ENOSYS || gpr2 == tcp->scno)) {
2070 * Return from execve.
2071 * Fake a return value of zero. We leave the TCB_WAITEXECVE
2072 * flag set for the post-execve SIGTRAP to see and reset.
2080 * Check the syscall return value register value for whether it is
2081 * a negated errno code indicating an error, or a success return value.
2084 is_negated_errno(unsigned long int val)
2086 unsigned long int max = -(long int) nerrnos;
2087 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
2088 if (current_wordsize < sizeof(val)) {
2089 val = (unsigned int) val;
2090 max = (unsigned int) max;
2098 is_negated_errno_x32(unsigned long long val)
2100 unsigned long long max = -(long long) nerrnos;
2102 * current_wordsize is 4 even in personality 0 (native X32)
2103 * but truncation _must not_ be done in it.
2104 * can't check current_wordsize here!
2106 if (current_personality != 0) {
2107 val = (uint32_t) val;
2108 max = (uint32_t) max;
2115 * 1: ok, continue in trace_syscall_exiting().
2116 * -1: error, trace_syscall_exiting() should print error indicator
2117 * ("????" etc) and bail out.
2120 get_error(struct tcb *tcp)
2123 int check_errno = 1;
2124 if (tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS) {
2127 #if defined(S390) || defined(S390X)
2128 if (check_errno && is_negated_errno(gpr2)) {
2136 if (check_errno && is_negated_errno(i386_regs.eax)) {
2138 u_error = -i386_regs.eax;
2141 tcp->u_rval = i386_regs.eax;
2143 #elif defined(X86_64)
2145 if (x86_io.iov_len == sizeof(i386_regs)) {
2146 /* Sign extend from 32 bits */
2147 rax = (int32_t)i386_regs.eax;
2149 rax = x86_64_regs.rax;
2151 if (check_errno && is_negated_errno(rax)) {
2159 /* In X32, return value is 64-bit (llseek uses one).
2160 * Using merely "long rax" would not work.
2163 if (x86_io.iov_len == sizeof(i386_regs)) {
2164 /* Sign extend from 32 bits */
2165 rax = (int32_t)i386_regs.eax;
2167 rax = x86_64_regs.rax;
2169 /* Careful: is_negated_errno() works only on longs */
2170 if (check_errno && is_negated_errno_x32(rax)) {
2175 tcp->u_rval = rax; /* truncating */
2183 if (check_errno && is_negated_errno(err)) {
2191 if (check_errno && ia64_r10) {
2195 tcp->u_rval = ia64_r8;
2199 if (check_errno && mips_a3) {
2203 tcp->u_rval = mips_r2;
2204 # if defined(LINUX_MIPSN32)
2205 tcp->u_lrval = mips_r2;
2208 #elif defined(POWERPC)
2209 if (check_errno && is_negated_errno(ppc_result)) {
2211 u_error = -ppc_result;
2214 tcp->u_rval = ppc_result;
2217 if (check_errno && is_negated_errno(m68k_d0)) {
2222 tcp->u_rval = m68k_d0;
2224 #elif defined(ARM) || defined(AARCH64)
2225 # if defined(AARCH64)
2226 if (tcp->currpers == 1) {
2227 if (check_errno && is_negated_errno(aarch64_regs.regs[0])) {
2229 u_error = -aarch64_regs.regs[0];
2232 tcp->u_rval = aarch64_regs.regs[0];
2238 if (check_errno && is_negated_errno(arm_regs.ARM_r0)) {
2240 u_error = -arm_regs.ARM_r0;
2243 tcp->u_rval = arm_regs.ARM_r0;
2246 #elif defined(AVR32)
2247 if (check_errno && avr32_regs.r12 && (unsigned) -avr32_regs.r12 < nerrnos) {
2249 u_error = -avr32_regs.r12;
2252 tcp->u_rval = avr32_regs.r12;
2255 if (check_errno && is_negated_errno(bfin_r0)) {
2259 tcp->u_rval = bfin_r0;
2261 #elif defined(ALPHA)
2262 if (check_errno && alpha_a3) {
2267 tcp->u_rval = alpha_r0;
2269 #elif defined(SPARC)
2270 if (check_errno && sparc_regs.psr & PSR_C) {
2272 u_error = sparc_regs.u_regs[U_REG_O0];
2275 tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
2277 #elif defined(SPARC64)
2278 if (check_errno && sparc_regs.tstate & 0x1100000000UL) {
2280 u_error = sparc_regs.u_regs[U_REG_O0];
2283 tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
2286 if (check_errno && is_negated_errno(hppa_r28)) {
2288 u_error = -hppa_r28;
2291 tcp->u_rval = hppa_r28;
2294 if (check_errno && is_negated_errno(sh_r0)) {
2299 tcp->u_rval = sh_r0;
2302 if (check_errno && is_negated_errno(sh64_r9)) {
2307 tcp->u_rval = sh64_r9;
2309 #elif defined(CRISV10) || defined(CRISV32)
2310 if (check_errno && cris_r10 && (unsigned) -cris_r10 < nerrnos) {
2312 u_error = -cris_r10;
2315 tcp->u_rval = cris_r10;
2319 * The standard tile calling convention returns the value (or negative
2320 * errno) in r0, and zero (or positive errno) in r1.
2321 * Until at least kernel 3.8, however, the r1 value is not reflected
2322 * in ptregs at this point, so we use r0 here.
2324 if (check_errno && is_negated_errno(tile_regs.regs[0])) {
2326 u_error = -tile_regs.regs[0];
2328 tcp->u_rval = tile_regs.regs[0];
2330 #elif defined(MICROBLAZE)
2331 if (check_errno && is_negated_errno(microblaze_r3)) {
2333 u_error = -microblaze_r3;
2336 tcp->u_rval = microblaze_r3;
2339 if (check_errno && is_negated_errno(or1k_regs.gpr[11])) {
2341 u_error = -or1k_regs.gpr[11];
2344 tcp->u_rval = or1k_regs.gpr[11];
2347 tcp->u_error = u_error;
2351 dumpio(struct tcb *tcp)
2357 if ((unsigned long) tcp->u_arg[0] >= num_quals)
2359 func = tcp->s_ent->sys_func;
2360 if (func == printargs)
2362 if (qual_flags[tcp->u_arg[0]] & QUAL_READ) {
2363 if (func == sys_read ||
2364 func == sys_pread ||
2366 func == sys_recvfrom)
2367 dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
2368 else if (func == sys_readv)
2369 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2372 if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) {
2373 if (func == sys_write ||
2374 func == sys_pwrite ||
2377 dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2378 else if (func == sys_writev)
2379 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2385 trace_syscall_exiting(struct tcb *tcp)
2392 /* Measure the exit time as early as possible to avoid errors. */
2394 gettimeofday(&tv, NULL);
2396 #if SUPPORTED_PERSONALITIES > 1
2397 update_personality(tcp, tcp->currpers);
2399 res = (get_regs_error ? -1 : get_syscall_result(tcp));
2401 syscall_fixup_on_sysexit(tcp); /* never fails */
2402 get_error(tcp); /* never fails */
2403 if (need_fork_exec_workarounds)
2404 syscall_fixup_for_fork_exec(tcp);
2410 struct timeval t = tv;
2411 count_syscall(tcp, &t);
2412 if (cflag == CFLAG_ONLY_STATS) {
2417 /* If not in -ff mode, and printing_tcp != tcp,
2418 * then the log currently does not end with output
2419 * of _our syscall entry_, but with something else.
2420 * We need to say which syscall's return is this.
2422 * Forced reprinting via TCB_REPRINT is used only by
2423 * "strace -ff -oLOG test/threaded_execve" corner case.
2424 * It's the only case when -ff mode needs reprinting.
2426 if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) {
2427 tcp->flags &= ~TCB_REPRINT;
2429 if (tcp->qual_flg & UNDEFINED_SCNO)
2430 tprintf("<... %s resumed> ", undefined_scno_name(tcp));
2432 tprintf("<... %s resumed> ", tcp->s_ent->sys_name);
2437 /* There was error in one of prior ptrace ops */
2440 tprints("= ? <unavailable>\n");
2442 tcp->flags &= ~TCB_INSYSCALL;
2447 if (tcp->qual_flg & QUAL_RAW) {
2448 /* sys_res = printargs(tcp); - but it's nop on sysexit */
2450 /* FIXME: not_failing_only (IOW, option -z) is broken:
2451 * failure of syscall is known only after syscall return.
2452 * Thus we end up with something like this on, say, ENOENT:
2453 * open("doesnt_exist", O_RDONLY <unfinished ...>
2454 * {next syscall decode}
2455 * whereas the intended result is that open(...) line
2456 * is not shown at all.
2458 if (not_failing_only && tcp->u_error)
2459 goto ret; /* ignore failed syscalls */
2460 sys_res = tcp->s_ent->sys_func(tcp);
2465 u_error = tcp->u_error;
2466 if (tcp->qual_flg & QUAL_RAW) {
2468 tprintf("= -1 (errno %ld)", u_error);
2470 tprintf("= %#lx", tcp->u_rval);
2472 else if (!(sys_res & RVAL_NONE) && u_error) {
2474 /* Blocked signals do not interrupt any syscalls.
2475 * In this case syscalls don't return ERESTARTfoo codes.
2477 * Deadly signals set to SIG_DFL interrupt syscalls
2478 * and kill the process regardless of which of the codes below
2479 * is returned by the interrupted syscall.
2480 * In some cases, kernel forces a kernel-generated deadly
2481 * signal to be unblocked and set to SIG_DFL (and thus cause
2482 * death) if it is blocked or SIG_IGNed: for example, SIGSEGV
2483 * or SIGILL. (The alternative is to leave process spinning
2484 * forever on the faulty instruction - not useful).
2486 * SIG_IGNed signals and non-deadly signals set to SIG_DFL
2487 * (for example, SIGCHLD, SIGWINCH) interrupt syscalls,
2488 * but kernel will always restart them.
2491 /* Most common type of signal-interrupted syscall exit code.
2492 * The system call will be restarted with the same arguments
2493 * if SA_RESTART is set; otherwise, it will fail with EINTR.
2495 tprints("= ? ERESTARTSYS (To be restarted if SA_RESTART is set)");
2497 case ERESTARTNOINTR:
2498 /* Rare. For example, fork() returns this if interrupted.
2499 * SA_RESTART is ignored (assumed set): the restart is unconditional.
2501 tprints("= ? ERESTARTNOINTR (To be restarted)");
2503 case ERESTARTNOHAND:
2504 /* pause(), rt_sigsuspend() etc use this code.
2505 * SA_RESTART is ignored (assumed not set):
2506 * syscall won't restart (will return EINTR instead)
2507 * even after signal with SA_RESTART set. However,
2508 * after SIG_IGN or SIG_DFL signal it will restart
2509 * (thus the name "restart only if has no handler").
2511 tprints("= ? ERESTARTNOHAND (Interrupted by signal)");
2513 case ERESTART_RESTARTBLOCK:
2514 /* Syscalls like nanosleep(), poll() which can't be
2515 * restarted with their original arguments use this
2516 * code. Kernel will execute restart_syscall() instead,
2517 * which changes arguments before restarting syscall.
2518 * SA_RESTART is ignored (assumed not set) similarly
2519 * to ERESTARTNOHAND. (Kernel can't honor SA_RESTART
2520 * since restart data is saved in "restart block"
2521 * in task struct, and if signal handler uses a syscall
2522 * which in turn saves another such restart block,
2523 * old data is lost and restart becomes impossible)
2525 tprints("= ? ERESTART_RESTARTBLOCK (Interrupted by signal)");
2529 tprintf("= -1 E??? (errno %ld)", u_error);
2530 else if (u_error < nerrnos)
2531 tprintf("= -1 %s (%s)", errnoent[u_error],
2534 tprintf("= -1 ERRNO_%ld (%s)", u_error,
2538 if ((sys_res & RVAL_STR) && tcp->auxstr)
2539 tprintf(" (%s)", tcp->auxstr);
2542 if (sys_res & RVAL_NONE)
2545 switch (sys_res & RVAL_MASK) {
2547 tprintf("= %#lx", tcp->u_rval);
2550 tprintf("= %#lo", tcp->u_rval);
2553 tprintf("= %lu", tcp->u_rval);
2556 tprintf("= %ld", tcp->u_rval);
2558 #if defined(LINUX_MIPSN32) || defined(X32)
2561 tprintf("= %#llx", tcp->u_lrval);
2564 tprintf("= %#llo", tcp->u_lrval);
2567 case RVAL_LUDECIMAL:
2568 tprintf("= %llu", tcp->u_lrval);
2572 tprintf("= %lld", tcp->u_lrval);
2578 "invalid rval format\n");
2582 if ((sys_res & RVAL_STR) && tcp->auxstr)
2583 tprintf(" (%s)", tcp->auxstr);
2586 tv_sub(&tv, &tv, &tcp->etime);
2587 tprintf(" <%ld.%06ld>",
2588 (long) tv.tv_sec, (long) tv.tv_usec);
2595 tcp->flags &= ~TCB_INSYSCALL;
2600 trace_syscall(struct tcb *tcp)
2602 return exiting(tcp) ?
2603 trace_syscall_exiting(tcp) : trace_syscall_entering(tcp);