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.
42 #include <sys/syscall.h>
43 #include <sys/param.h>
47 # define fpq kernel_fpq
49 # define fpu kernel_fpu
61 #ifndef PTRACE_PEEKUSR
62 # define PTRACE_PEEKUSR PTRACE_PEEKUSER
64 #elif defined(HAVE_LINUX_PTRACE_H)
66 #include <linux/ptrace.h>
69 #if defined(LINUX) && defined(IA64)
70 # include <asm/ptrace_offsets.h>
74 #ifndef SYS_ERRLIST_DECLARED
76 extern char *sys_errlist[];
77 #endif /* SYS_ERRLIST_DECLARED */
79 #define NR_SYSCALL_BASE 0
82 #define ERESTARTSYS 512
84 #ifndef ERESTARTNOINTR
85 #define ERESTARTNOINTR 513
87 #ifndef ERESTARTNOHAND
88 #define ERESTARTNOHAND 514 /* restart if no handler.. */
91 #define ENOIOCTLCMD 515 /* No ioctl command */
99 #undef NR_SYSCALL_BASE
100 #define NR_SYSCALL_BASE __NR_SYSCALL_BASE
106 /* Define these shorthand notations to simplify the syscallent files. */
107 #define TF TRACE_FILE
109 #define TN TRACE_NETWORK
110 #define TP TRACE_PROCESS
111 #define TS TRACE_SIGNAL
113 struct sysent sysent0[] = {
114 #include "syscallent.h"
116 int nsyscalls0 = sizeof sysent0 / sizeof sysent0[0];
118 #if SUPPORTED_PERSONALITIES >= 2
119 struct sysent sysent1[] = {
120 #include "syscallent1.h"
122 int nsyscalls1 = sizeof sysent1 / sizeof sysent1[0];
123 #endif /* SUPPORTED_PERSONALITIES >= 2 */
125 #if SUPPORTED_PERSONALITIES >= 3
126 struct sysent sysent2[] = {
127 #include "syscallent2.h"
129 int nsyscalls2 = sizeof sysent2 / sizeof sysent2[0];
130 #endif /* SUPPORTED_PERSONALITIES >= 3 */
132 struct sysent *sysent;
135 /* Now undef them since short defines cause wicked namespace pollution. */
142 char *errnoent0[] = {
143 #include "errnoent.h"
145 int nerrnos0 = sizeof errnoent0 / sizeof errnoent0[0];
147 #if SUPPORTED_PERSONALITIES >= 2
148 char *errnoent1[] = {
149 #include "errnoent1.h"
151 int nerrnos1 = sizeof errnoent1 / sizeof errnoent1[0];
152 #endif /* SUPPORTED_PERSONALITIES >= 2 */
154 #if SUPPORTED_PERSONALITIES >= 3
155 char *errnoent2[] = {
156 #include "errnoent2.h"
158 int nerrnos2 = sizeof errnoent2 / sizeof errnoent2[0];
159 #endif /* SUPPORTED_PERSONALITIES >= 3 */
164 int current_personality;
167 set_personality(personality)
170 switch (personality) {
172 errnoent = errnoent0;
175 nsyscalls = nsyscalls0;
176 ioctlent = ioctlent0;
177 nioctlents = nioctlents0;
178 signalent = signalent0;
179 nsignals = nsignals0;
182 #if SUPPORTED_PERSONALITIES >= 2
184 errnoent = errnoent1;
187 nsyscalls = nsyscalls1;
188 ioctlent = ioctlent1;
189 nioctlents = nioctlents1;
190 signalent = signalent1;
191 nsignals = nsignals1;
193 #endif /* SUPPORTED_PERSONALITIES >= 2 */
195 #if SUPPORTED_PERSONALITIES >= 3
197 errnoent = errnoent2;
200 nsyscalls = nsyscalls2;
201 ioctlent = ioctlent2;
202 nioctlents = nioctlents2;
203 signalent = signalent2;
204 nsignals = nsignals2;
206 #endif /* SUPPORTED_PERSONALITIES >= 3 */
212 current_personality = personality;
216 int qual_flags[MAX_QUALS];
218 static int call_count[MAX_QUALS];
219 static int error_count[MAX_QUALS];
220 static struct timeval tv_count[MAX_QUALS];
221 static int sorted_count[MAX_QUALS];
223 static struct timeval shortest = { 1000000, 0 };
225 static int lookup_syscall(), lookup_signal(), lookup_fault(), lookup_desc();
227 static struct qual_options {
233 { QUAL_TRACE, "trace", lookup_syscall, "system call" },
234 { QUAL_TRACE, "t", lookup_syscall, "system call" },
235 { QUAL_ABBREV, "abbrev", lookup_syscall, "system call" },
236 { QUAL_ABBREV, "a", lookup_syscall, "system call" },
237 { QUAL_VERBOSE, "verbose", lookup_syscall, "system call" },
238 { QUAL_VERBOSE, "v", lookup_syscall, "system call" },
239 { QUAL_RAW, "raw", lookup_syscall, "system call" },
240 { QUAL_RAW, "x", lookup_syscall, "system call" },
241 { QUAL_SIGNAL, "signal", lookup_signal, "signal" },
242 { QUAL_SIGNAL, "signals", lookup_signal, "signal" },
243 { QUAL_SIGNAL, "s", lookup_signal, "signal" },
244 { QUAL_FAULT, "fault", lookup_fault, "fault" },
245 { QUAL_FAULT, "faults", lookup_fault, "fault" },
246 { QUAL_FAULT, "m", lookup_fault, "fault" },
247 { QUAL_READ, "read", lookup_desc, "descriptor" },
248 { QUAL_READ, "reads", lookup_desc, "descriptor" },
249 { QUAL_READ, "r", lookup_desc, "descriptor" },
250 { QUAL_WRITE, "write", lookup_desc, "descriptor" },
251 { QUAL_WRITE, "writes", lookup_desc, "descriptor" },
252 { QUAL_WRITE, "w", lookup_desc, "descriptor" },
253 { 0, NULL, NULL, NULL },
262 for (i = 0; i < nsyscalls; i++) {
263 if (strcmp(s, sysent[i].sys_name) == 0)
276 if (s && *s && isdigit((unsigned char)*s))
280 for (i = 0; s[i]; i++)
281 s[i] = toupper((unsigned char)(s[i]));
282 if (strncmp(s, "SIG", 3) == 0)
284 for (i = 0; i <= NSIG; i++) {
285 if (strcmp(s, signame(i) + 3) == 0)
302 if (s && *s && isdigit((unsigned char)*s))
311 if (strcmp(s, "file") == 0)
313 if (strcmp(s, "ipc") == 0)
315 if (strcmp(s, "network") == 0)
316 return TRACE_NETWORK;
317 if (strcmp(s, "process") == 0)
318 return TRACE_PROCESS;
319 if (strcmp(s, "signal") == 0)
328 struct qual_options *opt;
333 opt = &qual_options[0];
334 for (i = 0; (p = qual_options[i].option_name); i++) {
336 if (strncmp(s, p, n) == 0 && s[n] == '=') {
337 opt = &qual_options[i];
347 if (strcmp(s, "none") == 0) {
351 if (strcmp(s, "all") == 0) {
352 for (i = 0; i < MAX_QUALS; i++) {
354 qual_flags[i] &= ~opt->bitflag;
356 qual_flags[i] |= opt->bitflag;
360 for (i = 0; i < MAX_QUALS; i++) {
362 qual_flags[i] |= opt->bitflag;
364 qual_flags[i] &= ~opt->bitflag;
366 for (p = strtok(s, ","); p; p = strtok(NULL, ",")) {
367 if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) {
368 for (i = 0; i < MAX_QUALS; i++) {
369 if (sysent[i].sys_flags & n) {
371 qual_flags[i] &= ~opt->bitflag;
373 qual_flags[i] |= opt->bitflag;
378 if ((n = (*opt->lookup)(p)) < 0) {
379 fprintf(stderr, "strace: invalid %s `%s'\n",
380 opt->argument_name, p);
384 qual_flags[n] &= ~opt->bitflag;
386 qual_flags[n] |= opt->bitflag;
397 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= MAX_QUALS)
399 switch (tcp->scno + NR_SYSCALL_BASE) {
407 if (qual_flags[tcp->u_arg[0]] & QUAL_READ)
408 dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
417 if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE)
418 dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
422 if (qual_flags[tcp->u_arg[0]] & QUAL_READ)
423 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
429 if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE)
430 dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
437 enum subcall_style { shift_style, deref_style, mask_style, door_style };
439 enum subcall_style { shift_style, deref_style, mask_style, door_style, table_style };
447 const struct subcall subcalls_table[] = {
448 { SYS_shmsys, 5, { SYS_shmat, SYS_shmctl, SYS_shmdt, SYS_shmget, SYS_shmctl } },
450 { SYS_semsys, 4, { SYS___semctl, SYS_semget, SYS_semop, SYS_semconfig } },
452 { SYS_semsys, 3, { SYS___semctl, SYS_semget, SYS_semop } },
454 { SYS_msgsys, 4, { SYS_msgctl, SYS_msgget, SYS_msgsnd, SYS_msgrcv } },
458 #if !(defined(LINUX) && ( defined(ALPHA) || defined(MIPS) ))
460 const int socket_map [] = {
463 /* SYS_CONNECT */ 98,
464 /* SYS_LISTEN */ 106,
466 /* SYS_GETSOCKNAME */ 150,
467 /* SYS_GETPEERNAME */ 141,
468 /* SYS_SOCKETPAIR */ 135,
471 /* SYS_SENDTO */ 133,
472 /* SYS_RECVFROM */ 125,
473 /* SYS_SHUTDOWN */ 134,
474 /* SYS_SETSOCKOPT */ 105,
475 /* SYS_GETSOCKOPT */ 118,
476 /* SYS_SENDMSG */ 114,
477 /* SYS_RECVMSG */ 113
481 sparc_socket_decode (tcp)
487 if (tcp->u_arg [0] < 1 || tcp->u_arg [0] > sizeof(socket_map)/sizeof(int)+1){
490 tcp->scno = socket_map [tcp->u_arg [0]-1];
491 n = tcp->u_nargs = sysent [tcp->scno].nargs;
492 addr = tcp->u_arg [1];
493 for (i = 0; i < n; i++){
495 if (umoven (tcp, addr, sizeof (arg), (void *) &arg) < 0)
497 tcp->u_arg [i] = arg;
498 addr += sizeof (arg);
503 decode_subcall(tcp, subcall, nsubcalls, style)
507 enum subcall_style style;
509 int i, addr, mask, arg;
513 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= nsubcalls)
515 tcp->scno = subcall + tcp->u_arg[0];
516 if (sysent[tcp->scno].nargs != -1)
517 tcp->u_nargs = sysent[tcp->scno].nargs;
520 for (i = 0; i < tcp->u_nargs; i++)
521 tcp->u_arg[i] = tcp->u_arg[i + 1];
524 if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= nsubcalls)
526 tcp->scno = subcall + tcp->u_arg[0];
527 addr = tcp->u_arg[1];
528 for (i = 0; i < sysent[tcp->scno].nargs; i++) {
529 if (umove(tcp, addr, &arg) < 0)
534 tcp->u_nargs = sysent[tcp->scno].nargs;
537 mask = (tcp->u_arg[0] >> 8) & 0xff;
538 for (i = 0; mask; i++)
542 tcp->u_arg[0] &= 0xff;
543 tcp->scno = subcall + i;
544 if (sysent[tcp->scno].nargs != -1)
545 tcp->u_nargs = sysent[tcp->scno].nargs;
549 * Oh, yuck. The call code is the *sixth* argument.
550 * (don't you mean the *last* argument? - JH)
552 if (tcp->u_arg[5] < 0 || tcp->u_arg[5] >= nsubcalls)
554 tcp->scno = subcall + tcp->u_arg[5];
555 if (sysent[tcp->scno].nargs != -1)
556 tcp->u_nargs = sysent[tcp->scno].nargs;
562 for (i = 0; i < sizeof(subcalls_table) / sizeof(struct subcall); i++)
563 if (subcalls_table[i].call == tcp->scno) break;
564 if (i < sizeof(subcalls_table) / sizeof(struct subcall) &&
565 tcp->u_arg[0] >= 0 && tcp->u_arg[0] < subcalls_table[i].nsubcalls) {
566 tcp->scno = subcalls_table[i].subcalls[tcp->u_arg[0]];
567 for (i = 0; i < tcp->u_nargs; i++)
568 tcp->u_arg[i] = tcp->u_arg[i + 1];
576 struct tcb *tcp_last = NULL;
579 internal_syscall(tcp)
583 * We must always trace a few critical system calls in order to
584 * correctly support following forks in the presence of tracing
587 switch (tcp->scno + NR_SYSCALL_BASE) {
667 #elif defined (POWERPC)
668 static long result,flags;
673 #elif defined (ALPHA)
676 #elif defined (SPARC)
677 static struct regs regs;
678 static unsigned long trap;
689 #elif defined(X86_64)
702 static int currpers=-1;
709 if (upeek(tcp->pid,PT_PSWADDR,&pc) < 0)
711 scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(pc-4),0);
715 #elif defined (POWERPC)
716 if (upeek(pid, 4*PT_R0, &scno) < 0)
718 if (!(tcp->flags & TCB_INSYSCALL)) {
719 /* Check if we return from execve. */
720 if (scno == 0 && (tcp->flags & TCB_WAITEXECVE)) {
721 tcp->flags &= ~TCB_WAITEXECVE;
726 if (upeek(pid, 4*ORIG_EAX, &scno) < 0)
728 #elif defined (X86_64)
729 if (upeek(pid, 8*ORIG_RAX, &scno) < 0)
732 if (!(tcp->flags & TCB_INSYSCALL)) {
735 /* Check CS register value. On x86-64 linux it is:
736 * 0x33 for long mode (64 bit)
737 * 0x23 for compatibility mode (32 bit)
738 * It takes only one ptrace and thus doesn't need
741 if (upeek(pid, 8*CS, &val) < 0)
745 case 0x23: currpers = 1; break;
746 case 0x33: currpers = 0; break;
748 fprintf(stderr, "Unknown value CS=0x%02X while "
749 "detecting personality of process "
750 "PID=%d\n", (int)val, pid);
751 currpers = current_personality;
755 /* This version analyzes the opcode of a syscall instruction.
756 * (int 0x80 on i386 vs. syscall on x86-64)
757 * It works, but is too complicated.
759 unsigned long val, rip, i;
761 if(upeek(pid, 8*RIP, &rip)<0)
762 perror("upeek(RIP)");
764 /* sizeof(syscall) == sizeof(int 0x80) == 2 */
768 call = ptrace(PTRACE_PEEKTEXT,pid,(char *)rip,0);
770 printf("ptrace_peektext failed: %s\n",
772 switch (call & 0xffff)
774 /* x86-64: syscall = 0x0f 0x05 */
775 case 0x050f: currpers = 0; break;
776 /* i386: int 0x80 = 0xcd 0x80 */
777 case 0x80cd: currpers = 1; break;
779 currpers = current_personality;
781 "Unknown syscall opcode (0x%04X) while "
782 "detecting personality of process "
783 "PID=%d\n", (int)call, pid);
787 if(currpers != current_personality)
789 char *names[]={"64 bit", "32 bit"};
790 set_personality(currpers);
791 printf("[ Process PID=%d runs in %s mode. ]\n",
792 pid, names[current_personality]);
796 # define IA64_PSR_IS ((long)1 << 34)
797 if (upeek (pid, PT_CR_IPSR, &psr) >= 0)
798 ia32 = (psr & IA64_PSR_IS) != 0;
799 if (!(tcp->flags & TCB_INSYSCALL)) {
801 if (upeek(pid, PT_R1, &scno) < 0) /* orig eax */
803 /* Check if we return from execve. */
805 if (upeek (pid, PT_R15, &scno) < 0)
809 /* syscall in progress */
810 if (upeek (pid, PT_R8, &r8) < 0)
812 if (upeek (pid, PT_R10, &r10) < 0)
815 if (tcp->flags & TCB_WAITEXECVE) {
816 tcp->flags &= ~TCB_WAITEXECVE;
823 upeek(pid, 4*15, &pc);
824 umoven(tcp, pc-4, 4, (char *)&scno);
828 if (upeek(pid, 4*PT_ORIG_D0, &scno) < 0)
831 if (upeek(pid, REG_A3, &a3) < 0)
834 if(!(tcp->flags & TCB_INSYSCALL)) {
835 if (upeek(pid, REG_V0, &scno) < 0)
838 if (scno < 0 || scno > nsyscalls) {
839 if(a3 == 0 || a3 == -1) {
841 fprintf (stderr, "stray syscall exit: v0 = %ld\n", scno);
846 if (upeek(pid, REG_V0, &r2) < 0)
849 #elif defined (ALPHA)
850 if (upeek(pid, REG_A3, &a3) < 0)
853 if (!(tcp->flags & TCB_INSYSCALL)) {
854 if (upeek(pid, REG_R0, &scno) < 0)
857 /* Check if we return from execve. */
858 if (scno == 0 && tcp->flags & TCB_WAITEXECVE) {
859 tcp->flags &= ~TCB_WAITEXECVE;
864 * Do some sanity checks to figure out if it's
865 * really a syscall entry
867 if (scno < 0 || scno > nsyscalls) {
868 if (a3 == 0 || a3 == -1) {
870 fprintf (stderr, "stray syscall exit: r0 = %ld\n", scno);
876 if (upeek(pid, REG_R0, &r0) < 0)
879 #elif defined (SPARC)
880 /* Everything we need is in the current register set. */
881 if (ptrace(PTRACE_GETREGS,pid,(char *)®s,0) < 0)
884 /* If we are entering, then disassemble the syscall trap. */
885 if (!(tcp->flags & TCB_INSYSCALL)) {
886 /* Retrieve the syscall trap instruction. */
888 trap = ptrace(PTRACE_PEEKTEXT,pid,(char *)regs.r_pc,0);
892 /* Disassemble the trap to see what personality to use. */
895 /* Linux/SPARC syscall trap. */
899 /* Linux/SPARC64 syscall trap. */
900 fprintf(stderr,"syscall: Linux/SPARC64 not supported yet\n");
903 /* SunOS syscall trap. (pers 1) */
904 fprintf(stderr,"syscall: SunOS no support\n");
907 /* Solaris 2.x syscall trap. (per 2) */
911 /* NetBSD/FreeBSD syscall trap. */
912 fprintf(stderr,"syscall: NetBSD/FreeBSD not supported\n");
915 /* Solaris 2.x gettimeofday */
919 /* Unknown syscall trap. */
920 if(tcp->flags & TCB_WAITEXECVE) {
921 tcp->flags &= ~TCB_WAITEXECVE;
924 fprintf(stderr,"syscall: unknown syscall trap %08x %08x\n", trap, regs.r_pc);
928 /* Extract the system call number from the registers. */
929 if (trap == 0x91d02027)
935 memmove (®s.r_o0, ®s.r_o1, 7*sizeof(regs.r_o0));
939 if (upeek(pid, PT_GR20, &scno) < 0)
941 if (!(tcp->flags & TCB_INSYSCALL)) {
942 /* Check if we return from execve. */
943 if ((tcp->flags & TCB_WAITEXECVE)) {
944 tcp->flags &= ~TCB_WAITEXECVE;
950 * In the new syscall ABI, the system call number is in R3.
952 if (upeek(pid, 4*(REG_REG0+3), &scno) < 0)
956 /* Odd as it may seem, a glibc bug has been known to cause
957 glibc to issue bogus negative syscall numbers. So for
958 our purposes, make strace print what it *should* have been */
959 long correct_scno = (scno & 0xff);
962 "Detected glibc bug: bogus system call number = %ld, "
963 "correcting to %ld\n",
970 if (!(tcp->flags & TCB_INSYSCALL)) {
971 /* Check if we return from execve. */
972 if (scno == 0 && tcp->flags & TCB_WAITEXECVE) {
973 tcp->flags &= ~TCB_WAITEXECVE;
980 if (upeek(pid, uoff(u_arg[7]), &scno) < 0)
983 /* new syscall ABI returns result in R0 */
984 if (upeek(pid, 4*REG_REG0, (long *)&r0) < 0)
988 #ifdef HAVE_PR_SYSCALL
989 scno = tcp->status.PR_SYSCALL;
990 #else /* !HAVE_PR_SYSCALL */
992 scno = tcp->status.PR_WHAT;
994 if (pread(tcp->pfd_reg, ®s, sizeof(regs), 0) < 0) {
998 switch (regs.r_eax) {
1001 pread(tcp->pfd, &scno, sizeof(scno), regs.r_esp + sizeof(int));
1007 #endif /* FREEBSD */
1008 #endif /* !HAVE_PR_SYSCALL */
1009 #endif /* USE_PROCFS */
1010 if (!(tcp->flags & TCB_INSYSCALL))
1022 #else /* USE_PROCFS */
1023 int scno = tcp->scno;
1025 if (!(tcp->flags & TCB_INSYSCALL)) {
1026 if (tcp->status.PR_WHY != PR_SYSENTRY) {
1030 || scno == SYS_vfork
1031 #endif /* SYS_vfork */
1033 || scno == SYS_fork1
1034 #endif /* SYS_fork1 */
1036 || scno == SYS_forkall
1037 #endif /* SYS_forkall */
1039 || scno == SYS_rfork1
1040 #endif /* SYS_fork1 */
1042 || scno == SYS_rforkall
1043 #endif /* SYS_rforkall */
1045 /* We are returning in the child, fake it. */
1046 tcp->status.PR_WHY = PR_SYSENTRY;
1048 tcp->status.PR_WHY = PR_SYSEXIT;
1051 fprintf(stderr, "syscall: missing entry\n");
1052 tcp->flags |= TCB_INSYSCALL;
1057 if (tcp->status.PR_WHY != PR_SYSEXIT) {
1058 fprintf(stderr, "syscall: missing exit\n");
1059 tcp->flags &= ~TCB_INSYSCALL;
1062 #endif /* USE_PROCFS */
1064 if (!(tcp->flags & TCB_INSYSCALL)) {
1066 fprintf(stderr, "syscall: missing entry\n");
1067 tcp->flags |= TCB_INSYSCALL;
1074 * This happens when a signal handler
1075 * for a signal which interrupted a
1076 * a system call makes another system call.
1078 fprintf(stderr, "syscall: missing exit\n");
1080 tcp->flags &= ~TCB_INSYSCALL;
1086 if (upeek(pid, 4*EAX, &eax) < 0)
1088 if (eax != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
1090 fprintf(stderr, "stray syscall exit: eax = %ld\n", eax);
1093 #elif defined (X86_64)
1094 if (upeek(pid, 8*RAX, &rax) < 0)
1096 if (rax != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
1098 fprintf(stderr, "stray syscall exit: rax = %ld\n", rax);
1101 #elif defined (S390)
1102 if (upeek(pid, PT_GPR2, &gpr2) < 0)
1104 if (gpr2 != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
1106 fprintf(stderr, "stray syscall exit: gpr2 = %ld\n", gpr2);
1109 #elif defined (POWERPC)
1110 # define SO_MASK 0x10000000
1111 if (upeek(pid, 4*PT_CCR, &flags) < 0)
1113 if (upeek(pid, 4*PT_R3, &result) < 0)
1115 if (flags & SO_MASK)
1117 #elif defined (M68K)
1118 if (upeek(pid, 4*PT_D0, &d0) < 0)
1120 if (d0 != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
1122 fprintf(stderr, "stray syscall exit: d0 = %ld\n", d0);
1126 if (upeek(pid, 4*0, (long *)&r0) < 0)
1128 if ( 0 && r0 != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
1130 fprintf(stderr, "stray syscall exit: d0 = %ld\n", r0);
1133 #elif defined (HPPA)
1134 if (upeek(pid, PT_GR28, &r28) < 0)
1137 if (upeek(pid, PT_R10, &r10) < 0)
1139 if (upeek(pid, PT_R8, &r8) < 0)
1141 if (ia32 && r8 != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
1143 fprintf(stderr, "stray syscall exit: r8 = %ld\n", r8);
1158 if (gpr2 && (unsigned) -gpr2 < nerrnos) {
1168 if (eax < 0 && -eax < nerrnos) {
1178 if (rax < 0 && -rax < nerrnos) {
1192 if (err < 0 && -err < nerrnos) {
1220 if (result && (unsigned) -result < nerrnos) {
1225 tcp->u_rval = result;
1228 #else /* !POWERPC */
1230 if (d0 && (unsigned) -d0 < nerrnos) {
1240 if (r0 && (unsigned) -r0 < nerrnos) {
1260 if (regs.r_psr & PSR_C) {
1262 u_error = regs.r_o0;
1265 tcp->u_rval = regs.r_o0;
1270 if (r28 && (unsigned) -r28 < nerrnos) {
1280 /* interpret R0 as return value or error number */
1281 if (r0 && (unsigned) -r0 < nerrnos) {
1295 #endif /* POWERPC */
1303 /* get error code from user struct */
1304 if (upeek(pid, uoff(u_error), &u_error) < 0)
1306 u_error >>= 24; /* u_error is a char */
1308 /* get system call return value */
1309 if (upeek(pid, uoff(u_rval1), &tcp->u_rval) < 0)
1314 /* Judicious guessing goes a long way. */
1315 if (tcp->status.pr_reg[R_PSR] & 0x100000) {
1317 u_error = tcp->status.pr_reg[R_O0];
1320 tcp->u_rval = tcp->status.pr_reg[R_O0];
1325 /* Wanna know how to kill an hour single-stepping? */
1326 if (tcp->status.PR_REG[EFL] & 0x1) {
1328 u_error = tcp->status.PR_REG[EAX];
1331 tcp->u_rval = tcp->status.PR_REG[EAX];
1332 #ifdef HAVE_LONG_LONG
1334 ((unsigned long long) tcp->status.PR_REG[EDX] << 32) +
1335 tcp->status.PR_REG[EAX];
1341 /* Wanna know how to kill an hour single-stepping? */
1342 if (tcp->status.PR_REG[EFLAGS] & 0x1) {
1344 u_error = tcp->status.PR_REG[RAX];
1347 tcp->u_rval = tcp->status.PR_REG[RAX];
1352 if (tcp->status.pr_reg[CTX_A3]) {
1354 u_error = tcp->status.pr_reg[CTX_V0];
1357 tcp->u_rval = tcp->status.pr_reg[CTX_V0];
1363 if (regs.r_eflags & PSL_C) {
1365 u_error = regs.r_eax;
1367 tcp->u_rval = regs.r_eax;
1369 ((unsigned long long) regs.r_edx << 32) + regs.r_eax;
1372 #endif /* FREEBSD */
1373 tcp->u_error = u_error;
1377 int syscall_enter(tcp)
1382 #endif /* !USE_PROCFS */
1387 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1388 tcp->u_nargs = sysent[tcp->scno].nargs;
1390 tcp->u_nargs = MAX_ARGS;
1391 for (i = 0; i < tcp->u_nargs; i++) {
1392 if (upeek(pid,i==0 ? PT_ORIGGPR2:PT_GPR2+(i<<2), &tcp->u_arg[i]) < 0)
1396 #elif defined (ALPHA)
1399 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1400 tcp->u_nargs = sysent[tcp->scno].nargs;
1402 tcp->u_nargs = MAX_ARGS;
1403 for (i = 0; i < tcp->u_nargs; i++) {
1404 /* WTA: if scno is out-of-bounds this will bomb. Add range-check
1405 * for scno somewhere above here!
1407 if (upeek(pid, REG_A0+i, &tcp->u_arg[i]) < 0)
1411 #elif defined (IA64)
1414 unsigned long *out0, *rbs_end, cfm, sof, sol, i;
1415 /* be backwards compatible with kernel < 2.4.4... */
1417 # define PT_RBS_END PT_AR_BSP
1420 if (upeek(pid, PT_RBS_END, (long *) &rbs_end) < 0)
1422 if (upeek(pid, PT_CFM, (long *) &cfm) < 0)
1425 sof = (cfm >> 0) & 0x7f;
1426 sol = (cfm >> 7) & 0x7f;
1427 out0 = ia64_rse_skip_regs(rbs_end, -sof + sol);
1429 if (tcp->scno >= 0 && tcp->scno < nsyscalls
1430 && sysent[tcp->scno].nargs != -1)
1431 tcp->u_nargs = sysent[tcp->scno].nargs;
1433 tcp->u_nargs = MAX_ARGS;
1434 for (i = 0; i < tcp->u_nargs; ++i) {
1435 if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i),
1436 sizeof(long), (char *) &tcp->u_arg[i]) < 0)
1442 if (/* EBX = out0 */
1443 upeek(pid, PT_R11, (long *) &tcp->u_arg[0]) < 0
1445 || upeek(pid, PT_R9, (long *) &tcp->u_arg[1]) < 0
1447 || upeek(pid, PT_R10, (long *) &tcp->u_arg[2]) < 0
1449 || upeek(pid, PT_R14, (long *) &tcp->u_arg[3]) < 0
1451 || upeek(pid, PT_R15, (long *) &tcp->u_arg[4]) < 0
1453 || upeek(pid, PT_R13, (long *) &tcp->u_arg[5]) < 0)
1456 for (i = 0; i < 6; ++i)
1457 /* truncate away IVE sign-extension */
1458 tcp->u_arg[i] &= 0xffffffff;
1460 if (tcp->scno >= 0 && tcp->scno < nsyscalls
1461 && sysent[tcp->scno].nargs != -1)
1462 tcp->u_nargs = sysent[tcp->scno].nargs;
1467 #elif defined (MIPS)
1472 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1473 nargs = tcp->u_nargs = sysent[tcp->scno].nargs;
1475 nargs = tcp->u_nargs = MAX_ARGS;
1477 if(upeek(pid, REG_SP, &sp) < 0)
1479 for(i = 0; i < 4; i++) {
1480 if (upeek(pid, REG_A0 + i, &tcp->u_arg[i])<0)
1483 umoven(tcp, sp+16, (nargs-4) * sizeof(tcp->u_arg[0]),
1484 (char *)(tcp->u_arg + 4));
1486 for(i = 0; i < nargs; i++) {
1487 if (upeek(pid, REG_A0 + i, &tcp->u_arg[i]) < 0)
1492 #elif defined (POWERPC)
1495 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1496 tcp->u_nargs = sysent[tcp->scno].nargs;
1498 tcp->u_nargs = MAX_ARGS;
1499 for (i = 0; i < tcp->u_nargs; i++) {
1500 if (upeek(pid, (i==0) ? (4*PT_ORIG_R3) : ((i+PT_R3)*4), &tcp->u_arg[i]) < 0)
1504 #elif defined (SPARC)
1508 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1509 tcp->u_nargs = sysent[tcp->scno].nargs;
1511 tcp->u_nargs = MAX_ARGS;
1512 for (i = 0; i < tcp->u_nargs; i++)
1513 tcp->u_arg[i] = *((®s.r_o0) + i);
1515 #elif defined (HPPA)
1519 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1520 tcp->u_nargs = sysent[tcp->scno].nargs;
1522 tcp->u_nargs = MAX_ARGS;
1523 for (i = 0; i < tcp->u_nargs; i++) {
1524 if (upeek(pid, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
1531 static int syscall_regs[] = {
1532 REG_REG0+4, REG_REG0+5, REG_REG0+6, REG_REG0+7,
1533 REG_REG0, REG_REG0+1, REG_REG0+2
1536 tcp->u_nargs = sysent[tcp->scno].nargs;
1537 for (i = 0; i < tcp->u_nargs; i++) {
1538 if (upeek(pid, 4*syscall_regs[i], &tcp->u_arg[i]) < 0)
1542 #elif defined(X86_64)
1545 static int argreg[SUPPORTED_PERSONALITIES][MAX_ARGS] = {
1546 {RDI,RSI,RDX,R10,R8,R9}, /* x86-64 ABI */
1547 {RBX,RCX,RDX,RDX,RSI,RDI,RBP} /* i386 ABI */
1550 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1551 tcp->u_nargs = sysent[tcp->scno].nargs;
1553 tcp->u_nargs = MAX_ARGS;
1554 for (i = 0; i < tcp->u_nargs; i++) {
1555 if (upeek(pid, argreg[current_personality][i]*8, &tcp->u_arg[i]) < 0)
1559 #else /* Other architecture (like i386) (32bits specific) */
1562 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1563 tcp->u_nargs = sysent[tcp->scno].nargs;
1565 tcp->u_nargs = MAX_ARGS;
1566 for (i = 0; i < tcp->u_nargs; i++) {
1567 if (upeek(pid, i*4, &tcp->u_arg[i]) < 0)
1576 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1577 tcp->u_nargs = sysent[tcp->scno].nargs;
1579 tcp->u_nargs = MAX_ARGS;
1580 for (i = 0; i < tcp->u_nargs; i++) {
1583 if (upeek(pid, uoff(u_arg[0]) +
1584 (i*sizeof(u->u_arg[0])), &tcp->u_arg[i]) < 0)
1592 * SGI is broken: even though it has pr_sysarg, it doesn't
1593 * set them on system call entry. Get a clue.
1595 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1596 tcp->u_nargs = sysent[tcp->scno].nargs;
1598 tcp->u_nargs = tcp->status.pr_nsysarg;
1599 if (tcp->u_nargs > 4) {
1600 memcpy(tcp->u_arg, &tcp->status.pr_reg[CTX_A0],
1601 4*sizeof(tcp->u_arg[0]));
1602 umoven(tcp, tcp->status.pr_reg[CTX_SP] + 16,
1603 (tcp->u_nargs - 4)*sizeof(tcp->u_arg[0]), (char *) (tcp->u_arg + 4));
1606 memcpy(tcp->u_arg, &tcp->status.pr_reg[CTX_A0],
1607 tcp->u_nargs*sizeof(tcp->u_arg[0]));
1611 * Like SGI, UnixWare doesn't set pr_sysarg until system call exit
1613 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1614 tcp->u_nargs = sysent[tcp->scno].nargs;
1616 tcp->u_nargs = tcp->status.pr_lwp.pr_nsysarg;
1617 umoven(tcp, tcp->status.PR_REG[UESP] + 4,
1618 tcp->u_nargs*sizeof(tcp->u_arg[0]), (char *) tcp->u_arg);
1619 #elif defined (HAVE_PR_SYSCALL)
1620 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1621 tcp->u_nargs = sysent[tcp->scno].nargs;
1623 tcp->u_nargs = tcp->status.pr_nsysarg;
1626 for (i = 0; i < tcp->u_nargs; i++)
1627 tcp->u_arg[i] = tcp->status.pr_sysarg[i];
1629 #elif defined (I386)
1630 if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
1631 tcp->u_nargs = sysent[tcp->scno].nargs;
1634 umoven(tcp, tcp->status.PR_REG[UESP] + 4,
1635 tcp->u_nargs*sizeof(tcp->u_arg[0]), (char *) tcp->u_arg);
1637 I DONT KNOW WHAT TO DO
1638 #endif /* !HAVE_PR_SYSCALL */
1641 if (tcp->scno >= 0 && tcp->scno < nsyscalls &&
1642 sysent[tcp->scno].nargs > tcp->status.val)
1643 tcp->u_nargs = sysent[tcp->scno].nargs;
1645 tcp->u_nargs = tcp->status.val;
1646 if (tcp->u_nargs < 0)
1648 if (tcp->u_nargs > MAX_ARGS)
1649 tcp->u_nargs = MAX_ARGS;
1650 switch(regs.r_eax) {
1652 pread(tcp->pfd, &tcp->u_arg, tcp->u_nargs * sizeof(unsigned long),
1653 regs.r_esp + sizeof(int) + sizeof(quad_t));
1656 pread(tcp->pfd, &tcp->u_arg, tcp->u_nargs * sizeof(unsigned long),
1657 regs.r_esp + 2 * sizeof(int));
1660 pread(tcp->pfd, &tcp->u_arg, tcp->u_nargs * sizeof(unsigned long),
1661 regs.r_esp + sizeof(int));
1664 #endif /* FREEBSD */
1676 /* Measure the exit time as early as possible to avoid errors. */
1677 if (dtime && (tcp->flags & TCB_INSYSCALL))
1678 gettimeofday(&tv, NULL);
1680 res = get_scno(tcp);
1684 res = syscall_fixup(tcp);
1688 if (tcp->flags & TCB_INSYSCALL) {
1690 res = get_error(tcp);
1693 u_error = tcp->u_error;
1696 internal_syscall(tcp);
1697 if (tcp->scno >= 0 && tcp->scno < nsyscalls &&
1698 !(qual_flags[tcp->scno] & QUAL_TRACE)) {
1699 tcp->flags &= ~TCB_INSYSCALL;
1703 if (tcp->flags & TCB_REPRINT) {
1706 if (tcp->scno >= nsyscalls || tcp->scno < 0)
1707 tprintf("syscall_%lu", tcp->scno);
1709 tprintf("%s", sysent[tcp->scno].sys_name);
1710 tprintf(" resumed> ");
1713 if (cflag && tcp->scno < nsyscalls && tcp->scno >= 0) {
1714 call_count[tcp->scno]++;
1716 error_count[tcp->scno]++;
1717 tv_sub(&tv, &tv, &tcp->etime);
1719 if (tv_cmp(&tv, &tcp->dtime) > 0) {
1720 static struct timeval one_tick =
1721 { 0, 1000000 / HZ };
1723 if (tv_nz(&tcp->dtime))
1725 else if (tv_cmp(&tv, &one_tick) > 0) {
1726 if (tv_cmp(&shortest, &one_tick) < 0)
1733 if (tv_cmp(&tv, &shortest) < 0)
1735 tv_add(&tv_count[tcp->scno],
1736 &tv_count[tcp->scno], &tv);
1737 tcp->flags &= ~TCB_INSYSCALL;
1741 if (tcp->scno >= nsyscalls || tcp->scno < 0
1742 || (qual_flags[tcp->scno] & QUAL_RAW))
1743 sys_res = printargs(tcp);
1745 sys_res = (*sysent[tcp->scno].sys_func)(tcp);
1746 u_error = tcp->u_error;
1749 if (tcp->scno >= nsyscalls || tcp->scno < 0 ||
1750 qual_flags[tcp->scno] & QUAL_RAW) {
1752 tprintf("= -1 (errno %ld)", u_error);
1754 tprintf("= %#lx", tcp->u_rval);
1756 else if (!(sys_res & RVAL_NONE) && u_error) {
1760 tprintf("= ? ERESTARTSYS (To be restarted)");
1762 case ERESTARTNOINTR:
1763 tprintf("= ? ERESTARTNOINTR (To be restarted)");
1765 case ERESTARTNOHAND:
1766 tprintf("= ? ERESTARTNOHAND (To be restarted)");
1772 tprintf("E??? (errno %ld)", u_error);
1773 else if (u_error < nerrnos && u_error < sys_nerr)
1774 tprintf("%s (%s)", errnoent[u_error],
1775 sys_errlist[u_error]);
1776 else if (u_error < nerrnos)
1777 tprintf("%s (errno %ld)",
1778 errnoent[u_error], u_error);
1779 else if (u_error < sys_nerr)
1780 tprintf("ERRNO_%ld (%s)", u_error,
1781 sys_errlist[u_error]);
1783 tprintf("E??? (errno %ld)", u_error);
1788 if (sys_res & RVAL_NONE)
1791 switch (sys_res & RVAL_MASK) {
1793 tprintf("= %#lx", tcp->u_rval);
1796 tprintf("= %#lo", tcp->u_rval);
1799 tprintf("= %lu", tcp->u_rval);
1802 tprintf("= %ld", tcp->u_rval);
1804 #ifdef HAVE_LONG_LONG
1806 tprintf("= %#llx", tcp->u_lrval);
1809 tprintf("= %#llo", tcp->u_lrval);
1811 case RVAL_LUDECIMAL:
1812 tprintf("= %llu", tcp->u_lrval);
1815 tprintf("= %lld", tcp->u_lrval);
1820 "invalid rval format\n");
1824 if ((sys_res & RVAL_STR) && tcp->auxstr)
1825 tprintf(" (%s)", tcp->auxstr);
1828 tv_sub(&tv, &tv, &tcp->etime);
1829 tprintf(" <%ld.%06ld>",
1830 (long) tv.tv_sec, (long) tv.tv_usec);
1835 if (fflush(tcp->outf) == EOF)
1837 tcp->flags &= ~TCB_INSYSCALL;
1841 /* Entering system call */
1842 res = syscall_enter(tcp);
1846 switch (tcp->scno + NR_SYSCALL_BASE) {
1848 #if !defined (ALPHA) && !defined(SPARC) && !defined(MIPS) && !defined(HPPA) && !defined(X86_64)
1849 case SYS_socketcall:
1850 decode_subcall(tcp, SYS_socket_subcall,
1851 SYS_socket_nsubcalls, deref_style);
1854 decode_subcall(tcp, SYS_ipc_subcall,
1855 SYS_ipc_nsubcalls, shift_style);
1857 #endif /* !ALPHA && !MIPS && !SPARC && !HPPA && !X86_64 */
1859 case SYS_socketcall:
1860 sparc_socket_decode (tcp);
1865 #ifdef SYS_pgrpsys_subcall
1867 decode_subcall(tcp, SYS_pgrpsys_subcall,
1868 SYS_pgrpsys_nsubcalls, shift_style);
1870 #endif /* SYS_pgrpsys_subcall */
1871 #ifdef SYS_sigcall_subcall
1873 decode_subcall(tcp, SYS_sigcall_subcall,
1874 SYS_sigcall_nsubcalls, mask_style);
1876 #endif /* SYS_sigcall_subcall */
1878 decode_subcall(tcp, SYS_msgsys_subcall,
1879 SYS_msgsys_nsubcalls, shift_style);
1882 decode_subcall(tcp, SYS_shmsys_subcall,
1883 SYS_shmsys_nsubcalls, shift_style);
1886 decode_subcall(tcp, SYS_semsys_subcall,
1887 SYS_semsys_nsubcalls, shift_style);
1891 decode_subcall(tcp, SYS_utssys_subcall,
1892 SYS_utssys_nsubcalls, shift_style);
1896 decode_subcall(tcp, SYS_sysfs_subcall,
1897 SYS_sysfs_nsubcalls, shift_style);
1900 decode_subcall(tcp, SYS_spcall_subcall,
1901 SYS_spcall_nsubcalls, shift_style);
1903 #ifdef SYS_context_subcall
1905 decode_subcall(tcp, SYS_context_subcall,
1906 SYS_context_nsubcalls, shift_style);
1908 #endif /* SYS_context_subcall */
1909 #ifdef SYS_door_subcall
1911 decode_subcall(tcp, SYS_door_subcall,
1912 SYS_door_nsubcalls, door_style);
1914 #endif /* SYS_door_subcall */
1915 #ifdef SYS_kaio_subcall
1917 decode_subcall(tcp, SYS_kaio_subcall,
1918 SYS_kaio_nsubcalls, shift_style);
1926 decode_subcall(tcp, 0, 0, table_style);
1931 decode_subcall(tcp, SYS_semsys_subcall,
1932 SYS_semsys_nsubcalls, shift_style);
1935 decode_subcall(tcp, SYS_msgsys_subcall,
1936 SYS_msgsys_nsubcalls, shift_style);
1939 decode_subcall(tcp, SYS_shmsys_subcall,
1940 SYS_shmsys_nsubcalls, shift_style);
1945 internal_syscall(tcp);
1946 if (tcp->scno >=0 && tcp->scno < nsyscalls && !(qual_flags[tcp->scno] & QUAL_TRACE)) {
1947 tcp->flags |= TCB_INSYSCALL;
1952 gettimeofday(&tcp->etime, NULL);
1953 tcp->flags |= TCB_INSYSCALL;
1958 tcp->flags &= ~TCB_REPRINT;
1960 if (tcp->scno >= nsyscalls || tcp->scno < 0)
1961 tprintf("syscall_%lu(", tcp->scno);
1963 tprintf("%s(", sysent[tcp->scno].sys_name);
1964 if (tcp->scno >= nsyscalls || tcp->scno < 0 ||
1965 ((qual_flags[tcp->scno] & QUAL_RAW) && tcp->scno != SYS_exit))
1966 sys_res = printargs(tcp);
1968 sys_res = (*sysent[tcp->scno].sys_func)(tcp);
1969 if (fflush(tcp->outf) == EOF)
1971 tcp->flags |= TCB_INSYSCALL;
1972 /* Measure the entrance time as late as possible to avoid errors. */
1974 gettimeofday(&tcp->etime, NULL);
1982 if (entering(tcp)) {
1985 for (i = 0; i < tcp->u_nargs; i++)
1986 tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]);
2000 if (ptrace(PTRACE_GETREGS,tcp->pid,(char *)®s,0) < 0)
2007 if (upeek(tcp->pid, uoff(u_rval2), &val) < 0)
2013 val = tcp->status.PR_REG[R_O1];
2016 val = tcp->status.PR_REG[EDX];
2019 val = tcp->status.PR_REG[RDX];
2022 val = tcp->status.PR_REG[CTX_V1];
2027 pread(tcp->pfd_reg, ®s, sizeof(regs), 0);
2034 * Apparently, indirect system calls have already be converted by ptrace(2),
2035 * so if you see "indir" this program has gone astray.
2043 if (entering(tcp)) {
2044 if ((scno = tcp->u_arg[0]) > nsyscalls) {
2045 fprintf(stderr, "Bogus syscall: %u\n", scno);
2048 nargs = sysent[scno].nargs;
2049 tprintf("%s", sysent[scno].sys_name);
2050 for (i = 0; i < nargs; i++)
2051 tprintf(", %#lx", tcp->u_arg[i+1]);
2061 return -tv_cmp(&tv_count[*((int *) a)], &tv_count[*((int *) b)]);
2069 return strcmp(sysent[*((int *) a)].sys_name,
2070 sysent[*((int *) b)].sys_name);
2078 int m = call_count[*((int *) a)], n = call_count[*((int *) b)];
2080 return (m < n) ? 1 : (m > n) ? -1 : 0;
2083 static int (*sortfun)();
2084 static struct timeval overhead = { -1, -1 };
2090 if (strcmp(sortby, "time") == 0)
2092 else if (strcmp(sortby, "calls") == 0)
2093 sortfun = count_cmp;
2094 else if (strcmp(sortby, "name") == 0)
2095 sortfun = syscall_cmp;
2096 else if (strcmp(sortby, "nothing") == 0)
2099 fprintf(stderr, "invalid sortby: `%s'\n", sortby);
2104 void set_overhead(n)
2107 overhead.tv_sec = n / 1000000;
2108 overhead.tv_usec = n % 1000000;
2116 int call_cum, error_cum;
2117 struct timeval tv_cum, dtv;
2119 char *dashes = "-------------------------";
2122 call_cum = error_cum = tv_cum.tv_sec = tv_cum.tv_usec = 0;
2123 if (overhead.tv_sec == -1) {
2124 tv_mul(&overhead, &shortest, 8);
2125 tv_div(&overhead, &overhead, 10);
2127 for (i = 0; i < nsyscalls; i++) {
2128 sorted_count[i] = i;
2129 if (call_count[i] == 0)
2131 tv_mul(&dtv, &overhead, call_count[i]);
2132 tv_sub(&tv_count[i], &tv_count[i], &dtv);
2133 call_cum += call_count[i];
2134 error_cum += error_count[i];
2135 tv_add(&tv_cum, &tv_cum, &tv_count[i]);
2138 qsort((void *) sorted_count, nsyscalls, sizeof(int), sortfun);
2139 fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %s\n",
2140 "% time", "seconds", "usecs/call",
2141 "calls", "errors", "syscall");
2142 fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %-16.16s\n",
2143 dashes, dashes, dashes, dashes, dashes, dashes);
2144 for (i = 0; i < nsyscalls; i++) {
2145 j = sorted_count[i];
2146 if (call_count[j] == 0)
2148 tv_div(&dtv, &tv_count[j], call_count[j]);
2150 sprintf(error_str, "%d", error_count[j]);
2152 error_str[0] = '\0';
2153 percent = 100.0*tv_float(&tv_count[j])/tv_float(&tv_cum);
2154 fprintf(outf, "%6.2f %4ld.%06ld %11ld %9d %9.9s %s\n",
2155 percent, (long) tv_count[j].tv_sec,
2156 (long) tv_count[j].tv_usec,
2157 (long) 1000000 * dtv.tv_sec + dtv.tv_usec,
2158 call_count[j], error_str, sysent[j].sys_name);
2160 fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %-16.16s\n",
2161 dashes, dashes, dashes, dashes, dashes, dashes);
2163 sprintf(error_str, "%d", error_cum);
2165 error_str[0] = '\0';
2166 fprintf(outf, "%6.6s %4ld.%06ld %11.11s %9d %9.9s %s\n",
2167 "100.00", (long) tv_cum.tv_sec, (long) tv_cum.tv_usec, "",
2168 call_cum, error_str, "total");