defs.h revision 2950de36314b5ea88a3741e24f948113358f7ce2
1/* 2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> 3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> 4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 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. 17 * 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. 28 */ 29 30#ifdef HAVE_CONFIG_H 31# include "config.h" 32#endif 33 34#include <features.h> 35#ifdef HAVE_STDBOOL_H 36# include <stdbool.h> 37#endif 38#include <stdint.h> 39#include <inttypes.h> 40#include <sys/types.h> 41#ifdef STDC_HEADERS 42# include <stddef.h> 43#endif 44#include <unistd.h> 45#include <stdlib.h> 46#include <stdio.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. 49 */ 50/* #include <ctype.h> */ 51#include <string.h> 52#include <errno.h> 53#include <time.h> 54#include <sys/time.h> 55#include <sys/syscall.h> 56 57#include "mpers_type.h" 58 59#ifndef HAVE_STRERROR 60const char *strerror(int); 61#endif 62#ifndef HAVE_STPCPY 63/* Some libc have stpcpy, some don't. Sigh... 64 * Roll our private implementation... 65 */ 66#undef stpcpy 67#define stpcpy strace_stpcpy 68extern char *stpcpy(char *dst, const char *src); 69#endif 70 71#if defined __GNUC__ && defined __GNUC_MINOR__ 72# define GNUC_PREREQ(maj, min) \ 73 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) 74#else 75# define __attribute__(x) /* empty */ 76# define GNUC_PREREQ(maj, min) 0 77#endif 78 79#if GNUC_PREREQ(2, 5) 80# define ATTRIBUTE_NORETURN __attribute__((__noreturn__)) 81#else 82# define ATTRIBUTE_NORETURN /* empty */ 83#endif 84 85#if GNUC_PREREQ(2, 7) 86# define ATTRIBUTE_FORMAT(args) __attribute__((__format__ args)) 87# define ATTRIBUTE_ALIGNED(arg) __attribute__((__aligned__(arg))) 88# define ATTRIBUTE_PACKED __attribute__((__packed__)) 89#else 90# define ATTRIBUTE_FORMAT(args) /* empty */ 91# define ATTRIBUTE_ALIGNED(arg) /* empty */ 92# define ATTRIBUTE_PACKED /* empty */ 93#endif 94 95#if GNUC_PREREQ(3, 0) 96# define ATTRIBUTE_MALLOC __attribute__((__malloc__)) 97#else 98# define ATTRIBUTE_MALLOC /* empty */ 99#endif 100 101#if GNUC_PREREQ(3, 1) 102# define ATTRIBUTE_NOINLINE __attribute__((__noinline__)) 103#else 104# define ATTRIBUTE_NOINLINE /* empty */ 105#endif 106 107#if GNUC_PREREQ(4, 3) 108# define ATTRIBUTE_ALLOC_SIZE(args) __attribute__((__alloc_size__ args)) 109#else 110# define ATTRIBUTE_ALLOC_SIZE(args) /* empty */ 111#endif 112 113#ifndef offsetof 114# define offsetof(type, member) \ 115 (((char *) &(((type *) NULL)->member)) - ((char *) (type *) NULL)) 116#endif 117 118#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 119 120/* macros */ 121#ifndef MAX 122# define MAX(a, b) (((a) > (b)) ? (a) : (b)) 123#endif 124#ifndef MIN 125# define MIN(a, b) (((a) < (b)) ? (a) : (b)) 126#endif 127#define CLAMP(val, min, max) MIN(MAX(min, val), max) 128 129/* Glibc has an efficient macro for sigemptyset 130 * (it just does one or two assignments of 0 to internal vector of longs). 131 */ 132#if defined(__GLIBC__) && defined(__sigemptyset) && !defined(sigemptyset) 133# define sigemptyset __sigemptyset 134#endif 135 136/* Configuration section */ 137#ifndef DEFAULT_STRLEN 138/* default maximum # of bytes printed in `printstr', change with -s switch */ 139# define DEFAULT_STRLEN 32 140#endif 141#ifndef DEFAULT_ACOLUMN 142# define DEFAULT_ACOLUMN 40 /* default alignment column for results */ 143#endif 144/* 145 * Maximum number of args to a syscall. 146 * 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. 150 */ 151#ifndef MAX_ARGS 152# ifdef LINUX_MIPSO32 153# define MAX_ARGS 7 154# else 155# define MAX_ARGS 6 156# endif 157#endif 158/* default sorting method for call profiling */ 159#ifndef DEFAULT_SORTBY 160# define DEFAULT_SORTBY "time" 161#endif 162/* 163 * Experimental code using PTRACE_SEIZE can be enabled here. 164 * This needs Linux kernel 3.4.x or later to work. 165 */ 166#define USE_SEIZE 1 167/* To force NOMMU build, set to 1 */ 168#define NOMMU_SYSTEM 0 169/* 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. 176 */ 177#define USE_CUSTOM_PRINTF 0 178 179#ifndef ERESTARTSYS 180# define ERESTARTSYS 512 181#endif 182#ifndef ERESTARTNOINTR 183# define ERESTARTNOINTR 513 184#endif 185#ifndef ERESTARTNOHAND 186# define ERESTARTNOHAND 514 187#endif 188#ifndef ERESTART_RESTARTBLOCK 189# define ERESTART_RESTARTBLOCK 516 190#endif 191 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" 201# endif 202# endif 203#endif 204 205#ifdef X86_64 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" 214# endif 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" 219# endif 220#endif 221 222#ifdef X32 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" 230# endif 231#endif 232 233#ifdef ARM 234/* one personality */ 235#endif 236 237#ifdef AARCH64 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" 247# endif 248#endif 249 250#ifdef POWERPC64 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" 258# endif 259#endif 260 261#ifdef TILE 262# define SUPPORTED_PERSONALITIES 2 263# define PERSONALITY0_WORDSIZE 8 264# define PERSONALITY1_WORDSIZE 4 265# ifdef __tilepro__ 266# define DEFAULT_PERSONALITY 1 267# endif 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" 272# endif 273#endif 274 275#ifndef SUPPORTED_PERSONALITIES 276# define SUPPORTED_PERSONALITIES 1 277#endif 278#ifndef DEFAULT_PERSONALITY 279# define DEFAULT_PERSONALITY 0 280#endif 281#ifndef PERSONALITY0_WORDSIZE 282# define PERSONALITY0_WORDSIZE SIZEOF_LONG 283#endif 284 285#ifndef PERSONALITY0_INCLUDE_PRINTERS_DECLS 286# define PERSONALITY0_INCLUDE_PRINTERS_DECLS "native_printer_decls.h" 287#endif 288#ifndef PERSONALITY0_INCLUDE_PRINTERS_DEFS 289# define PERSONALITY0_INCLUDE_PRINTERS_DEFS "native_printer_defs.h" 290#endif 291 292#ifndef PERSONALITY1_INCLUDE_PRINTERS_DECLS 293# define PERSONALITY1_INCLUDE_PRINTERS_DECLS "native_printer_decls.h" 294#endif 295#ifndef PERSONALITY1_INCLUDE_PRINTERS_DEFS 296# define PERSONALITY1_INCLUDE_PRINTERS_DEFS "native_printer_defs.h" 297#endif 298 299#ifndef PERSONALITY2_INCLUDE_PRINTERS_DECLS 300# define PERSONALITY2_INCLUDE_PRINTERS_DECLS "native_printer_decls.h" 301#endif 302#ifndef PERSONALITY2_INCLUDE_PRINTERS_DEFS 303# define PERSONALITY2_INCLUDE_PRINTERS_DEFS "native_printer_defs.h" 304#endif 305 306#ifndef PERSONALITY1_INCLUDE_FUNCS 307# define PERSONALITY1_INCLUDE_FUNCS "empty.h" 308#endif 309#ifndef PERSONALITY2_INCLUDE_FUNCS 310# define PERSONALITY2_INCLUDE_FUNCS "empty.h" 311#endif 312 313typedef struct sysent { 314 unsigned nargs; 315 int sys_flags; 316 int sen; 317 int (*sys_func)(); 318 const char *sys_name; 319} struct_sysent; 320 321typedef struct ioctlent { 322 const char *symbol; 323 unsigned int code; 324} struct_ioctlent; 325 326/* Trace Control Block */ 327struct tcb { 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 */ 337#endif 338 long u_rval; /* Return value */ 339#if SUPPORTED_PERSONALITIES > 1 340 unsigned int currpers; /* Personality at the time of scno update */ 341#endif 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 */ 351 352#ifdef USE_LIBUNWIND 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; 358#endif 359}; 360 361/* TCB flags */ 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 */ 365/* 366 * Are we in system call entry or in syscall exit? 367 * 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() 375 * and below. 376 * The bit is cleared after all syscall exit processing is done. 377 * 378 * Use entering(tcp) / exiting(tcp) to check this bit to make code more readable. 379 */ 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 */ 384 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 */ 393typedef uint8_t qualbits_t; 394#define UNDEFINED_SCNO 0x100 /* Used only in tcp->qual_flg */ 395 396#define DEFAULT_QUAL_FLAGS (QUAL_TRACE | QUAL_ABBREV | QUAL_VERBOSE) 397 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) 404 405struct xlat { 406 unsigned int val; 407 const char *str; 408}; 409#define XLAT(x) { x, #x } 410#define XLAT_END { 0, NULL } 411 412extern const struct xlat addrfams[]; 413extern const struct xlat adjtimex_modes[]; 414extern const struct xlat adjtimex_status[]; 415extern const struct xlat at_flags[]; 416extern const struct xlat open_access_modes[]; 417extern const struct xlat open_mode_flags[]; 418extern const struct xlat resource_flags[]; 419extern const struct xlat sigev_value[]; 420extern const struct xlat whence_codes[]; 421 422/* Format of syscall return values */ 423#define RVAL_DECIMAL 000 /* decimal format */ 424#define RVAL_HEX 001 /* hex format */ 425#define RVAL_OCTAL 002 /* octal format */ 426#define RVAL_UDECIMAL 003 /* unsigned decimal format */ 427#if defined(LINUX_MIPSN32) || defined(X32) 428# if 0 /* unused so far */ 429# define RVAL_LDECIMAL 004 /* long decimal format */ 430# define RVAL_LHEX 005 /* long hex format */ 431# define RVAL_LOCTAL 006 /* long octal format */ 432# endif 433# define RVAL_LUDECIMAL 007 /* long unsigned decimal format */ 434#endif 435#define RVAL_FD 010 /* file descriptor */ 436#define RVAL_MASK 017 /* mask for these values */ 437 438#define RVAL_STR 020 /* Print `auxstr' field after return val */ 439#define RVAL_NONE 040 /* Print nothing */ 440 441#define RVAL_DECODED 0100 /* syscall decoding finished */ 442 443#define TRACE_FILE 001 /* Trace file-related syscalls. */ 444#define TRACE_IPC 002 /* Trace IPC-related syscalls. */ 445#define TRACE_NETWORK 004 /* Trace network-related syscalls. */ 446#define TRACE_PROCESS 010 /* Trace process-related syscalls. */ 447#define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */ 448#define TRACE_DESC 040 /* Trace file descriptor-related syscalls. */ 449#define TRACE_MEMORY 0100 /* Trace memory mapping-related syscalls. */ 450#define SYSCALL_NEVER_FAILS 0200 /* Syscall is always successful. */ 451#define STACKTRACE_INVALIDATE_CACHE 0400 /* Trigger proc/maps cache updating */ 452#define STACKTRACE_CAPTURE_ON_ENTER 01000 /* Capture stacktrace on "entering" stage */ 453#define TRACE_INDIRECT_SUBCALL 02000 /* Syscall is an indirect socket/ipc subcall. */ 454 455#define indirect_ipccall(tcp) (tcp->s_ent->sys_flags & TRACE_INDIRECT_SUBCALL) 456 457#if defined(ARM) || defined(AARCH64) \ 458 || defined(I386) || defined(X32) || defined(X86_64) \ 459 || defined(IA64) \ 460 || defined(BFIN) \ 461 || defined(M68K) \ 462 || defined(MICROBLAZE) \ 463 || defined(S390) \ 464 || defined(SH) || defined(SH64) \ 465 || defined(SPARC) || defined(SPARC64) \ 466 /**/ 467# define NEED_UID16_PARSERS 1 468#else 469# define NEED_UID16_PARSERS 0 470#endif 471 472typedef enum { 473 CFLAG_NONE = 0, 474 CFLAG_ONLY_STATS, 475 CFLAG_BOTH 476} cflag_t; 477extern cflag_t cflag; 478extern bool debug_flag; 479extern bool Tflag; 480extern bool iflag; 481extern bool count_wallclock; 482extern unsigned int qflag; 483extern bool not_failing_only; 484extern unsigned int show_fd_path; 485extern bool hide_log_until_execve; 486/* are we filtering traces based on paths? */ 487extern const char **paths_selected; 488#define tracing_paths (paths_selected != NULL) 489extern unsigned xflag; 490extern unsigned followfork; 491#ifdef USE_LIBUNWIND 492/* if this is true do the stack trace for every system call */ 493extern bool stack_trace_enabled; 494#endif 495extern unsigned ptrace_setoptions; 496extern unsigned max_strlen; 497extern unsigned os_release; 498#undef KERNEL_VERSION 499#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) 500 501enum bitness_t { BITNESS_CURRENT = 0, BITNESS_32 }; 502 503void error_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2)); 504void perror_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2)); 505void error_msg_and_die(const char *fmt, ...) 506 ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN; 507void perror_msg_and_die(const char *fmt, ...) 508 ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN; 509void die_out_of_memory(void) ATTRIBUTE_NORETURN; 510 511void *xmalloc(size_t size) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1)); 512void *xcalloc(size_t nmemb, size_t size) 513 ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1, 2)); 514void *xreallocarray(void *ptr, size_t nmemb, size_t size) 515 ATTRIBUTE_ALLOC_SIZE((2, 3)); 516char *xstrdup(const char *str) ATTRIBUTE_MALLOC; 517 518#if USE_CUSTOM_PRINTF 519/* 520 * See comment in vsprintf.c for allowed formats. 521 * Short version: %h[h]u, %zu, %tu are not allowed, use %[l[l]]u. 522 */ 523int strace_vfprintf(FILE *fp, const char *fmt, va_list args); 524#else 525# define strace_vfprintf vfprintf 526#endif 527 528extern void set_sortby(const char *); 529extern void set_overhead(int); 530extern void qualify(const char *); 531extern void print_pc(struct tcb *); 532extern int trace_syscall(struct tcb *); 533extern void count_syscall(struct tcb *, const struct timeval *); 534extern void call_summary(FILE *); 535 536extern void clear_regs(void); 537extern void get_regs(pid_t pid); 538extern int get_scno(struct tcb *tcp); 539extern const char *syscall_name(long scno); 540 541extern bool is_erestart(struct tcb *); 542extern void temporarily_clear_syserror(struct tcb *); 543extern void restore_cleared_syserror(struct tcb *); 544 545extern int umoven(struct tcb *, long, unsigned int, void *); 546#define umove(pid, addr, objp) \ 547 umoven((pid), (addr), sizeof(*(objp)), (void *) (objp)) 548extern int umoven_or_printaddr(struct tcb *, long, unsigned int, void *); 549#define umove_or_printaddr(pid, addr, objp) \ 550 umoven_or_printaddr((pid), (addr), sizeof(*(objp)), (void *) (objp)) 551extern int umove_ulong_or_printaddr(struct tcb *, long, unsigned long *); 552extern int umove_ulong_array_or_printaddr(struct tcb *, long, unsigned long *, size_t); 553extern int umovestr(struct tcb *, long, unsigned int, char *); 554extern int upeek(int pid, long, long *); 555 556#if defined ALPHA || defined IA64 || defined MIPS \ 557 || defined SH || defined SPARC || defined SPARC64 558# define HAVE_GETRVAL2 559extern long getrval2(struct tcb *); 560#else 561# undef HAVE_GETRVAL2 562#endif 563 564extern const char *signame(const int); 565extern void pathtrace_select(const char *); 566extern int pathtrace_match(struct tcb *); 567extern int getfdpath(struct tcb *, int, char *, unsigned); 568 569extern const char *xlookup(const struct xlat *, const unsigned int); 570extern const char *xlat_search(const struct xlat *, const size_t, const unsigned int); 571 572extern unsigned long get_pagesize(void); 573extern int string_to_uint(const char *str); 574extern int next_set_bit(const void *bit_array, unsigned cur_bit, unsigned size_bits); 575 576#define QUOTE_0_TERMINATED 0x01 577#define QUOTE_OMIT_LEADING_TRAILING_QUOTES 0x02 578 579extern int print_quoted_string(const char *, unsigned int, unsigned int); 580 581/* a refers to the lower numbered u_arg, 582 * b refers to the higher numbered u_arg 583 */ 584#ifdef HAVE_LITTLE_ENDIAN_LONG_LONG 585# define LONG_LONG(a,b) \ 586 ((long long)((unsigned long long)(unsigned)(a) | ((unsigned long long)(b)<<32))) 587#else 588# define LONG_LONG(a,b) \ 589 ((long long)((unsigned long long)(unsigned)(b) | ((unsigned long long)(a)<<32))) 590#endif 591extern int getllval(struct tcb *, unsigned long long *, int); 592extern int printllval(struct tcb *, const char *, int) 593 ATTRIBUTE_FORMAT((printf, 2, 0)); 594 595extern void printaddr(long); 596extern void printxvals(const unsigned int, const char *, const struct xlat *, ...); 597#define printxval(xlat, val, dflt) printxvals(val, dflt, xlat, NULL) 598extern int printargs(struct tcb *); 599extern int printargs_lu(struct tcb *); 600extern int printargs_ld(struct tcb *); 601extern void addflags(const struct xlat *, int); 602extern int printflags(const struct xlat *, int, const char *); 603extern const char *sprintflags(const char *, const struct xlat *, int); 604extern const char *sprintmode(int); 605extern const char *sprinttime(time_t); 606extern void dumpiov_in_msghdr(struct tcb *, long); 607extern void dumpiov_in_mmsghdr(struct tcb *, long); 608extern void dumpiov(struct tcb *, int, long); 609extern void dumpstr(struct tcb *, long, int); 610extern void printstr(struct tcb *, long, long); 611extern bool printnum_short(struct tcb *, long, const char *) 612 ATTRIBUTE_FORMAT((printf, 3, 0)); 613extern bool printnum_int(struct tcb *, long, const char *) 614 ATTRIBUTE_FORMAT((printf, 3, 0)); 615extern bool printnum_int64(struct tcb *, long, const char *) 616 ATTRIBUTE_FORMAT((printf, 3, 0)); 617 618#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 619extern bool printnum_long_int(struct tcb *, long, const char *, const char *) 620 ATTRIBUTE_FORMAT((printf, 3, 0)) 621 ATTRIBUTE_FORMAT((printf, 4, 0)); 622# define printnum_slong(tcp, addr) \ 623 printnum_long_int((tcp), (addr), "%" PRId64, "%d") 624# define printnum_ulong(tcp, addr) \ 625 printnum_long_int((tcp), (addr), "%" PRIu64, "%u") 626# define printnum_ptr(tcp, addr) \ 627 printnum_long_int((tcp), (addr), "%#" PRIx64, "%#x") 628#elif SIZEOF_LONG > 4 629# define printnum_slong(tcp, addr) \ 630 printnum_int64((tcp), (addr), "%" PRId64) 631# define printnum_ulong(tcp, addr) \ 632 printnum_int64((tcp), (addr), "%" PRIu64) 633# define printnum_ptr(tcp, addr) \ 634 printnum_int64((tcp), (addr), "%#" PRIx64) 635#else 636# define printnum_slong(tcp, addr) \ 637 printnum_int((tcp), (addr), "%d") 638# define printnum_ulong(tcp, addr) \ 639 printnum_int((tcp), (addr), "%u") 640# define printnum_ptr(tcp, addr) \ 641 printnum_int((tcp), (addr), "%#x") 642#endif 643 644extern bool printpair_int(struct tcb *, long, const char *) 645 ATTRIBUTE_FORMAT((printf, 3, 0)); 646extern bool printpair_int64(struct tcb *, long, const char *) 647 ATTRIBUTE_FORMAT((printf, 3, 0)); 648extern void printpath(struct tcb *, long); 649extern void printpathn(struct tcb *, long, unsigned int); 650#define TIMESPEC_TEXT_BUFSIZE \ 651 (sizeof(intmax_t)*3 * 2 + sizeof("{tv_sec=%jd, tv_nsec=%jd}")) 652#define TIMEVAL_TEXT_BUFSIZE TIMESPEC_TEXT_BUFSIZE 653extern void printtv_bitness(struct tcb *, long, enum bitness_t, int); 654extern char *sprinttv(char *, struct tcb *, long, enum bitness_t, int special); 655extern void printfd(struct tcb *, int); 656extern bool print_sockaddr_by_inode(const unsigned long, const char *); 657extern void print_dirfd(struct tcb *, int); 658extern void printsock(struct tcb *, long, int); 659extern void print_sock_optmgmt(struct tcb *, long, int); 660#ifdef ALPHA 661extern void printrusage32(struct tcb *, long); 662extern void print_timeval32(struct tcb *tcp, long); 663extern void print_timeval32_pair(struct tcb *tcp, long); 664extern void print_itimerval32(struct tcb *tcp, long); 665#endif 666extern void printuid(const char *, const unsigned int); 667extern void print_sigset_addr_len(struct tcb *, long, long); 668extern const char *sprintsigmask_n(const char *, const void *, unsigned int); 669#define tprintsigmask_addr(prefix, mask) \ 670 tprints(sprintsigmask_n((prefix), (mask), sizeof(mask))) 671extern void printsignal(int); 672extern void tprint_iov(struct tcb *, unsigned long, unsigned long, int decode_iov); 673extern void tprint_iov_upto(struct tcb *, unsigned long, unsigned long, int decode_iov, unsigned long); 674extern void tprint_open_modes(int); 675extern const char *sprint_open_modes(int); 676extern void print_seccomp_filter(struct tcb *tcp, unsigned long); 677 678extern int block_ioctl(struct tcb *, const unsigned int, long); 679extern int evdev_ioctl(struct tcb *, const unsigned int, long); 680extern int loop_ioctl(struct tcb *, const unsigned int, long); 681extern int mtd_ioctl(struct tcb *, const unsigned int, long); 682extern int ptp_ioctl(struct tcb *, const unsigned int, long); 683extern int rtc_ioctl(struct tcb *, const unsigned int, long); 684extern int scsi_ioctl(struct tcb *, const unsigned int, long); 685extern int sock_ioctl(struct tcb *, const unsigned int, long); 686extern int term_ioctl(struct tcb *, const unsigned int, long); 687extern int ubi_ioctl(struct tcb *, const unsigned int, long); 688extern int v4l2_ioctl(struct tcb *, const unsigned int, long); 689 690extern int tv_nz(const struct timeval *); 691extern int tv_cmp(const struct timeval *, const struct timeval *); 692extern double tv_float(const struct timeval *); 693extern void tv_add(struct timeval *, const struct timeval *, const struct timeval *); 694extern void tv_sub(struct timeval *, const struct timeval *, const struct timeval *); 695extern void tv_mul(struct timeval *, const struct timeval *, int); 696extern void tv_div(struct timeval *, const struct timeval *, int); 697 698#ifdef USE_LIBUNWIND 699extern void unwind_init(void); 700extern void unwind_tcb_init(struct tcb *tcp); 701extern void unwind_tcb_fin(struct tcb *tcp); 702extern void unwind_cache_invalidate(struct tcb* tcp); 703extern void unwind_print_stacktrace(struct tcb* tcp); 704extern void unwind_capture_stacktrace(struct tcb* tcp); 705#endif 706 707/* Strace log generation machinery. 708 * 709 * printing_tcp: tcb which has incomplete line being printed right now. 710 * NULL if last line has been completed ('\n'-terminated). 711 * printleader(tcp) examines it, finishes incomplete line if needed, 712 * the sets it to tcp. 713 * line_ended() clears printing_tcp and resets ->curcol = 0. 714 * tcp->curcol == 0 check is also used to detect completeness 715 * of last line, since in -ff mode just checking printing_tcp for NULL 716 * is not enough. 717 * 718 * If you change this code, test log generation in both -f and -ff modes 719 * using: 720 * strace -oLOG -f[f] test/threaded_execve 721 * strace -oLOG -f[f] test/sigkill_rain 722 * strace -oLOG -f[f] -p "`pidof web_browser`" 723 */ 724extern struct tcb *printing_tcp; 725extern void printleader(struct tcb *); 726extern void line_ended(void); 727extern void tabto(void); 728extern void tprintf(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2)); 729extern void tprints(const char *str); 730 731#if SUPPORTED_PERSONALITIES > 1 732extern void set_personality(int personality); 733extern unsigned current_personality; 734#else 735# define set_personality(personality) ((void)0) 736# define current_personality 0 737#endif 738 739#if SUPPORTED_PERSONALITIES == 1 740# define current_wordsize PERSONALITY0_WORDSIZE 741#else 742# if SUPPORTED_PERSONALITIES == 2 && PERSONALITY0_WORDSIZE == PERSONALITY1_WORDSIZE 743# define current_wordsize PERSONALITY0_WORDSIZE 744# else 745extern unsigned current_wordsize; 746# endif 747#endif 748 749/* In many, many places we play fast and loose and use 750 * tprintf("%d", (int) tcp->u_arg[N]) to print fds, pids etc. 751 * We probably need to use widen_to_long() instead: 752 */ 753#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 754# define widen_to_long(v) (current_wordsize == 4 ? (long)(int32_t)(v) : (long)(v)) 755#else 756# define widen_to_long(v) ((long)(v)) 757#endif 758 759extern const struct_sysent sysent0[]; 760extern const char *const errnoent0[]; 761extern const char *const signalent0[]; 762extern const struct_ioctlent ioctlent0[]; 763extern qualbits_t *qual_vec[SUPPORTED_PERSONALITIES]; 764#define qual_flags (qual_vec[current_personality]) 765 766#if SUPPORTED_PERSONALITIES > 1 767extern const struct_sysent *sysent; 768extern const char *const *errnoent; 769extern const char *const *signalent; 770extern const struct_ioctlent *ioctlent; 771#else 772# define sysent sysent0 773# define errnoent errnoent0 774# define signalent signalent0 775# define ioctlent ioctlent0 776#endif 777 778extern unsigned nsyscalls; 779extern unsigned nerrnos; 780extern unsigned nsignals; 781extern unsigned nioctlents; 782extern unsigned num_quals; 783 784#if SUPPORTED_PERSONALITIES > 1 785# include "printers.h" 786#else 787# include "native_printer_decls.h" 788#endif 789 790/* 791 * If you need non-NULL sysent[scno].sys_func and sysent[scno].sys_name 792 */ 793#define SCNO_IS_VALID(scno) \ 794 ((unsigned long)(scno) < nsyscalls && sysent[scno].sys_func) 795 796/* Only ensures that sysent[scno] isn't out of range */ 797#define SCNO_IN_RANGE(scno) \ 798 ((unsigned long)(scno) < nsyscalls) 799 800#define MPERS_FUNC_NAME__(prefix, name) prefix ## name 801#define MPERS_FUNC_NAME_(prefix, name) MPERS_FUNC_NAME__(prefix, name) 802#define MPERS_FUNC_NAME(name) MPERS_FUNC_NAME_(MPERS_PREFIX, name) 803 804#define SYS_FUNC_NAME(syscall_name) MPERS_FUNC_NAME(sys_ ## syscall_name) 805 806#define SYS_FUNC(syscall_name) int SYS_FUNC_NAME(syscall_name)(struct tcb *tcp) 807 808#define MPERS_PRINTER_DECL(type, name) type MPERS_FUNC_NAME(name) 809