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>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifdef _LARGEFILE64_SOURCE
34 /* This is the macro everything checks before using foo64 names. */
35 # ifndef _LFS64_LARGEFILE
36 # define _LFS64_LARGEFILE 1
42 # if _MIPS_SIM == _MIPS_SIM_ABI64
43 # define LINUX_MIPSN64
44 # elif _MIPS_SIM == _MIPS_SIM_NABI32
45 # define LINUX_MIPSN32
46 # elif _MIPS_SIM == _MIPS_SIM_ABI32
47 # define LINUX_MIPSO32
49 # error Unsupported _MIPS_SIM
59 #include <sys/types.h>
66 /* Open-coding isprint(ch) et al proved more efficient than calling
67 * generalized libc interface. We don't *want* to do non-ASCII anyway.
69 /* #include <ctype.h> */
75 #include <sys/syscall.h>
78 const char *strerror(int);
81 /* Some libc have stpcpy, some don't. Sigh...
82 * Roll our private implementation...
85 #define stpcpy strace_stpcpy
86 extern char *stpcpy(char *dst, const char *src);
90 # define __attribute__(x) /*nothing*/
94 # define offsetof(type, member) \
95 (((char *) &(((type *) NULL)->member)) - ((char *) (type *) NULL))
98 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
102 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
105 # define MIN(a, b) (((a) < (b)) ? (a) : (b))
107 #define CLAMP(val, min, max) MIN(MAX(min, val), max)
109 /* Glibc has an efficient macro for sigemptyset
110 * (it just does one or two assignments of 0 to internal vector of longs).
112 #if defined(__GLIBC__) && defined(__sigemptyset) && !defined(sigemptyset)
113 # define sigemptyset __sigemptyset
116 /* Configuration section */
117 #ifndef DEFAULT_STRLEN
118 /* default maximum # of bytes printed in `printstr', change with -s switch */
119 # define DEFAULT_STRLEN 32
121 #ifndef DEFAULT_ACOLUMN
122 # define DEFAULT_ACOLUMN 40 /* default alignment column for results */
125 * Maximum number of args to a syscall.
127 * Make sure that all entries in all syscallent.h files have nargs <= MAX_ARGS!
128 * linux/<ARCH>/syscallent*.h:
129 * all have nargs <= 6 except mips o32 which has nargs <= 7.
132 # ifdef LINUX_MIPSO32
138 /* default sorting method for call profiling */
139 #ifndef DEFAULT_SORTBY
140 # define DEFAULT_SORTBY "time"
143 * Experimental code using PTRACE_SEIZE can be enabled here.
144 * This needs Linux kernel 3.4.x or later to work.
147 /* To force NOMMU build, set to 1 */
148 #define NOMMU_SYSTEM 0
150 #if (defined(SPARC) || defined(SPARC64) \
151 || defined(I386) || defined(X32) || defined(X86_64) \
152 || defined(ARM) || defined(AARCH64) \
158 ) && defined(__GLIBC__)
159 # include <sys/ptrace.h>
161 /* Work around awkward prototype in ptrace.h. */
162 # define ptrace xptrace
163 # include <sys/ptrace.h>
167 # include <asm/ptrace.h>
170 extern long ptrace(int, int, char *, long);
174 # include <asm/ptrace.h> /* struct pt_regs */
177 #if !HAVE_DECL_PTRACE_SETOPTIONS
178 # define PTRACE_SETOPTIONS 0x4200
180 #if !HAVE_DECL_PTRACE_GETEVENTMSG
181 # define PTRACE_GETEVENTMSG 0x4201
183 #if !HAVE_DECL_PTRACE_GETSIGINFO
184 # define PTRACE_GETSIGINFO 0x4202
187 #if !HAVE_DECL_PTRACE_O_TRACESYSGOOD
188 # define PTRACE_O_TRACESYSGOOD 0x00000001
190 #if !HAVE_DECL_PTRACE_O_TRACEFORK
191 # define PTRACE_O_TRACEFORK 0x00000002
193 #if !HAVE_DECL_PTRACE_O_TRACEVFORK
194 # define PTRACE_O_TRACEVFORK 0x00000004
196 #if !HAVE_DECL_PTRACE_O_TRACECLONE
197 # define PTRACE_O_TRACECLONE 0x00000008
199 #if !HAVE_DECL_PTRACE_O_TRACEEXEC
200 # define PTRACE_O_TRACEEXEC 0x00000010
202 #if !HAVE_DECL_PTRACE_O_TRACEEXIT
203 # define PTRACE_O_TRACEEXIT 0x00000040
206 #if !HAVE_DECL_PTRACE_EVENT_FORK
207 # define PTRACE_EVENT_FORK 1
209 #if !HAVE_DECL_PTRACE_EVENT_VFORK
210 # define PTRACE_EVENT_VFORK 2
212 #if !HAVE_DECL_PTRACE_EVENT_CLONE
213 # define PTRACE_EVENT_CLONE 3
215 #if !HAVE_DECL_PTRACE_EVENT_EXEC
216 # define PTRACE_EVENT_EXEC 4
218 #if !HAVE_DECL_PTRACE_EVENT_VFORK_DONE
219 # define PTRACE_EVENT_VFORK_DONE 5
221 #if !HAVE_DECL_PTRACE_EVENT_EXIT
222 # define PTRACE_EVENT_EXIT 6
225 #if !defined(__GLIBC__)
226 # define PTRACE_PEEKUSER PTRACE_PEEKUSR
227 # define PTRACE_POKEUSER PTRACE_POKEUSR
232 # define PTRACE_SEIZE 0x4206
233 # undef PTRACE_INTERRUPT
234 # define PTRACE_INTERRUPT 0x4207
235 # undef PTRACE_LISTEN
236 # define PTRACE_LISTEN 0x4208
237 # undef PTRACE_EVENT_STOP
238 # define PTRACE_EVENT_STOP 128
256 # define PT_GR20 (20*4)
257 # define PT_GR26 (26*4)
258 # define PT_GR28 (28*4)
259 # define PT_IAOQ0 (106*4)
260 # define PT_IAOQ1 (107*4)
263 /* SH64 Linux - this code assumes the following kernel API for system calls:
265 System Call Offset 16 (actually, (syscall no.) | (0x1n << 16),
266 where n = no. of parameters.
267 Other regs Offset 24+
269 On entry: R2-7 = parameters 1-6 (as many as necessary)
270 On return: R9 = result. */
272 /* Offset for peeks of registers */
273 # define REG_OFFSET (24)
274 # define REG_GENERAL(x) (8*(x)+REG_OFFSET)
275 # define REG_PC (0*8)
276 # define REG_SYSCALL (2*8)
282 # define ARM_cpsr uregs[16]
283 # define ARM_pc uregs[15]
284 # define ARM_lr uregs[14]
285 # define ARM_sp uregs[13]
286 # define ARM_ip uregs[12]
287 # define ARM_fp uregs[11]
288 # define ARM_r10 uregs[10]
289 # define ARM_r9 uregs[9]
290 # define ARM_r8 uregs[8]
291 # define ARM_r7 uregs[7]
292 # define ARM_r6 uregs[6]
293 # define ARM_r5 uregs[5]
294 # define ARM_r4 uregs[4]
295 # define ARM_r3 uregs[3]
296 # define ARM_r2 uregs[2]
297 # define ARM_r1 uregs[1]
298 # define ARM_r0 uregs[0]
299 # define ARM_ORIG_r0 uregs[17]
302 #if defined(SPARC) || defined(SPARC64)
303 /* Indexes into the pt_regs.u_reg[] array -- UREG_XX from kernel are all off
304 * by 1 and use Ix instead of Ox. These work for both 32 and 64 bit Linux. */
308 # define PERSONALITY0_WORDSIZE 4
309 # define PERSONALITY1_WORDSIZE 4
310 # if defined(SPARC64)
311 # include <asm/psrcompat.h>
312 # define SUPPORTED_PERSONALITIES 3
313 # define PERSONALITY2_WORDSIZE 8
315 # include <asm/psr.h>
316 # define SUPPORTED_PERSONALITIES 2
317 # endif /* SPARC64 */
318 #endif /* SPARC[64] */
321 # define SUPPORTED_PERSONALITIES 3
322 # define PERSONALITY0_WORDSIZE 8
323 # define PERSONALITY1_WORDSIZE 4
324 # define PERSONALITY2_WORDSIZE 4
328 # define SUPPORTED_PERSONALITIES 2
329 # define PERSONALITY0_WORDSIZE 4
330 # define PERSONALITY1_WORDSIZE 4
334 /* one personality */
338 /* The existing ARM personality, then AArch64 */
339 # define SUPPORTED_PERSONALITIES 2
340 # define PERSONALITY0_WORDSIZE 4
341 # define PERSONALITY1_WORDSIZE 8
342 # define DEFAULT_PERSONALITY 1
346 # define SUPPORTED_PERSONALITIES 2
347 # define PERSONALITY0_WORDSIZE 8
348 # define PERSONALITY1_WORDSIZE 4
352 # define SUPPORTED_PERSONALITIES 2
353 # define PERSONALITY0_WORDSIZE 8
354 # define PERSONALITY1_WORDSIZE 4
356 # define DEFAULT_PERSONALITY 1
360 #ifndef SUPPORTED_PERSONALITIES
361 # define SUPPORTED_PERSONALITIES 1
363 #ifndef DEFAULT_PERSONALITY
364 # define DEFAULT_PERSONALITY 0
366 #ifndef PERSONALITY0_WORDSIZE
367 # define PERSONALITY0_WORDSIZE (int)(sizeof(long))
371 extern struct user_regs_struct i386_regs;
374 #elif defined(SPARC) || defined(SPARC64)
375 extern struct pt_regs sparc_regs;
377 extern struct pt_regs arm_regs;
379 extern struct pt_regs tile_regs;
382 typedef struct sysent {
386 const char *sys_name;
389 typedef struct ioctlent {
395 /* Trace Control Block */
397 int flags; /* See below for TCB_ values */
398 int pid; /* Process Id of this entry */
399 int qual_flg; /* qual_flags[scno] or DEFAULT_QUAL_FLAGS + RAW */
400 int u_error; /* Error code */
401 long scno; /* System call number */
402 long u_arg[MAX_ARGS]; /* System call arguments */
403 #if defined(LINUX_MIPSN32) || defined(X32)
404 long long ext_arg[MAX_ARGS];
405 long long u_lrval; /* long long return value */
407 long u_rval; /* Return value */
408 #if SUPPORTED_PERSONALITIES > 1
409 int currpers; /* Personality at the time of scno update */
411 int curcol; /* Output column for this process */
412 FILE *outf; /* Output file for this process */
413 const char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */
414 const struct_sysent *s_ent; /* sysent[scno] or dummy struct for bad scno */
415 struct timeval stime; /* System time usage as of last process wait */
416 struct timeval dtime; /* Delta for system time usage */
417 struct timeval etime; /* Syscall entry time */
418 /* Support for tracing forked processes: */
419 long inst[2]; /* Saved clone args (badly named) */
423 #define TCB_INUSE 00001 /* This table entry is in use */
424 /* We have attached to this process, but did not see it stopping yet */
425 #define TCB_STARTUP 00002
426 #define TCB_IGNORE_ONE_SIGSTOP 00004 /* Next SIGSTOP is to be ignored */
428 * Are we in system call entry or in syscall exit?
430 * This bit is set after all syscall entry processing is done.
431 * Therefore, this bit will be set when next ptrace stop occurs,
432 * which should be syscall exit stop. Other stops which are possible
433 * directly after syscall entry (death, ptrace event stop)
434 * are simpler and handled without calling trace_syscall(), therefore
435 * the places where TCB_INSYSCALL can be set but we aren't in syscall stop
436 * are limited to trace(), this condition is never observed in trace_syscall()
438 * The bit is cleared after all syscall exit processing is done.
439 * User-generated SIGTRAPs and post-execve SIGTRAP make it necessary
440 * to be very careful and NOT set TCB_INSYSCALL bit when they are encountered.
441 * TCB_WAITEXECVE bit is used for this purpose (see below).
443 * Use entering(tcp) / exiting(tcp) to check this bit to make code more readable.
445 #define TCB_INSYSCALL 00010
446 #define TCB_ATTACHED 00020 /* It is attached already */
447 /* Are we PROG from "strace PROG [ARGS]" invocation? */
448 #define TCB_STRACE_CHILD 0040
449 #define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */
450 #define TCB_REPRINT 00200 /* We should reprint this syscall on exit */
451 #define TCB_FILTERED 00400 /* This system call has been filtered out */
452 /* x86 does not need TCB_WAITEXECVE.
453 * It can detect post-execve SIGTRAP by looking at eax/rax.
454 * See "not a syscall entry (eax = %ld)\n" message.
456 * Note! On new kernels (about 2.5.46+), we use PTRACE_O_TRACEEXEC, which
457 * suppresses post-execve SIGTRAP. If you are adding a new arch which is
458 * only supported by newer kernels, you most likely don't need to define
462 || defined(SPARC) || defined(SPARC64) \
463 || defined(POWERPC) \
466 || defined(SH) || defined(SH64) \
467 || defined(S390) || defined(S390X) \
470 /* This tracee has entered into execve syscall. Expect post-execve SIGTRAP
471 * to happen. (When it is detected, tracee is continued and this bit is cleared.)
473 # define TCB_WAITEXECVE 01000
476 /* qualifier flags */
477 #define QUAL_TRACE 0x001 /* this system call should be traced */
478 #define QUAL_ABBREV 0x002 /* abbreviate the structures of this syscall */
479 #define QUAL_VERBOSE 0x004 /* decode the structures of this syscall */
480 #define QUAL_RAW 0x008 /* print all args in hex for this syscall */
481 #define QUAL_SIGNAL 0x010 /* report events with this signal */
482 #define QUAL_READ 0x020 /* dump data read on this file descriptor */
483 #define QUAL_WRITE 0x040 /* dump data written to this file descriptor */
484 typedef uint8_t qualbits_t;
485 #define UNDEFINED_SCNO 0x100 /* Used only in tcp->qual_flg */
487 #define DEFAULT_QUAL_FLAGS (QUAL_TRACE | QUAL_ABBREV | QUAL_VERBOSE)
489 #define entering(tcp) (!((tcp)->flags & TCB_INSYSCALL))
490 #define exiting(tcp) ((tcp)->flags & TCB_INSYSCALL)
491 #define syserror(tcp) ((tcp)->u_error != 0)
492 #define verbose(tcp) ((tcp)->qual_flg & QUAL_VERBOSE)
493 #define abbrev(tcp) ((tcp)->qual_flg & QUAL_ABBREV)
494 #define filtered(tcp) ((tcp)->flags & TCB_FILTERED)
501 extern const struct xlat open_mode_flags[];
502 extern const struct xlat addrfams[];
503 extern const struct xlat struct_user_offsets[];
504 extern const struct xlat open_access_modes[];
505 extern const struct xlat whence_codes[];
507 /* Format of syscall return values */
508 #define RVAL_DECIMAL 000 /* decimal format */
509 #define RVAL_HEX 001 /* hex format */
510 #define RVAL_OCTAL 002 /* octal format */
511 #define RVAL_UDECIMAL 003 /* unsigned decimal format */
512 #if defined(LINUX_MIPSN32) || defined(X32)
513 # if 0 /* unused so far */
514 # define RVAL_LDECIMAL 004 /* long decimal format */
515 # define RVAL_LHEX 005 /* long hex format */
516 # define RVAL_LOCTAL 006 /* long octal format */
518 # define RVAL_LUDECIMAL 007 /* long unsigned decimal format */
520 #define RVAL_MASK 007 /* mask for these values */
522 #define RVAL_STR 010 /* Print `auxstr' field after return val */
523 #define RVAL_NONE 020 /* Print nothing */
525 #define TRACE_FILE 001 /* Trace file-related syscalls. */
526 #define TRACE_IPC 002 /* Trace IPC-related syscalls. */
527 #define TRACE_NETWORK 004 /* Trace network-related syscalls. */
528 #define TRACE_PROCESS 010 /* Trace process-related syscalls. */
529 #define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */
530 #define TRACE_DESC 040 /* Trace file descriptor-related syscalls. */
531 #define TRACE_MEMORY 0100 /* Trace memory mapping-related syscalls. */
532 #define SYSCALL_NEVER_FAILS 0200 /* Syscall is always successful. */
539 extern cflag_t cflag;
540 extern bool debug_flag;
542 extern unsigned int qflag;
543 extern bool not_failing_only;
544 extern bool show_fd_path;
545 extern bool hide_log_until_execve;
546 /* are we filtering traces based on paths? */
547 extern const char **paths_selected;
548 #define tracing_paths (paths_selected != NULL)
549 extern bool need_fork_exec_workarounds;
550 extern unsigned xflag;
551 extern unsigned followfork;
552 extern unsigned ptrace_setoptions;
553 extern unsigned max_strlen;
554 extern unsigned os_release;
555 #undef KERNEL_VERSION
556 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
558 enum bitness_t { BITNESS_CURRENT = 0, BITNESS_32 };
560 void error_msg(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
561 void perror_msg(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
562 void error_msg_and_die(const char *fmt, ...) __attribute__ ((noreturn, format(printf, 1, 2)));
563 void perror_msg_and_die(const char *fmt, ...) __attribute__ ((noreturn, format(printf, 1, 2)));
564 void die_out_of_memory(void) __attribute__ ((noreturn));
566 #ifdef USE_CUSTOM_PRINTF
568 * Speed-optimized vfprintf implementation.
569 * See comment in vsprintf.c for allowed formats.
570 * Short version: %h[h]u, %zu, %tu are not allowed, use %[l[l]]u.
572 * It results in strace using about 5% less CPU in user space
573 * (compared to glibc version).
574 * But strace spends a lot of time in kernel space,
575 * so overall it does not appear to be a significant win.
576 * Thus disabled by default.
578 int strace_vfprintf(FILE *fp, const char *fmt, va_list args);
580 # define strace_vfprintf vfprintf
583 extern void set_sortby(const char *);
584 extern void set_overhead(int);
585 extern void qualify(const char *);
586 extern int trace_syscall(struct tcb *);
587 extern void count_syscall(struct tcb *, struct timeval *);
588 extern void call_summary(FILE *);
592 || defined(X86_64) || defined(X32) \
593 || defined(AARCH64) \
595 || defined(SPARC) || defined(SPARC64) \
599 extern long get_regs_error;
600 # define clear_regs() (get_regs_error = -1)
601 extern void get_regs(pid_t pid);
603 # define get_regs_error 0
604 # define clear_regs() ((void)0)
605 # define get_regs(pid) ((void)0)
607 extern int umoven(struct tcb *, long, int, char *);
608 #define umove(pid, addr, objp) \
609 umoven((pid), (addr), sizeof(*(objp)), (char *) (objp))
610 extern int umovestr(struct tcb *, long, int, char *);
611 extern int upeek(struct tcb *, long, long *);
612 #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH)
613 extern long getrval2(struct tcb *);
616 * On Linux, "setbpt" is a misnomer: we don't set a breakpoint
617 * (IOW: no poking in user's text segment),
618 * instead we change fork/vfork/clone into clone(CLONE_PTRACE).
619 * On newer kernels, we use PTRACE_O_TRACECLONE/TRACE[V]FORK instead.
621 extern int setbpt(struct tcb *);
622 extern int clearbpt(struct tcb *);
624 extern const char *signame(int);
625 extern int is_restart_error(struct tcb *);
626 extern void pathtrace_select(const char *);
627 extern int pathtrace_match(struct tcb *);
628 extern int getfdpath(struct tcb *, int, char *, unsigned);
630 extern const char *xlookup(const struct xlat *, int);
632 extern int string_to_uint(const char *str);
633 extern int string_quote(const char *, char *, long, int);
635 /* a refers to the lower numbered u_arg,
636 * b refers to the higher numbered u_arg
638 #if HAVE_LITTLE_ENDIAN_LONG_LONG
639 # define LONG_LONG(a,b) \
640 ((long long)((unsigned long long)(unsigned)(a) | ((unsigned long long)(b)<<32)))
642 # define LONG_LONG(a,b) \
643 ((long long)((unsigned long long)(unsigned)(b) | ((unsigned long long)(a)<<32)))
645 extern int printllval(struct tcb *, const char *, int);
647 extern void printxval(const struct xlat *, int, const char *);
648 extern int printargs(struct tcb *);
649 extern int printargs_lu(struct tcb *);
650 extern int printargs_ld(struct tcb *);
651 extern void addflags(const struct xlat *, int);
652 extern int printflags(const struct xlat *, int, const char *);
653 extern const char *sprintflags(const char *, const struct xlat *, int);
654 extern void dumpiov(struct tcb *, int, long);
655 extern void dumpstr(struct tcb *, long, int);
656 extern void printstr(struct tcb *, long, long);
657 extern void printnum(struct tcb *, long, const char *);
658 extern void printnum_int(struct tcb *, long, const char *);
659 extern void printpath(struct tcb *, long);
660 extern void printpathn(struct tcb *, long, int);
661 #define TIMESPEC_TEXT_BUFSIZE (sizeof(long)*3 * 2 + sizeof("{%u, %u}"))
662 #define TIMEVAL_TEXT_BUFSIZE TIMESPEC_TEXT_BUFSIZE
663 extern void printtv_bitness(struct tcb *, long, enum bitness_t, int);
664 #define printtv(tcp, addr) \
665 printtv_bitness((tcp), (addr), BITNESS_CURRENT, 0)
666 #define printtv_special(tcp, addr) \
667 printtv_bitness((tcp), (addr), BITNESS_CURRENT, 1)
668 extern char *sprinttv(char *, struct tcb *, long, enum bitness_t, int special);
669 extern void print_timespec(struct tcb *, long);
670 extern void sprint_timespec(char *, struct tcb *, long);
671 #ifdef HAVE_SIGINFO_T
672 extern void printsiginfo(siginfo_t *, int);
673 extern void printsiginfo_at(struct tcb *tcp, long addr);
675 extern void printfd(struct tcb *, int);
676 extern void printsock(struct tcb *, long, int);
677 extern void print_sock_optmgmt(struct tcb *, long, int);
678 extern void printrusage(struct tcb *, long);
680 extern void printrusage32(struct tcb *, long);
682 extern void printuid(const char *, unsigned long);
683 extern void printcall(struct tcb *);
684 extern void print_sigset(struct tcb *, long, int);
685 extern void printsignal(int);
686 extern void tprint_iov(struct tcb *, unsigned long, unsigned long, int decode_iov);
687 extern void tprint_iov_upto(struct tcb *, unsigned long, unsigned long, int decode_iov, unsigned long);
688 extern void tprint_open_modes(mode_t);
689 extern const char *sprint_open_modes(mode_t);
690 extern void print_loff_t(struct tcb *, long);
692 extern const struct_ioctlent *ioctl_lookup(long);
693 extern const struct_ioctlent *ioctl_next_match(const struct_ioctlent *);
694 extern int ioctl_decode(struct tcb *, long, long);
695 extern int term_ioctl(struct tcb *, long, long);
696 extern int sock_ioctl(struct tcb *, long, long);
697 extern int proc_ioctl(struct tcb *, int, int);
698 extern int rtc_ioctl(struct tcb *, long, long);
699 extern int scsi_ioctl(struct tcb *, long, long);
700 extern int block_ioctl(struct tcb *, long, long);
701 extern int mtd_ioctl(struct tcb *, long, long);
702 extern int ubi_ioctl(struct tcb *, long, long);
703 extern int loop_ioctl(struct tcb *, long, long);
705 extern int tv_nz(struct timeval *);
706 extern int tv_cmp(struct timeval *, struct timeval *);
707 extern double tv_float(struct timeval *);
708 extern void tv_add(struct timeval *, struct timeval *, struct timeval *);
709 extern void tv_sub(struct timeval *, struct timeval *, struct timeval *);
710 extern void tv_mul(struct timeval *, struct timeval *, int);
711 extern void tv_div(struct timeval *, struct timeval *, int);
713 /* Strace log generation machinery.
715 * printing_tcp: tcb which has incomplete line being printed right now.
716 * NULL if last line has been completed ('\n'-terminated).
717 * printleader(tcp) examines it, finishes incomplete line if needed,
718 * the sets it to tcp.
719 * line_ended() clears printing_tcp and resets ->curcol = 0.
720 * tcp->curcol == 0 check is also used to detect completeness
721 * of last line, since in -ff mode just checking printing_tcp for NULL
724 * If you change this code, test log generation in both -f and -ff modes
726 * strace -oLOG -f[f] test/threaded_execve
727 * strace -oLOG -f[f] test/sigkill_rain
728 * strace -oLOG -f[f] -p "`pidof web_browser`"
730 extern struct tcb *printing_tcp;
731 extern void printleader(struct tcb *);
732 extern void line_ended(void);
733 extern void tabto(void);
734 extern void tprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
735 extern void tprints(const char *str);
737 #if SUPPORTED_PERSONALITIES > 1
738 extern void set_personality(int personality);
739 extern unsigned current_personality;
741 # define set_personality(personality) ((void)0)
742 # define current_personality 0
745 #if SUPPORTED_PERSONALITIES == 1
746 # define current_wordsize PERSONALITY0_WORDSIZE
748 # if SUPPORTED_PERSONALITIES == 2 && PERSONALITY0_WORDSIZE == PERSONALITY1_WORDSIZE
749 # define current_wordsize PERSONALITY0_WORDSIZE
751 extern unsigned current_wordsize;
755 /* In many, many places we play fast and loose and use
756 * tprintf("%d", (int) tcp->u_arg[N]) to print fds, pids etc.
757 * We probably need to use widen_to_long() instead:
759 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
760 # define widen_to_long(v) (current_wordsize == 4 ? (long)(int32_t)(v) : (long)(v))
762 # define widen_to_long(v) ((long)(v))
765 extern const struct_sysent sysent0[];
766 extern const char *const errnoent0[];
767 extern const char *const signalent0[];
768 extern const struct_ioctlent ioctlent0[];
769 extern qualbits_t *qual_vec[SUPPORTED_PERSONALITIES];
770 #define qual_flags (qual_vec[current_personality])
771 #if SUPPORTED_PERSONALITIES > 1
772 extern const struct_sysent *sysent;
773 extern const char *const *errnoent;
774 extern const char *const *signalent;
775 extern const struct_ioctlent *ioctlent;
777 # define sysent sysent0
778 # define errnoent errnoent0
779 # define signalent signalent0
780 # define ioctlent ioctlent0
782 extern unsigned nsyscalls;
783 extern unsigned nerrnos;
784 extern unsigned nsignals;
785 extern unsigned nioctlents;
786 extern unsigned num_quals;
789 * If you need non-NULL sysent[scno].sys_func and sysent[scno].sys_name
791 #define SCNO_IS_VALID(scno) \
792 ((unsigned long)(scno) < nsyscalls && sysent[scno].sys_func)
794 /* Only ensures that sysent[scno] isn't out of range */
795 #define SCNO_IN_RANGE(scno) \
796 ((unsigned long)(scno) < nsyscalls)