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