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