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>
61 #include <sys/syscall.h>
64 const char *strerror(int);
67 /* Some libc have stpcpy, some don't. Sigh...
68 * Roll our private implementation...
71 #define stpcpy strace_stpcpy
72 extern char *stpcpy(char *dst, const char *src);
76 # define __attribute__(x) /*nothing*/
80 # define offsetof(type, member) \
81 (((char *) &(((type *) NULL)->member)) - ((char *) (type *) NULL))
84 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
86 /* Glibc has an efficient macro for sigemptyset
87 * (it just does one or two assignments of 0 to internal vector of longs).
89 #if defined(__GLIBC__) && defined(__sigemptyset) && !defined(sigemptyset)
90 # define sigemptyset __sigemptyset
93 /* Configuration section */
96 # define MAX_QUALS 7000 /* maximum number of syscalls, signals, etc. */
98 # define MAX_QUALS 2048 /* maximum number of syscalls, signals, etc. */
101 #ifndef DEFAULT_STRLEN
102 /* default maximum # of bytes printed in `printstr', change with -s switch */
103 # define DEFAULT_STRLEN 32
105 #ifndef DEFAULT_ACOLUMN
106 # define DEFAULT_ACOLUMN 40 /* default alignment column for results */
109 * Maximum number of args to a syscall.
111 * Make sure that all entries in all syscallent.h files have nargs <= MAX_ARGS!
112 * linux/<ARCH>/syscallent.h: all have nargs <= 6.
117 /* default sorting method for call profiling */
118 #ifndef DEFAULT_SORTBY
119 # define DEFAULT_SORTBY "time"
122 * Experimental code using PTRACE_SEIZE can be enabled here.
123 * This needs Linux kernel 3.4.x or later to work.
127 #if defined(MIPS) && _MIPS_SIM == _MIPS_SIM_ABI32
128 # define LINUX_MIPSO32
130 #if defined(MIPS) && _MIPS_SIM == _MIPS_SIM_NABI32
131 # define LINUX_MIPSN32
133 #if defined(MIPS) && _MIPS_SIM == _MIPS_SIM_ABI64
134 # define LINUX_MIPSN64
137 #if (defined(SPARC) || defined(SPARC64) \
139 || defined(ARM) || defined(AARCH64) \
142 ) && defined(__GLIBC__)
143 # include <sys/ptrace.h>
145 /* Work around awkward prototype in ptrace.h. */
146 # define ptrace xptrace
147 # include <sys/ptrace.h>
151 # include <asm/ptrace.h>
154 extern long ptrace(int, int, char *, long);
158 # include <asm/ptrace.h> /* struct pt_regs */
161 #if !HAVE_DECL_PTRACE_SETOPTIONS
162 # define PTRACE_SETOPTIONS 0x4200
164 #if !HAVE_DECL_PTRACE_GETEVENTMSG
165 # define PTRACE_GETEVENTMSG 0x4201
167 #if !HAVE_DECL_PTRACE_GETSIGINFO
168 # define PTRACE_GETSIGINFO 0x4202
171 #if !HAVE_DECL_PTRACE_O_TRACESYSGOOD
172 # define PTRACE_O_TRACESYSGOOD 0x00000001
174 #if !HAVE_DECL_PTRACE_O_TRACEFORK
175 # define PTRACE_O_TRACEFORK 0x00000002
177 #if !HAVE_DECL_PTRACE_O_TRACEVFORK
178 # define PTRACE_O_TRACEVFORK 0x00000004
180 #if !HAVE_DECL_PTRACE_O_TRACECLONE
181 # define PTRACE_O_TRACECLONE 0x00000008
183 #if !HAVE_DECL_PTRACE_O_TRACEEXEC
184 # define PTRACE_O_TRACEEXEC 0x00000010
186 #if !HAVE_DECL_PTRACE_O_TRACEEXIT
187 # define PTRACE_O_TRACEEXIT 0x00000040
190 #if !HAVE_DECL_PTRACE_EVENT_FORK
191 # define PTRACE_EVENT_FORK 1
193 #if !HAVE_DECL_PTRACE_EVENT_VFORK
194 # define PTRACE_EVENT_VFORK 2
196 #if !HAVE_DECL_PTRACE_EVENT_CLONE
197 # define PTRACE_EVENT_CLONE 3
199 #if !HAVE_DECL_PTRACE_EVENT_EXEC
200 # define PTRACE_EVENT_EXEC 4
202 #if !HAVE_DECL_PTRACE_EVENT_VFORK_DONE
203 # define PTRACE_EVENT_VFORK_DONE 5
205 #if !HAVE_DECL_PTRACE_EVENT_EXIT
206 # define PTRACE_EVENT_EXIT 6
209 #if !defined(__GLIBC__)
210 # define PTRACE_PEEKUSER PTRACE_PEEKUSR
211 # define PTRACE_POKEUSER PTRACE_POKEUSR
216 # define PTRACE_SEIZE 0x4206
217 # undef PTRACE_INTERRUPT
218 # define PTRACE_INTERRUPT 0x4207
219 # undef PTRACE_LISTEN
220 # define PTRACE_LISTEN 0x4208
221 # undef PTRACE_EVENT_STOP
222 # define PTRACE_EVENT_STOP 128
240 # define PT_GR20 (20*4)
241 # define PT_GR26 (26*4)
242 # define PT_GR28 (28*4)
243 # define PT_IAOQ0 (106*4)
244 # define PT_IAOQ1 (107*4)
247 /* SH64 Linux - this code assumes the following kernel API for system calls:
249 System Call Offset 16 (actually, (syscall no.) | (0x1n << 16),
250 where n = no. of parameters.
251 Other regs Offset 24+
253 On entry: R2-7 = parameters 1-6 (as many as necessary)
254 On return: R9 = result. */
256 /* Offset for peeks of registers */
257 # define REG_OFFSET (24)
258 # define REG_GENERAL(x) (8*(x)+REG_OFFSET)
259 # define REG_PC (0*8)
260 # define REG_SYSCALL (2*8)
266 # define ARM_cpsr uregs[16]
267 # define ARM_pc uregs[15]
268 # define ARM_lr uregs[14]
269 # define ARM_sp uregs[13]
270 # define ARM_ip uregs[12]
271 # define ARM_fp uregs[11]
272 # define ARM_r10 uregs[10]
273 # define ARM_r9 uregs[9]
274 # define ARM_r8 uregs[8]
275 # define ARM_r7 uregs[7]
276 # define ARM_r6 uregs[6]
277 # define ARM_r5 uregs[5]
278 # define ARM_r4 uregs[4]
279 # define ARM_r3 uregs[3]
280 # define ARM_r2 uregs[2]
281 # define ARM_r1 uregs[1]
282 # define ARM_r0 uregs[0]
283 # define ARM_ORIG_r0 uregs[17]
286 #if defined(SPARC) || defined(SPARC64)
287 /* Indexes into the pt_regs.u_reg[] array -- UREG_XX from kernel are all off
288 * by 1 and use Ix instead of Ox. These work for both 32 and 64 bit Linux. */
292 # define PERSONALITY0_WORDSIZE 4
293 # define PERSONALITY1_WORDSIZE 4
294 # if defined(SPARC64)
295 # include <asm/psrcompat.h>
296 # define SUPPORTED_PERSONALITIES 3
297 # define PERSONALITY2_WORDSIZE 8
299 # include <asm/psr.h>
300 # define SUPPORTED_PERSONALITIES 2
301 # endif /* SPARC64 */
302 #endif /* SPARC[64] */
305 # define SUPPORTED_PERSONALITIES 3
306 # define PERSONALITY0_WORDSIZE 8
307 # define PERSONALITY1_WORDSIZE 4
308 # define PERSONALITY2_WORDSIZE 4
312 # define SUPPORTED_PERSONALITIES 2
313 # define PERSONALITY0_WORDSIZE 4
314 # define PERSONALITY1_WORDSIZE 4
318 # define SUPPORTED_PERSONALITIES 2
319 # define PERSONALITY0_WORDSIZE 4
320 # define PERSONALITY1_WORDSIZE 4
324 /* The existing ARM personality, then AArch64 */
325 # define SUPPORTED_PERSONALITIES 2
326 # define PERSONALITY0_WORDSIZE 4
327 # define PERSONALITY1_WORDSIZE 8
328 # define DEFAULT_PERSONALITY 1
332 # define SUPPORTED_PERSONALITIES 2
333 # define PERSONALITY0_WORDSIZE 8
334 # define PERSONALITY1_WORDSIZE 4
338 # define SUPPORTED_PERSONALITIES 2
339 # define PERSONALITY0_WORDSIZE 8
340 # define PERSONALITY1_WORDSIZE 4
342 # define DEFAULT_PERSONALITY 1
346 #ifndef SUPPORTED_PERSONALITIES
347 # define SUPPORTED_PERSONALITIES 1
349 #ifndef DEFAULT_PERSONALITY
350 # define DEFAULT_PERSONALITY 0
352 #ifndef PERSONALITY0_WORDSIZE
353 # define PERSONALITY0_WORDSIZE (int)(sizeof(long))
357 extern struct user_regs_struct i386_regs;
362 #if defined(SPARC) || defined(SPARC64)
363 extern struct pt_regs sparc_regs;
366 extern struct pt_regs arm_regs;
369 extern struct pt_regs tile_regs;
372 /* Trace Control Block */
374 int flags; /* See below for TCB_ values */
375 int pid; /* Process Id of this entry */
376 int u_nargs; /* System call argument count */
377 int u_error; /* Error code */
378 long scno; /* System call number */
379 long u_arg[MAX_ARGS]; /* System call arguments */
380 #if defined(LINUX_MIPSN32) || defined(X32)
381 long long ext_arg[MAX_ARGS];
382 long long u_lrval; /* long long return value */
384 long u_rval; /* Return value */
385 #if SUPPORTED_PERSONALITIES > 1
386 int currpers; /* Personality at the time of scno update */
388 int curcol; /* Output column for this process */
389 FILE *outf; /* Output file for this process */
390 const char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */
391 struct timeval stime; /* System time usage as of last process wait */
392 struct timeval dtime; /* Delta for system time usage */
393 struct timeval etime; /* Syscall entry time */
394 /* Support for tracing forked processes: */
395 long inst[2]; /* Saved clone args (badly named) */
399 #define TCB_INUSE 00001 /* This table entry is in use */
400 /* We have attached to this process, but did not see it stopping yet */
401 #define TCB_STARTUP 00002
402 #define TCB_IGNORE_ONE_SIGSTOP 00004 /* Next SIGSTOP is to be ignored */
404 * Are we in system call entry or in syscall exit?
406 * This bit is set after all syscall entry processing is done.
407 * Therefore, this bit will be set when next ptrace stop occurs,
408 * which should be syscall exit stop. Other stops which are possible
409 * directly after syscall entry (death, ptrace event stop)
410 * are simpler and handled without calling trace_syscall(), therefore
411 * the places where TCB_INSYSCALL can be set but we aren't in syscall stop
412 * are limited to trace(), this condition is never observed in trace_syscall()
414 * The bit is cleared after all syscall exit processing is done.
415 * User-generated SIGTRAPs and post-execve SIGTRAP make it necessary
416 * to be very careful and NOT set TCB_INSYSCALL bit when they are encountered.
417 * TCB_WAITEXECVE bit is used for this purpose (see below).
419 * Use entering(tcp) / exiting(tcp) to check this bit to make code more readable.
421 #define TCB_INSYSCALL 00010
422 #define TCB_ATTACHED 00020 /* It is attached already */
423 /* Are we PROG from "strace PROG [ARGS]" invocation? */
424 #define TCB_STRACE_CHILD 0040
425 #define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */
426 #define TCB_REPRINT 00200 /* We should reprint this syscall on exit */
427 #define TCB_FILTERED 00400 /* This system call has been filtered out */
428 /* x86 does not need TCB_WAITEXECVE.
429 * It can detect post-execve SIGTRAP by looking at eax/rax.
430 * See "not a syscall entry (eax = %ld)\n" message.
432 * Note! On new kernels (about 2.5.46+), we use PTRACE_O_TRACEEXEC, which
433 * suppresses post-execve SIGTRAP. If you are adding a new arch which is
434 * only supported by newer kernels, you most likely don't need to define
438 || defined(SPARC) || defined(SPARC64) \
439 || defined(POWERPC) \
442 || defined(SH) || defined(SH64) \
443 || defined(S390) || defined(S390X) \
446 /* This tracee has entered into execve syscall. Expect post-execve SIGTRAP
447 * to happen. (When it is detected, tracee is continued and this bit is cleared.)
449 # define TCB_WAITEXECVE 01000
452 /* qualifier flags */
453 #define QUAL_TRACE 0001 /* this system call should be traced */
454 #define QUAL_ABBREV 0002 /* abbreviate the structures of this syscall */
455 #define QUAL_VERBOSE 0004 /* decode the structures of this syscall */
456 #define QUAL_RAW 0010 /* print all args in hex for this syscall */
457 #define QUAL_SIGNAL 0020 /* report events with this signal */
458 #define QUAL_FAULT 0040 /* report events with this fault */
459 #define QUAL_READ 0100 /* dump data read on this file descriptor */
460 #define QUAL_WRITE 0200 /* dump data written to this file descriptor */
462 #define entering(tcp) (!((tcp)->flags & TCB_INSYSCALL))
463 #define exiting(tcp) ((tcp)->flags & TCB_INSYSCALL)
464 #define syserror(tcp) ((tcp)->u_error != 0)
465 #define verbose(tcp) (qual_flags[(tcp)->scno] & QUAL_VERBOSE)
466 #define abbrev(tcp) (qual_flags[(tcp)->scno] & QUAL_ABBREV)
467 #define filtered(tcp) ((tcp)->flags & TCB_FILTERED)
474 extern const struct xlat open_mode_flags[];
475 extern const struct xlat addrfams[];
476 extern const struct xlat struct_user_offsets[];
477 extern const struct xlat open_access_modes[];
478 extern const struct xlat whence_codes[];
480 /* Format of syscall return values */
481 #define RVAL_DECIMAL 000 /* decimal format */
482 #define RVAL_HEX 001 /* hex format */
483 #define RVAL_OCTAL 002 /* octal format */
484 #define RVAL_UDECIMAL 003 /* unsigned decimal format */
485 #if defined(LINUX_MIPSN32) || defined(X32)
486 # if 0 /* unused so far */
487 # define RVAL_LDECIMAL 004 /* long decimal format */
488 # define RVAL_LHEX 005 /* long hex format */
489 # define RVAL_LOCTAL 006 /* long octal format */
491 # define RVAL_LUDECIMAL 007 /* long unsigned decimal format */
493 #define RVAL_MASK 007 /* mask for these values */
495 #define RVAL_STR 010 /* Print `auxstr' field after return val */
496 #define RVAL_NONE 020 /* Print nothing */
498 #define TRACE_FILE 001 /* Trace file-related syscalls. */
499 #define TRACE_IPC 002 /* Trace IPC-related syscalls. */
500 #define TRACE_NETWORK 004 /* Trace network-related syscalls. */
501 #define TRACE_PROCESS 010 /* Trace process-related syscalls. */
502 #define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */
503 #define TRACE_DESC 040 /* Trace file descriptor-related syscalls. */
504 #define TRACE_MEMORY 0100 /* Trace memory mapping-related syscalls. */
505 #define SYSCALL_NEVER_FAILS 0200 /* Syscall is always successful. */
512 extern cflag_t cflag;
513 extern int *qual_flags;
514 extern bool debug_flag;
517 extern bool not_failing_only;
518 extern bool show_fd_path;
519 extern bool tracing_paths;
520 extern bool need_fork_exec_workarounds;
521 extern unsigned xflag;
522 extern unsigned followfork;
523 extern unsigned ptrace_setoptions;
524 extern unsigned max_strlen;
525 extern unsigned os_release;
526 #undef KERNEL_VERSION
527 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
529 enum bitness_t { BITNESS_CURRENT = 0, BITNESS_32 };
531 void error_msg(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
532 void perror_msg(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
533 void error_msg_and_die(const char *fmt, ...) __attribute__ ((noreturn, format(printf, 1, 2)));
534 void perror_msg_and_die(const char *fmt, ...) __attribute__ ((noreturn, format(printf, 1, 2)));
535 void die_out_of_memory(void) __attribute__ ((noreturn));
537 #ifdef USE_CUSTOM_PRINTF
539 * Speed-optimized vfprintf implementation.
540 * See comment in vsprintf.c for allowed formats.
541 * Short version: %h[h]u, %zu, %tu are not allowed, use %[l[l]]u.
543 * It results in strace using about 5% less CPU in user space
544 * (compared to glibc version).
545 * But strace spends a lot of time in kernel space,
546 * so overall it does not appear to be a significant win.
547 * Thus disabled by default.
549 int strace_vfprintf(FILE *fp, const char *fmt, va_list args);
551 # define strace_vfprintf vfprintf
554 extern void set_sortby(const char *);
555 extern void set_overhead(int);
556 extern void qualify(const char *);
557 extern int trace_syscall(struct tcb *);
558 extern void count_syscall(struct tcb *, struct timeval *);
559 extern void call_summary(FILE *);
563 || defined(X86_64) || defined(X32) \
564 || defined(AARCH64) \
566 || defined(SPARC) || defined(SPARC64) \
569 extern long get_regs_error;
570 # define clear_regs() (get_regs_error = -1)
571 extern void get_regs(pid_t pid);
573 # define get_regs_error 0
574 # define clear_regs() ((void)0)
575 # define get_regs(pid) ((void)0)
577 extern int umoven(struct tcb *, long, int, char *);
578 #define umove(pid, addr, objp) \
579 umoven((pid), (addr), sizeof(*(objp)), (char *) (objp))
580 extern int umovestr(struct tcb *, long, int, char *);
581 extern int upeek(struct tcb *, long, long *);
582 #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH)
583 extern long getrval2(struct tcb *);
586 * On Linux, "setbpt" is a misnomer: we don't set a breakpoint
587 * (IOW: no poking in user's text segment),
588 * instead we change fork/vfork/clone into clone(CLONE_PTRACE).
589 * On newer kernels, we use PTRACE_O_TRACECLONE/TRACE[V]FORK instead.
591 extern int setbpt(struct tcb *);
592 extern int clearbpt(struct tcb *);
594 extern const char *signame(int);
595 extern int is_restart_error(struct tcb *);
596 extern int pathtrace_select(const char *);
597 extern int pathtrace_match(struct tcb *);
598 extern const char *getfdpath(struct tcb *, int);
600 extern const char *xlookup(const struct xlat *, int);
602 extern int string_to_uint(const char *str);
603 extern int string_quote(const char *, char *, long, int);
605 /* a refers to the lower numbered u_arg,
606 * b refers to the higher numbered u_arg
608 #if HAVE_LITTLE_ENDIAN_LONG_LONG
609 # define LONG_LONG(a,b) \
610 ((long long)((unsigned long long)(unsigned)(a) | ((unsigned long long)(b)<<32)))
612 # define LONG_LONG(a,b) \
613 ((long long)((unsigned long long)(unsigned)(b) | ((unsigned long long)(a)<<32)))
615 extern int printllval(struct tcb *, const char *, int);
617 extern void printxval(const struct xlat *, int, const char *);
618 extern int printargs(struct tcb *);
619 extern int printargs_lu(struct tcb *);
620 extern int printargs_ld(struct tcb *);
621 extern void addflags(const struct xlat *, int);
622 extern int printflags(const struct xlat *, int, const char *);
623 extern const char *sprintflags(const char *, const struct xlat *, int);
624 extern void dumpiov(struct tcb *, int, long);
625 extern void dumpstr(struct tcb *, long, int);
626 extern void printstr(struct tcb *, long, long);
627 extern void printnum(struct tcb *, long, const char *);
628 extern void printnum_int(struct tcb *, long, const char *);
629 extern void printpath(struct tcb *, long);
630 extern void printpathn(struct tcb *, long, int);
631 #define TIMESPEC_TEXT_BUFSIZE (sizeof(long)*3 * 2 + sizeof("{%u, %u}"))
632 #define TIMEVAL_TEXT_BUFSIZE TIMESPEC_TEXT_BUFSIZE
633 extern void printtv_bitness(struct tcb *, long, enum bitness_t, int);
634 #define printtv(tcp, addr) \
635 printtv_bitness((tcp), (addr), BITNESS_CURRENT, 0)
636 #define printtv_special(tcp, addr) \
637 printtv_bitness((tcp), (addr), BITNESS_CURRENT, 1)
638 extern char *sprinttv(char *, struct tcb *, long, enum bitness_t, int special);
639 extern void print_timespec(struct tcb *, long);
640 extern void sprint_timespec(char *, struct tcb *, long);
641 #ifdef HAVE_SIGINFO_T
642 extern void printsiginfo(siginfo_t *, int);
643 extern void printsiginfo_at(struct tcb *tcp, long addr);
645 extern void printfd(struct tcb *, int);
646 extern void printsock(struct tcb *, long, int);
647 extern void print_sock_optmgmt(struct tcb *, long, int);
648 extern void printrusage(struct tcb *, long);
650 extern void printrusage32(struct tcb *, long);
652 extern void printuid(const char *, unsigned long);
653 extern void printcall(struct tcb *);
654 extern void print_sigset(struct tcb *, long, int);
655 extern void printsignal(int);
656 extern void tprint_iov(struct tcb *, unsigned long, unsigned long, int decode_iov);
657 extern void tprint_iov_upto(struct tcb *, unsigned long, unsigned long, int decode_iov, unsigned long);
658 extern void tprint_open_modes(mode_t);
659 extern const char *sprint_open_modes(mode_t);
660 extern void print_loff_t(struct tcb *, long);
662 extern const struct ioctlent *ioctl_lookup(long);
663 extern const struct ioctlent *ioctl_next_match(const struct ioctlent *);
664 extern int ioctl_decode(struct tcb *, long, long);
665 extern int term_ioctl(struct tcb *, long, long);
666 extern int sock_ioctl(struct tcb *, long, long);
667 extern int proc_ioctl(struct tcb *, int, int);
668 extern int rtc_ioctl(struct tcb *, long, long);
669 extern int scsi_ioctl(struct tcb *, long, long);
670 extern int block_ioctl(struct tcb *, long, long);
671 extern int mtd_ioctl(struct tcb *, long, long);
672 extern int loop_ioctl(struct tcb *, long, long);
674 extern int tv_nz(struct timeval *);
675 extern int tv_cmp(struct timeval *, struct timeval *);
676 extern double tv_float(struct timeval *);
677 extern void tv_add(struct timeval *, struct timeval *, struct timeval *);
678 extern void tv_sub(struct timeval *, struct timeval *, struct timeval *);
679 extern void tv_mul(struct timeval *, struct timeval *, int);
680 extern void tv_div(struct timeval *, struct timeval *, int);
682 /* Strace log generation machinery.
684 * printing_tcp: tcb which has incomplete line being printed right now.
685 * NULL if last line has been completed ('\n'-terminated).
686 * printleader(tcp) examines it, finishes incomplete line if needed,
687 * the sets it to tcp.
688 * line_ended() clears printing_tcp and resets ->curcol = 0.
689 * tcp->curcol == 0 check is also used to detect completeness
690 * of last line, since in -ff mode just checking printing_tcp for NULL
693 * If you change this code, test log generation in both -f and -ff modes
695 * strace -oLOG -f[f] test/threaded_execve
696 * strace -oLOG -f[f] test/sigkill_rain
697 * strace -oLOG -f[f] -p "`pidof web_browser`"
699 extern struct tcb *printing_tcp;
700 extern void printleader(struct tcb *);
701 extern void line_ended(void);
702 extern void tabto(void);
703 extern void tprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
704 extern void tprints(const char *str);
706 #if SUPPORTED_PERSONALITIES > 1
707 extern void set_personality(int personality);
708 extern unsigned current_personality;
710 # define set_personality(personality) ((void)0)
711 # define current_personality 0
714 #if SUPPORTED_PERSONALITIES == 1
715 # define current_wordsize PERSONALITY0_WORDSIZE
717 # if SUPPORTED_PERSONALITIES == 2 && PERSONALITY0_WORDSIZE == PERSONALITY1_WORDSIZE
718 # define current_wordsize PERSONALITY0_WORDSIZE
720 extern unsigned current_wordsize;
724 /* In many, many places we play fast and loose and use
725 * tprintf("%d", (int) tcp->u_arg[N]) to print fds, pids etc.
726 * We probably need to use widen_to_long() instead:
728 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
729 # define widen_to_long(v) (current_wordsize == 4 ? (long)(int32_t)(v) : (long)(v))
731 # define widen_to_long(v) ((long)(v))
738 const char *sys_name;
747 extern const struct sysent *sysent;
748 extern unsigned nsyscalls;
749 extern const char *const *errnoent;
750 extern unsigned nerrnos;
751 extern const struct ioctlent *ioctlent;
752 extern unsigned nioctlents;
753 extern const char *const *signalent;
754 extern unsigned nsignals;
757 * If you need non-NULL sysent[scno].sys_func and sysent[scno].sys_name
759 #define SCNO_IS_VALID(scno) \
760 ((unsigned long)(scno) < nsyscalls && sysent[scno].sys_func)
762 /* Only ensures that sysent[scno] isn't out of range */
763 #define SCNO_IN_RANGE(scno) \
764 ((unsigned long)(scno) < nsyscalls)