2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Linux for s390 port by D.J. Barrow
8 * <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <sys/param.h>
40 # ifndef PTRACE_PEEKUSR
41 # define PTRACE_PEEKUSR PTRACE_PEEKUSER
43 #elif defined(HAVE_LINUX_PTRACE_H)
44 # undef PTRACE_SYSCALL
45 # ifdef HAVE_STRUCT_IA64_FPREG
46 # define ia64_fpreg XXX_ia64_fpreg
48 # ifdef HAVE_STRUCT_PT_ALL_USER_REGS
49 # define pt_all_user_regs XXX_pt_all_user_regs
51 # include <linux/ptrace.h>
53 # undef pt_all_user_regs
57 # undef PTRACE_GETREGS
58 # define PTRACE_GETREGS PTRACE_GETREGS64
59 # undef PTRACE_SETREGS
60 # define PTRACE_SETREGS PTRACE_SETREGS64
64 # include <asm/ptrace_offsets.h>
68 /* for struct iovec */
76 # include <asm/ptrace.h>
80 # define ERESTARTSYS 512
82 #ifndef ERESTARTNOINTR
83 # define ERESTARTNOINTR 513
85 #ifndef ERESTARTNOHAND
86 # define ERESTARTNOHAND 514 /* restart if no handler */
88 #ifndef ERESTART_RESTARTBLOCK
89 # define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
93 # warning: NSIG is not defined, using 32
97 /* Ugh. Is this really correct? ARM has no RT signals?! */
104 /* Define these shorthand notations to simplify the syscallent files. */
105 #define TD TRACE_DESC
106 #define TF TRACE_FILE
108 #define TN TRACE_NETWORK
109 #define TP TRACE_PROCESS
110 #define TS TRACE_SIGNAL
111 #define TM TRACE_MEMORY
112 #define NF SYSCALL_NEVER_FAILS
115 const struct_sysent sysent0[] = {
116 #include "syscallent.h"
119 #if SUPPORTED_PERSONALITIES > 1
120 static const struct_sysent sysent1[] = {
121 # include "syscallent1.h"
125 #if SUPPORTED_PERSONALITIES > 2
126 static const struct_sysent sysent2[] = {
127 # include "syscallent2.h"
131 /* Now undef them since short defines cause wicked namespace pollution. */
143 * `ioctlent.h' may be generated from `ioctlent.raw' by the auxiliary
144 * program `ioctlsort', such that the list is sorted by the `code' field.
145 * This has the side-effect of resolving the _IO.. macros into
146 * plain integers, eliminating the need to include here everything
150 const char *const errnoent0[] = {
151 #include "errnoent.h"
153 const char *const signalent0[] = {
154 #include "signalent.h"
156 const struct_ioctlent ioctlent0[] = {
157 #include "ioctlent.h"
160 #if SUPPORTED_PERSONALITIES > 1
161 static const char *const errnoent1[] = {
162 # include "errnoent1.h"
164 static const char *const signalent1[] = {
165 # include "signalent1.h"
167 static const struct_ioctlent ioctlent1[] = {
168 # include "ioctlent1.h"
172 #if SUPPORTED_PERSONALITIES > 2
173 static const char *const errnoent2[] = {
174 # include "errnoent2.h"
176 static const char *const signalent2[] = {
177 # include "signalent2.h"
179 static const struct_ioctlent ioctlent2[] = {
180 # include "ioctlent2.h"
185 nsyscalls0 = ARRAY_SIZE(sysent0)
186 #if SUPPORTED_PERSONALITIES > 1
187 , nsyscalls1 = ARRAY_SIZE(sysent1)
188 # if SUPPORTED_PERSONALITIES > 2
189 , nsyscalls2 = ARRAY_SIZE(sysent2)
195 nerrnos0 = ARRAY_SIZE(errnoent0)
196 #if SUPPORTED_PERSONALITIES > 1
197 , nerrnos1 = ARRAY_SIZE(errnoent1)
198 # if SUPPORTED_PERSONALITIES > 2
199 , nerrnos2 = ARRAY_SIZE(errnoent2)
205 nsignals0 = ARRAY_SIZE(signalent0)
206 #if SUPPORTED_PERSONALITIES > 1
207 , nsignals1 = ARRAY_SIZE(signalent1)
208 # if SUPPORTED_PERSONALITIES > 2
209 , nsignals2 = ARRAY_SIZE(signalent2)
215 nioctlents0 = ARRAY_SIZE(ioctlent0)
216 #if SUPPORTED_PERSONALITIES > 1
217 , nioctlents1 = ARRAY_SIZE(ioctlent1)
218 # if SUPPORTED_PERSONALITIES > 2
219 , nioctlents2 = ARRAY_SIZE(ioctlent2)
224 #if SUPPORTED_PERSONALITIES > 1
225 const struct_sysent *sysent = sysent0;
226 const char *const *errnoent = errnoent0;
227 const char *const *signalent = signalent0;
228 const struct_ioctlent *ioctlent = ioctlent0;
230 unsigned nsyscalls = nsyscalls0;
231 unsigned nerrnos = nerrnos0;
232 unsigned nsignals = nsignals0;
233 unsigned nioctlents = nioctlents0;
236 qualbits_t *qual_vec[SUPPORTED_PERSONALITIES];
238 static const unsigned nsyscall_vec[SUPPORTED_PERSONALITIES] = {
240 #if SUPPORTED_PERSONALITIES > 1
243 #if SUPPORTED_PERSONALITIES > 2
247 static const struct_sysent *const sysent_vec[SUPPORTED_PERSONALITIES] = {
249 #if SUPPORTED_PERSONALITIES > 1
252 #if SUPPORTED_PERSONALITIES > 2
258 MAX_NSYSCALLS1 = (nsyscalls0
259 #if SUPPORTED_PERSONALITIES > 1
260 > nsyscalls1 ? nsyscalls0 : nsyscalls1
263 MAX_NSYSCALLS2 = (MAX_NSYSCALLS1
264 #if SUPPORTED_PERSONALITIES > 2
265 > nsyscalls2 ? MAX_NSYSCALLS1 : nsyscalls2
268 MAX_NSYSCALLS = MAX_NSYSCALLS2,
269 /* We are ready for arches with up to 255 signals,
270 * even though the largest known signo is on MIPS and it is 128.
271 * The number of existing syscalls on all arches is
272 * larger that 255 anyway, so it is just a pedantic matter.
274 MIN_QUALS = MAX_NSYSCALLS > 255 ? MAX_NSYSCALLS : 255
277 #if SUPPORTED_PERSONALITIES > 1
278 unsigned current_personality;
280 # ifndef current_wordsize
281 unsigned current_wordsize;
282 static const int personality_wordsize[SUPPORTED_PERSONALITIES] = {
283 PERSONALITY0_WORDSIZE,
284 PERSONALITY1_WORDSIZE,
285 # if SUPPORTED_PERSONALITIES > 2
286 PERSONALITY2_WORDSIZE,
292 set_personality(int personality)
294 nsyscalls = nsyscall_vec[personality];
295 sysent = sysent_vec[personality];
297 switch (personality) {
299 errnoent = errnoent0;
301 ioctlent = ioctlent0;
302 nioctlents = nioctlents0;
303 signalent = signalent0;
304 nsignals = nsignals0;
308 errnoent = errnoent1;
310 ioctlent = ioctlent1;
311 nioctlents = nioctlents1;
312 signalent = signalent1;
313 nsignals = nsignals1;
316 # if SUPPORTED_PERSONALITIES > 2
318 errnoent = errnoent2;
320 ioctlent = ioctlent2;
321 nioctlents = nioctlents2;
322 signalent = signalent2;
323 nsignals = nsignals2;
328 current_personality = personality;
329 # ifndef current_wordsize
330 current_wordsize = personality_wordsize[personality];
335 update_personality(struct tcb *tcp, int personality)
337 if (personality == current_personality)
339 set_personality(personality);
341 if (personality == tcp->currpers)
343 tcp->currpers = personality;
345 # if defined(POWERPC64)
347 static const char *const names[] = {"64 bit", "32 bit"};
348 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
349 tcp->pid, names[personality]);
351 # elif defined(X86_64)
353 static const char *const names[] = {"64 bit", "32 bit", "x32"};
354 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
355 tcp->pid, names[personality]);
359 static const char *const names[] = {"x32", "32 bit"};
360 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
361 tcp->pid, names[personality]);
363 # elif defined(AARCH64)
365 static const char *const names[] = {"32-bit", "AArch64"};
366 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
367 tcp->pid, names[personality]);
371 static const char *const names[] = {"64-bit", "32-bit"};
372 fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
373 tcp->pid, names[personality]);
379 static int qual_syscall(), qual_signal(), qual_desc();
381 static const struct qual_options {
383 const char *option_name;
384 int (*qualify)(const char *, int, int);
385 const char *argument_name;
387 { QUAL_TRACE, "trace", qual_syscall, "system call" },
388 { QUAL_TRACE, "t", qual_syscall, "system call" },
389 { QUAL_ABBREV, "abbrev", qual_syscall, "system call" },
390 { QUAL_ABBREV, "a", qual_syscall, "system call" },
391 { QUAL_VERBOSE, "verbose", qual_syscall, "system call" },
392 { QUAL_VERBOSE, "v", qual_syscall, "system call" },
393 { QUAL_RAW, "raw", qual_syscall, "system call" },
394 { QUAL_RAW, "x", qual_syscall, "system call" },
395 { QUAL_SIGNAL, "signal", qual_signal, "signal" },
396 { QUAL_SIGNAL, "signals", qual_signal, "signal" },
397 { QUAL_SIGNAL, "s", qual_signal, "signal" },
398 { QUAL_READ, "read", qual_desc, "descriptor" },
399 { QUAL_READ, "reads", qual_desc, "descriptor" },
400 { QUAL_READ, "r", qual_desc, "descriptor" },
401 { QUAL_WRITE, "write", qual_desc, "descriptor" },
402 { QUAL_WRITE, "writes", qual_desc, "descriptor" },
403 { QUAL_WRITE, "w", qual_desc, "descriptor" },
404 { 0, NULL, NULL, NULL },
408 reallocate_qual(int n)
412 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
413 qp = qual_vec[p] = realloc(qual_vec[p], n * sizeof(qualbits_t));
416 memset(&qp[num_quals], 0, (n - num_quals) * sizeof(qualbits_t));
422 qualify_one(int n, int bitflag, int not, int pers)
427 reallocate_qual(n + 1);
429 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
430 if (pers == p || pers < 0) {
432 qual_vec[p][n] &= ~bitflag;
434 qual_vec[p][n] |= bitflag;
440 qual_syscall(const char *s, int bitflag, int not)
446 if (*s >= '0' && *s <= '9') {
447 i = string_to_uint(s);
448 if (i >= MAX_NSYSCALLS)
450 qualify_one(i, bitflag, not, -1);
454 for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
455 for (i = 0; i < nsyscall_vec[p]; i++) {
456 if (sysent_vec[p][i].sys_name
457 && strcmp(s, sysent_vec[p][i].sys_name) == 0
459 qualify_one(i, bitflag, not, p);
469 qual_signal(const char *s, int bitflag, int not)
473 if (*s >= '0' && *s <= '9') {
474 int signo = string_to_uint(s);
475 if (signo < 0 || signo > 255)
477 qualify_one(signo, bitflag, not, -1);
480 if (strncasecmp(s, "SIG", 3) == 0)
482 for (i = 0; i <= NSIG; i++) {
483 if (strcasecmp(s, signame(i) + 3) == 0) {
484 qualify_one(i, bitflag, not, -1);
492 qual_desc(const char *s, int bitflag, int not)
494 if (*s >= '0' && *s <= '9') {
495 int desc = string_to_uint(s);
496 if (desc < 0 || desc > 0x7fff) /* paranoia */
498 qualify_one(desc, bitflag, not, -1);
505 lookup_class(const char *s)
507 if (strcmp(s, "file") == 0)
509 if (strcmp(s, "ipc") == 0)
511 if (strcmp(s, "network") == 0)
512 return TRACE_NETWORK;
513 if (strcmp(s, "process") == 0)
514 return TRACE_PROCESS;
515 if (strcmp(s, "signal") == 0)
517 if (strcmp(s, "desc") == 0)
519 if (strcmp(s, "memory") == 0)
525 qualify(const char *s)
527 const struct qual_options *opt;
534 reallocate_qual(MIN_QUALS);
536 opt = &qual_options[0];
537 for (i = 0; (p = qual_options[i].option_name); i++) {
539 if (strncmp(s, p, n) == 0 && s[n] == '=') {
540 opt = &qual_options[i];
550 if (strcmp(s, "none") == 0) {
554 if (strcmp(s, "all") == 0) {
555 for (i = 0; i < num_quals; i++) {
556 qualify_one(i, opt->bitflag, not, -1);
560 for (i = 0; i < num_quals; i++) {
561 qualify_one(i, opt->bitflag, !not, -1);
566 for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) {
567 if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) {
569 for (pers = 0; pers < SUPPORTED_PERSONALITIES; pers++) {
570 for (i = 0; i < nsyscall_vec[pers]; i++)
571 if (sysent_vec[pers][i].sys_flags & n)
572 qualify_one(i, opt->bitflag, not, pers);
576 if (opt->qualify(p, opt->bitflag, not)) {
577 error_msg_and_die("invalid %s '%s'",
578 opt->argument_name, p);
585 #ifdef SYS_socket_subcall
587 decode_socket_subcall(struct tcb *tcp)
590 unsigned int i, n, size;
592 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_socket_nsubcalls)
595 tcp->scno = SYS_socket_subcall + tcp->u_arg[0];
596 tcp->qual_flg = qual_flags[tcp->scno];
597 tcp->s_ent = &sysent[tcp->scno];
598 addr = tcp->u_arg[1];
599 size = current_wordsize;
600 n = tcp->s_ent->nargs;
601 for (i = 0; i < n; ++i) {
602 if (size == sizeof(int)) {
604 if (umove(tcp, addr, &arg) < 0)
610 if (umove(tcp, addr, &arg) < 0)
619 #ifdef SYS_ipc_subcall
621 decode_ipc_subcall(struct tcb *tcp)
625 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= SYS_ipc_nsubcalls)
628 tcp->scno = SYS_ipc_subcall + tcp->u_arg[0];
629 tcp->qual_flg = qual_flags[tcp->scno];
630 tcp->s_ent = &sysent[tcp->scno];
631 n = tcp->s_ent->nargs;
632 for (i = 0; i < n; i++)
633 tcp->u_arg[i] = tcp->u_arg[i + 1];
638 printargs(struct tcb *tcp)
642 int n = tcp->s_ent->nargs;
643 for (i = 0; i < n; i++)
644 tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]);
650 printargs_lu(struct tcb *tcp)
654 int n = tcp->s_ent->nargs;
655 for (i = 0; i < n; i++)
656 tprintf("%s%lu", i ? ", " : "", tcp->u_arg[i]);
662 printargs_ld(struct tcb *tcp)
666 int n = tcp->s_ent->nargs;
667 for (i = 0; i < n; i++)
668 tprintf("%s%ld", i ? ", " : "", tcp->u_arg[i]);
673 #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH)
675 getrval2(struct tcb *tcp)
679 # if defined(SPARC) || defined(SPARC64)
680 val = sparc_regs.u_regs[U_REG_O1];
682 if (upeek(tcp, 4*(REG_REG0+1), &val) < 0)
685 if (upeek(tcp, PT_R9, &val) < 0)
694 is_restart_error(struct tcb *tcp)
696 switch (tcp->u_error) {
700 case ERESTART_RESTARTBLOCK:
709 struct user_regs_struct i386_regs;
710 #elif defined(X86_64) || defined(X32)
712 * On i386, pt_regs and user_regs_struct are the same,
713 * but on 64 bit x86, user_regs_struct has six more fields:
714 * fs_base, gs_base, ds, es, fs, gs.
715 * PTRACE_GETREGS fills them too, so struct pt_regs would overflow.
717 struct i386_user_regs_struct {
737 struct user_regs_struct x86_64_r;
738 struct i386_user_regs_struct i386_r;
740 # define x86_64_regs x86_regs_union.x86_64_r
741 # define i386_regs x86_regs_union.i386_r
742 static struct iovec x86_io = {
743 .iov_base = &x86_regs_union
746 long ia32 = 0; /* not static */
747 static long ia64_r8, ia64_r10;
748 #elif defined(POWERPC)
749 static long ppc_result;
755 struct pt_regs arm_regs; /* not static */
756 #elif defined(AARCH64)
758 struct user_pt_regs aarch64_r;
759 struct arm_pt_regs arm_r;
761 # define aarch64_regs arm_regs_union.aarch64_r
762 # define arm_regs arm_regs_union.arm_r
763 static struct iovec aarch64_io = {
764 .iov_base = &arm_regs_union
767 static long alpha_r0;
768 static long alpha_a3;
770 static struct pt_regs avr32_regs;
771 #elif defined(SPARC) || defined(SPARC64)
772 struct pt_regs sparc_regs; /* not static */
773 #elif defined(LINUX_MIPSN32)
774 static long long mips_a3;
775 static long long mips_r2;
779 #elif defined(S390) || defined(S390X)
781 static long syscall_mode;
783 static long hppa_r28;
788 #elif defined(CRISV10) || defined(CRISV32)
789 static long cris_r10;
791 struct pt_regs tile_regs;
792 #elif defined(MICROBLAZE)
793 static long microblaze_r3;
795 static struct user_regs_struct or1k_regs;
796 static struct iovec or1k_io = {
797 .iov_base = &or1k_regs
800 static struct user_gp_regs metag_regs;
801 static struct iovec metag_io = {
802 .iov_base = &metag_regs
807 printcall(struct tcb *tcp)
809 #define PRINTBADPC tprintf(sizeof(long) == 4 ? "[????????] " : \
810 sizeof(long) == 8 ? "[????????????????] " : \
812 if (get_regs_error) {
817 tprintf("[%08lx] ", i386_regs.eip);
818 #elif defined(S390) || defined(S390X)
820 if (upeek(tcp, PT_PSWADDR, &psw) < 0) {
825 tprintf("[%08lx] ", psw);
827 tprintf("[%016lx] ", psw);
829 #elif defined(X86_64) || defined(X32)
830 if (x86_io.iov_len == sizeof(i386_regs)) {
831 tprintf("[%08x] ", (unsigned) i386_regs.eip);
834 tprintf("[%016lx] ", (unsigned long) x86_64_regs.rip);
836 /* Note: this truncates 64-bit rip to 32 bits */
837 tprintf("[%08lx] ", (unsigned long) x86_64_regs.rip);
842 if (upeek(tcp, PT_B0, &ip) < 0) {
846 tprintf("[%08lx] ", ip);
847 #elif defined(POWERPC)
849 if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &pc) < 0) {
854 tprintf("[%016lx] ", pc);
856 tprintf("[%08lx] ", pc);
860 if (upeek(tcp, 4*PT_PC, &pc) < 0) {
861 tprints("[????????] ");
864 tprintf("[%08lx] ", pc);
867 if (upeek(tcp, REG_PC, &pc) < 0) {
868 tprints("[????????????????] ");
871 tprintf("[%08lx] ", pc);
873 tprintf("[%08lx] ", sparc_regs.pc);
874 #elif defined(SPARC64)
875 tprintf("[%08lx] ", sparc_regs.tpc);
878 if (upeek(tcp, PT_IAOQ0, &pc) < 0) {
879 tprints("[????????] ");
882 tprintf("[%08lx] ", pc);
885 if (upeek(tcp, REG_EPC, &pc) < 0) {
886 tprints("[????????] ");
889 tprintf("[%08lx] ", pc);
892 if (upeek(tcp, 4*REG_PC, &pc) < 0) {
893 tprints("[????????] ");
896 tprintf("[%08lx] ", pc);
899 if (upeek(tcp, REG_PC, &pc) < 0) {
900 tprints("[????????????????] ");
903 tprintf("[%08lx] ", pc);
905 tprintf("[%08lx] ", arm_regs.ARM_pc);
906 #elif defined(AARCH64)
907 /* tprintf("[%016lx] ", aarch64_regs.regs[???]); */
909 tprintf("[%08lx] ", avr32_regs.pc);
912 if (upeek(tcp, PT_PC, &pc) < 0) {
916 tprintf("[%08lx] ", pc);
917 #elif defined(CRISV10)
919 if (upeek(tcp, 4*PT_IRP, &pc) < 0) {
923 tprintf("[%08lx] ", pc);
924 #elif defined(CRISV32)
926 if (upeek(tcp, 4*PT_ERP, &pc) < 0) {
930 tprintf("[%08lx] ", pc);
933 tprintf("[%016lx] ", (unsigned long) tile_regs.pc);
935 tprintf("[%08lx] ", (unsigned long) tile_regs.pc);
938 tprintf("[%08lx] ", or1k_regs.pc);
940 tprintf("[%08lx] ", metag_regs.pc);
941 #endif /* architecture */
944 /* Shuffle syscall numbers so that we don't have huge gaps in syscall table.
945 * The shuffling should be reversible: shuffle_scno(shuffle_scno(n)) == n.
947 #if defined(ARM) /* So far only ARM needs this */
949 shuffle_scno(unsigned long scno)
951 if (scno <= ARM_LAST_ORDINARY_SYSCALL)
954 /* __ARM_NR_cmpxchg? Swap with LAST_ORDINARY+1 */
955 if (scno == 0x000ffff0)
956 return ARM_LAST_ORDINARY_SYSCALL+1;
957 if (scno == ARM_LAST_ORDINARY_SYSCALL+1)
960 /* Is it ARM specific syscall?
961 * Swap with [LAST_ORDINARY+2, LAST_ORDINARY+2 + LAST_SPECIAL] range.
963 if (scno >= 0x000f0000
964 && scno <= 0x000f0000 + ARM_LAST_SPECIAL_SYSCALL
966 return scno - 0x000f0000 + (ARM_LAST_ORDINARY_SYSCALL+2);
968 if (/* scno >= ARM_LAST_ORDINARY_SYSCALL+2 - always true */ 1
969 && scno <= (ARM_LAST_ORDINARY_SYSCALL+2) + ARM_LAST_SPECIAL_SYSCALL
971 return scno + 0x000f0000 - (ARM_LAST_ORDINARY_SYSCALL+2);
977 # define shuffle_scno(scno) ((long)(scno))
981 undefined_scno_name(struct tcb *tcp)
983 static char buf[sizeof("syscall_%lu") + sizeof(long)*3];
985 sprintf(buf, "syscall_%lu", shuffle_scno(tcp->scno));
992 #if defined(PTRACE_GETREGSET) && defined(NT_PRSTATUS)
994 static void get_regset(pid_t pid)
996 static struct iovec arm_io = {
997 .iov_base = &arm_regs,
998 .iov_len = sizeof(arm_regs)
1000 get_regs_error = ptrace(PTRACE_GETREGSET, pid,
1001 NT_PRSTATUS, (long) &arm_io);
1003 # elif defined(I386)
1004 static void get_regset(pid_t pid)
1006 static struct iovec i386_io = {
1007 .iov_base = &i386_regs,
1008 .iov_len = sizeof(i386_regs)
1010 get_regs_error = ptrace(PTRACE_GETREGSET, pid,
1011 NT_PRSTATUS, (long) &i386_io);
1013 # elif defined(X86_64)
1014 static void get_regset(pid_t pid)
1016 /* x86_io.iov_base = &x86_regs_union; - already is */
1017 x86_io.iov_len = sizeof(x86_regs_union);
1018 get_regs_error = ptrace(PTRACE_GETREGSET, pid,
1019 NT_PRSTATUS, (long) &x86_io);
1022 #endif /* PTRACE_GETREGSET && NT_PRSTATUS */
1027 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &avr32_regs);
1029 /* x86_io.iov_base = &x86_regs_union; - already is */
1030 x86_io.iov_len = sizeof(x86_regs_union);
1031 get_regs_error = ptrace(PTRACE_GETREGSET, pid,
1032 NT_PRSTATUS, (long) &x86_io);
1033 # elif defined(ARM) || defined(I386) || defined(X86_64)
1034 # if defined(PTRACE_GETREGSET) && defined(NT_PRSTATUS)
1035 static int getregset_support;
1037 if (getregset_support >= 0) {
1039 if (getregset_support > 0)
1041 if (get_regs_error >= 0) {
1042 getregset_support = 1;
1045 if (errno == EPERM || errno == ESRCH)
1047 getregset_support = -1;
1049 # endif /* PTRACE_GETREGSET && NT_PRSTATUS */
1051 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &arm_regs);
1052 # elif defined(I386)
1053 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &i386_regs);
1054 # elif defined(X86_64)
1055 /* Use old method, with unreliable heuristical detection of 32-bitness. */
1056 x86_io.iov_len = sizeof(x86_64_regs);
1057 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &x86_64_regs);
1058 if (!get_regs_error && x86_64_regs.cs == 0x23) {
1059 x86_io.iov_len = sizeof(i386_regs);
1061 * The order is important: i386_regs and x86_64_regs
1062 * are overlaid in memory!
1064 i386_regs.ebx = x86_64_regs.rbx;
1065 i386_regs.ecx = x86_64_regs.rcx;
1066 i386_regs.edx = x86_64_regs.rdx;
1067 i386_regs.esi = x86_64_regs.rsi;
1068 i386_regs.edi = x86_64_regs.rdi;
1069 i386_regs.ebp = x86_64_regs.rbp;
1070 i386_regs.eax = x86_64_regs.rax;
1071 /* i386_regs.xds = x86_64_regs.ds; unused by strace */
1072 /* i386_regs.xes = x86_64_regs.es; ditto... */
1073 /* i386_regs.xfs = x86_64_regs.fs; */
1074 /* i386_regs.xgs = x86_64_regs.gs; */
1075 i386_regs.orig_eax = x86_64_regs.orig_rax;
1076 i386_regs.eip = x86_64_regs.rip;
1077 /* i386_regs.xcs = x86_64_regs.cs; */
1078 /* i386_regs.eflags = x86_64_regs.eflags; */
1079 i386_regs.esp = x86_64_regs.rsp;
1080 /* i386_regs.xss = x86_64_regs.ss; */
1084 # endif /* ARM || I386 || X86_64 */
1085 # elif defined(AARCH64)
1086 /*aarch64_io.iov_base = &arm_regs_union; - already is */
1087 aarch64_io.iov_len = sizeof(arm_regs_union);
1088 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, (void *)&aarch64_io);
1090 /* Paranoia checks */
1093 switch (aarch64_io.iov_len) {
1094 case sizeof(aarch64_regs):
1095 /* We are in 64-bit mode */
1097 case sizeof(arm_regs):
1098 /* We are in 32-bit mode */
1101 get_regs_error = -1;
1105 # elif defined(SPARC) || defined(SPARC64)
1106 get_regs_error = ptrace(PTRACE_GETREGS, pid, (char *)&sparc_regs, 0);
1107 # elif defined(TILE)
1108 get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, (long) &tile_regs);
1109 # elif defined(OR1K)
1110 or1k_io.iov_len = sizeof(or1k_regs);
1111 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &or1k_io);
1112 # elif defined(METAG)
1113 metag_io.iov_len = sizeof(metag_regs);
1114 get_regs_error = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &metag_io);
1120 * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently.
1121 * 1: ok, continue in trace_syscall_entering().
1122 * other: error, trace_syscall_entering() should print error indicator
1123 * ("????" etc) and bail out.
1126 get_scno(struct tcb *tcp)
1130 #if defined(S390) || defined(S390X)
1131 if (upeek(tcp, PT_GPR2, &syscall_mode) < 0)
1134 if (syscall_mode != -ENOSYS) {
1136 * Since kernel version 2.5.44 the scno gets passed in gpr2.
1138 scno = syscall_mode;
1141 * Old style of "passing" the scno via the SVC instruction.
1144 long opcode, offset_reg, tmp;
1146 static const int gpr_offset[16] = {
1147 PT_GPR0, PT_GPR1, PT_ORIGGPR2, PT_GPR3,
1148 PT_GPR4, PT_GPR5, PT_GPR6, PT_GPR7,
1149 PT_GPR8, PT_GPR9, PT_GPR10, PT_GPR11,
1150 PT_GPR12, PT_GPR13, PT_GPR14, PT_GPR15
1153 if (upeek(tcp, PT_PSWADDR, &psw) < 0)
1156 opcode = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(psw - sizeof(long)), 0);
1158 perror_msg("peektext(psw-oneword)");
1163 * We have to check if the SVC got executed directly or via an
1164 * EXECUTE instruction. In case of EXECUTE it is necessary to do
1165 * instruction decoding to derive the system call number.
1166 * Unfortunately the opcode sizes of EXECUTE and SVC are differently,
1167 * so that this doesn't work if a SVC opcode is part of an EXECUTE
1168 * opcode. Since there is no way to find out the opcode size this
1169 * is the best we can do...
1171 if ((opcode & 0xff00) == 0x0a00) {
1173 scno = opcode & 0xff;
1176 /* SVC got executed by EXECUTE instruction */
1179 * Do instruction decoding of EXECUTE. If you really want to
1180 * understand this, read the Principles of Operations.
1182 svc_addr = (void *) (opcode & 0xfff);
1185 offset_reg = (opcode & 0x000f0000) >> 16;
1186 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1191 offset_reg = (opcode & 0x0000f000) >> 12;
1192 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1196 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, svc_addr, 0);
1205 offset_reg = (opcode & 0x00f00000) >> 20;
1206 if (offset_reg && (upeek(tcp, gpr_offset[offset_reg], &tmp) < 0))
1209 scno = (scno | tmp) & 0xff;
1212 #elif defined(POWERPC)
1213 if (upeek(tcp, sizeof(unsigned long)*PT_R0, &scno) < 0)
1216 /* TODO: speed up strace by not doing this at every syscall.
1217 * We only need to do it after execve.
1222 /* Check for 64/32 bit mode. */
1223 if (upeek(tcp, sizeof(unsigned long)*PT_MSR, &val) < 0)
1225 /* SF is bit 0 of MSR */
1230 update_personality(tcp, currpers);
1232 #elif defined(AVR32)
1233 scno = avr32_regs.r8;
1235 if (upeek(tcp, PT_ORIG_P0, &scno))
1238 scno = i386_regs.orig_eax;
1239 #elif defined(X86_64) || defined(X32)
1240 # ifndef __X32_SYSCALL_BIT
1241 # define __X32_SYSCALL_BIT 0x40000000
1245 /* GETREGSET of NT_PRSTATUS tells us regset size,
1246 * which unambiguously detects i386.
1248 * Linux kernel distinguishes x86-64 and x32 processes
1249 * solely by looking at __X32_SYSCALL_BIT:
1250 * arch/x86/include/asm/compat.h::is_x32_task():
1251 * if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
1254 if (x86_io.iov_len == sizeof(i386_regs)) {
1255 scno = i386_regs.orig_eax;
1258 scno = x86_64_regs.orig_rax;
1260 if (scno & __X32_SYSCALL_BIT) {
1261 scno -= __X32_SYSCALL_BIT;
1266 /* cs = 0x33 for long mode (native 64 bit and x32)
1267 * cs = 0x23 for compatibility mode (32 bit)
1268 * ds = 0x2b for x32 mode (x86-64 in 32 bit)
1270 scno = x86_64_regs.orig_rax;
1271 switch (x86_64_regs.cs) {
1272 case 0x23: currpers = 1; break;
1274 if (x86_64_regs.ds == 0x2b) {
1276 scno &= ~__X32_SYSCALL_BIT;
1281 fprintf(stderr, "Unknown value CS=0x%08X while "
1282 "detecting personality of process "
1283 "PID=%d\n", (int)x86_64_regs.cs, tcp->pid);
1284 currpers = current_personality;
1288 /* This version analyzes the opcode of a syscall instruction.
1289 * (int 0x80 on i386 vs. syscall on x86-64)
1290 * It works, but is too complicated, and strictly speaking, unreliable.
1292 unsigned long call, rip = x86_64_regs.rip;
1293 /* sizeof(syscall) == sizeof(int 0x80) == 2 */
1296 call = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)rip, (char *)0);
1298 fprintf(stderr, "ptrace_peektext failed: %s\n",
1300 switch (call & 0xffff) {
1301 /* x86-64: syscall = 0x0f 0x05 */
1302 case 0x050f: currpers = 0; break;
1303 /* i386: int 0x80 = 0xcd 0x80 */
1304 case 0x80cd: currpers = 1; break;
1306 currpers = current_personality;
1308 "Unknown syscall opcode (0x%04X) while "
1309 "detecting personality of process "
1310 "PID=%d\n", (int)call, tcp->pid);
1316 /* If we are built for a x32 system, then personality 0 is x32
1317 * (not x86_64), and stracing of x86_64 apps is not supported.
1318 * Stracing of i386 apps is still supported.
1320 if (currpers == 0) {
1321 fprintf(stderr, "syscall_%lu(...) in unsupported "
1322 "64-bit mode of process PID=%d\n",
1326 currpers &= ~2; /* map 2,1 to 0,1 */
1328 update_personality(tcp, currpers);
1330 # define IA64_PSR_IS ((long)1 << 34)
1332 if (upeek(tcp, PT_CR_IPSR, &psr) >= 0)
1333 ia32 = (psr & IA64_PSR_IS) != 0;
1335 if (upeek(tcp, PT_R1, &scno) < 0)
1338 if (upeek(tcp, PT_R15, &scno) < 0)
1341 #elif defined(AARCH64)
1342 switch (aarch64_io.iov_len) {
1343 case sizeof(aarch64_regs):
1344 /* We are in 64-bit mode */
1345 scno = aarch64_regs.regs[8];
1346 update_personality(tcp, 1);
1348 case sizeof(arm_regs):
1349 /* We are in 32-bit mode */
1350 scno = arm_regs.ARM_r7;
1351 update_personality(tcp, 0);
1355 if (arm_regs.ARM_ip != 0) {
1356 /* It is not a syscall entry */
1357 fprintf(stderr, "pid %d stray syscall exit\n", tcp->pid);
1358 tcp->flags |= TCB_INSYSCALL;
1361 /* Note: we support only 32-bit CPUs, not 26-bit */
1363 if (arm_regs.ARM_cpsr & 0x20) {
1365 scno = arm_regs.ARM_r7;
1369 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(arm_regs.ARM_pc - 4), NULL);
1373 /* EABI syscall convention? */
1374 if (scno == 0xef000000) {
1375 scno = arm_regs.ARM_r7; /* yes */
1377 if ((scno & 0x0ff00000) != 0x0f900000) {
1378 fprintf(stderr, "pid %d unknown syscall trap 0x%08lx\n",
1382 /* Fixup the syscall number */
1387 scno = shuffle_scno(scno);
1389 if (upeek(tcp, 4*PT_ORIG_D0, &scno) < 0)
1391 #elif defined(LINUX_MIPSN32)
1392 unsigned long long regs[38];
1394 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
1396 mips_a3 = regs[REG_A3];
1397 mips_r2 = regs[REG_V0];
1400 if (!SCNO_IN_RANGE(scno)) {
1401 if (mips_a3 == 0 || mips_a3 == -1) {
1403 fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
1408 if (upeek(tcp, REG_A3, &mips_a3) < 0)
1410 if (upeek(tcp, REG_V0, &scno) < 0)
1413 if (!SCNO_IN_RANGE(scno)) {
1414 if (mips_a3 == 0 || mips_a3 == -1) {
1416 fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
1420 #elif defined(ALPHA)
1421 if (upeek(tcp, REG_A3, &alpha_a3) < 0)
1423 if (upeek(tcp, REG_R0, &scno) < 0)
1427 * Do some sanity checks to figure out if it's
1428 * really a syscall entry
1430 if (!SCNO_IN_RANGE(scno)) {
1431 if (alpha_a3 == 0 || alpha_a3 == -1) {
1433 fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno);
1437 #elif defined(SPARC) || defined(SPARC64)
1438 /* Disassemble the syscall trap. */
1439 /* Retrieve the syscall trap instruction. */
1442 # if defined(SPARC64)
1443 trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.tpc, 0);
1446 trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.pc, 0);
1451 /* Disassemble the trap to see what personality to use. */
1454 /* Linux/SPARC syscall trap. */
1455 update_personality(tcp, 0);
1458 /* Linux/SPARC64 syscall trap. */
1459 update_personality(tcp, 2);
1462 /* SunOS syscall trap. (pers 1) */
1463 fprintf(stderr, "syscall: SunOS no support\n");
1466 /* Solaris 2.x syscall trap. (per 2) */
1467 update_personality(tcp, 1);
1470 /* NetBSD/FreeBSD syscall trap. */
1471 fprintf(stderr, "syscall: NetBSD/FreeBSD not supported\n");
1474 /* Solaris 2.x gettimeofday */
1475 update_personality(tcp, 1);
1478 # if defined(SPARC64)
1479 fprintf(stderr, "syscall: unknown syscall trap %08lx %016lx\n", trap, sparc_regs.tpc);
1481 fprintf(stderr, "syscall: unknown syscall trap %08lx %08lx\n", trap, sparc_regs.pc);
1486 /* Extract the system call number from the registers. */
1487 if (trap == 0x91d02027)
1490 scno = sparc_regs.u_regs[U_REG_G1];
1492 scno = sparc_regs.u_regs[U_REG_O0];
1493 memmove(&sparc_regs.u_regs[U_REG_O0], &sparc_regs.u_regs[U_REG_O1], 7*sizeof(sparc_regs.u_regs[0]));
1496 if (upeek(tcp, PT_GR20, &scno) < 0)
1500 * In the new syscall ABI, the system call number is in R3.
1502 if (upeek(tcp, 4*(REG_REG0+3), &scno) < 0)
1506 /* Odd as it may seem, a glibc bug has been known to cause
1507 glibc to issue bogus negative syscall numbers. So for
1508 our purposes, make strace print what it *should* have been */
1509 long correct_scno = (scno & 0xff);
1512 "Detected glibc bug: bogus system call"
1513 " number = %ld, correcting to %ld\n",
1516 scno = correct_scno;
1519 if (upeek(tcp, REG_SYSCALL, &scno) < 0)
1522 #elif defined(CRISV10) || defined(CRISV32)
1523 if (upeek(tcp, 4*PT_R9, &scno) < 0)
1527 scno = tile_regs.regs[10];
1531 # ifndef PT_FLAGS_COMPAT
1532 # define PT_FLAGS_COMPAT 0x10000 /* from Linux 3.8 on */
1534 if (tile_regs.flags & PT_FLAGS_COMPAT)
1539 update_personality(tcp, currpers);
1540 #elif defined(MICROBLAZE)
1541 if (upeek(tcp, 0, &scno) < 0)
1544 scno = or1k_regs.gpr[11];
1545 #elif defined(METAG)
1546 scno = metag_regs.dx[0][1]; /* syscall number in D1Re0 (D1.0) */
1550 if (SCNO_IS_VALID(tcp->scno)) {
1551 tcp->s_ent = &sysent[scno];
1552 tcp->qual_flg = qual_flags[scno];
1554 static const struct_sysent unknown = {
1557 .sys_func = printargs,
1558 .sys_name = "unknown", /* not used */
1560 tcp->s_ent = &unknown;
1561 tcp->qual_flg = UNDEFINED_SCNO | QUAL_RAW | DEFAULT_QUAL_FLAGS;
1566 /* Called at each syscall entry.
1568 * 0: "ignore this ptrace stop", bail out of trace_syscall_entering() silently.
1569 * 1: ok, continue in trace_syscall_entering().
1570 * other: error, trace_syscall_entering() should print error indicator
1571 * ("????" etc) and bail out.
1574 syscall_fixup_on_sysenter(struct tcb *tcp)
1576 /* A common case of "not a syscall entry" is post-execve SIGTRAP */
1578 if (i386_regs.eax != -ENOSYS) {
1580 fprintf(stderr, "not a syscall entry (eax = %ld)\n", i386_regs.eax);
1583 #elif defined(X86_64) || defined(X32)
1586 if (x86_io.iov_len == sizeof(i386_regs)) {
1587 /* Sign extend from 32 bits */
1588 rax = (int32_t)i386_regs.eax;
1590 /* Note: in X32 build, this truncates 64 to 32 bits */
1591 rax = x86_64_regs.rax;
1593 if (rax != -ENOSYS) {
1595 fprintf(stderr, "not a syscall entry (rax = %ld)\n", rax);
1599 #elif defined(S390) || defined(S390X)
1600 /* TODO: we already fetched PT_GPR2 in get_scno
1601 * and stored it in syscall_mode, reuse it here
1602 * instead of re-fetching?
1604 if (upeek(tcp, PT_GPR2, &gpr2) < 0)
1606 if (syscall_mode != -ENOSYS)
1607 syscall_mode = tcp->scno;
1608 if (gpr2 != syscall_mode) {
1610 fprintf(stderr, "not a syscall entry (gpr2 = %ld)\n", gpr2);
1614 /* TODO? Eliminate upeek's in arches below like we did in x86 */
1615 if (upeek(tcp, 4*PT_D0, &m68k_d0) < 0)
1617 if (m68k_d0 != -ENOSYS) {
1619 fprintf(stderr, "not a syscall entry (d0 = %ld)\n", m68k_d0);
1623 if (upeek(tcp, PT_R10, &ia64_r10) < 0)
1625 if (upeek(tcp, PT_R8, &ia64_r8) < 0)
1627 if (ia32 && ia64_r8 != -ENOSYS) {
1629 fprintf(stderr, "not a syscall entry (r8 = %ld)\n", ia64_r8);
1632 #elif defined(CRISV10) || defined(CRISV32)
1633 if (upeek(tcp, 4*PT_R10, &cris_r10) < 0)
1635 if (cris_r10 != -ENOSYS) {
1637 fprintf(stderr, "not a syscall entry (r10 = %ld)\n", cris_r10);
1640 #elif defined(MICROBLAZE)
1641 if (upeek(tcp, 3 * 4, µblaze_r3) < 0)
1643 if (microblaze_r3 != -ENOSYS) {
1645 fprintf(stderr, "not a syscall entry (r3 = %ld)\n", microblaze_r3);
1653 internal_fork(struct tcb *tcp)
1655 #if defined S390 || defined S390X || defined CRISV10 || defined CRISV32
1656 # define ARG_FLAGS 1
1658 # define ARG_FLAGS 0
1660 #ifndef CLONE_UNTRACED
1661 # define CLONE_UNTRACED 0x00800000
1663 if ((ptrace_setoptions
1664 & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
1665 == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
1671 if (entering(tcp)) {
1673 * We won't see the new child if clone is called with
1674 * CLONE_UNTRACED, so we keep the same logic with that option
1675 * and don't trace it.
1677 if ((tcp->s_ent->sys_func == sys_clone)
1678 && (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED)
1683 if (tcp->flags & TCB_BPTSET)
1688 #if defined(TCB_WAITEXECVE)
1690 internal_exec(struct tcb *tcp)
1692 /* Maybe we have post-execve SIGTRAP suppressed? */
1693 if (ptrace_setoptions & PTRACE_O_TRACEEXEC)
1694 return; /* yes, no need to do anything */
1696 if (exiting(tcp) && syserror(tcp))
1697 /* Error in execve, no post-execve SIGTRAP expected */
1698 tcp->flags &= ~TCB_WAITEXECVE;
1700 tcp->flags |= TCB_WAITEXECVE;
1705 syscall_fixup_for_fork_exec(struct tcb *tcp)
1708 * We must always trace a few critical system calls in order to
1709 * correctly support following forks in the presence of tracing
1714 func = tcp->s_ent->sys_func;
1716 if ( sys_fork == func
1717 || sys_vfork == func
1718 || sys_clone == func
1724 #if defined(TCB_WAITEXECVE)
1725 if ( sys_execve == func
1726 # if defined(SPARC) || defined(SPARC64)
1727 || sys_execv == func
1736 /* Return -1 on error or 1 on success (never 0!) */
1738 get_syscall_args(struct tcb *tcp)
1742 nargs = tcp->s_ent->nargs;
1744 #if defined(S390) || defined(S390X)
1745 for (i = 0; i < nargs; ++i)
1746 if (upeek(tcp, i==0 ? PT_ORIGGPR2 : PT_GPR2 + i*sizeof(long), &tcp->u_arg[i]) < 0)
1748 #elif defined(ALPHA)
1749 for (i = 0; i < nargs; ++i)
1750 if (upeek(tcp, REG_A0+i, &tcp->u_arg[i]) < 0)
1754 unsigned long *out0, cfm, sof, sol;
1756 /* be backwards compatible with kernel < 2.4.4... */
1758 # define PT_RBS_END PT_AR_BSP
1761 if (upeek(tcp, PT_RBS_END, &rbs_end) < 0)
1763 if (upeek(tcp, PT_CFM, (long *) &cfm) < 0)
1766 sof = (cfm >> 0) & 0x7f;
1767 sol = (cfm >> 7) & 0x7f;
1768 out0 = ia64_rse_skip_regs((unsigned long *) rbs_end, -sof + sol);
1770 for (i = 0; i < nargs; ++i) {
1771 if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i),
1772 sizeof(long), (char *) &tcp->u_arg[i]) < 0)
1776 static const int argreg[MAX_ARGS] = { PT_R11 /* EBX = out0 */,
1777 PT_R9 /* ECX = out1 */,
1778 PT_R10 /* EDX = out2 */,
1779 PT_R14 /* ESI = out3 */,
1780 PT_R15 /* EDI = out4 */,
1781 PT_R13 /* EBP = out5 */};
1783 for (i = 0; i < nargs; ++i) {
1784 if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
1786 /* truncate away IVE sign-extension */
1787 tcp->u_arg[i] &= 0xffffffff;
1790 #elif defined(LINUX_MIPSN32) || defined(LINUX_MIPSN64)
1791 /* N32 and N64 both use up to six registers. */
1792 unsigned long long regs[38];
1794 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
1797 for (i = 0; i < nargs; ++i) {
1798 tcp->u_arg[i] = regs[REG_A0 + i];
1799 # if defined(LINUX_MIPSN32)
1800 tcp->ext_arg[i] = regs[REG_A0 + i];
1807 if (upeek(tcp, REG_SP, &sp) < 0)
1809 for (i = 0; i < 4; ++i)
1810 if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
1812 umoven(tcp, sp + 16, (nargs - 4) * sizeof(tcp->u_arg[0]),
1813 (char *)(tcp->u_arg + 4));
1815 for (i = 0; i < nargs; ++i)
1816 if (upeek(tcp, REG_A0 + i, &tcp->u_arg[i]) < 0)
1819 #elif defined(POWERPC)
1821 # define PT_ORIG_R3 34
1823 for (i = 0; i < nargs; ++i) {
1824 if (upeek(tcp, (i==0) ?
1825 (sizeof(unsigned long) * PT_ORIG_R3) :
1826 ((i+PT_R3) * sizeof(unsigned long)),
1827 &tcp->u_arg[i]) < 0)
1830 #elif defined(SPARC) || defined(SPARC64)
1831 for (i = 0; i < nargs; ++i)
1832 tcp->u_arg[i] = sparc_regs.u_regs[U_REG_O0 + i];
1834 for (i = 0; i < nargs; ++i)
1835 if (upeek(tcp, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
1837 #elif defined(ARM) || defined(AARCH64)
1838 # if defined(AARCH64)
1839 if (tcp->currpers == 1)
1840 for (i = 0; i < nargs; ++i)
1841 tcp->u_arg[i] = aarch64_regs.regs[i];
1844 for (i = 0; i < nargs; ++i)
1845 tcp->u_arg[i] = arm_regs.uregs[i];
1846 #elif defined(AVR32)
1849 tcp->u_arg[0] = avr32_regs.r12;
1850 tcp->u_arg[1] = avr32_regs.r11;
1851 tcp->u_arg[2] = avr32_regs.r10;
1852 tcp->u_arg[3] = avr32_regs.r9;
1853 tcp->u_arg[4] = avr32_regs.r5;
1854 tcp->u_arg[5] = avr32_regs.r3;
1856 static const int argreg[MAX_ARGS] = { PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5 };
1858 for (i = 0; i < nargs; ++i)
1859 if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
1862 static const int syscall_regs[MAX_ARGS] = {
1863 4 * (REG_REG0+4), 4 * (REG_REG0+5), 4 * (REG_REG0+6),
1864 4 * (REG_REG0+7), 4 * (REG_REG0 ), 4 * (REG_REG0+1)
1867 for (i = 0; i < nargs; ++i)
1868 if (upeek(tcp, syscall_regs[i], &tcp->u_arg[i]) < 0)
1872 /* Registers used by SH5 Linux system calls for parameters */
1873 static const int syscall_regs[MAX_ARGS] = { 2, 3, 4, 5, 6, 7 };
1875 for (i = 0; i < nargs; ++i)
1876 if (upeek(tcp, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0)
1881 tcp->u_arg[0] = i386_regs.ebx;
1882 tcp->u_arg[1] = i386_regs.ecx;
1883 tcp->u_arg[2] = i386_regs.edx;
1884 tcp->u_arg[3] = i386_regs.esi;
1885 tcp->u_arg[4] = i386_regs.edi;
1886 tcp->u_arg[5] = i386_regs.ebp;
1887 #elif defined(X86_64) || defined(X32)
1890 if (x86_io.iov_len != sizeof(i386_regs)) {
1891 /* x86-64 or x32 ABI */
1892 tcp->u_arg[0] = x86_64_regs.rdi;
1893 tcp->u_arg[1] = x86_64_regs.rsi;
1894 tcp->u_arg[2] = x86_64_regs.rdx;
1895 tcp->u_arg[3] = x86_64_regs.r10;
1896 tcp->u_arg[4] = x86_64_regs.r8;
1897 tcp->u_arg[5] = x86_64_regs.r9;
1899 tcp->ext_arg[0] = x86_64_regs.rdi;
1900 tcp->ext_arg[1] = x86_64_regs.rsi;
1901 tcp->ext_arg[2] = x86_64_regs.rdx;
1902 tcp->ext_arg[3] = x86_64_regs.r10;
1903 tcp->ext_arg[4] = x86_64_regs.r8;
1904 tcp->ext_arg[5] = x86_64_regs.r9;
1908 /* Zero-extend from 32 bits */
1909 /* Use widen_to_long(tcp->u_arg[N]) in syscall handlers
1910 * if you need to use *sign-extended* parameter.
1912 tcp->u_arg[0] = (long)(uint32_t)i386_regs.ebx;
1913 tcp->u_arg[1] = (long)(uint32_t)i386_regs.ecx;
1914 tcp->u_arg[2] = (long)(uint32_t)i386_regs.edx;
1915 tcp->u_arg[3] = (long)(uint32_t)i386_regs.esi;
1916 tcp->u_arg[4] = (long)(uint32_t)i386_regs.edi;
1917 tcp->u_arg[5] = (long)(uint32_t)i386_regs.ebp;
1919 #elif defined(MICROBLAZE)
1920 for (i = 0; i < nargs; ++i)
1921 if (upeek(tcp, (5 + i) * 4, &tcp->u_arg[i]) < 0)
1923 #elif defined(CRISV10) || defined(CRISV32)
1924 static const int crisregs[MAX_ARGS] = {
1925 4*PT_ORIG_R10, 4*PT_R11, 4*PT_R12,
1926 4*PT_R13 , 4*PT_MOF, 4*PT_SRP
1929 for (i = 0; i < nargs; ++i)
1930 if (upeek(tcp, crisregs[i], &tcp->u_arg[i]) < 0)
1933 for (i = 0; i < nargs; ++i)
1934 tcp->u_arg[i] = tile_regs.regs[i];
1936 for (i = 0; i < nargs; ++i)
1937 if (upeek(tcp, (i < 5 ? i : i + 2)*4, &tcp->u_arg[i]) < 0)
1941 for (i = 0; i < 6; ++i)
1942 tcp->u_arg[i] = or1k_regs.gpr[3 + i];
1943 #elif defined(METAG)
1944 for (i = 0; i < nargs; i++)
1945 /* arguments go backwards from D1Ar1 (D1.3) */
1946 tcp->u_arg[i] = ((unsigned long *)&metag_regs.dx[3][1])[-i];
1947 #else /* Other architecture (32bits specific) */
1948 for (i = 0; i < nargs; ++i)
1949 if (upeek(tcp, i*4, &tcp->u_arg[i]) < 0)
1956 trace_syscall_entering(struct tcb *tcp)
1960 #if defined TCB_WAITEXECVE
1961 if (tcp->flags & TCB_WAITEXECVE) {
1962 /* This is the post-execve SIGTRAP. */
1963 tcp->flags &= ~TCB_WAITEXECVE;
1968 scno_good = res = (get_regs_error ? -1 : get_scno(tcp));
1972 res = syscall_fixup_on_sysenter(tcp);
1976 res = get_syscall_args(tcp);
1982 tprints("????" /* anti-trigraph gap */ "(");
1983 else if (tcp->qual_flg & UNDEFINED_SCNO)
1984 tprintf("%s(", undefined_scno_name(tcp));
1986 tprintf("%s(", tcp->s_ent->sys_name);
1988 * " <unavailable>" will be added later by the code which
1989 * detects ptrace errors.
1994 #if defined(SYS_socket_subcall) || defined(SYS_ipc_subcall)
1996 # ifdef SYS_socket_subcall
1997 if (tcp->s_ent->sys_func == sys_socketcall) {
1998 decode_socket_subcall(tcp);
2002 # ifdef SYS_ipc_subcall
2003 if (tcp->s_ent->sys_func == sys_ipc) {
2004 decode_ipc_subcall(tcp);
2012 if (need_fork_exec_workarounds)
2013 syscall_fixup_for_fork_exec(tcp);
2015 if (!(tcp->qual_flg & QUAL_TRACE)
2016 || (tracing_paths && !pathtrace_match(tcp))
2018 tcp->flags |= TCB_INSYSCALL | TCB_FILTERED;
2022 tcp->flags &= ~TCB_FILTERED;
2024 if (cflag == CFLAG_ONLY_STATS) {
2030 if (tcp->qual_flg & UNDEFINED_SCNO)
2031 tprintf("%s(", undefined_scno_name(tcp));
2033 tprintf("%s(", tcp->s_ent->sys_name);
2034 if ((tcp->qual_flg & QUAL_RAW) && tcp->s_ent->sys_func != sys_exit)
2035 res = printargs(tcp);
2037 res = tcp->s_ent->sys_func(tcp);
2041 tcp->flags |= TCB_INSYSCALL;
2042 /* Measure the entrance time as late as possible to avoid errors. */
2044 gettimeofday(&tcp->etime, NULL);
2049 * 1: ok, continue in trace_syscall_exiting().
2050 * -1: error, trace_syscall_exiting() should print error indicator
2051 * ("????" etc) and bail out.
2054 get_syscall_result(struct tcb *tcp)
2056 #if defined(S390) || defined(S390X)
2057 if (upeek(tcp, PT_GPR2, &gpr2) < 0)
2059 #elif defined(POWERPC)
2060 # define SO_MASK 0x10000000
2063 if (upeek(tcp, sizeof(unsigned long)*PT_CCR, &flags) < 0)
2065 if (upeek(tcp, sizeof(unsigned long)*PT_R3, &ppc_result) < 0)
2067 if (flags & SO_MASK)
2068 ppc_result = -ppc_result;
2070 #elif defined(AVR32)
2071 /* already done by get_regs */
2073 if (upeek(tcp, PT_R0, &bfin_r0) < 0)
2076 /* already done by get_regs */
2077 #elif defined(X86_64) || defined(X32)
2078 /* already done by get_regs */
2080 # define IA64_PSR_IS ((long)1 << 34)
2082 if (upeek(tcp, PT_CR_IPSR, &psr) >= 0)
2083 ia32 = (psr & IA64_PSR_IS) != 0;
2084 if (upeek(tcp, PT_R8, &ia64_r8) < 0)
2086 if (upeek(tcp, PT_R10, &ia64_r10) < 0)
2089 /* already done by get_regs */
2090 #elif defined(AARCH64)
2091 /* register reading already done by get_regs */
2093 /* Used to do this, but we did it on syscall entry already: */
2094 /* We are in 64-bit mode (personality 1) if register struct is aarch64_regs,
2095 * else it's personality 0.
2097 /*update_personality(tcp, aarch64_io.iov_len == sizeof(aarch64_regs));*/
2099 if (upeek(tcp, 4*PT_D0, &m68k_d0) < 0)
2101 #elif defined(LINUX_MIPSN32)
2102 unsigned long long regs[38];
2104 if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long) ®s) < 0)
2106 mips_a3 = regs[REG_A3];
2107 mips_r2 = regs[REG_V0];
2109 if (upeek(tcp, REG_A3, &mips_a3) < 0)
2111 if (upeek(tcp, REG_V0, &mips_r2) < 0)
2113 #elif defined(ALPHA)
2114 if (upeek(tcp, REG_A3, &alpha_a3) < 0)
2116 if (upeek(tcp, REG_R0, &alpha_r0) < 0)
2118 #elif defined(SPARC) || defined(SPARC64)
2119 /* already done by get_regs */
2121 if (upeek(tcp, PT_GR28, &hppa_r28) < 0)
2124 /* new syscall ABI returns result in R0 */
2125 if (upeek(tcp, 4*REG_REG0, (long *)&sh_r0) < 0)
2128 /* ABI defines result returned in r9 */
2129 if (upeek(tcp, REG_GENERAL(9), (long *)&sh64_r9) < 0)
2131 #elif defined(CRISV10) || defined(CRISV32)
2132 if (upeek(tcp, 4*PT_R10, &cris_r10) < 0)
2135 /* already done by get_regs */
2136 #elif defined(MICROBLAZE)
2137 if (upeek(tcp, 3 * 4, µblaze_r3) < 0)
2140 /* already done by get_regs */
2141 #elif defined(METAG)
2142 /* already done by get_regs */
2147 /* Called at each syscall exit */
2149 syscall_fixup_on_sysexit(struct tcb *tcp)
2151 #if defined(S390) || defined(S390X)
2152 if (syscall_mode != -ENOSYS)
2153 syscall_mode = tcp->scno;
2154 if ((tcp->flags & TCB_WAITEXECVE)
2155 && (gpr2 == -ENOSYS || gpr2 == tcp->scno)) {
2157 * Return from execve.
2158 * Fake a return value of zero. We leave the TCB_WAITEXECVE
2159 * flag set for the post-execve SIGTRAP to see and reset.
2167 * Check the syscall return value register value for whether it is
2168 * a negated errno code indicating an error, or a success return value.
2171 is_negated_errno(unsigned long int val)
2173 unsigned long int max = -(long int) nerrnos;
2174 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
2175 if (current_wordsize < sizeof(val)) {
2176 val = (unsigned int) val;
2177 max = (unsigned int) max;
2185 is_negated_errno_x32(unsigned long long val)
2187 unsigned long long max = -(long long) nerrnos;
2189 * current_wordsize is 4 even in personality 0 (native X32)
2190 * but truncation _must not_ be done in it.
2191 * can't check current_wordsize here!
2193 if (current_personality != 0) {
2194 val = (uint32_t) val;
2195 max = (uint32_t) max;
2202 * 1: ok, continue in trace_syscall_exiting().
2203 * -1: error, trace_syscall_exiting() should print error indicator
2204 * ("????" etc) and bail out.
2207 get_error(struct tcb *tcp)
2210 int check_errno = 1;
2211 if (tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS) {
2214 #if defined(S390) || defined(S390X)
2215 if (check_errno && is_negated_errno(gpr2)) {
2223 if (check_errno && is_negated_errno(i386_regs.eax)) {
2225 u_error = -i386_regs.eax;
2228 tcp->u_rval = i386_regs.eax;
2230 #elif defined(X86_64)
2232 if (x86_io.iov_len == sizeof(i386_regs)) {
2233 /* Sign extend from 32 bits */
2234 rax = (int32_t)i386_regs.eax;
2236 rax = x86_64_regs.rax;
2238 if (check_errno && is_negated_errno(rax)) {
2246 /* In X32, return value is 64-bit (llseek uses one).
2247 * Using merely "long rax" would not work.
2250 if (x86_io.iov_len == sizeof(i386_regs)) {
2251 /* Sign extend from 32 bits */
2252 rax = (int32_t)i386_regs.eax;
2254 rax = x86_64_regs.rax;
2256 /* Careful: is_negated_errno() works only on longs */
2257 if (check_errno && is_negated_errno_x32(rax)) {
2262 tcp->u_rval = rax; /* truncating */
2270 if (check_errno && is_negated_errno(err)) {
2278 if (check_errno && ia64_r10) {
2282 tcp->u_rval = ia64_r8;
2286 if (check_errno && mips_a3) {
2290 tcp->u_rval = mips_r2;
2291 # if defined(LINUX_MIPSN32)
2292 tcp->u_lrval = mips_r2;
2295 #elif defined(POWERPC)
2296 if (check_errno && is_negated_errno(ppc_result)) {
2298 u_error = -ppc_result;
2301 tcp->u_rval = ppc_result;
2304 if (check_errno && is_negated_errno(m68k_d0)) {
2309 tcp->u_rval = m68k_d0;
2311 #elif defined(ARM) || defined(AARCH64)
2312 # if defined(AARCH64)
2313 if (tcp->currpers == 1) {
2314 if (check_errno && is_negated_errno(aarch64_regs.regs[0])) {
2316 u_error = -aarch64_regs.regs[0];
2319 tcp->u_rval = aarch64_regs.regs[0];
2325 if (check_errno && is_negated_errno(arm_regs.ARM_r0)) {
2327 u_error = -arm_regs.ARM_r0;
2330 tcp->u_rval = arm_regs.ARM_r0;
2333 #elif defined(AVR32)
2334 if (check_errno && avr32_regs.r12 && (unsigned) -avr32_regs.r12 < nerrnos) {
2336 u_error = -avr32_regs.r12;
2339 tcp->u_rval = avr32_regs.r12;
2342 if (check_errno && is_negated_errno(bfin_r0)) {
2346 tcp->u_rval = bfin_r0;
2348 #elif defined(ALPHA)
2349 if (check_errno && alpha_a3) {
2354 tcp->u_rval = alpha_r0;
2356 #elif defined(SPARC)
2357 if (check_errno && sparc_regs.psr & PSR_C) {
2359 u_error = sparc_regs.u_regs[U_REG_O0];
2362 tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
2364 #elif defined(SPARC64)
2365 if (check_errno && sparc_regs.tstate & 0x1100000000UL) {
2367 u_error = sparc_regs.u_regs[U_REG_O0];
2370 tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
2373 if (check_errno && is_negated_errno(hppa_r28)) {
2375 u_error = -hppa_r28;
2378 tcp->u_rval = hppa_r28;
2381 if (check_errno && is_negated_errno(sh_r0)) {
2386 tcp->u_rval = sh_r0;
2389 if (check_errno && is_negated_errno(sh64_r9)) {
2394 tcp->u_rval = sh64_r9;
2396 #elif defined(METAG)
2397 /* result pointer in D0Re0 (D0.0) */
2398 if (check_errno && is_negated_errno(metag_regs.dx[0][0])) {
2400 u_error = -metag_regs.dx[0][0];
2403 tcp->u_rval = metag_regs.dx[0][0];
2405 #elif defined(CRISV10) || defined(CRISV32)
2406 if (check_errno && cris_r10 && (unsigned) -cris_r10 < nerrnos) {
2408 u_error = -cris_r10;
2411 tcp->u_rval = cris_r10;
2415 * The standard tile calling convention returns the value (or negative
2416 * errno) in r0, and zero (or positive errno) in r1.
2417 * Until at least kernel 3.8, however, the r1 value is not reflected
2418 * in ptregs at this point, so we use r0 here.
2420 if (check_errno && is_negated_errno(tile_regs.regs[0])) {
2422 u_error = -tile_regs.regs[0];
2424 tcp->u_rval = tile_regs.regs[0];
2426 #elif defined(MICROBLAZE)
2427 if (check_errno && is_negated_errno(microblaze_r3)) {
2429 u_error = -microblaze_r3;
2432 tcp->u_rval = microblaze_r3;
2435 if (check_errno && is_negated_errno(or1k_regs.gpr[11])) {
2437 u_error = -or1k_regs.gpr[11];
2440 tcp->u_rval = or1k_regs.gpr[11];
2443 tcp->u_error = u_error;
2447 dumpio(struct tcb *tcp)
2453 if ((unsigned long) tcp->u_arg[0] >= num_quals)
2455 func = tcp->s_ent->sys_func;
2456 if (func == printargs)
2458 if (qual_flags[tcp->u_arg[0]] & QUAL_READ) {
2459 if (func == sys_read ||
2460 func == sys_pread ||
2462 func == sys_recvfrom)
2463 dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
2464 else if (func == sys_readv)
2465 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2468 if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) {
2469 if (func == sys_write ||
2470 func == sys_pwrite ||
2473 dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2474 else if (func == sys_writev)
2475 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2481 trace_syscall_exiting(struct tcb *tcp)
2488 /* Measure the exit time as early as possible to avoid errors. */
2490 gettimeofday(&tv, NULL);
2492 #if SUPPORTED_PERSONALITIES > 1
2493 update_personality(tcp, tcp->currpers);
2495 res = (get_regs_error ? -1 : get_syscall_result(tcp));
2497 syscall_fixup_on_sysexit(tcp); /* never fails */
2498 get_error(tcp); /* never fails */
2499 if (need_fork_exec_workarounds)
2500 syscall_fixup_for_fork_exec(tcp);
2506 struct timeval t = tv;
2507 count_syscall(tcp, &t);
2508 if (cflag == CFLAG_ONLY_STATS) {
2513 /* If not in -ff mode, and printing_tcp != tcp,
2514 * then the log currently does not end with output
2515 * of _our syscall entry_, but with something else.
2516 * We need to say which syscall's return is this.
2518 * Forced reprinting via TCB_REPRINT is used only by
2519 * "strace -ff -oLOG test/threaded_execve" corner case.
2520 * It's the only case when -ff mode needs reprinting.
2522 if ((followfork < 2 && printing_tcp != tcp) || (tcp->flags & TCB_REPRINT)) {
2523 tcp->flags &= ~TCB_REPRINT;
2525 if (tcp->qual_flg & UNDEFINED_SCNO)
2526 tprintf("<... %s resumed> ", undefined_scno_name(tcp));
2528 tprintf("<... %s resumed> ", tcp->s_ent->sys_name);
2533 /* There was error in one of prior ptrace ops */
2536 tprints("= ? <unavailable>\n");
2538 tcp->flags &= ~TCB_INSYSCALL;
2543 if (tcp->qual_flg & QUAL_RAW) {
2544 /* sys_res = printargs(tcp); - but it's nop on sysexit */
2546 /* FIXME: not_failing_only (IOW, option -z) is broken:
2547 * failure of syscall is known only after syscall return.
2548 * Thus we end up with something like this on, say, ENOENT:
2549 * open("doesnt_exist", O_RDONLY <unfinished ...>
2550 * {next syscall decode}
2551 * whereas the intended result is that open(...) line
2552 * is not shown at all.
2554 if (not_failing_only && tcp->u_error)
2555 goto ret; /* ignore failed syscalls */
2556 sys_res = tcp->s_ent->sys_func(tcp);
2561 u_error = tcp->u_error;
2562 if (tcp->qual_flg & QUAL_RAW) {
2564 tprintf("= -1 (errno %ld)", u_error);
2566 tprintf("= %#lx", tcp->u_rval);
2568 else if (!(sys_res & RVAL_NONE) && u_error) {
2570 /* Blocked signals do not interrupt any syscalls.
2571 * In this case syscalls don't return ERESTARTfoo codes.
2573 * Deadly signals set to SIG_DFL interrupt syscalls
2574 * and kill the process regardless of which of the codes below
2575 * is returned by the interrupted syscall.
2576 * In some cases, kernel forces a kernel-generated deadly
2577 * signal to be unblocked and set to SIG_DFL (and thus cause
2578 * death) if it is blocked or SIG_IGNed: for example, SIGSEGV
2579 * or SIGILL. (The alternative is to leave process spinning
2580 * forever on the faulty instruction - not useful).
2582 * SIG_IGNed signals and non-deadly signals set to SIG_DFL
2583 * (for example, SIGCHLD, SIGWINCH) interrupt syscalls,
2584 * but kernel will always restart them.
2587 /* Most common type of signal-interrupted syscall exit code.
2588 * The system call will be restarted with the same arguments
2589 * if SA_RESTART is set; otherwise, it will fail with EINTR.
2591 tprints("= ? ERESTARTSYS (To be restarted if SA_RESTART is set)");
2593 case ERESTARTNOINTR:
2594 /* Rare. For example, fork() returns this if interrupted.
2595 * SA_RESTART is ignored (assumed set): the restart is unconditional.
2597 tprints("= ? ERESTARTNOINTR (To be restarted)");
2599 case ERESTARTNOHAND:
2600 /* pause(), rt_sigsuspend() etc use this code.
2601 * SA_RESTART is ignored (assumed not set):
2602 * syscall won't restart (will return EINTR instead)
2603 * even after signal with SA_RESTART set. However,
2604 * after SIG_IGN or SIG_DFL signal it will restart
2605 * (thus the name "restart only if has no handler").
2607 tprints("= ? ERESTARTNOHAND (To be restarted if no handler)");
2609 case ERESTART_RESTARTBLOCK:
2610 /* Syscalls like nanosleep(), poll() which can't be
2611 * restarted with their original arguments use this
2612 * code. Kernel will execute restart_syscall() instead,
2613 * which changes arguments before restarting syscall.
2614 * SA_RESTART is ignored (assumed not set) similarly
2615 * to ERESTARTNOHAND. (Kernel can't honor SA_RESTART
2616 * since restart data is saved in "restart block"
2617 * in task struct, and if signal handler uses a syscall
2618 * which in turn saves another such restart block,
2619 * old data is lost and restart becomes impossible)
2621 tprints("= ? ERESTART_RESTARTBLOCK (Interrupted by signal)");
2625 tprintf("= -1 E??? (errno %ld)", u_error);
2626 else if (u_error < nerrnos)
2627 tprintf("= -1 %s (%s)", errnoent[u_error],
2630 tprintf("= -1 ERRNO_%ld (%s)", u_error,
2634 if ((sys_res & RVAL_STR) && tcp->auxstr)
2635 tprintf(" (%s)", tcp->auxstr);
2638 if (sys_res & RVAL_NONE)
2641 switch (sys_res & RVAL_MASK) {
2643 tprintf("= %#lx", tcp->u_rval);
2646 tprintf("= %#lo", tcp->u_rval);
2649 tprintf("= %lu", tcp->u_rval);
2652 tprintf("= %ld", tcp->u_rval);
2654 #if defined(LINUX_MIPSN32) || defined(X32)
2657 tprintf("= %#llx", tcp->u_lrval);
2660 tprintf("= %#llo", tcp->u_lrval);
2663 case RVAL_LUDECIMAL:
2664 tprintf("= %llu", tcp->u_lrval);
2668 tprintf("= %lld", tcp->u_lrval);
2674 "invalid rval format\n");
2678 if ((sys_res & RVAL_STR) && tcp->auxstr)
2679 tprintf(" (%s)", tcp->auxstr);
2682 tv_sub(&tv, &tv, &tcp->etime);
2683 tprintf(" <%ld.%06ld>",
2684 (long) tv.tv_sec, (long) tv.tv_usec);
2691 tcp->flags &= ~TCB_INSYSCALL;
2696 trace_syscall(struct tcb *tcp)
2698 return exiting(tcp) ?
2699 trace_syscall_exiting(tcp) : trace_syscall_entering(tcp);