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
48 #include <sys/types.h>
55 /* Open-coding isprint(ch) et al proved more efficient than calling
56 * generalized libc interface. We don't *want* to do non-ASCII anyway.
58 /* #include <ctype.h> */
64 #include <sys/syscall.h>
67 const char *strerror(int);
70 /* Some libc have stpcpy, some don't. Sigh...
71 * Roll our private implementation...
74 #define stpcpy strace_stpcpy
75 extern char *stpcpy(char *dst, const char *src);
79 # define __attribute__(x) /*nothing*/
83 # define offsetof(type, member) \
84 (((char *) &(((type *) NULL)->member)) - ((char *) (type *) NULL))
87 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
89 /* Glibc has an efficient macro for sigemptyset
90 * (it just does one or two assignments of 0 to internal vector of longs).
92 #if defined(__GLIBC__) && defined(__sigemptyset) && !defined(sigemptyset)
93 # define sigemptyset __sigemptyset
96 /* Configuration section */
97 #ifndef DEFAULT_STRLEN
98 /* default maximum # of bytes printed in `printstr', change with -s switch */
99 # define DEFAULT_STRLEN 32
101 #ifndef DEFAULT_ACOLUMN
102 # define DEFAULT_ACOLUMN 40 /* default alignment column for results */
105 * Maximum number of args to a syscall.
107 * Make sure that all entries in all syscallent.h files have nargs <= MAX_ARGS!
108 * linux/<ARCH>/syscallent.h: all have nargs <= 6.
113 /* default sorting method for call profiling */
114 #ifndef DEFAULT_SORTBY
115 # define DEFAULT_SORTBY "time"
118 * Experimental code using PTRACE_SEIZE can be enabled here.
119 * This needs Linux kernel 3.4.x or later to work.
122 /* To force NOMMU build, set to 1 */
123 #define NOMMU_SYSTEM 0
126 #if defined(MIPS) && _MIPS_SIM == _MIPS_SIM_ABI32
127 # define LINUX_MIPSO32
129 #if defined(MIPS) && _MIPS_SIM == _MIPS_SIM_NABI32
130 # define LINUX_MIPSN32
132 #if defined(MIPS) && _MIPS_SIM == _MIPS_SIM_ABI64
133 # define LINUX_MIPSN64
136 #if (defined(SPARC) || defined(SPARC64) \
137 || defined(I386) || defined(X32) || defined(X86_64) \
138 || defined(ARM) || defined(AARCH64) \
143 ) && defined(__GLIBC__)
144 # include <sys/ptrace.h>
146 /* Work around awkward prototype in ptrace.h. */
147 # define ptrace xptrace
148 # include <sys/ptrace.h>
152 # include <asm/ptrace.h>
155 extern long ptrace(int, int, char *, long);
159 # include <asm/ptrace.h> /* struct pt_regs */
162 #if !HAVE_DECL_PTRACE_SETOPTIONS
163 # define PTRACE_SETOPTIONS 0x4200
165 #if !HAVE_DECL_PTRACE_GETEVENTMSG
166 # define PTRACE_GETEVENTMSG 0x4201
168 #if !HAVE_DECL_PTRACE_GETSIGINFO
169 # define PTRACE_GETSIGINFO 0x4202
172 #if !HAVE_DECL_PTRACE_O_TRACESYSGOOD
173 # define PTRACE_O_TRACESYSGOOD 0x00000001
175 #if !HAVE_DECL_PTRACE_O_TRACEFORK
176 # define PTRACE_O_TRACEFORK 0x00000002
178 #if !HAVE_DECL_PTRACE_O_TRACEVFORK
179 # define PTRACE_O_TRACEVFORK 0x00000004
181 #if !HAVE_DECL_PTRACE_O_TRACECLONE
182 # define PTRACE_O_TRACECLONE 0x00000008
184 #if !HAVE_DECL_PTRACE_O_TRACEEXEC
185 # define PTRACE_O_TRACEEXEC 0x00000010
187 #if !HAVE_DECL_PTRACE_O_TRACEEXIT
188 # define PTRACE_O_TRACEEXIT 0x00000040
191 #if !HAVE_DECL_PTRACE_EVENT_FORK
192 # define PTRACE_EVENT_FORK 1
194 #if !HAVE_DECL_PTRACE_EVENT_VFORK
195 # define PTRACE_EVENT_VFORK 2
197 #if !HAVE_DECL_PTRACE_EVENT_CLONE
198 # define PTRACE_EVENT_CLONE 3
200 #if !HAVE_DECL_PTRACE_EVENT_EXEC
201 # define PTRACE_EVENT_EXEC 4
203 #if !HAVE_DECL_PTRACE_EVENT_VFORK_DONE
204 # define PTRACE_EVENT_VFORK_DONE 5
206 #if !HAVE_DECL_PTRACE_EVENT_EXIT
207 # define PTRACE_EVENT_EXIT 6
210 #if !defined(__GLIBC__)
211 # define PTRACE_PEEKUSER PTRACE_PEEKUSR
212 # define PTRACE_POKEUSER PTRACE_POKEUSR
217 # define PTRACE_SEIZE 0x4206
218 # undef PTRACE_INTERRUPT
219 # define PTRACE_INTERRUPT 0x4207
220 # undef PTRACE_LISTEN
221 # define PTRACE_LISTEN 0x4208
222 # undef PTRACE_EVENT_STOP
223 # define PTRACE_EVENT_STOP 128
241 # define PT_GR20 (20*4)
242 # define PT_GR26 (26*4)
243 # define PT_GR28 (28*4)
244 # define PT_IAOQ0 (106*4)
245 # define PT_IAOQ1 (107*4)
248 /* SH64 Linux - this code assumes the following kernel API for system calls:
250 System Call Offset 16 (actually, (syscall no.) | (0x1n << 16),
251 where n = no. of parameters.
252 Other regs Offset 24+
254 On entry: R2-7 = parameters 1-6 (as many as necessary)
255 On return: R9 = result. */
257 /* Offset for peeks of registers */
258 # define REG_OFFSET (24)
259 # define REG_GENERAL(x) (8*(x)+REG_OFFSET)
260 # define REG_PC (0*8)
261 # define REG_SYSCALL (2*8)
267 # define ARM_cpsr uregs[16]
268 # define ARM_pc uregs[15]
269 # define ARM_lr uregs[14]
270 # define ARM_sp uregs[13]
271 # define ARM_ip uregs[12]
272 # define ARM_fp uregs[11]
273 # define ARM_r10 uregs[10]
274 # define ARM_r9 uregs[9]
275 # define ARM_r8 uregs[8]
276 # define ARM_r7 uregs[7]
277 # define ARM_r6 uregs[6]
278 # define ARM_r5 uregs[5]
279 # define ARM_r4 uregs[4]
280 # define ARM_r3 uregs[3]
281 # define ARM_r2 uregs[2]
282 # define ARM_r1 uregs[1]
283 # define ARM_r0 uregs[0]
284 # define ARM_ORIG_r0 uregs[17]
287 #if defined(SPARC) || defined(SPARC64)
288 /* Indexes into the pt_regs.u_reg[] array -- UREG_XX from kernel are all off
289 * by 1 and use Ix instead of Ox. These work for both 32 and 64 bit Linux. */
293 # define PERSONALITY0_WORDSIZE 4
294 # define PERSONALITY1_WORDSIZE 4
295 # if defined(SPARC64)
296 # include <asm/psrcompat.h>
297 # define SUPPORTED_PERSONALITIES 3
298 # define PERSONALITY2_WORDSIZE 8
300 # include <asm/psr.h>
301 # define SUPPORTED_PERSONALITIES 2
302 # endif /* SPARC64 */
303 #endif /* SPARC[64] */
306 # define SUPPORTED_PERSONALITIES 3
307 # define PERSONALITY0_WORDSIZE 8
308 # define PERSONALITY1_WORDSIZE 4
309 # define PERSONALITY2_WORDSIZE 4
313 # define SUPPORTED_PERSONALITIES 2
314 # define PERSONALITY0_WORDSIZE 4
315 # define PERSONALITY1_WORDSIZE 4
319 /* one personality */
323 /* The existing ARM personality, then AArch64 */
324 # define SUPPORTED_PERSONALITIES 2
325 # define PERSONALITY0_WORDSIZE 4
326 # define PERSONALITY1_WORDSIZE 8
327 # define DEFAULT_PERSONALITY 1
331 # define SUPPORTED_PERSONALITIES 2
332 # define PERSONALITY0_WORDSIZE 8
333 # define PERSONALITY1_WORDSIZE 4
337 # define SUPPORTED_PERSONALITIES 2
338 # define PERSONALITY0_WORDSIZE 8
339 # define PERSONALITY1_WORDSIZE 4
341 # define DEFAULT_PERSONALITY 1
345 #ifndef SUPPORTED_PERSONALITIES
346 # define SUPPORTED_PERSONALITIES 1
348 #ifndef DEFAULT_PERSONALITY
349 # define DEFAULT_PERSONALITY 0
351 #ifndef PERSONALITY0_WORDSIZE
352 # define PERSONALITY0_WORDSIZE (int)(sizeof(long))
356 extern struct user_regs_struct i386_regs;
359 #elif defined(SPARC) || defined(SPARC64)
360 extern struct pt_regs sparc_regs;
362 extern struct pt_regs arm_regs;
364 extern struct pt_regs tile_regs;
367 typedef struct sysent {
371 const char *sys_name;
374 typedef struct ioctlent {
380 /* Trace Control Block */
382 int flags; /* See below for TCB_ values */
383 int pid; /* Process Id of this entry */
384 int qual_flg; /* qual_flags[scno] or DEFAULT_QUAL_FLAGS + RAW */
385 int u_error; /* Error code */
386 long scno; /* System call number */
387 long u_arg[MAX_ARGS]; /* System call arguments */
388 #if defined(LINUX_MIPSN32) || defined(X32)
389 long long ext_arg[MAX_ARGS];
390 long long u_lrval; /* long long return value */
392 long u_rval; /* Return value */
393 #if SUPPORTED_PERSONALITIES > 1
394 int currpers; /* Personality at the time of scno update */
396 int curcol; /* Output column for this process */
397 FILE *outf; /* Output file for this process */
398 const char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */
399 const struct_sysent *s_ent; /* sysent[scno] or dummy struct for bad scno */
400 struct timeval stime; /* System time usage as of last process wait */
401 struct timeval dtime; /* Delta for system time usage */
402 struct timeval etime; /* Syscall entry time */
403 /* Support for tracing forked processes: */
404 long inst[2]; /* Saved clone args (badly named) */
408 #define TCB_INUSE 00001 /* This table entry is in use */
409 /* We have attached to this process, but did not see it stopping yet */
410 #define TCB_STARTUP 00002
411 #define TCB_IGNORE_ONE_SIGSTOP 00004 /* Next SIGSTOP is to be ignored */
413 * Are we in system call entry or in syscall exit?
415 * This bit is set after all syscall entry processing is done.
416 * Therefore, this bit will be set when next ptrace stop occurs,
417 * which should be syscall exit stop. Other stops which are possible
418 * directly after syscall entry (death, ptrace event stop)
419 * are simpler and handled without calling trace_syscall(), therefore
420 * the places where TCB_INSYSCALL can be set but we aren't in syscall stop
421 * are limited to trace(), this condition is never observed in trace_syscall()
423 * The bit is cleared after all syscall exit processing is done.
424 * User-generated SIGTRAPs and post-execve SIGTRAP make it necessary
425 * to be very careful and NOT set TCB_INSYSCALL bit when they are encountered.
426 * TCB_WAITEXECVE bit is used for this purpose (see below).
428 * Use entering(tcp) / exiting(tcp) to check this bit to make code more readable.
430 #define TCB_INSYSCALL 00010
431 #define TCB_ATTACHED 00020 /* It is attached already */
432 /* Are we PROG from "strace PROG [ARGS]" invocation? */
433 #define TCB_STRACE_CHILD 0040
434 #define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */
435 #define TCB_REPRINT 00200 /* We should reprint this syscall on exit */
436 #define TCB_FILTERED 00400 /* This system call has been filtered out */
437 /* x86 does not need TCB_WAITEXECVE.
438 * It can detect post-execve SIGTRAP by looking at eax/rax.
439 * See "not a syscall entry (eax = %ld)\n" message.
441 * Note! On new kernels (about 2.5.46+), we use PTRACE_O_TRACEEXEC, which
442 * suppresses post-execve SIGTRAP. If you are adding a new arch which is
443 * only supported by newer kernels, you most likely don't need to define
447 || defined(SPARC) || defined(SPARC64) \
448 || defined(POWERPC) \
451 || defined(SH) || defined(SH64) \
452 || defined(S390) || defined(S390X) \
455 /* This tracee has entered into execve syscall. Expect post-execve SIGTRAP
456 * to happen. (When it is detected, tracee is continued and this bit is cleared.)
458 # define TCB_WAITEXECVE 01000
461 /* qualifier flags */
462 #define QUAL_TRACE 0x001 /* this system call should be traced */
463 #define QUAL_ABBREV 0x002 /* abbreviate the structures of this syscall */
464 #define QUAL_VERBOSE 0x004 /* decode the structures of this syscall */
465 #define QUAL_RAW 0x008 /* print all args in hex for this syscall */
466 #define QUAL_SIGNAL 0x010 /* report events with this signal */
467 #define QUAL_READ 0x020 /* dump data read on this file descriptor */
468 #define QUAL_WRITE 0x040 /* dump data written to this file descriptor */
469 typedef uint8_t qualbits_t;
470 #define UNDEFINED_SCNO 0x100 /* Used only in tcp->qual_flg */
472 #define DEFAULT_QUAL_FLAGS (QUAL_TRACE | QUAL_ABBREV | QUAL_VERBOSE)
474 #define entering(tcp) (!((tcp)->flags & TCB_INSYSCALL))
475 #define exiting(tcp) ((tcp)->flags & TCB_INSYSCALL)
476 #define syserror(tcp) ((tcp)->u_error != 0)
477 #define verbose(tcp) ((tcp)->qual_flg & QUAL_VERBOSE)
478 #define abbrev(tcp) ((tcp)->qual_flg & QUAL_ABBREV)
479 #define filtered(tcp) ((tcp)->flags & TCB_FILTERED)
486 extern const struct xlat open_mode_flags[];
487 extern const struct xlat addrfams[];
488 extern const struct xlat struct_user_offsets[];
489 extern const struct xlat open_access_modes[];
490 extern const struct xlat whence_codes[];
492 /* Format of syscall return values */
493 #define RVAL_DECIMAL 000 /* decimal format */
494 #define RVAL_HEX 001 /* hex format */
495 #define RVAL_OCTAL 002 /* octal format */
496 #define RVAL_UDECIMAL 003 /* unsigned decimal format */
497 #if defined(LINUX_MIPSN32) || defined(X32)
498 # if 0 /* unused so far */
499 # define RVAL_LDECIMAL 004 /* long decimal format */
500 # define RVAL_LHEX 005 /* long hex format */
501 # define RVAL_LOCTAL 006 /* long octal format */
503 # define RVAL_LUDECIMAL 007 /* long unsigned decimal format */
505 #define RVAL_MASK 007 /* mask for these values */
507 #define RVAL_STR 010 /* Print `auxstr' field after return val */
508 #define RVAL_NONE 020 /* Print nothing */
510 #define TRACE_FILE 001 /* Trace file-related syscalls. */
511 #define TRACE_IPC 002 /* Trace IPC-related syscalls. */
512 #define TRACE_NETWORK 004 /* Trace network-related syscalls. */
513 #define TRACE_PROCESS 010 /* Trace process-related syscalls. */
514 #define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */
515 #define TRACE_DESC 040 /* Trace file descriptor-related syscalls. */
516 #define TRACE_MEMORY 0100 /* Trace memory mapping-related syscalls. */
517 #define SYSCALL_NEVER_FAILS 0200 /* Syscall is always successful. */
524 extern cflag_t cflag;
525 extern bool debug_flag;
528 extern bool not_failing_only;
529 extern bool show_fd_path;
530 /* are we filtering traces based on paths? */
531 extern const char **paths_selected;
532 #define tracing_paths (paths_selected != NULL)
533 extern bool need_fork_exec_workarounds;
534 extern unsigned xflag;
535 extern unsigned followfork;
536 extern unsigned ptrace_setoptions;
537 extern unsigned max_strlen;
538 extern unsigned os_release;
539 #undef KERNEL_VERSION
540 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
542 enum bitness_t { BITNESS_CURRENT = 0, BITNESS_32 };
544 void error_msg(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
545 void perror_msg(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
546 void error_msg_and_die(const char *fmt, ...) __attribute__ ((noreturn, format(printf, 1, 2)));
547 void perror_msg_and_die(const char *fmt, ...) __attribute__ ((noreturn, format(printf, 1, 2)));
548 void die_out_of_memory(void) __attribute__ ((noreturn));
550 #ifdef USE_CUSTOM_PRINTF
552 * Speed-optimized vfprintf implementation.
553 * See comment in vsprintf.c for allowed formats.
554 * Short version: %h[h]u, %zu, %tu are not allowed, use %[l[l]]u.
556 * It results in strace using about 5% less CPU in user space
557 * (compared to glibc version).
558 * But strace spends a lot of time in kernel space,
559 * so overall it does not appear to be a significant win.
560 * Thus disabled by default.
562 int strace_vfprintf(FILE *fp, const char *fmt, va_list args);
564 # define strace_vfprintf vfprintf
567 extern void set_sortby(const char *);
568 extern void set_overhead(int);
569 extern void qualify(const char *);
570 extern int trace_syscall(struct tcb *);
571 extern void count_syscall(struct tcb *, struct timeval *);
572 extern void call_summary(FILE *);
576 || defined(X86_64) || defined(X32) \
577 || defined(AARCH64) \
579 || defined(SPARC) || defined(SPARC64) \
583 extern long get_regs_error;
584 # define clear_regs() (get_regs_error = -1)
585 extern void get_regs(pid_t pid);
587 # define get_regs_error 0
588 # define clear_regs() ((void)0)
589 # define get_regs(pid) ((void)0)
591 extern int umoven(struct tcb *, long, int, char *);
592 #define umove(pid, addr, objp) \
593 umoven((pid), (addr), sizeof(*(objp)), (char *) (objp))
594 extern int umovestr(struct tcb *, long, int, char *);
595 extern int upeek(struct tcb *, long, long *);
596 #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH)
597 extern long getrval2(struct tcb *);
600 * On Linux, "setbpt" is a misnomer: we don't set a breakpoint
601 * (IOW: no poking in user's text segment),
602 * instead we change fork/vfork/clone into clone(CLONE_PTRACE).
603 * On newer kernels, we use PTRACE_O_TRACECLONE/TRACE[V]FORK instead.
605 extern int setbpt(struct tcb *);
606 extern int clearbpt(struct tcb *);
608 extern const char *signame(int);
609 extern int is_restart_error(struct tcb *);
610 extern void pathtrace_select(const char *);
611 extern int pathtrace_match(struct tcb *);
612 extern int getfdpath(struct tcb *, int, char *, unsigned);
614 extern const char *xlookup(const struct xlat *, int);
616 extern int string_to_uint(const char *str);
617 extern int string_quote(const char *, char *, long, int);
619 /* a refers to the lower numbered u_arg,
620 * b refers to the higher numbered u_arg
622 #if HAVE_LITTLE_ENDIAN_LONG_LONG
623 # define LONG_LONG(a,b) \
624 ((long long)((unsigned long long)(unsigned)(a) | ((unsigned long long)(b)<<32)))
626 # define LONG_LONG(a,b) \
627 ((long long)((unsigned long long)(unsigned)(b) | ((unsigned long long)(a)<<32)))
629 extern int printllval(struct tcb *, const char *, int);
631 extern void printxval(const struct xlat *, int, const char *);
632 extern int printargs(struct tcb *);
633 extern int printargs_lu(struct tcb *);
634 extern int printargs_ld(struct tcb *);
635 extern void addflags(const struct xlat *, int);
636 extern int printflags(const struct xlat *, int, const char *);
637 extern const char *sprintflags(const char *, const struct xlat *, int);
638 extern void dumpiov(struct tcb *, int, long);
639 extern void dumpstr(struct tcb *, long, int);
640 extern void printstr(struct tcb *, long, long);
641 extern void printnum(struct tcb *, long, const char *);
642 extern void printnum_int(struct tcb *, long, const char *);
643 extern void printpath(struct tcb *, long);
644 extern void printpathn(struct tcb *, long, int);
645 #define TIMESPEC_TEXT_BUFSIZE (sizeof(long)*3 * 2 + sizeof("{%u, %u}"))
646 #define TIMEVAL_TEXT_BUFSIZE TIMESPEC_TEXT_BUFSIZE
647 extern void printtv_bitness(struct tcb *, long, enum bitness_t, int);
648 #define printtv(tcp, addr) \
649 printtv_bitness((tcp), (addr), BITNESS_CURRENT, 0)
650 #define printtv_special(tcp, addr) \
651 printtv_bitness((tcp), (addr), BITNESS_CURRENT, 1)
652 extern char *sprinttv(char *, struct tcb *, long, enum bitness_t, int special);
653 extern void print_timespec(struct tcb *, long);
654 extern void sprint_timespec(char *, struct tcb *, long);
655 #ifdef HAVE_SIGINFO_T
656 extern void printsiginfo(siginfo_t *, int);
657 extern void printsiginfo_at(struct tcb *tcp, long addr);
659 extern void printfd(struct tcb *, int);
660 extern void printsock(struct tcb *, long, int);
661 extern void print_sock_optmgmt(struct tcb *, long, int);
662 extern void printrusage(struct tcb *, long);
664 extern void printrusage32(struct tcb *, long);
666 extern void printuid(const char *, unsigned long);
667 extern void printcall(struct tcb *);
668 extern void print_sigset(struct tcb *, long, int);
669 extern void printsignal(int);
670 extern void tprint_iov(struct tcb *, unsigned long, unsigned long, int decode_iov);
671 extern void tprint_iov_upto(struct tcb *, unsigned long, unsigned long, int decode_iov, unsigned long);
672 extern void tprint_open_modes(mode_t);
673 extern const char *sprint_open_modes(mode_t);
674 extern void print_loff_t(struct tcb *, long);
676 extern const struct_ioctlent *ioctl_lookup(long);
677 extern const struct_ioctlent *ioctl_next_match(const struct_ioctlent *);
678 extern int ioctl_decode(struct tcb *, long, long);
679 extern int term_ioctl(struct tcb *, long, long);
680 extern int sock_ioctl(struct tcb *, long, long);
681 extern int proc_ioctl(struct tcb *, int, int);
682 extern int rtc_ioctl(struct tcb *, long, long);
683 extern int scsi_ioctl(struct tcb *, long, long);
684 extern int block_ioctl(struct tcb *, long, long);
685 extern int mtd_ioctl(struct tcb *, long, long);
686 extern int loop_ioctl(struct tcb *, long, long);
688 extern int tv_nz(struct timeval *);
689 extern int tv_cmp(struct timeval *, struct timeval *);
690 extern double tv_float(struct timeval *);
691 extern void tv_add(struct timeval *, struct timeval *, struct timeval *);
692 extern void tv_sub(struct timeval *, struct timeval *, struct timeval *);
693 extern void tv_mul(struct timeval *, struct timeval *, int);
694 extern void tv_div(struct timeval *, struct timeval *, int);
696 /* Strace log generation machinery.
698 * printing_tcp: tcb which has incomplete line being printed right now.
699 * NULL if last line has been completed ('\n'-terminated).
700 * printleader(tcp) examines it, finishes incomplete line if needed,
701 * the sets it to tcp.
702 * line_ended() clears printing_tcp and resets ->curcol = 0.
703 * tcp->curcol == 0 check is also used to detect completeness
704 * of last line, since in -ff mode just checking printing_tcp for NULL
707 * If you change this code, test log generation in both -f and -ff modes
709 * strace -oLOG -f[f] test/threaded_execve
710 * strace -oLOG -f[f] test/sigkill_rain
711 * strace -oLOG -f[f] -p "`pidof web_browser`"
713 extern struct tcb *printing_tcp;
714 extern void printleader(struct tcb *);
715 extern void line_ended(void);
716 extern void tabto(void);
717 extern void tprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
718 extern void tprints(const char *str);
720 #if SUPPORTED_PERSONALITIES > 1
721 extern void set_personality(int personality);
722 extern unsigned current_personality;
724 # define set_personality(personality) ((void)0)
725 # define current_personality 0
728 #if SUPPORTED_PERSONALITIES == 1
729 # define current_wordsize PERSONALITY0_WORDSIZE
731 # if SUPPORTED_PERSONALITIES == 2 && PERSONALITY0_WORDSIZE == PERSONALITY1_WORDSIZE
732 # define current_wordsize PERSONALITY0_WORDSIZE
734 extern unsigned current_wordsize;
738 /* In many, many places we play fast and loose and use
739 * tprintf("%d", (int) tcp->u_arg[N]) to print fds, pids etc.
740 * We probably need to use widen_to_long() instead:
742 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
743 # define widen_to_long(v) (current_wordsize == 4 ? (long)(int32_t)(v) : (long)(v))
745 # define widen_to_long(v) ((long)(v))
748 extern const struct_sysent sysent0[];
749 extern const char *const errnoent0[];
750 extern const char *const signalent0[];
751 extern const struct_ioctlent ioctlent0[];
752 extern qualbits_t *qual_vec[SUPPORTED_PERSONALITIES];
753 #define qual_flags (qual_vec[current_personality])
754 #if SUPPORTED_PERSONALITIES > 1
755 extern const struct_sysent *sysent;
756 extern const char *const *errnoent;
757 extern const char *const *signalent;
758 extern const struct_ioctlent *ioctlent;
760 # define sysent sysent0
761 # define errnoent errnoent0
762 # define signalent signalent0
763 # define ioctlent ioctlent0
765 extern unsigned nsyscalls;
766 extern unsigned nerrnos;
767 extern unsigned nsignals;
768 extern unsigned nioctlents;
769 extern unsigned num_quals;
772 * If you need non-NULL sysent[scno].sys_func and sysent[scno].sys_name
774 #define SCNO_IS_VALID(scno) \
775 ((unsigned long)(scno) < nsyscalls && sysent[scno].sys_func)
777 /* Only ensures that sysent[scno] isn't out of range */
778 #define SCNO_IN_RANGE(scno) \
779 ((unsigned long)(scno) < nsyscalls)