]> granicus.if.org Git - strace/blob - defs.h
decode_poll_exiting: reserve more space in output buffer
[strace] / defs.h
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 #ifndef HAVE_STRERROR
58 const char *strerror(int);
59 #endif
60 #ifndef HAVE_STPCPY
61 /* Some libc have stpcpy, some don't. Sigh...
62  * Roll our private implementation...
63  */
64 #undef stpcpy
65 #define stpcpy strace_stpcpy
66 extern char *stpcpy(char *dst, const char *src);
67 #endif
68
69 #if defined __GNUC__ && defined __GNUC_MINOR__
70 # define GNUC_PREREQ(maj, min)  \
71         ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
72 #else
73 # define __attribute__(x)       /* empty */
74 # define GNUC_PREREQ(maj, min)  0
75 #endif
76
77 #if GNUC_PREREQ(2, 5)
78 # define ATTRIBUTE_NORETURN     __attribute__((__noreturn__))
79 #else
80 # define ATTRIBUTE_NORETURN     /* empty */
81 #endif
82
83 #if GNUC_PREREQ(2, 7)
84 # define ATTRIBUTE_FORMAT(args) __attribute__((__format__ args))
85 # define ATTRIBUTE_ALIGNED(arg) __attribute__((__aligned__(arg)))
86 # define ATTRIBUTE_PACKED       __attribute__((__packed__))
87 #else
88 # define ATTRIBUTE_FORMAT(args) /* empty */
89 # define ATTRIBUTE_ALIGNED(arg) /* empty */
90 # define ATTRIBUTE_PACKED       /* empty */
91 #endif
92
93 #if GNUC_PREREQ(3, 0)
94 # define ATTRIBUTE_MALLOC       __attribute__((__malloc__))
95 #else
96 # define ATTRIBUTE_MALLOC       /* empty */
97 #endif
98
99 #if GNUC_PREREQ(3, 1)
100 # define ATTRIBUTE_NOINLINE     __attribute__((__noinline__))
101 #else
102 # define ATTRIBUTE_NOINLINE     /* empty */
103 #endif
104
105 #if GNUC_PREREQ(4, 3)
106 # define ATTRIBUTE_ALLOC_SIZE(args)     __attribute__((__alloc_size__ args))
107 #else
108 # define ATTRIBUTE_ALLOC_SIZE(args)     /* empty */
109 #endif
110
111 #ifndef offsetof
112 # define offsetof(type, member) \
113         (((char *) &(((type *) NULL)->member)) - ((char *) (type *) NULL))
114 #endif
115
116 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
117
118 /* macros */
119 #ifndef MAX
120 # define MAX(a, b)              (((a) > (b)) ? (a) : (b))
121 #endif
122 #ifndef MIN
123 # define MIN(a, b)              (((a) < (b)) ? (a) : (b))
124 #endif
125 #define CLAMP(val, min, max) MIN(MAX(min, val), max)
126
127 /* Glibc has an efficient macro for sigemptyset
128  * (it just does one or two assignments of 0 to internal vector of longs).
129  */
130 #if defined(__GLIBC__) && defined(__sigemptyset) && !defined(sigemptyset)
131 # define sigemptyset __sigemptyset
132 #endif
133
134 /* Configuration section */
135 #ifndef DEFAULT_STRLEN
136 /* default maximum # of bytes printed in `printstr', change with -s switch */
137 # define DEFAULT_STRLEN 32
138 #endif
139 #ifndef DEFAULT_ACOLUMN
140 # define DEFAULT_ACOLUMN        40      /* default alignment column for results */
141 #endif
142 /*
143  * Maximum number of args to a syscall.
144  *
145  * Make sure that all entries in all syscallent.h files have nargs <= MAX_ARGS!
146  * linux/<ARCH>/syscallent*.h:
147  *      all have nargs <= 6 except mips o32 which has nargs <= 7.
148  */
149 #ifndef MAX_ARGS
150 # ifdef LINUX_MIPSO32
151 #  define MAX_ARGS      7
152 # else
153 #  define MAX_ARGS      6
154 # endif
155 #endif
156 /* default sorting method for call profiling */
157 #ifndef DEFAULT_SORTBY
158 # define DEFAULT_SORTBY "time"
159 #endif
160 /*
161  * Experimental code using PTRACE_SEIZE can be enabled here.
162  * This needs Linux kernel 3.4.x or later to work.
163  */
164 #define USE_SEIZE 1
165 /* To force NOMMU build, set to 1 */
166 #define NOMMU_SYSTEM 0
167 /*
168  * Set to 1 to use speed-optimized vfprintf implementation.
169  * It results in strace using about 5% less CPU in user space
170  * (compared to glibc version).
171  * But strace spends a lot of time in kernel space,
172  * so overall it does not appear to be a significant win.
173  * Thus disabled by default.
174  */
175 #define USE_CUSTOM_PRINTF 0
176
177 #ifndef ERESTARTSYS
178 # define ERESTARTSYS    512
179 #endif
180 #ifndef ERESTARTNOINTR
181 # define ERESTARTNOINTR 513
182 #endif
183 #ifndef ERESTARTNOHAND
184 # define ERESTARTNOHAND 514
185 #endif
186 #ifndef ERESTART_RESTARTBLOCK
187 # define ERESTART_RESTARTBLOCK 516
188 #endif
189
190 #if defined(SPARC) || defined(SPARC64)
191 # define PERSONALITY0_WORDSIZE 4
192 # if defined(SPARC64)
193 #  define SUPPORTED_PERSONALITIES 2
194 #  define PERSONALITY1_WORDSIZE 8
195 # endif
196 #endif
197
198 #ifdef X86_64
199 # define SUPPORTED_PERSONALITIES 3
200 # define PERSONALITY0_WORDSIZE 8
201 # define PERSONALITY1_WORDSIZE 4
202 # define PERSONALITY2_WORDSIZE 4
203 #endif
204
205 #ifdef X32
206 # define SUPPORTED_PERSONALITIES 2
207 # define PERSONALITY0_WORDSIZE 4
208 # define PERSONALITY1_WORDSIZE 4
209 #endif
210
211 #ifdef ARM
212 /* one personality */
213 #endif
214
215 #ifdef AARCH64
216 /* The existing ARM personality, then AArch64 */
217 # define SUPPORTED_PERSONALITIES 2
218 # define PERSONALITY0_WORDSIZE 4
219 # define PERSONALITY1_WORDSIZE 8
220 # define DEFAULT_PERSONALITY 1
221 #endif
222
223 #ifdef POWERPC64
224 # define SUPPORTED_PERSONALITIES 2
225 # define PERSONALITY0_WORDSIZE 8
226 # define PERSONALITY1_WORDSIZE 4
227 #endif
228
229 #ifdef TILE
230 # define SUPPORTED_PERSONALITIES 2
231 # define PERSONALITY0_WORDSIZE 8
232 # define PERSONALITY1_WORDSIZE 4
233 # ifdef __tilepro__
234 #  define DEFAULT_PERSONALITY 1
235 # endif
236 #endif
237
238 #ifndef SUPPORTED_PERSONALITIES
239 # define SUPPORTED_PERSONALITIES 1
240 #endif
241 #ifndef DEFAULT_PERSONALITY
242 # define DEFAULT_PERSONALITY 0
243 #endif
244 #ifndef PERSONALITY0_WORDSIZE
245 # define PERSONALITY0_WORDSIZE SIZEOF_LONG
246 #endif
247
248 typedef struct sysent {
249         unsigned nargs;
250         int     sys_flags;
251         int     sen;
252         int     (*sys_func)();
253         const char *sys_name;
254 } struct_sysent;
255
256 typedef struct ioctlent {
257         const char *symbol;
258         unsigned int code;
259 } struct_ioctlent;
260
261 /* Trace Control Block */
262 struct tcb {
263         int flags;              /* See below for TCB_ values */
264         int pid;                /* If 0, this tcb is free */
265         int qual_flg;           /* qual_flags[scno] or DEFAULT_QUAL_FLAGS + RAW */
266         int u_error;            /* Error code */
267         long scno;              /* System call number */
268         long u_arg[MAX_ARGS];   /* System call arguments */
269 #if defined(LINUX_MIPSN32) || defined(X32)
270         long long ext_arg[MAX_ARGS];
271         long long u_lrval;      /* long long return value */
272 #endif
273         long u_rval;            /* Return value */
274 #if SUPPORTED_PERSONALITIES > 1
275         unsigned int currpers;  /* Personality at the time of scno update */
276 #endif
277         int sys_func_rval;      /* Syscall entry parser's return value */
278         int curcol;             /* Output column for this process */
279         FILE *outf;             /* Output file for this process */
280         const char *auxstr;     /* Auxiliary info from syscall (see RVAL_STR) */
281         const struct_sysent *s_ent; /* sysent[scno] or dummy struct for bad scno */
282         const struct_sysent *s_prev_ent; /* for "resuming interrupted SYSCALL" msg */
283         struct timeval stime;   /* System time usage as of last process wait */
284         struct timeval dtime;   /* Delta for system time usage */
285         struct timeval etime;   /* Syscall entry time */
286
287 #ifdef USE_LIBUNWIND
288         struct UPT_info* libunwind_ui;
289         struct mmap_cache_t* mmap_cache;
290         unsigned int mmap_cache_size;
291         unsigned int mmap_cache_generation;
292         struct queue_t* queue;
293 #endif
294 };
295
296 /* TCB flags */
297 /* We have attached to this process, but did not see it stopping yet */
298 #define TCB_STARTUP             0x01
299 #define TCB_IGNORE_ONE_SIGSTOP  0x02    /* Next SIGSTOP is to be ignored */
300 /*
301  * Are we in system call entry or in syscall exit?
302  *
303  * This bit is set after all syscall entry processing is done.
304  * Therefore, this bit will be set when next ptrace stop occurs,
305  * which should be syscall exit stop. Other stops which are possible
306  * directly after syscall entry (death, ptrace event stop)
307  * are simpler and handled without calling trace_syscall(), therefore
308  * the places where TCB_INSYSCALL can be set but we aren't in syscall stop
309  * are limited to trace(), this condition is never observed in trace_syscall()
310  * and below.
311  * The bit is cleared after all syscall exit processing is done.
312  *
313  * Use entering(tcp) / exiting(tcp) to check this bit to make code more readable.
314  */
315 #define TCB_INSYSCALL   0x04
316 #define TCB_ATTACHED    0x08    /* We attached to it already */
317 #define TCB_REPRINT     0x10    /* We should reprint this syscall on exit */
318 #define TCB_FILTERED    0x20    /* This system call has been filtered out */
319
320 /* qualifier flags */
321 #define QUAL_TRACE      0x001   /* this system call should be traced */
322 #define QUAL_ABBREV     0x002   /* abbreviate the structures of this syscall */
323 #define QUAL_VERBOSE    0x004   /* decode the structures of this syscall */
324 #define QUAL_RAW        0x008   /* print all args in hex for this syscall */
325 #define QUAL_SIGNAL     0x010   /* report events with this signal */
326 #define QUAL_READ       0x020   /* dump data read on this file descriptor */
327 #define QUAL_WRITE      0x040   /* dump data written to this file descriptor */
328 typedef uint8_t qualbits_t;
329 #define UNDEFINED_SCNO  0x100   /* Used only in tcp->qual_flg */
330
331 #define DEFAULT_QUAL_FLAGS (QUAL_TRACE | QUAL_ABBREV | QUAL_VERBOSE)
332
333 #define entering(tcp)   (!((tcp)->flags & TCB_INSYSCALL))
334 #define exiting(tcp)    ((tcp)->flags & TCB_INSYSCALL)
335 #define syserror(tcp)   ((tcp)->u_error != 0)
336 #define verbose(tcp)    ((tcp)->qual_flg & QUAL_VERBOSE)
337 #define abbrev(tcp)     ((tcp)->qual_flg & QUAL_ABBREV)
338 #define filtered(tcp)   ((tcp)->flags & TCB_FILTERED)
339
340 struct xlat {
341         unsigned int val;
342         const char *str;
343 };
344 #define XLAT(x) { x, #x }
345 #define XLAT_END { 0, NULL }
346
347 extern const struct xlat addrfams[];
348 extern const struct xlat at_flags[];
349 extern const struct xlat open_access_modes[];
350 extern const struct xlat open_mode_flags[];
351 extern const struct xlat whence_codes[];
352
353 /* Format of syscall return values */
354 #define RVAL_DECIMAL    000     /* decimal format */
355 #define RVAL_HEX        001     /* hex format */
356 #define RVAL_OCTAL      002     /* octal format */
357 #define RVAL_UDECIMAL   003     /* unsigned decimal format */
358 #if defined(LINUX_MIPSN32) || defined(X32)
359 # if 0 /* unused so far */
360 #  define RVAL_LDECIMAL 004     /* long decimal format */
361 #  define RVAL_LHEX     005     /* long hex format */
362 #  define RVAL_LOCTAL   006     /* long octal format */
363 # endif
364 # define RVAL_LUDECIMAL 007     /* long unsigned decimal format */
365 #endif
366 #define RVAL_FD         010     /* file descriptor */
367 #define RVAL_MASK       017     /* mask for these values */
368
369 #define RVAL_STR        020     /* Print `auxstr' field after return val */
370 #define RVAL_NONE       040     /* Print nothing */
371
372 #define RVAL_DECODED    0100    /* syscall decoding finished */
373
374 #define TRACE_FILE      001     /* Trace file-related syscalls. */
375 #define TRACE_IPC       002     /* Trace IPC-related syscalls. */
376 #define TRACE_NETWORK   004     /* Trace network-related syscalls. */
377 #define TRACE_PROCESS   010     /* Trace process-related syscalls. */
378 #define TRACE_SIGNAL    020     /* Trace signal-related syscalls. */
379 #define TRACE_DESC      040     /* Trace file descriptor-related syscalls. */
380 #define TRACE_MEMORY    0100    /* Trace memory mapping-related syscalls. */
381 #define SYSCALL_NEVER_FAILS     0200    /* Syscall is always successful. */
382 #define STACKTRACE_INVALIDATE_CACHE 0400  /* Trigger proc/maps cache updating */
383 #define STACKTRACE_CAPTURE_ON_ENTER 01000 /* Capture stacktrace on "entering" stage */
384 #define TRACE_INDIRECT_SUBCALL  02000   /* Syscall is an indirect socket/ipc subcall. */
385
386 #if defined(ARM) || defined(AARCH64) \
387  || defined(I386) || defined(X32) || defined(X86_64) \
388  || defined(IA64) \
389  || defined(BFIN) \
390  || defined(M68K) \
391  || defined(MICROBLAZE) \
392  || defined(S390) \
393  || defined(SH) || defined(SH64) \
394  || defined(SPARC) || defined(SPARC64) \
395  /**/
396 # define NEED_UID16_PARSERS 1
397 #else
398 # define NEED_UID16_PARSERS 0
399 #endif
400
401 typedef enum {
402         CFLAG_NONE = 0,
403         CFLAG_ONLY_STATS,
404         CFLAG_BOTH
405 } cflag_t;
406 extern cflag_t cflag;
407 extern bool debug_flag;
408 extern bool Tflag;
409 extern bool iflag;
410 extern bool count_wallclock;
411 extern unsigned int qflag;
412 extern bool not_failing_only;
413 extern unsigned int show_fd_path;
414 extern bool hide_log_until_execve;
415 /* are we filtering traces based on paths? */
416 extern const char **paths_selected;
417 #define tracing_paths (paths_selected != NULL)
418 extern unsigned xflag;
419 extern unsigned followfork;
420 #ifdef USE_LIBUNWIND
421 /* if this is true do the stack trace for every system call */
422 extern bool stack_trace_enabled;
423 #endif
424 extern unsigned ptrace_setoptions;
425 extern unsigned max_strlen;
426 extern unsigned os_release;
427 #undef KERNEL_VERSION
428 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
429
430 enum bitness_t { BITNESS_CURRENT = 0, BITNESS_32 };
431
432 void error_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
433 void perror_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
434 void error_msg_and_die(const char *fmt, ...)
435         ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
436 void perror_msg_and_die(const char *fmt, ...)
437         ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
438 void die_out_of_memory(void) ATTRIBUTE_NORETURN;
439
440 void *xmalloc(size_t size) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1));
441 void *xcalloc(size_t nmemb, size_t size)
442         ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1, 2));
443 void *xreallocarray(void *ptr, size_t nmemb, size_t size)
444         ATTRIBUTE_ALLOC_SIZE((2, 3));
445 char *xstrdup(const char *str) ATTRIBUTE_MALLOC;
446
447 #if USE_CUSTOM_PRINTF
448 /*
449  * See comment in vsprintf.c for allowed formats.
450  * Short version: %h[h]u, %zu, %tu are not allowed, use %[l[l]]u.
451  */
452 int strace_vfprintf(FILE *fp, const char *fmt, va_list args);
453 #else
454 # define strace_vfprintf vfprintf
455 #endif
456
457 extern void set_sortby(const char *);
458 extern void set_overhead(int);
459 extern void qualify(const char *);
460 extern void print_pc(struct tcb *);
461 extern int trace_syscall(struct tcb *);
462 extern void count_syscall(struct tcb *, const struct timeval *);
463 extern void call_summary(FILE *);
464
465 extern void clear_regs(void);
466 extern void get_regs(pid_t pid);
467 extern int get_scno(struct tcb *tcp);
468
469 extern int umoven(struct tcb *, long, unsigned int, void *);
470 #define umove(pid, addr, objp)  \
471         umoven((pid), (addr), sizeof(*(objp)), (void *) (objp))
472 extern int umoven_or_printaddr(struct tcb *, long, unsigned int, void *);
473 #define umove_or_printaddr(pid, addr, objp)     \
474         umoven_or_printaddr((pid), (addr), sizeof(*(objp)), (void *) (objp))
475 extern int umovestr(struct tcb *, long, unsigned int, char *);
476 extern int upeek(int pid, long, long *);
477
478 #if defined ALPHA || defined IA64 || defined MIPS \
479  || defined SH || defined SPARC || defined SPARC64
480 # define HAVE_GETRVAL2
481 extern long getrval2(struct tcb *);
482 #else
483 # undef HAVE_GETRVAL2
484 #endif
485
486 extern const char *signame(const int);
487 extern void pathtrace_select(const char *);
488 extern int pathtrace_match(struct tcb *);
489 extern int getfdpath(struct tcb *, int, char *, unsigned);
490
491 extern const char *xlookup(const struct xlat *, const unsigned int);
492 extern const char *xlat_search(const struct xlat *, const size_t, const unsigned int);
493
494 extern unsigned long get_pagesize(void);
495 extern int string_to_uint(const char *str);
496 extern int next_set_bit(const void *bit_array, unsigned cur_bit, unsigned size_bits);
497
498 #define QUOTE_0_TERMINATED                      0x01
499 #define QUOTE_OMIT_LEADING_TRAILING_QUOTES      0x02
500
501 extern int print_quoted_string(const char *, unsigned int, unsigned int);
502
503 /* a refers to the lower numbered u_arg,
504  * b refers to the higher numbered u_arg
505  */
506 #ifdef HAVE_LITTLE_ENDIAN_LONG_LONG
507 # define LONG_LONG(a,b) \
508         ((long long)((unsigned long long)(unsigned)(a) | ((unsigned long long)(b)<<32)))
509 #else
510 # define LONG_LONG(a,b) \
511         ((long long)((unsigned long long)(unsigned)(b) | ((unsigned long long)(a)<<32)))
512 #endif
513 extern int getllval(struct tcb *, unsigned long long *, int);
514 extern int printllval(struct tcb *, const char *, int)
515         ATTRIBUTE_FORMAT((printf, 2, 0));
516
517 extern void printaddr(long);
518 extern void printxval(const struct xlat *, const unsigned int, const char *);
519 extern int printargs(struct tcb *);
520 extern int printargs_lu(struct tcb *);
521 extern int printargs_ld(struct tcb *);
522 extern void addflags(const struct xlat *, int);
523 extern int printflags(const struct xlat *, int, const char *);
524 extern const char *sprintflags(const char *, const struct xlat *, int);
525 extern const char *sprintmode(int);
526 extern const char *sprinttime(time_t);
527 extern void dumpiov_in_msghdr(struct tcb *, long);
528 extern void dumpiov_in_mmsghdr(struct tcb *, long);
529 extern void dumpiov(struct tcb *, int, long);
530 extern void dumpstr(struct tcb *, long, int);
531 extern void printstr(struct tcb *, long, long);
532 extern void printnum_short(struct tcb *, long, const char *)
533         ATTRIBUTE_FORMAT((printf, 3, 0));
534 extern void printnum_int(struct tcb *, long, const char *)
535         ATTRIBUTE_FORMAT((printf, 3, 0));
536 extern void printnum_long(struct tcb *, long, const char *)
537         ATTRIBUTE_FORMAT((printf, 3, 0));
538 #if SIZEOF_LONG == 8
539 # define printnum_int64 printnum_long
540 #else
541 extern void printnum_int64(struct tcb *, long, const char *)
542         ATTRIBUTE_FORMAT((printf, 3, 0));
543 #endif
544 extern void printpair_int(struct tcb *, long, const char *)
545         ATTRIBUTE_FORMAT((printf, 3, 0));
546 extern void printpair_long(struct tcb *, long, const char *)
547         ATTRIBUTE_FORMAT((printf, 3, 0));
548 #if SIZEOF_LONG == 8
549 # define printpair_int64 printpair_long
550 #else
551 extern void printpair_int64(struct tcb *, long, const char *)
552         ATTRIBUTE_FORMAT((printf, 3, 0));
553 #endif
554 extern void printpath(struct tcb *, long);
555 extern void printpathn(struct tcb *, long, unsigned int);
556 #define TIMESPEC_TEXT_BUFSIZE (sizeof(long)*3 * 2 + sizeof("{%u, %u}"))
557 #define TIMEVAL_TEXT_BUFSIZE  TIMESPEC_TEXT_BUFSIZE
558 extern void printtv_bitness(struct tcb *, long, enum bitness_t, int);
559 #define printtv(tcp, addr)      \
560         printtv_bitness((tcp), (addr), BITNESS_CURRENT, 0)
561 #define printtv_special(tcp, addr)      \
562         printtv_bitness((tcp), (addr), BITNESS_CURRENT, 1)
563 extern char *sprinttv(char *, struct tcb *, long, enum bitness_t, int special);
564 extern void print_timespec(struct tcb *, long);
565 extern void sprint_timespec(char *, struct tcb *, long);
566 extern void printsiginfo_at(struct tcb *tcp, long addr);
567 extern void printfd(struct tcb *, int);
568 extern bool print_sockaddr_by_inode(const unsigned long, const char *);
569 extern void print_dirfd(struct tcb *, int);
570 extern void printsock(struct tcb *, long, int);
571 extern void print_sock_optmgmt(struct tcb *, long, int);
572 extern void printrusage(struct tcb *, long);
573 #ifdef ALPHA
574 extern void printrusage32(struct tcb *, long);
575 #endif
576 extern void printuid(const char *, const unsigned int);
577 extern void print_sigset_addr_len(struct tcb *, long, long);
578 extern const char *sprintsigmask_n(const char *, const void *, unsigned int);
579 #define tprintsigmask_addr(prefix, mask) \
580         tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
581 extern void printsignal(int);
582 extern void tprint_iov(struct tcb *, unsigned long, unsigned long, int decode_iov);
583 extern void tprint_iov_upto(struct tcb *, unsigned long, unsigned long, int decode_iov, unsigned long);
584 extern void tprint_open_modes(int);
585 extern const char *sprint_open_modes(int);
586 extern void print_seccomp_filter(struct tcb *tcp, unsigned long);
587
588 extern int block_ioctl(struct tcb *, const unsigned int, long);
589 extern int evdev_ioctl(struct tcb *, const unsigned int, long);
590 extern int loop_ioctl(struct tcb *, const unsigned int, long);
591 extern int mtd_ioctl(struct tcb *, const unsigned int, long);
592 extern int ptp_ioctl(struct tcb *, const unsigned int, long);
593 extern int rtc_ioctl(struct tcb *, const unsigned int, long);
594 extern int scsi_ioctl(struct tcb *, const unsigned int, long);
595 extern int sock_ioctl(struct tcb *, const unsigned int, long);
596 extern int term_ioctl(struct tcb *, const unsigned int, long);
597 extern int ubi_ioctl(struct tcb *, const unsigned int, long);
598 extern int v4l2_ioctl(struct tcb *, const unsigned int, long);
599
600 extern int tv_nz(const struct timeval *);
601 extern int tv_cmp(const struct timeval *, const struct timeval *);
602 extern double tv_float(const struct timeval *);
603 extern void tv_add(struct timeval *, const struct timeval *, const struct timeval *);
604 extern void tv_sub(struct timeval *, const struct timeval *, const struct timeval *);
605 extern void tv_mul(struct timeval *, const struct timeval *, int);
606 extern void tv_div(struct timeval *, const struct timeval *, int);
607
608 #ifdef USE_LIBUNWIND
609 extern void unwind_init(void);
610 extern void unwind_tcb_init(struct tcb *tcp);
611 extern void unwind_tcb_fin(struct tcb *tcp);
612 extern void unwind_cache_invalidate(struct tcb* tcp);
613 extern void unwind_print_stacktrace(struct tcb* tcp);
614 extern void unwind_capture_stacktrace(struct tcb* tcp);
615 #endif
616
617 /* Strace log generation machinery.
618  *
619  * printing_tcp: tcb which has incomplete line being printed right now.
620  * NULL if last line has been completed ('\n'-terminated).
621  * printleader(tcp) examines it, finishes incomplete line if needed,
622  * the sets it to tcp.
623  * line_ended() clears printing_tcp and resets ->curcol = 0.
624  * tcp->curcol == 0 check is also used to detect completeness
625  * of last line, since in -ff mode just checking printing_tcp for NULL
626  * is not enough.
627  *
628  * If you change this code, test log generation in both -f and -ff modes
629  * using:
630  * strace -oLOG -f[f] test/threaded_execve
631  * strace -oLOG -f[f] test/sigkill_rain
632  * strace -oLOG -f[f] -p "`pidof web_browser`"
633  */
634 extern struct tcb *printing_tcp;
635 extern void printleader(struct tcb *);
636 extern void line_ended(void);
637 extern void tabto(void);
638 extern void tprintf(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
639 extern void tprints(const char *str);
640
641 #if SUPPORTED_PERSONALITIES > 1
642 extern void set_personality(int personality);
643 extern unsigned current_personality;
644 #else
645 # define set_personality(personality) ((void)0)
646 # define current_personality 0
647 #endif
648
649 #if SUPPORTED_PERSONALITIES == 1
650 # define current_wordsize PERSONALITY0_WORDSIZE
651 #else
652 # if SUPPORTED_PERSONALITIES == 2 && PERSONALITY0_WORDSIZE == PERSONALITY1_WORDSIZE
653 #  define current_wordsize PERSONALITY0_WORDSIZE
654 # else
655 extern unsigned current_wordsize;
656 # endif
657 #endif
658
659 /* In many, many places we play fast and loose and use
660  * tprintf("%d", (int) tcp->u_arg[N]) to print fds, pids etc.
661  * We probably need to use widen_to_long() instead:
662  */
663 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
664 # define widen_to_long(v) (current_wordsize == 4 ? (long)(int32_t)(v) : (long)(v))
665 #else
666 # define widen_to_long(v) ((long)(v))
667 #endif
668
669 extern const struct_sysent sysent0[];
670 extern const char *const errnoent0[];
671 extern const char *const signalent0[];
672 extern const struct_ioctlent ioctlent0[];
673 extern qualbits_t *qual_vec[SUPPORTED_PERSONALITIES];
674 #define qual_flags (qual_vec[current_personality])
675 #if SUPPORTED_PERSONALITIES > 1
676 extern const struct_sysent *sysent;
677 extern const char *const *errnoent;
678 extern const char *const *signalent;
679 extern const struct_ioctlent *ioctlent;
680 #else
681 # define sysent     sysent0
682 # define errnoent   errnoent0
683 # define signalent  signalent0
684 # define ioctlent   ioctlent0
685 #endif
686 extern unsigned nsyscalls;
687 extern unsigned nerrnos;
688 extern unsigned nsignals;
689 extern unsigned nioctlents;
690 extern unsigned num_quals;
691
692 /*
693  * If you need non-NULL sysent[scno].sys_func and sysent[scno].sys_name
694  */
695 #define SCNO_IS_VALID(scno) \
696         ((unsigned long)(scno) < nsyscalls && sysent[scno].sys_func)
697
698 /* Only ensures that sysent[scno] isn't out of range */
699 #define SCNO_IN_RANGE(scno) \
700         ((unsigned long)(scno) < nsyscalls)
701
702 #ifndef SYS_FUNC_NAME
703 # define SYS_FUNC_NAME(syscall_name) sys_ ## syscall_name
704 #endif
705
706 #define SYS_FUNC(syscall_name) int SYS_FUNC_NAME(syscall_name)(struct tcb *tcp)