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.
40 #include <sys/types.h>
47 /* Open-coding isprint(ch) et al proved more efficient than calling
48 * generalized libc interface. We don't *want* to do non-ASCII anyway.
50 /* #include <ctype.h> */
55 #include <sys/syscall.h>
57 #include "mpers_type.h"
60 const char *strerror(int);
63 /* Some libc have stpcpy, some don't. Sigh...
64 * Roll our private implementation...
67 #define stpcpy strace_stpcpy
68 extern char *stpcpy(char *dst, const char *src);
71 #if defined __GNUC__ && defined __GNUC_MINOR__
72 # define GNUC_PREREQ(maj, min) \
73 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
75 # define __attribute__(x) /* empty */
76 # define GNUC_PREREQ(maj, min) 0
80 # define ATTRIBUTE_NORETURN __attribute__((__noreturn__))
82 # define ATTRIBUTE_NORETURN /* empty */
86 # define ATTRIBUTE_FORMAT(args) __attribute__((__format__ args))
87 # define ATTRIBUTE_ALIGNED(arg) __attribute__((__aligned__(arg)))
88 # define ATTRIBUTE_PACKED __attribute__((__packed__))
90 # define ATTRIBUTE_FORMAT(args) /* empty */
91 # define ATTRIBUTE_ALIGNED(arg) /* empty */
92 # define ATTRIBUTE_PACKED /* empty */
96 # define ATTRIBUTE_MALLOC __attribute__((__malloc__))
98 # define ATTRIBUTE_MALLOC /* empty */
101 #if GNUC_PREREQ(3, 1)
102 # define ATTRIBUTE_NOINLINE __attribute__((__noinline__))
104 # define ATTRIBUTE_NOINLINE /* empty */
107 #if GNUC_PREREQ(4, 3)
108 # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__((__alloc_size__ args))
110 # define ATTRIBUTE_ALLOC_SIZE(args) /* empty */
114 # define offsetof(type, member) \
115 (((char *) &(((type *) NULL)->member)) - ((char *) (type *) NULL))
118 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
122 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
125 # define MIN(a, b) (((a) < (b)) ? (a) : (b))
127 #define CLAMP(val, min, max) MIN(MAX(min, val), max)
129 /* Glibc has an efficient macro for sigemptyset
130 * (it just does one or two assignments of 0 to internal vector of longs).
132 #if defined(__GLIBC__) && defined(__sigemptyset) && !defined(sigemptyset)
133 # define sigemptyset __sigemptyset
136 /* Configuration section */
137 #ifndef DEFAULT_STRLEN
138 /* default maximum # of bytes printed in `printstr', change with -s switch */
139 # define DEFAULT_STRLEN 32
141 #ifndef DEFAULT_ACOLUMN
142 # define DEFAULT_ACOLUMN 40 /* default alignment column for results */
145 * Maximum number of args to a syscall.
147 * Make sure that all entries in all syscallent.h files have nargs <= MAX_ARGS!
148 * linux/<ARCH>/syscallent*.h:
149 * all have nargs <= 6 except mips o32 which has nargs <= 7.
152 # ifdef LINUX_MIPSO32
158 /* default sorting method for call profiling */
159 #ifndef DEFAULT_SORTBY
160 # define DEFAULT_SORTBY "time"
163 * Experimental code using PTRACE_SEIZE can be enabled here.
164 * This needs Linux kernel 3.4.x or later to work.
167 /* To force NOMMU build, set to 1 */
168 #define NOMMU_SYSTEM 0
170 * Set to 1 to use speed-optimized vfprintf implementation.
171 * It results in strace using about 5% less CPU in user space
172 * (compared to glibc version).
173 * But strace spends a lot of time in kernel space,
174 * so overall it does not appear to be a significant win.
175 * Thus disabled by default.
177 #define USE_CUSTOM_PRINTF 0
180 # define ERESTARTSYS 512
182 #ifndef ERESTARTNOINTR
183 # define ERESTARTNOINTR 513
185 #ifndef ERESTARTNOHAND
186 # define ERESTARTNOHAND 514
188 #ifndef ERESTART_RESTARTBLOCK
189 # define ERESTART_RESTARTBLOCK 516
192 #if defined(SPARC) || defined(SPARC64)
193 # define PERSONALITY0_WORDSIZE 4
194 # if defined(SPARC64)
195 # define SUPPORTED_PERSONALITIES 2
196 # define PERSONALITY1_WORDSIZE 8
197 # ifdef HAVE_M32_MPERS
198 # define PERSONALITY1_INCLUDE_FUNCS "m32_funcs.h"
199 # define PERSONALITY1_INCLUDE_PRINTERS_DECLS "m32_printer_decls.h"
200 # define PERSONALITY1_INCLUDE_PRINTERS_DEFS "m32_printer_defs.h"
206 # define SUPPORTED_PERSONALITIES 3
207 # define PERSONALITY0_WORDSIZE 8
208 # define PERSONALITY1_WORDSIZE 4
209 # define PERSONALITY2_WORDSIZE 4
210 # ifdef HAVE_M32_MPERS
211 # define PERSONALITY1_INCLUDE_FUNCS "m32_funcs.h"
212 # define PERSONALITY1_INCLUDE_PRINTERS_DECLS "m32_printer_decls.h"
213 # define PERSONALITY1_INCLUDE_PRINTERS_DEFS "m32_printer_defs.h"
215 # ifdef HAVE_MX32_MPERS
216 # define PERSONALITY2_INCLUDE_FUNCS "mx32_funcs.h"
217 # define PERSONALITY2_INCLUDE_PRINTERS_DECLS "mx32_printer_decls.h"
218 # define PERSONALITY2_INCLUDE_PRINTERS_DEFS "mx32_printer_defs.h"
223 # define SUPPORTED_PERSONALITIES 2
224 # define PERSONALITY0_WORDSIZE 4
225 # define PERSONALITY1_WORDSIZE 4
226 # ifdef HAVE_M32_MPERS
227 # define PERSONALITY1_INCLUDE_FUNCS "m32_funcs.h"
228 # define PERSONALITY1_INCLUDE_PRINTERS_DECLS "m32_printer_decls.h"
229 # define PERSONALITY1_INCLUDE_PRINTERS_DEFS "m32_printer_defs.h"
234 /* one personality */
238 /* The existing ARM personality, then AArch64 */
239 # define SUPPORTED_PERSONALITIES 2
240 # define PERSONALITY0_WORDSIZE 4
241 # define PERSONALITY1_WORDSIZE 8
242 # define DEFAULT_PERSONALITY 1
243 # ifdef HAVE_M32_MPERS
244 # define PERSONALITY0_INCLUDE_FUNCS "m32_funcs.h"
245 # define PERSONALITY0_INCLUDE_PRINTERS_DECLS "m32_printer_decls.h"
246 # define PERSONALITY0_INCLUDE_PRINTERS_DEFS "m32_printer_defs.h"
251 # define SUPPORTED_PERSONALITIES 2
252 # define PERSONALITY0_WORDSIZE 8
253 # define PERSONALITY1_WORDSIZE 4
254 # ifdef HAVE_M32_MPERS
255 # define PERSONALITY1_INCLUDE_FUNCS "m32_funcs.h"
256 # define PERSONALITY1_INCLUDE_PRINTERS_DECLS "m32_printer_decls.h"
257 # define PERSONALITY1_INCLUDE_PRINTERS_DEFS "m32_printer_defs.h"
262 # define SUPPORTED_PERSONALITIES 2
263 # define PERSONALITY0_WORDSIZE 8
264 # define PERSONALITY1_WORDSIZE 4
266 # define DEFAULT_PERSONALITY 1
268 # ifdef HAVE_M32_MPERS
269 # define PERSONALITY1_INCLUDE_FUNCS "m32_funcs.h"
270 # define PERSONALITY1_INCLUDE_PRINTERS_DECLS "m32_printer_decls.h"
271 # define PERSONALITY1_INCLUDE_PRINTERS_DEFS "m32_printer_defs.h"
275 #ifndef SUPPORTED_PERSONALITIES
276 # define SUPPORTED_PERSONALITIES 1
278 #ifndef DEFAULT_PERSONALITY
279 # define DEFAULT_PERSONALITY 0
281 #ifndef PERSONALITY0_WORDSIZE
282 # define PERSONALITY0_WORDSIZE SIZEOF_LONG
285 #ifndef PERSONALITY0_INCLUDE_PRINTERS_DECLS
286 # define PERSONALITY0_INCLUDE_PRINTERS_DECLS "native_printer_decls.h"
288 #ifndef PERSONALITY0_INCLUDE_PRINTERS_DEFS
289 # define PERSONALITY0_INCLUDE_PRINTERS_DEFS "native_printer_defs.h"
292 #ifndef PERSONALITY1_INCLUDE_PRINTERS_DECLS
293 # define PERSONALITY1_INCLUDE_PRINTERS_DECLS "native_printer_decls.h"
295 #ifndef PERSONALITY1_INCLUDE_PRINTERS_DEFS
296 # define PERSONALITY1_INCLUDE_PRINTERS_DEFS "native_printer_defs.h"
299 #ifndef PERSONALITY2_INCLUDE_PRINTERS_DECLS
300 # define PERSONALITY2_INCLUDE_PRINTERS_DECLS "native_printer_decls.h"
302 #ifndef PERSONALITY2_INCLUDE_PRINTERS_DEFS
303 # define PERSONALITY2_INCLUDE_PRINTERS_DEFS "native_printer_defs.h"
306 #ifndef PERSONALITY1_INCLUDE_FUNCS
307 # define PERSONALITY1_INCLUDE_FUNCS "empty.h"
309 #ifndef PERSONALITY2_INCLUDE_FUNCS
310 # define PERSONALITY2_INCLUDE_FUNCS "empty.h"
313 typedef struct sysent {
318 const char *sys_name;
321 typedef struct ioctlent {
326 /* Trace Control Block */
328 int flags; /* See below for TCB_ values */
329 int pid; /* If 0, this tcb is free */
330 int qual_flg; /* qual_flags[scno] or DEFAULT_QUAL_FLAGS + RAW */
331 int u_error; /* Error code */
332 long scno; /* System call number */
333 long u_arg[MAX_ARGS]; /* System call arguments */
334 #if defined(LINUX_MIPSN32) || defined(X32)
335 long long ext_arg[MAX_ARGS];
336 long long u_lrval; /* long long return value */
338 long u_rval; /* Return value */
339 #if SUPPORTED_PERSONALITIES > 1
340 unsigned int currpers; /* Personality at the time of scno update */
342 int sys_func_rval; /* Syscall entry parser's return value */
343 int curcol; /* Output column for this process */
344 FILE *outf; /* Output file for this process */
345 const char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */
346 const struct_sysent *s_ent; /* sysent[scno] or dummy struct for bad scno */
347 const struct_sysent *s_prev_ent; /* for "resuming interrupted SYSCALL" msg */
348 struct timeval stime; /* System time usage as of last process wait */
349 struct timeval dtime; /* Delta for system time usage */
350 struct timeval etime; /* Syscall entry time */
353 struct UPT_info* libunwind_ui;
354 struct mmap_cache_t* mmap_cache;
355 unsigned int mmap_cache_size;
356 unsigned int mmap_cache_generation;
357 struct queue_t* queue;
362 /* We have attached to this process, but did not see it stopping yet */
363 #define TCB_STARTUP 0x01
364 #define TCB_IGNORE_ONE_SIGSTOP 0x02 /* Next SIGSTOP is to be ignored */
366 * Are we in system call entry or in syscall exit?
368 * This bit is set after all syscall entry processing is done.
369 * Therefore, this bit will be set when next ptrace stop occurs,
370 * which should be syscall exit stop. Other stops which are possible
371 * directly after syscall entry (death, ptrace event stop)
372 * are simpler and handled without calling trace_syscall(), therefore
373 * the places where TCB_INSYSCALL can be set but we aren't in syscall stop
374 * are limited to trace(), this condition is never observed in trace_syscall()
376 * The bit is cleared after all syscall exit processing is done.
378 * Use entering(tcp) / exiting(tcp) to check this bit to make code more readable.
380 #define TCB_INSYSCALL 0x04
381 #define TCB_ATTACHED 0x08 /* We attached to it already */
382 #define TCB_REPRINT 0x10 /* We should reprint this syscall on exit */
383 #define TCB_FILTERED 0x20 /* This system call has been filtered out */
385 /* qualifier flags */
386 #define QUAL_TRACE 0x001 /* this system call should be traced */
387 #define QUAL_ABBREV 0x002 /* abbreviate the structures of this syscall */
388 #define QUAL_VERBOSE 0x004 /* decode the structures of this syscall */
389 #define QUAL_RAW 0x008 /* print all args in hex for this syscall */
390 #define QUAL_SIGNAL 0x010 /* report events with this signal */
391 #define QUAL_READ 0x020 /* dump data read on this file descriptor */
392 #define QUAL_WRITE 0x040 /* dump data written to this file descriptor */
393 typedef uint8_t qualbits_t;
394 #define UNDEFINED_SCNO 0x100 /* Used only in tcp->qual_flg */
396 #define DEFAULT_QUAL_FLAGS (QUAL_TRACE | QUAL_ABBREV | QUAL_VERBOSE)
398 #define entering(tcp) (!((tcp)->flags & TCB_INSYSCALL))
399 #define exiting(tcp) ((tcp)->flags & TCB_INSYSCALL)
400 #define syserror(tcp) ((tcp)->u_error != 0)
401 #define verbose(tcp) ((tcp)->qual_flg & QUAL_VERBOSE)
402 #define abbrev(tcp) ((tcp)->qual_flg & QUAL_ABBREV)
403 #define filtered(tcp) ((tcp)->flags & TCB_FILTERED)
409 #define XLAT(x) { x, #x }
410 #define XLAT_END { 0, NULL }
412 extern const struct xlat addrfams[];
413 extern const struct xlat at_flags[];
414 extern const struct xlat open_access_modes[];
415 extern const struct xlat open_mode_flags[];
416 extern const struct xlat resource_flags[];
417 extern const struct xlat whence_codes[];
419 /* Format of syscall return values */
420 #define RVAL_DECIMAL 000 /* decimal format */
421 #define RVAL_HEX 001 /* hex format */
422 #define RVAL_OCTAL 002 /* octal format */
423 #define RVAL_UDECIMAL 003 /* unsigned decimal format */
424 #if defined(LINUX_MIPSN32) || defined(X32)
425 # if 0 /* unused so far */
426 # define RVAL_LDECIMAL 004 /* long decimal format */
427 # define RVAL_LHEX 005 /* long hex format */
428 # define RVAL_LOCTAL 006 /* long octal format */
430 # define RVAL_LUDECIMAL 007 /* long unsigned decimal format */
432 #define RVAL_FD 010 /* file descriptor */
433 #define RVAL_MASK 017 /* mask for these values */
435 #define RVAL_STR 020 /* Print `auxstr' field after return val */
436 #define RVAL_NONE 040 /* Print nothing */
438 #define RVAL_DECODED 0100 /* syscall decoding finished */
440 #define TRACE_FILE 001 /* Trace file-related syscalls. */
441 #define TRACE_IPC 002 /* Trace IPC-related syscalls. */
442 #define TRACE_NETWORK 004 /* Trace network-related syscalls. */
443 #define TRACE_PROCESS 010 /* Trace process-related syscalls. */
444 #define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */
445 #define TRACE_DESC 040 /* Trace file descriptor-related syscalls. */
446 #define TRACE_MEMORY 0100 /* Trace memory mapping-related syscalls. */
447 #define SYSCALL_NEVER_FAILS 0200 /* Syscall is always successful. */
448 #define STACKTRACE_INVALIDATE_CACHE 0400 /* Trigger proc/maps cache updating */
449 #define STACKTRACE_CAPTURE_ON_ENTER 01000 /* Capture stacktrace on "entering" stage */
450 #define TRACE_INDIRECT_SUBCALL 02000 /* Syscall is an indirect socket/ipc subcall. */
452 #define indirect_ipccall(tcp) (tcp->s_ent->sys_flags & TRACE_INDIRECT_SUBCALL)
454 #if defined(ARM) || defined(AARCH64) \
455 || defined(I386) || defined(X32) || defined(X86_64) \
459 || defined(MICROBLAZE) \
461 || defined(SH) || defined(SH64) \
462 || defined(SPARC) || defined(SPARC64) \
464 # define NEED_UID16_PARSERS 1
466 # define NEED_UID16_PARSERS 0
474 extern cflag_t cflag;
475 extern bool debug_flag;
478 extern bool count_wallclock;
479 extern unsigned int qflag;
480 extern bool not_failing_only;
481 extern unsigned int show_fd_path;
482 extern bool hide_log_until_execve;
483 /* are we filtering traces based on paths? */
484 extern const char **paths_selected;
485 #define tracing_paths (paths_selected != NULL)
486 extern unsigned xflag;
487 extern unsigned followfork;
489 /* if this is true do the stack trace for every system call */
490 extern bool stack_trace_enabled;
492 extern unsigned ptrace_setoptions;
493 extern unsigned max_strlen;
494 extern unsigned os_release;
495 #undef KERNEL_VERSION
496 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
498 enum bitness_t { BITNESS_CURRENT = 0, BITNESS_32 };
500 void error_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
501 void perror_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
502 void error_msg_and_die(const char *fmt, ...)
503 ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
504 void perror_msg_and_die(const char *fmt, ...)
505 ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
506 void die_out_of_memory(void) ATTRIBUTE_NORETURN;
508 void *xmalloc(size_t size) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1));
509 void *xcalloc(size_t nmemb, size_t size)
510 ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1, 2));
511 void *xreallocarray(void *ptr, size_t nmemb, size_t size)
512 ATTRIBUTE_ALLOC_SIZE((2, 3));
513 char *xstrdup(const char *str) ATTRIBUTE_MALLOC;
515 #if USE_CUSTOM_PRINTF
517 * See comment in vsprintf.c for allowed formats.
518 * Short version: %h[h]u, %zu, %tu are not allowed, use %[l[l]]u.
520 int strace_vfprintf(FILE *fp, const char *fmt, va_list args);
522 # define strace_vfprintf vfprintf
525 extern void set_sortby(const char *);
526 extern void set_overhead(int);
527 extern void qualify(const char *);
528 extern void print_pc(struct tcb *);
529 extern int trace_syscall(struct tcb *);
530 extern void count_syscall(struct tcb *, const struct timeval *);
531 extern void call_summary(FILE *);
533 extern void clear_regs(void);
534 extern void get_regs(pid_t pid);
535 extern int get_scno(struct tcb *tcp);
536 extern const char *syscall_name(long scno);
538 extern int umoven(struct tcb *, long, unsigned int, void *);
539 #define umove(pid, addr, objp) \
540 umoven((pid), (addr), sizeof(*(objp)), (void *) (objp))
541 extern int umoven_or_printaddr(struct tcb *, long, unsigned int, void *);
542 #define umove_or_printaddr(pid, addr, objp) \
543 umoven_or_printaddr((pid), (addr), sizeof(*(objp)), (void *) (objp))
544 extern int umove_ulong_or_printaddr(struct tcb *, long, unsigned long *);
545 extern int umovestr(struct tcb *, long, unsigned int, char *);
546 extern int upeek(int pid, long, long *);
548 #if defined ALPHA || defined IA64 || defined MIPS \
549 || defined SH || defined SPARC || defined SPARC64
550 # define HAVE_GETRVAL2
551 extern long getrval2(struct tcb *);
553 # undef HAVE_GETRVAL2
556 extern const char *signame(const int);
557 extern void pathtrace_select(const char *);
558 extern int pathtrace_match(struct tcb *);
559 extern int getfdpath(struct tcb *, int, char *, unsigned);
561 extern const char *xlookup(const struct xlat *, const unsigned int);
562 extern const char *xlat_search(const struct xlat *, const size_t, const unsigned int);
564 extern unsigned long get_pagesize(void);
565 extern int string_to_uint(const char *str);
566 extern int next_set_bit(const void *bit_array, unsigned cur_bit, unsigned size_bits);
568 #define QUOTE_0_TERMINATED 0x01
569 #define QUOTE_OMIT_LEADING_TRAILING_QUOTES 0x02
571 extern int print_quoted_string(const char *, unsigned int, unsigned int);
573 /* a refers to the lower numbered u_arg,
574 * b refers to the higher numbered u_arg
576 #ifdef HAVE_LITTLE_ENDIAN_LONG_LONG
577 # define LONG_LONG(a,b) \
578 ((long long)((unsigned long long)(unsigned)(a) | ((unsigned long long)(b)<<32)))
580 # define LONG_LONG(a,b) \
581 ((long long)((unsigned long long)(unsigned)(b) | ((unsigned long long)(a)<<32)))
583 extern int getllval(struct tcb *, unsigned long long *, int);
584 extern int printllval(struct tcb *, const char *, int)
585 ATTRIBUTE_FORMAT((printf, 2, 0));
587 extern void printaddr(long);
588 extern void printxvals(const unsigned int, const char *, const struct xlat *, ...);
589 #define printxval(xlat, val, dflt) printxvals(val, dflt, xlat, NULL)
590 extern int printargs(struct tcb *);
591 extern int printargs_lu(struct tcb *);
592 extern int printargs_ld(struct tcb *);
593 extern void addflags(const struct xlat *, int);
594 extern int printflags(const struct xlat *, int, const char *);
595 extern const char *sprintflags(const char *, const struct xlat *, int);
596 extern const char *sprintmode(int);
597 extern const char *sprinttime(time_t);
598 extern void dumpiov_in_msghdr(struct tcb *, long);
599 extern void dumpiov_in_mmsghdr(struct tcb *, long);
600 extern void dumpiov(struct tcb *, int, long);
601 extern void dumpstr(struct tcb *, long, int);
602 extern void printstr(struct tcb *, long, long);
603 extern bool printnum_short(struct tcb *, long, const char *)
604 ATTRIBUTE_FORMAT((printf, 3, 0));
605 extern bool printnum_int(struct tcb *, long, const char *)
606 ATTRIBUTE_FORMAT((printf, 3, 0));
607 extern bool printnum_int64(struct tcb *, long, const char *)
608 ATTRIBUTE_FORMAT((printf, 3, 0));
610 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
611 extern bool printnum_long_int(struct tcb *, long, const char *, const char *)
612 ATTRIBUTE_FORMAT((printf, 3, 0))
613 ATTRIBUTE_FORMAT((printf, 4, 0));
614 # define printnum_slong(tcp, addr) \
615 printnum_long_int((tcp), (addr), "%" PRId64, "%d")
616 # define printnum_ulong(tcp, addr) \
617 printnum_long_int((tcp), (addr), "%" PRIu64, "%u")
618 # define printnum_ptr(tcp, addr) \
619 printnum_long_int((tcp), (addr), "%#" PRIx64, "%#x")
620 #elif SIZEOF_LONG > 4
621 # define printnum_slong(tcp, addr) \
622 printnum_int64((tcp), (addr), "%" PRId64)
623 # define printnum_ulong(tcp, addr) \
624 printnum_int64((tcp), (addr), "%" PRIu64)
625 # define printnum_ptr(tcp, addr) \
626 printnum_int64((tcp), (addr), "%#" PRIx64)
628 # define printnum_slong(tcp, addr) \
629 printnum_int((tcp), (addr), "%d")
630 # define printnum_ulong(tcp, addr) \
631 printnum_int((tcp), (addr), "%u")
632 # define printnum_ptr(tcp, addr) \
633 printnum_int((tcp), (addr), "%#x")
636 extern bool printpair_int(struct tcb *, long, const char *)
637 ATTRIBUTE_FORMAT((printf, 3, 0));
638 extern bool printpair_int64(struct tcb *, long, const char *)
639 ATTRIBUTE_FORMAT((printf, 3, 0));
640 extern void printpath(struct tcb *, long);
641 extern void printpathn(struct tcb *, long, unsigned int);
642 #define TIMESPEC_TEXT_BUFSIZE (sizeof(long)*3 * 2 + sizeof("{%u, %u}"))
643 #define TIMEVAL_TEXT_BUFSIZE TIMESPEC_TEXT_BUFSIZE
644 extern void printtv_bitness(struct tcb *, long, enum bitness_t, int);
645 #define printtv(tcp, addr) \
646 printtv_bitness((tcp), (addr), BITNESS_CURRENT, 0)
647 #define printtv_special(tcp, addr) \
648 printtv_bitness((tcp), (addr), BITNESS_CURRENT, 1)
649 extern char *sprinttv(char *, struct tcb *, long, enum bitness_t, int special);
650 extern void print_timespec(struct tcb *, long);
651 extern void sprint_timespec(char *, struct tcb *, long);
652 extern void printsigevent(struct tcb *tcp, long arg);
653 extern void printfd(struct tcb *, int);
654 extern bool print_sockaddr_by_inode(const unsigned long, const char *);
655 extern void print_dirfd(struct tcb *, int);
656 extern void printsock(struct tcb *, long, int);
657 extern void print_sock_optmgmt(struct tcb *, long, int);
659 extern void printrusage32(struct tcb *, long);
661 extern void printuid(const char *, const unsigned int);
662 extern void print_sigset_addr_len(struct tcb *, long, long);
663 extern const char *sprintsigmask_n(const char *, const void *, unsigned int);
664 #define tprintsigmask_addr(prefix, mask) \
665 tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
666 extern void printsignal(int);
667 extern void tprint_iov(struct tcb *, unsigned long, unsigned long, int decode_iov);
668 extern void tprint_iov_upto(struct tcb *, unsigned long, unsigned long, int decode_iov, unsigned long);
669 extern void tprint_open_modes(int);
670 extern const char *sprint_open_modes(int);
671 extern void print_seccomp_filter(struct tcb *tcp, unsigned long);
673 extern int block_ioctl(struct tcb *, const unsigned int, long);
674 extern int evdev_ioctl(struct tcb *, const unsigned int, long);
675 extern int loop_ioctl(struct tcb *, const unsigned int, long);
676 extern int mtd_ioctl(struct tcb *, const unsigned int, long);
677 extern int ptp_ioctl(struct tcb *, const unsigned int, long);
678 extern int rtc_ioctl(struct tcb *, const unsigned int, long);
679 extern int scsi_ioctl(struct tcb *, const unsigned int, long);
680 extern int sock_ioctl(struct tcb *, const unsigned int, long);
681 extern int term_ioctl(struct tcb *, const unsigned int, long);
682 extern int ubi_ioctl(struct tcb *, const unsigned int, long);
683 extern int v4l2_ioctl(struct tcb *, const unsigned int, long);
685 extern int tv_nz(const struct timeval *);
686 extern int tv_cmp(const struct timeval *, const struct timeval *);
687 extern double tv_float(const struct timeval *);
688 extern void tv_add(struct timeval *, const struct timeval *, const struct timeval *);
689 extern void tv_sub(struct timeval *, const struct timeval *, const struct timeval *);
690 extern void tv_mul(struct timeval *, const struct timeval *, int);
691 extern void tv_div(struct timeval *, const struct timeval *, int);
694 extern void unwind_init(void);
695 extern void unwind_tcb_init(struct tcb *tcp);
696 extern void unwind_tcb_fin(struct tcb *tcp);
697 extern void unwind_cache_invalidate(struct tcb* tcp);
698 extern void unwind_print_stacktrace(struct tcb* tcp);
699 extern void unwind_capture_stacktrace(struct tcb* tcp);
702 /* Strace log generation machinery.
704 * printing_tcp: tcb which has incomplete line being printed right now.
705 * NULL if last line has been completed ('\n'-terminated).
706 * printleader(tcp) examines it, finishes incomplete line if needed,
707 * the sets it to tcp.
708 * line_ended() clears printing_tcp and resets ->curcol = 0.
709 * tcp->curcol == 0 check is also used to detect completeness
710 * of last line, since in -ff mode just checking printing_tcp for NULL
713 * If you change this code, test log generation in both -f and -ff modes
715 * strace -oLOG -f[f] test/threaded_execve
716 * strace -oLOG -f[f] test/sigkill_rain
717 * strace -oLOG -f[f] -p "`pidof web_browser`"
719 extern struct tcb *printing_tcp;
720 extern void printleader(struct tcb *);
721 extern void line_ended(void);
722 extern void tabto(void);
723 extern void tprintf(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
724 extern void tprints(const char *str);
726 #if SUPPORTED_PERSONALITIES > 1
727 extern void set_personality(int personality);
728 extern unsigned current_personality;
730 # define set_personality(personality) ((void)0)
731 # define current_personality 0
734 #if SUPPORTED_PERSONALITIES == 1
735 # define current_wordsize PERSONALITY0_WORDSIZE
737 # if SUPPORTED_PERSONALITIES == 2 && PERSONALITY0_WORDSIZE == PERSONALITY1_WORDSIZE
738 # define current_wordsize PERSONALITY0_WORDSIZE
740 extern unsigned current_wordsize;
744 /* In many, many places we play fast and loose and use
745 * tprintf("%d", (int) tcp->u_arg[N]) to print fds, pids etc.
746 * We probably need to use widen_to_long() instead:
748 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
749 # define widen_to_long(v) (current_wordsize == 4 ? (long)(int32_t)(v) : (long)(v))
751 # define widen_to_long(v) ((long)(v))
754 extern const struct_sysent sysent0[];
755 extern const char *const errnoent0[];
756 extern const char *const signalent0[];
757 extern const struct_ioctlent ioctlent0[];
758 extern qualbits_t *qual_vec[SUPPORTED_PERSONALITIES];
759 #define qual_flags (qual_vec[current_personality])
761 #if SUPPORTED_PERSONALITIES > 1
762 extern const struct_sysent *sysent;
763 extern const char *const *errnoent;
764 extern const char *const *signalent;
765 extern const struct_ioctlent *ioctlent;
767 # define sysent sysent0
768 # define errnoent errnoent0
769 # define signalent signalent0
770 # define ioctlent ioctlent0
773 extern unsigned nsyscalls;
774 extern unsigned nerrnos;
775 extern unsigned nsignals;
776 extern unsigned nioctlents;
777 extern unsigned num_quals;
779 #if SUPPORTED_PERSONALITIES > 1
780 # include "printers.h"
781 extern const struct_printers *printers;
782 # define MPERS_PRINTER_NAME(printer_name) printers->printer_name
784 # include "native_printer_decls.h"
785 # define MPERS_PRINTER_NAME(printer_name) printer_name
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)
798 #define MPERS_FUNC_NAME__(prefix, name) prefix ## name
799 #define MPERS_FUNC_NAME_(prefix, name) MPERS_FUNC_NAME__(prefix, name)
800 #define MPERS_FUNC_NAME(name) MPERS_FUNC_NAME_(MPERS_PREFIX, name)
802 #define SYS_FUNC_NAME(syscall_name) MPERS_FUNC_NAME(sys_ ## syscall_name)
804 #define SYS_FUNC(syscall_name) int SYS_FUNC_NAME(syscall_name)(struct tcb *tcp)
806 #define MPERS_PRINTER_DECL(type, name) type MPERS_FUNC_NAME(name)