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