]> granicus.if.org Git - strace/blob - defs.h
Do not use off_t in sendfile decoding
[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 #ifdef _LARGEFILE64_SOURCE
34 /* This is the macro everything checks before using foo64 names.  */
35 # ifndef _LFS64_LARGEFILE
36 #  define _LFS64_LARGEFILE 1
37 # endif
38 #endif
39 #ifdef MIPS
40 # include <sgidefs.h>
41 #endif
42 #include <features.h>
43 #ifdef HAVE_STDBOOL_H
44 # include <stdbool.h>
45 #endif
46 #include <stdint.h>
47 #include <inttypes.h>
48 #include <sys/types.h>
49 #ifdef STDC_HEADERS
50 # include <stddef.h>
51 #endif
52 #include <unistd.h>
53 #include <stdlib.h>
54 #include <stdio.h>
55 /* Open-coding isprint(ch) et al proved more efficient than calling
56  * generalized libc interface. We don't *want* to do non-ASCII anyway.
57  */
58 /* #include <ctype.h> */
59 #include <string.h>
60 #include <errno.h>
61 #include <signal.h>
62 #include <time.h>
63 #include <sys/time.h>
64 #include <sys/syscall.h>
65
66 #ifndef HAVE_STRERROR
67 const char *strerror(int);
68 #endif
69 #ifndef HAVE_STPCPY
70 /* Some libc have stpcpy, some don't. Sigh...
71  * Roll our private implementation...
72  */
73 #undef stpcpy
74 #define stpcpy strace_stpcpy
75 extern char *stpcpy(char *dst, const char *src);
76 #endif
77
78 #if !defined __GNUC__
79 # define __attribute__(x) /*nothing*/
80 #endif
81
82 #ifndef offsetof
83 # define offsetof(type, member) \
84         (((char *) &(((type *) NULL)->member)) - ((char *) (type *) NULL))
85 #endif
86
87 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
88
89 /* Glibc has an efficient macro for sigemptyset
90  * (it just does one or two assignments of 0 to internal vector of longs).
91  */
92 #if defined(__GLIBC__) && defined(__sigemptyset) && !defined(sigemptyset)
93 # define sigemptyset __sigemptyset
94 #endif
95
96 /* Configuration section */
97 #ifndef DEFAULT_STRLEN
98 /* default maximum # of bytes printed in `printstr', change with -s switch */
99 # define DEFAULT_STRLEN 32
100 #endif
101 #ifndef DEFAULT_ACOLUMN
102 # define DEFAULT_ACOLUMN        40      /* default alignment column for results */
103 #endif
104 /*
105  * Maximum number of args to a syscall.
106  *
107  * Make sure that all entries in all syscallent.h files have nargs <= MAX_ARGS!
108  * linux/<ARCH>/syscallent.h: all have nargs <= 6.
109  */
110 #ifndef MAX_ARGS
111 # define MAX_ARGS       6
112 #endif
113 /* default sorting method for call profiling */
114 #ifndef DEFAULT_SORTBY
115 # define DEFAULT_SORTBY "time"
116 #endif
117 /*
118  * Experimental code using PTRACE_SEIZE can be enabled here.
119  * This needs Linux kernel 3.4.x or later to work.
120  */
121 #define USE_SEIZE 1
122 /* To force NOMMU build, set to 1 */
123 #define NOMMU_SYSTEM 0
124
125
126 #if defined(MIPS) && _MIPS_SIM == _MIPS_SIM_ABI32
127 # define LINUX_MIPSO32
128 #endif
129 #if defined(MIPS) && _MIPS_SIM == _MIPS_SIM_NABI32
130 # define LINUX_MIPSN32
131 #endif
132 #if defined(MIPS) && _MIPS_SIM == _MIPS_SIM_ABI64
133 # define LINUX_MIPSN64
134 #endif
135
136 #if (defined(SPARC) || defined(SPARC64) \
137     || defined(I386) || defined(X32) || defined(X86_64) \
138     || defined(ARM) || defined(AARCH64) \
139     || defined(AVR32) \
140     || defined(OR1K) \
141     || defined(METAG) \
142     || defined(TILE) \
143     ) && defined(__GLIBC__)
144 # include <sys/ptrace.h>
145 #else
146 /* Work around awkward prototype in ptrace.h. */
147 # define ptrace xptrace
148 # include <sys/ptrace.h>
149 # undef ptrace
150 # ifdef POWERPC
151 #  define __KERNEL__
152 #  include <asm/ptrace.h>
153 #  undef __KERNEL__
154 # endif
155 extern long ptrace(int, int, char *, long);
156 #endif
157
158 #if defined(TILE)
159 # include <asm/ptrace.h>  /* struct pt_regs */
160 #endif
161
162 #if !HAVE_DECL_PTRACE_SETOPTIONS
163 # define PTRACE_SETOPTIONS      0x4200
164 #endif
165 #if !HAVE_DECL_PTRACE_GETEVENTMSG
166 # define PTRACE_GETEVENTMSG     0x4201
167 #endif
168 #if !HAVE_DECL_PTRACE_GETSIGINFO
169 # define PTRACE_GETSIGINFO      0x4202
170 #endif
171
172 #if !HAVE_DECL_PTRACE_O_TRACESYSGOOD
173 # define PTRACE_O_TRACESYSGOOD  0x00000001
174 #endif
175 #if !HAVE_DECL_PTRACE_O_TRACEFORK
176 # define PTRACE_O_TRACEFORK     0x00000002
177 #endif
178 #if !HAVE_DECL_PTRACE_O_TRACEVFORK
179 # define PTRACE_O_TRACEVFORK    0x00000004
180 #endif
181 #if !HAVE_DECL_PTRACE_O_TRACECLONE
182 # define PTRACE_O_TRACECLONE    0x00000008
183 #endif
184 #if !HAVE_DECL_PTRACE_O_TRACEEXEC
185 # define PTRACE_O_TRACEEXEC     0x00000010
186 #endif
187 #if !HAVE_DECL_PTRACE_O_TRACEEXIT
188 # define PTRACE_O_TRACEEXIT     0x00000040
189 #endif
190
191 #if !HAVE_DECL_PTRACE_EVENT_FORK
192 # define PTRACE_EVENT_FORK      1
193 #endif
194 #if !HAVE_DECL_PTRACE_EVENT_VFORK
195 # define PTRACE_EVENT_VFORK     2
196 #endif
197 #if !HAVE_DECL_PTRACE_EVENT_CLONE
198 # define PTRACE_EVENT_CLONE     3
199 #endif
200 #if !HAVE_DECL_PTRACE_EVENT_EXEC
201 # define PTRACE_EVENT_EXEC      4
202 #endif
203 #if !HAVE_DECL_PTRACE_EVENT_VFORK_DONE
204 # define PTRACE_EVENT_VFORK_DONE        5
205 #endif
206 #if !HAVE_DECL_PTRACE_EVENT_EXIT
207 # define PTRACE_EVENT_EXIT      6
208 #endif
209
210 #if !defined(__GLIBC__)
211 # define PTRACE_PEEKUSER PTRACE_PEEKUSR
212 # define PTRACE_POKEUSER PTRACE_POKEUSR
213 #endif
214
215 #if USE_SEIZE
216 # undef PTRACE_SEIZE
217 # define PTRACE_SEIZE           0x4206
218 # undef PTRACE_INTERRUPT
219 # define PTRACE_INTERRUPT       0x4207
220 # undef PTRACE_LISTEN
221 # define PTRACE_LISTEN          0x4208
222 # undef PTRACE_EVENT_STOP
223 # define PTRACE_EVENT_STOP      128
224 #endif
225
226 #ifdef ALPHA
227 # define REG_R0 0
228 # define REG_A0 16
229 # define REG_A3 19
230 # define REG_FP 30
231 # define REG_PC 64
232 #endif /* ALPHA */
233 #ifdef MIPS
234 # define REG_V0 2
235 # define REG_A0 4
236 # define REG_A3 7
237 # define REG_SP 29
238 # define REG_EPC 64
239 #endif /* MIPS */
240 #ifdef HPPA
241 # define PT_GR20 (20*4)
242 # define PT_GR26 (26*4)
243 # define PT_GR28 (28*4)
244 # define PT_IAOQ0 (106*4)
245 # define PT_IAOQ1 (107*4)
246 #endif /* HPPA */
247 #ifdef SH64
248    /* SH64 Linux - this code assumes the following kernel API for system calls:
249           PC           Offset 0
250           System Call  Offset 16 (actually, (syscall no.) | (0x1n << 16),
251                        where n = no. of parameters.
252           Other regs   Offset 24+
253
254           On entry:    R2-7 = parameters 1-6 (as many as necessary)
255           On return:   R9   = result. */
256
257    /* Offset for peeks of registers */
258 # define REG_OFFSET         (24)
259 # define REG_GENERAL(x)     (8*(x)+REG_OFFSET)
260 # define REG_PC             (0*8)
261 # define REG_SYSCALL        (2*8)
262 #endif /* SH64 */
263 #ifdef AARCH64
264 struct arm_pt_regs {
265         int uregs[18];
266 };
267 # define ARM_cpsr       uregs[16]
268 # define ARM_pc         uregs[15]
269 # define ARM_lr         uregs[14]
270 # define ARM_sp         uregs[13]
271 # define ARM_ip         uregs[12]
272 # define ARM_fp         uregs[11]
273 # define ARM_r10        uregs[10]
274 # define ARM_r9         uregs[9]
275 # define ARM_r8         uregs[8]
276 # define ARM_r7         uregs[7]
277 # define ARM_r6         uregs[6]
278 # define ARM_r5         uregs[5]
279 # define ARM_r4         uregs[4]
280 # define ARM_r3         uregs[3]
281 # define ARM_r2         uregs[2]
282 # define ARM_r1         uregs[1]
283 # define ARM_r0         uregs[0]
284 # define ARM_ORIG_r0    uregs[17]
285 #endif /* AARCH64 */
286
287 #if defined(SPARC) || defined(SPARC64)
288 /* Indexes into the pt_regs.u_reg[] array -- UREG_XX from kernel are all off
289  * by 1 and use Ix instead of Ox.  These work for both 32 and 64 bit Linux. */
290 # define U_REG_G1 0
291 # define U_REG_O0 7
292 # define U_REG_O1 8
293 # define PERSONALITY0_WORDSIZE 4
294 # define PERSONALITY1_WORDSIZE 4
295 # if defined(SPARC64)
296 #  include <asm/psrcompat.h>
297 #  define SUPPORTED_PERSONALITIES 3
298 #  define PERSONALITY2_WORDSIZE 8
299 # else
300 #  include <asm/psr.h>
301 #  define SUPPORTED_PERSONALITIES 2
302 # endif /* SPARC64 */
303 #endif /* SPARC[64] */
304
305 #ifdef X86_64
306 # define SUPPORTED_PERSONALITIES 3
307 # define PERSONALITY0_WORDSIZE 8
308 # define PERSONALITY1_WORDSIZE 4
309 # define PERSONALITY2_WORDSIZE 4
310 #endif
311
312 #ifdef X32
313 # define SUPPORTED_PERSONALITIES 2
314 # define PERSONALITY0_WORDSIZE 4
315 # define PERSONALITY1_WORDSIZE 4
316 #endif
317
318 #ifdef ARM
319 /* one personality */
320 #endif
321
322 #ifdef AARCH64
323 /* The existing ARM personality, then AArch64 */
324 # define SUPPORTED_PERSONALITIES 2
325 # define PERSONALITY0_WORDSIZE 4
326 # define PERSONALITY1_WORDSIZE 8
327 # define DEFAULT_PERSONALITY 1
328 #endif
329
330 #ifdef POWERPC64
331 # define SUPPORTED_PERSONALITIES 2
332 # define PERSONALITY0_WORDSIZE 8
333 # define PERSONALITY1_WORDSIZE 4
334 #endif
335
336 #ifdef TILE
337 # define SUPPORTED_PERSONALITIES 2
338 # define PERSONALITY0_WORDSIZE 8
339 # define PERSONALITY1_WORDSIZE 4
340 # ifdef __tilepro__
341 #  define DEFAULT_PERSONALITY 1
342 # endif
343 #endif
344
345 #ifndef SUPPORTED_PERSONALITIES
346 # define SUPPORTED_PERSONALITIES 1
347 #endif
348 #ifndef DEFAULT_PERSONALITY
349 # define DEFAULT_PERSONALITY 0
350 #endif
351 #ifndef PERSONALITY0_WORDSIZE
352 # define PERSONALITY0_WORDSIZE (int)(sizeof(long))
353 #endif
354
355 #if defined(I386)
356 extern struct user_regs_struct i386_regs;
357 #elif defined(IA64)
358 extern long ia32;
359 #elif defined(SPARC) || defined(SPARC64)
360 extern struct pt_regs sparc_regs;
361 #elif defined(ARM)
362 extern struct pt_regs arm_regs;
363 #elif defined(TILE)
364 extern struct pt_regs tile_regs;
365 #endif
366
367 typedef struct sysent {
368         unsigned nargs;
369         int     sys_flags;
370         int     (*sys_func)();
371         const char *sys_name;
372 } struct_sysent;
373
374 typedef struct ioctlent {
375         const char *doth;
376         const char *symbol;
377         unsigned long code;
378 } struct_ioctlent;
379
380 /* Trace Control Block */
381 struct tcb {
382         int flags;              /* See below for TCB_ values */
383         int pid;                /* Process Id of this entry */
384         int qual_flg;           /* qual_flags[scno] or DEFAULT_QUAL_FLAGS + RAW */
385         int u_error;            /* Error code */
386         long scno;              /* System call number */
387         long u_arg[MAX_ARGS];   /* System call arguments */
388 #if defined(LINUX_MIPSN32) || defined(X32)
389         long long ext_arg[MAX_ARGS];
390         long long u_lrval;      /* long long return value */
391 #endif
392         long u_rval;            /* Return value */
393 #if SUPPORTED_PERSONALITIES > 1
394         int currpers;           /* Personality at the time of scno update */
395 #endif
396         int curcol;             /* Output column for this process */
397         FILE *outf;             /* Output file for this process */
398         const char *auxstr;     /* Auxiliary info from syscall (see RVAL_STR) */
399         const struct_sysent *s_ent; /* sysent[scno] or dummy struct for bad scno */
400         struct timeval stime;   /* System time usage as of last process wait */
401         struct timeval dtime;   /* Delta for system time usage */
402         struct timeval etime;   /* Syscall entry time */
403                                 /* Support for tracing forked processes: */
404         long inst[2];           /* Saved clone args (badly named) */
405 };
406
407 /* TCB flags */
408 #define TCB_INUSE               00001   /* This table entry is in use */
409 /* We have attached to this process, but did not see it stopping yet */
410 #define TCB_STARTUP             00002
411 #define TCB_IGNORE_ONE_SIGSTOP  00004   /* Next SIGSTOP is to be ignored */
412 /*
413  * Are we in system call entry or in syscall exit?
414  *
415  * This bit is set after all syscall entry processing is done.
416  * Therefore, this bit will be set when next ptrace stop occurs,
417  * which should be syscall exit stop. Other stops which are possible
418  * directly after syscall entry (death, ptrace event stop)
419  * are simpler and handled without calling trace_syscall(), therefore
420  * the places where TCB_INSYSCALL can be set but we aren't in syscall stop
421  * are limited to trace(), this condition is never observed in trace_syscall()
422  * and below.
423  * The bit is cleared after all syscall exit processing is done.
424  * User-generated SIGTRAPs and post-execve SIGTRAP make it necessary
425  * to be very careful and NOT set TCB_INSYSCALL bit when they are encountered.
426  * TCB_WAITEXECVE bit is used for this purpose (see below).
427  *
428  * Use entering(tcp) / exiting(tcp) to check this bit to make code more readable.
429  */
430 #define TCB_INSYSCALL   00010
431 #define TCB_ATTACHED    00020   /* It is attached already */
432 /* Are we PROG from "strace PROG [ARGS]" invocation? */
433 #define TCB_STRACE_CHILD 0040
434 #define TCB_BPTSET      00100   /* "Breakpoint" set after fork(2) */
435 #define TCB_REPRINT     00200   /* We should reprint this syscall on exit */
436 #define TCB_FILTERED    00400   /* This system call has been filtered out */
437 /* x86 does not need TCB_WAITEXECVE.
438  * It can detect post-execve SIGTRAP by looking at eax/rax.
439  * See "not a syscall entry (eax = %ld)\n" message.
440  *
441  * Note! On new kernels (about 2.5.46+), we use PTRACE_O_TRACEEXEC, which
442  * suppresses post-execve SIGTRAP. If you are adding a new arch which is
443  * only supported by newer kernels, you most likely don't need to define
444  * TCB_WAITEXECVE!
445  */
446 #if defined(ALPHA) \
447  || defined(SPARC) || defined(SPARC64) \
448  || defined(POWERPC) \
449  || defined(IA64) \
450  || defined(HPPA) \
451  || defined(SH) || defined(SH64) \
452  || defined(S390) || defined(S390X) \
453  || defined(ARM) \
454  || defined(MIPS)
455 /* This tracee has entered into execve syscall. Expect post-execve SIGTRAP
456  * to happen. (When it is detected, tracee is continued and this bit is cleared.)
457  */
458 # define TCB_WAITEXECVE 01000
459 #endif
460
461 /* qualifier flags */
462 #define QUAL_TRACE      0x001   /* this system call should be traced */
463 #define QUAL_ABBREV     0x002   /* abbreviate the structures of this syscall */
464 #define QUAL_VERBOSE    0x004   /* decode the structures of this syscall */
465 #define QUAL_RAW        0x008   /* print all args in hex for this syscall */
466 #define QUAL_SIGNAL     0x010   /* report events with this signal */
467 #define QUAL_READ       0x020   /* dump data read on this file descriptor */
468 #define QUAL_WRITE      0x040   /* dump data written to this file descriptor */
469 typedef uint8_t qualbits_t;
470 #define UNDEFINED_SCNO  0x100   /* Used only in tcp->qual_flg */
471
472 #define DEFAULT_QUAL_FLAGS (QUAL_TRACE | QUAL_ABBREV | QUAL_VERBOSE)
473
474 #define entering(tcp)   (!((tcp)->flags & TCB_INSYSCALL))
475 #define exiting(tcp)    ((tcp)->flags & TCB_INSYSCALL)
476 #define syserror(tcp)   ((tcp)->u_error != 0)
477 #define verbose(tcp)    ((tcp)->qual_flg & QUAL_VERBOSE)
478 #define abbrev(tcp)     ((tcp)->qual_flg & QUAL_ABBREV)
479 #define filtered(tcp)   ((tcp)->flags & TCB_FILTERED)
480
481 struct xlat {
482         int val;
483         const char *str;
484 };
485
486 extern const struct xlat open_mode_flags[];
487 extern const struct xlat addrfams[];
488 extern const struct xlat struct_user_offsets[];
489 extern const struct xlat open_access_modes[];
490 extern const struct xlat whence_codes[];
491
492 /* Format of syscall return values */
493 #define RVAL_DECIMAL    000     /* decimal format */
494 #define RVAL_HEX        001     /* hex format */
495 #define RVAL_OCTAL      002     /* octal format */
496 #define RVAL_UDECIMAL   003     /* unsigned decimal format */
497 #if defined(LINUX_MIPSN32) || defined(X32)
498 # if 0 /* unused so far */
499 #  define RVAL_LDECIMAL 004     /* long decimal format */
500 #  define RVAL_LHEX     005     /* long hex format */
501 #  define RVAL_LOCTAL   006     /* long octal format */
502 # endif
503 # define RVAL_LUDECIMAL 007     /* long unsigned decimal format */
504 #endif
505 #define RVAL_MASK       007     /* mask for these values */
506
507 #define RVAL_STR        010     /* Print `auxstr' field after return val */
508 #define RVAL_NONE       020     /* Print nothing */
509
510 #define TRACE_FILE      001     /* Trace file-related syscalls. */
511 #define TRACE_IPC       002     /* Trace IPC-related syscalls. */
512 #define TRACE_NETWORK   004     /* Trace network-related syscalls. */
513 #define TRACE_PROCESS   010     /* Trace process-related syscalls. */
514 #define TRACE_SIGNAL    020     /* Trace signal-related syscalls. */
515 #define TRACE_DESC      040     /* Trace file descriptor-related syscalls. */
516 #define TRACE_MEMORY    0100    /* Trace memory mapping-related syscalls. */
517 #define SYSCALL_NEVER_FAILS     0200    /* Syscall is always successful. */
518
519 typedef enum {
520         CFLAG_NONE = 0,
521         CFLAG_ONLY_STATS,
522         CFLAG_BOTH
523 } cflag_t;
524 extern cflag_t cflag;
525 extern bool debug_flag;
526 extern bool Tflag;
527 extern bool qflag;
528 extern bool not_failing_only;
529 extern bool show_fd_path;
530 /* are we filtering traces based on paths? */
531 extern const char **paths_selected;
532 #define tracing_paths (paths_selected != NULL)
533 extern bool need_fork_exec_workarounds;
534 extern unsigned xflag;
535 extern unsigned followfork;
536 extern unsigned ptrace_setoptions;
537 extern unsigned max_strlen;
538 extern unsigned os_release;
539 #undef KERNEL_VERSION
540 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
541
542 enum bitness_t { BITNESS_CURRENT = 0, BITNESS_32 };
543
544 void error_msg(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
545 void perror_msg(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
546 void error_msg_and_die(const char *fmt, ...) __attribute__ ((noreturn, format(printf, 1, 2)));
547 void perror_msg_and_die(const char *fmt, ...) __attribute__ ((noreturn, format(printf, 1, 2)));
548 void die_out_of_memory(void) __attribute__ ((noreturn));
549
550 #ifdef USE_CUSTOM_PRINTF
551 /*
552  * Speed-optimized vfprintf implementation.
553  * See comment in vsprintf.c for allowed formats.
554  * Short version: %h[h]u, %zu, %tu are not allowed, use %[l[l]]u.
555  *
556  * It results in strace using about 5% less CPU in user space
557  * (compared to glibc version).
558  * But strace spends a lot of time in kernel space,
559  * so overall it does not appear to be a significant win.
560  * Thus disabled by default.
561  */
562 int strace_vfprintf(FILE *fp, const char *fmt, va_list args);
563 #else
564 # define strace_vfprintf vfprintf
565 #endif
566
567 extern void set_sortby(const char *);
568 extern void set_overhead(int);
569 extern void qualify(const char *);
570 extern int trace_syscall(struct tcb *);
571 extern void count_syscall(struct tcb *, struct timeval *);
572 extern void call_summary(FILE *);
573
574 #if defined(AVR32) \
575  || defined(I386) \
576  || defined(X86_64) || defined(X32) \
577  || defined(AARCH64) \
578  || defined(ARM) \
579  || defined(SPARC) || defined(SPARC64) \
580  || defined(TILE) \
581  || defined(OR1K) \
582  || defined(METAG)
583 extern long get_regs_error;
584 # define clear_regs()  (get_regs_error = -1)
585 extern void get_regs(pid_t pid);
586 #else
587 # define get_regs_error 0
588 # define clear_regs()  ((void)0)
589 # define get_regs(pid) ((void)0)
590 #endif
591 extern int umoven(struct tcb *, long, int, char *);
592 #define umove(pid, addr, objp)  \
593         umoven((pid), (addr), sizeof(*(objp)), (char *) (objp))
594 extern int umovestr(struct tcb *, long, int, char *);
595 extern int upeek(struct tcb *, long, long *);
596 #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH)
597 extern long getrval2(struct tcb *);
598 #endif
599 /*
600  * On Linux, "setbpt" is a misnomer: we don't set a breakpoint
601  * (IOW: no poking in user's text segment),
602  * instead we change fork/vfork/clone into clone(CLONE_PTRACE).
603  * On newer kernels, we use PTRACE_O_TRACECLONE/TRACE[V]FORK instead.
604  */
605 extern int setbpt(struct tcb *);
606 extern int clearbpt(struct tcb *);
607
608 extern const char *signame(int);
609 extern int is_restart_error(struct tcb *);
610 extern void pathtrace_select(const char *);
611 extern int pathtrace_match(struct tcb *);
612 extern int getfdpath(struct tcb *, int, char *, unsigned);
613
614 extern const char *xlookup(const struct xlat *, int);
615
616 extern int string_to_uint(const char *str);
617 extern int string_quote(const char *, char *, long, int);
618
619 /* a refers to the lower numbered u_arg,
620  * b refers to the higher numbered u_arg
621  */
622 #if HAVE_LITTLE_ENDIAN_LONG_LONG
623 # define LONG_LONG(a,b) \
624         ((long long)((unsigned long long)(unsigned)(a) | ((unsigned long long)(b)<<32)))
625 #else
626 # define LONG_LONG(a,b) \
627         ((long long)((unsigned long long)(unsigned)(b) | ((unsigned long long)(a)<<32)))
628 #endif
629 extern int printllval(struct tcb *, const char *, int);
630
631 extern void printxval(const struct xlat *, int, const char *);
632 extern int printargs(struct tcb *);
633 extern int printargs_lu(struct tcb *);
634 extern int printargs_ld(struct tcb *);
635 extern void addflags(const struct xlat *, int);
636 extern int printflags(const struct xlat *, int, const char *);
637 extern const char *sprintflags(const char *, const struct xlat *, int);
638 extern void dumpiov(struct tcb *, int, long);
639 extern void dumpstr(struct tcb *, long, int);
640 extern void printstr(struct tcb *, long, long);
641 extern void printnum(struct tcb *, long, const char *);
642 extern void printnum_int(struct tcb *, long, const char *);
643 extern void printpath(struct tcb *, long);
644 extern void printpathn(struct tcb *, long, int);
645 #define TIMESPEC_TEXT_BUFSIZE (sizeof(long)*3 * 2 + sizeof("{%u, %u}"))
646 #define TIMEVAL_TEXT_BUFSIZE  TIMESPEC_TEXT_BUFSIZE
647 extern void printtv_bitness(struct tcb *, long, enum bitness_t, int);
648 #define printtv(tcp, addr)      \
649         printtv_bitness((tcp), (addr), BITNESS_CURRENT, 0)
650 #define printtv_special(tcp, addr)      \
651         printtv_bitness((tcp), (addr), BITNESS_CURRENT, 1)
652 extern char *sprinttv(char *, struct tcb *, long, enum bitness_t, int special);
653 extern void print_timespec(struct tcb *, long);
654 extern void sprint_timespec(char *, struct tcb *, long);
655 #ifdef HAVE_SIGINFO_T
656 extern void printsiginfo(siginfo_t *, int);
657 extern void printsiginfo_at(struct tcb *tcp, long addr);
658 #endif
659 extern void printfd(struct tcb *, int);
660 extern void printsock(struct tcb *, long, int);
661 extern void print_sock_optmgmt(struct tcb *, long, int);
662 extern void printrusage(struct tcb *, long);
663 #ifdef ALPHA
664 extern void printrusage32(struct tcb *, long);
665 #endif
666 extern void printuid(const char *, unsigned long);
667 extern void printcall(struct tcb *);
668 extern void print_sigset(struct tcb *, long, int);
669 extern void printsignal(int);
670 extern void tprint_iov(struct tcb *, unsigned long, unsigned long, int decode_iov);
671 extern void tprint_iov_upto(struct tcb *, unsigned long, unsigned long, int decode_iov, unsigned long);
672 extern void tprint_open_modes(mode_t);
673 extern const char *sprint_open_modes(mode_t);
674 extern void print_loff_t(struct tcb *, long);
675
676 extern const struct_ioctlent *ioctl_lookup(long);
677 extern const struct_ioctlent *ioctl_next_match(const struct_ioctlent *);
678 extern int ioctl_decode(struct tcb *, long, long);
679 extern int term_ioctl(struct tcb *, long, long);
680 extern int sock_ioctl(struct tcb *, long, long);
681 extern int proc_ioctl(struct tcb *, int, int);
682 extern int rtc_ioctl(struct tcb *, long, long);
683 extern int scsi_ioctl(struct tcb *, long, long);
684 extern int block_ioctl(struct tcb *, long, long);
685 extern int mtd_ioctl(struct tcb *, long, long);
686 extern int loop_ioctl(struct tcb *, long, long);
687
688 extern int tv_nz(struct timeval *);
689 extern int tv_cmp(struct timeval *, struct timeval *);
690 extern double tv_float(struct timeval *);
691 extern void tv_add(struct timeval *, struct timeval *, struct timeval *);
692 extern void tv_sub(struct timeval *, struct timeval *, struct timeval *);
693 extern void tv_mul(struct timeval *, struct timeval *, int);
694 extern void tv_div(struct timeval *, struct timeval *, int);
695
696 /* Strace log generation machinery.
697  *
698  * printing_tcp: tcb which has incomplete line being printed right now.
699  * NULL if last line has been completed ('\n'-terminated).
700  * printleader(tcp) examines it, finishes incomplete line if needed,
701  * the sets it to tcp.
702  * line_ended() clears printing_tcp and resets ->curcol = 0.
703  * tcp->curcol == 0 check is also used to detect completeness
704  * of last line, since in -ff mode just checking printing_tcp for NULL
705  * is not enough.
706  *
707  * If you change this code, test log generation in both -f and -ff modes
708  * using:
709  * strace -oLOG -f[f] test/threaded_execve
710  * strace -oLOG -f[f] test/sigkill_rain
711  * strace -oLOG -f[f] -p "`pidof web_browser`"
712  */
713 extern struct tcb *printing_tcp;
714 extern void printleader(struct tcb *);
715 extern void line_ended(void);
716 extern void tabto(void);
717 extern void tprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
718 extern void tprints(const char *str);
719
720 #if SUPPORTED_PERSONALITIES > 1
721 extern void set_personality(int personality);
722 extern unsigned current_personality;
723 #else
724 # define set_personality(personality) ((void)0)
725 # define current_personality 0
726 #endif
727
728 #if SUPPORTED_PERSONALITIES == 1
729 # define current_wordsize PERSONALITY0_WORDSIZE
730 #else
731 # if SUPPORTED_PERSONALITIES == 2 && PERSONALITY0_WORDSIZE == PERSONALITY1_WORDSIZE
732 #  define current_wordsize PERSONALITY0_WORDSIZE
733 # else
734 extern unsigned current_wordsize;
735 # endif
736 #endif
737
738 /* In many, many places we play fast and loose and use
739  * tprintf("%d", (int) tcp->u_arg[N]) to print fds, pids etc.
740  * We probably need to use widen_to_long() instead:
741  */
742 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
743 # define widen_to_long(v) (current_wordsize == 4 ? (long)(int32_t)(v) : (long)(v))
744 #else
745 # define widen_to_long(v) ((long)(v))
746 #endif
747
748 extern const struct_sysent sysent0[];
749 extern const char *const errnoent0[];
750 extern const char *const signalent0[];
751 extern const struct_ioctlent ioctlent0[];
752 extern qualbits_t *qual_vec[SUPPORTED_PERSONALITIES];
753 #define qual_flags (qual_vec[current_personality])
754 #if SUPPORTED_PERSONALITIES > 1
755 extern const struct_sysent *sysent;
756 extern const char *const *errnoent;
757 extern const char *const *signalent;
758 extern const struct_ioctlent *ioctlent;
759 #else
760 # define sysent     sysent0
761 # define errnoent   errnoent0
762 # define signalent  signalent0
763 # define ioctlent   ioctlent0
764 #endif
765 extern unsigned nsyscalls;
766 extern unsigned nerrnos;
767 extern unsigned nsignals;
768 extern unsigned nioctlents;
769 extern unsigned num_quals;
770
771 /*
772  * If you need non-NULL sysent[scno].sys_func and sysent[scno].sys_name
773  */
774 #define SCNO_IS_VALID(scno) \
775         ((unsigned long)(scno) < nsyscalls && sysent[scno].sys_func)
776
777 /* Only ensures that sysent[scno] isn't out of range */
778 #define SCNO_IN_RANGE(scno) \
779         ((unsigned long)(scno) < nsyscalls)