blob: 0396b11cbb53cf06a5abd2bb93fcec135400b100 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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 * $Id$
30 */
31
Roland McGrath795edb12005-02-02 04:44:57 +000032#ifdef HAVE_CONFIG_H
33#include "config.h"
34#endif
35
Wichert Akkermanb859bea1999-04-18 22:50:50 +000036#ifdef linux
37#include <features.h>
38#endif
39
Roland McGrathe6d3a292003-01-14 09:46:18 +000040#ifdef _LARGEFILE64_SOURCE
41/* This is the macro everything checks before using foo64 names. */
42# ifndef _LFS64_LARGEFILE
43# define _LFS64_LARGEFILE 1
44# endif
45#endif
46
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047/* configuration section */
48#ifndef MAX_QUALS
Roland McGrath63d01462002-12-30 00:25:36 +000049#if defined(LINUX) && defined(MIPS)
50#define MAX_QUALS 5000 /* maximum number of syscalls, signals, etc. */
Wichert Akkermanfd89ced2000-04-13 17:06:09 +000051#else
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000052#define MAX_QUALS 2048 /* maximum number of syscalls, signals, etc. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +000054#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055#ifndef DEFAULT_STRLEN
56#define DEFAULT_STRLEN 32 /* default maximum # of bytes printed in
57 `printstr', change with `-s' switch */
58#endif
59#ifndef DEFAULT_ACOLUMN
60#define DEFAULT_ACOLUMN 40 /* default alignment column for results */
61#endif
62#ifndef MAX_ARGS
63#define MAX_ARGS 32 /* maximum number of args to a syscall */
64#endif
65#ifndef DEFAULT_SORTBY
66#define DEFAULT_SORTBY "time" /* default sorting method for call profiling */
67#endif
68
69#include <sys/types.h>
70#include <unistd.h>
71#include <stdlib.h>
72#include <stdio.h>
73#include <ctype.h>
74#include <string.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000075#include <time.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000076#include <sys/time.h>
77#include <errno.h>
78
79#ifdef STDC_HEADERS
80#include <stddef.h>
81#endif /* STDC_HEADERS */
82
John Hughes58265892001-10-18 15:13:53 +000083#ifdef HAVE_SIGINFO_T
84#include <signal.h>
85#endif
86
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000087#if defined(LINUX)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000088# if defined(SPARC) || defined(SPARC64)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000089# define LINUXSPARC
90# endif
91# if defined(ALPHA)
92# define LINUX_64BIT
93# endif
Michal Ludvig0e035502002-09-23 15:41:01 +000094# if defined(X86_64)
95# define LINUX_X86_64
96# endif
Roland McGrathee9d4352002-12-18 04:16:10 +000097#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000098
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000099#if defined(SVR4) || defined(FREEBSD)
100#define USE_PROCFS
101#else
102#undef USE_PROCFS
103#endif
104
105#ifdef FREEBSD
106#ifndef I386
107#error "FreeBSD support is only for i386 arch right now."
108#endif
109#include <machine/psl.h>
110#include <machine/reg.h>
111#include <sys/syscall.h>
112#endif
113
114#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000115#include <sys/procfs.h>
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000116#ifdef HAVE_MP_PROCFS
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000117#include <sys/uio.h>
118#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000119#ifdef FREEBSD
120#include <sys/pioctl.h>
121#endif /* FREEBSD */
122#else /* !USE_PROCFS */
Michal Ludvig0e035502002-09-23 15:41:01 +0000123#if (defined(LINUXSPARC) || defined (LINUX_X86_64)) && defined(__GLIBC__)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000124#include <sys/ptrace.h>
125#else
126/* Work around awkward prototype in ptrace.h. */
127#define ptrace xptrace
128#include <sys/ptrace.h>
129#undef ptrace
130#ifdef POWERPC
131#define __KERNEL__
132#include <asm/ptrace.h>
133#undef __KERNEL__
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000134#endif
135#ifdef __STDC__
136#ifdef LINUX
137extern long ptrace(int, int, char *, long);
138#else /* !LINUX */
139extern int ptrace(int, int, char *, int, ...);
140#endif /* !LINUX */
141#else /* !__STDC__ */
142extern int ptrace();
143#endif /* !__STDC__ */
144#endif /* !LINUXSPARC */
145#endif /* !SVR4 */
146
147#ifdef LINUX
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000148#if !defined(__GLIBC__)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000149#define PTRACE_PEEKUSER PTRACE_PEEKUSR
150#define PTRACE_POKEUSER PTRACE_POKEUSR
151#endif
152#ifdef ALPHA
Wichert Akkermanf90da011999-10-31 21:15:38 +0000153# define REG_R0 0
154# define REG_A0 16
155# define REG_A3 19
156# define REG_FP 30
157# define REG_PC 64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000158#endif /* ALPHA */
Wichert Akkermanf90da011999-10-31 21:15:38 +0000159#ifdef MIPS
160# define REG_V0 2
161# define REG_A0 4
162# define REG_A3 7
163# define REG_SP 29
164# define REG_EPC 64
165#endif /* MIPS */
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000166#ifdef HPPA
167# define PT_GR20 (20*4)
168# define PT_GR26 (26*4)
169# define PT_GR28 (28*4)
170# define PT_IAOQ0 (106*4)
171# define PT_IAOQ1 (107*4)
172#endif /* HPPA */
Roland McGrathf5a47772003-06-26 22:40:42 +0000173#ifdef SH64
174 /* SH64 Linux - this code assumes the following kernel API for system calls:
Roland McGrathe1e584b2003-06-02 19:18:58 +0000175 PC Offset 0
176 System Call Offset 16 (actually, (syscall no.) | (0x1n << 16),
177 where n = no. of parameters.
178 Other regs Offset 24+
179
180 On entry: R2-7 = parameters 1-6 (as many as necessary)
181 On return: R9 = result. */
182
183 /* Offset for peeks of registers */
184# define REG_OFFSET (24)
185# define REG_GENERAL(x) (8*(x)+REG_OFFSET)
186# define REG_PC (0*8)
187# define REG_SYSCALL (2*8)
Roland McGrathf5a47772003-06-26 22:40:42 +0000188#endif /* SH64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000189#endif /* LINUX */
190
191#define SUPPORTED_PERSONALITIES 1
192#define DEFAULT_PERSONALITY 0
193
194#ifdef LINUXSPARC
195#include <linux/a.out.h>
196#include <asm/psr.h>
Roland McGrath4b2dcca2006-01-12 10:18:53 +0000197#define PERSONALITY0_WORDSIZE 4
198#define PERSONALITY1_WORDSIZE 4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000199#undef SUPPORTED_PERSONALITIES
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000200#if defined(SPARC64)
201#define SUPPORTED_PERSONALITIES 3
Roland McGrath4b2dcca2006-01-12 10:18:53 +0000202#define PERSONALITY2_WORDSIZE 8
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000203#else
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000204#define SUPPORTED_PERSONALITIES 2
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000205#endif /* SPARC64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000206#endif /* LINUXSPARC */
207
Michal Ludvig0e035502002-09-23 15:41:01 +0000208#ifdef X86_64
209#undef SUPPORTED_PERSONALITIES
210#define SUPPORTED_PERSONALITIES 2
Roland McGrath4b2dcca2006-01-12 10:18:53 +0000211#define PERSONALITY0_WORDSIZE 8
212#define PERSONALITY1_WORDSIZE 4
Roland McGrathee9d4352002-12-18 04:16:10 +0000213#endif
214
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000215#ifdef SVR4
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000216#ifdef HAVE_MP_PROCFS
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000217extern int mp_ioctl (int f, int c, void *a, int s);
218#define IOCTL(f,c,a) mp_ioctl (f, c, a, sizeof *a)
219#define IOCTL_STATUS(t) \
220 pread (t->pfd_stat, &t->status, sizeof t->status, 0)
221#define IOCTL_WSTOP(t) \
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000222 (IOCTL (t->pfd, PCWSTOP, (char *)NULL) < 0 ? -1 : \
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000223 IOCTL_STATUS (t))
224#define PR_WHY pr_lwp.pr_why
225#define PR_WHAT pr_lwp.pr_what
226#define PR_REG pr_lwp.pr_context.uc_mcontext.gregs
227#define PR_FLAGS pr_lwp.pr_flags
John Hughes25299712001-03-06 10:10:06 +0000228#define PR_SYSCALL pr_lwp.pr_syscall
John Hughes58265892001-10-18 15:13:53 +0000229#define PR_INFO pr_lwp.pr_info
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000230#define PIOCSTIP PCSTOP
231#define PIOCSET PCSET
232#define PIOCRESET PCRESET
233#define PIOCSTRACE PCSTRACE
234#define PIOCSFAULT PCSFAULT
235#define PIOCWSTOP PCWSTOP
236#define PIOCSTOP PCSTOP
237#define PIOCSENTRY PCSENTRY
238#define PIOCSEXIT PCSEXIT
239#define PIOCRUN PCRUN
240#else
241#define IOCTL ioctl
242#define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status)
Roland McGrathee9d4352002-12-18 04:16:10 +0000243#define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWSTOP, &t->status)
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000244#define PR_WHY pr_why
245#define PR_WHAT pr_what
246#define PR_REG pr_reg
247#define PR_FLAGS pr_flags
John Hughes25299712001-03-06 10:10:06 +0000248#define PR_SYSCALL pr_syscall
John Hughes58265892001-10-18 15:13:53 +0000249#define PR_INFO pr_info
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000250#endif
251#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000252#ifdef FREEBSD
253#define IOCTL ioctl
254#define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status)
255#define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWAIT, &t->status)
256#define PIOCRUN PIOCCONT
257#define PIOCWSTOP PIOCWAIT
258#define PR_WHY why
259#define PR_WHAT val
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000260#define PR_FLAGS state
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000261/* from /usr/src/sys/miscfs/procfs/procfs_vnops.c,
262 status.state = 0 for running, 1 for stopped */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000263#define PR_ASLEEP 1
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000264#define PR_SYSENTRY S_SCE
265#define PR_SYSEXIT S_SCX
266#define PR_SIGNALLED S_SIG
267#define PR_FAULTED S_CORE
268#endif
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000269
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270/* Trace Control Block */
271struct tcb {
272 short flags; /* See below for TCB_ values */
273 int pid; /* Process Id of this entry */
274 long scno; /* System call number */
275 int u_nargs; /* System call arguments */
276 long u_arg[MAX_ARGS]; /* System call arguments */
277 int u_error; /* Error code */
278 long u_rval; /* (first) return value */
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000279#ifdef HAVE_LONG_LONG
280 long long u_lrval; /* long long return value */
281#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000282 FILE *outf; /* Output file for this process */
Wichert Akkerman43a74822000-06-27 17:33:32 +0000283 const char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000284 struct timeval stime; /* System time usage as of last process wait */
285 struct timeval dtime; /* Delta for system time usage */
286 struct timeval etime; /* Syscall entry time */
287 /* Support for tracing forked processes */
288 struct tcb *parent; /* Parent of this process */
289 int nchildren; /* # of traced children */
290 int waitpid; /* pid(s) this process is waiting for */
Roland McGrath09623452003-05-23 02:27:13 +0000291 int nzombies; /* # of formerly traced children now dead */
Roland McGrath923f7502003-01-09 06:53:27 +0000292#ifdef LINUX
293 int nclone_threads; /* # of nchildren with CLONE_THREAD */
294 int nclone_detached; /* # of nchildren with CLONE_DETACHED */
295 int nclone_waiting; /* clone threads in wait4 (TCB_SUSPENDED) */
296#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000297 /* (1st arg of wait4()) */
298 long baddr; /* `Breakpoint' address */
299 long inst[2]; /* Instructions on above */
300 int pfd; /* proc file descriptor */
301#ifdef SVR4
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000302#ifdef HAVE_MP_PROCFS
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000303 int pfd_stat;
304 int pfd_as;
305 pstatus_t status;
306#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000307 prstatus_t status; /* procfs status structure */
308#endif
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000309#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000310#ifdef FREEBSD
311 struct procfs_status status;
312 int pfd_reg;
313 int pfd_status;
314#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000315};
316
317/* TCB flags */
318#define TCB_STARTUP 00001 /* We have just begun ptracing this process */
319#define TCB_INUSE 00002 /* This table entry is in use */
320#define TCB_INSYSCALL 00004 /* A system call is in progress */
321#define TCB_ATTACHED 00010 /* Process is not our own child */
322#define TCB_EXITING 00020 /* As far as we know, this process is exiting */
323#define TCB_SUSPENDED 00040 /* Process has done a wait(4), that can
324 not be allowed to complete just now */
325#define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */
326#define TCB_SIGTRAPPED 00200 /* Process wanted to block SIGTRAP */
327#define TCB_FOLLOWFORK 00400 /* Process should have forks followed */
328#define TCB_REPRINT 01000 /* We should reprint this syscall on exit */
329#ifdef LINUX
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000330# if defined(ALPHA) || defined(SPARC) || defined(SPARC64) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH) || defined(SH64) || defined(S390) || defined(S390X) || defined(ARM)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000331# define TCB_WAITEXECVE 02000 /* ignore SIGTRAP after exceve */
332# endif
Roland McGrath923f7502003-01-09 06:53:27 +0000333# define TCB_CLONE_DETACHED 04000 /* CLONE_DETACHED set in creating syscall */
334# define TCB_CLONE_THREAD 010000 /* CLONE_THREAD set in creating syscall */
335# define TCB_GROUP_EXITING 020000 /* TCB_EXITING was exit_group, not _exit */
336# include <sys/syscall.h>
337# ifndef __NR_exit_group
338# /* Hack: Most headers around are too old to have __NR_exit_group. */
339# ifdef ALPHA
340# define __NR_exit_group 405
341# elif defined I386
342# define __NR_exit_group 252
Dmitry V. Levinaca9a742006-10-11 22:56:49 +0000343# elif defined X86_64
344# define __NR_exit_group 231
Roland McGrath923f7502003-01-09 06:53:27 +0000345# elif defined IA64
346# define __NR_exit_group 1236
347# elif defined POWERPC
348# define __NR_exit_group 234
349# elif defined S390 || defined S390X
350# define __NR_exit_group 248
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000351# elif defined SPARC || defined SPARC64
Roland McGrath923f7502003-01-09 06:53:27 +0000352# define __NR_exit_group 188
Roland McGrath165155a2005-07-19 07:42:17 +0000353# elif defined M68K
354# define __NR_exit_group 247
Roland McGrath923f7502003-01-09 06:53:27 +0000355# endif /* ALPHA et al */
356# endif /* !__NR_exit_group */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000357#endif /* LINUX */
358
359/* qualifier flags */
360#define QUAL_TRACE 0001 /* this system call should be traced */
361#define QUAL_ABBREV 0002 /* abbreviate the structures of this syscall */
362#define QUAL_VERBOSE 0004 /* decode the structures of this syscall */
363#define QUAL_RAW 0010 /* print all args in hex for this syscall */
364#define QUAL_SIGNAL 0020 /* report events with this signal */
365#define QUAL_FAULT 0040 /* report events with this fault */
366#define QUAL_READ 0100 /* dump data read on this file descriptor */
367#define QUAL_WRITE 0200 /* dump data written to this file descriptor */
368
369#define entering(tcp) (!((tcp)->flags & TCB_INSYSCALL))
370#define exiting(tcp) ((tcp)->flags & TCB_INSYSCALL)
371#define syserror(tcp) ((tcp)->u_error != 0)
372#define verbose(tcp) (qual_flags[(tcp)->scno] & QUAL_VERBOSE)
373#define abbrev(tcp) (qual_flags[(tcp)->scno] & QUAL_ABBREV)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000374
375struct xlat {
376 int val;
377 char *str;
378};
379
380/* Format of syscall return values */
381#define RVAL_DECIMAL 000 /* decimal format */
382#define RVAL_HEX 001 /* hex format */
383#define RVAL_OCTAL 002 /* octal format */
384#define RVAL_UDECIMAL 003 /* unsigned decimal format */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000385#define RVAL_LDECIMAL 004 /* long decimal format */
386#define RVAL_LHEX 005 /* long hex format */
387#define RVAL_LOCTAL 006 /* long octal format */
388#define RVAL_LUDECIMAL 007 /* long unsigned decimal format */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000389#define RVAL_MASK 007 /* mask for these values */
390
391#define RVAL_STR 010 /* Print `auxstr' field after return val */
392#define RVAL_NONE 020 /* Print nothing */
393
394#ifndef offsetof
395#define offsetof(type, member) (((char *) &(((type *) NULL)->member)) - \
396 ((char *) (type *) NULL))
397#endif /* !offsetof */
398
399/* get offset of member within a user struct */
400#define uoff(member) offsetof(struct user, member)
401
402#define TRACE_FILE 001 /* Trace file-related syscalls. */
403#define TRACE_IPC 002 /* Trace IPC-related syscalls. */
404#define TRACE_NETWORK 004 /* Trace network-related syscalls. */
405#define TRACE_PROCESS 010 /* Trace process-related syscalls. */
406#define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */
Roland McGrath2fe7b132005-07-05 03:25:35 +0000407#define TRACE_DESC 040 /* Trace file descriptor-related syscalls. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408
Roland McGrathee9d4352002-12-18 04:16:10 +0000409extern struct tcb **tcbtab;
Roland McGrath138c6a32006-01-12 09:50:49 +0000410extern int *qual_flags;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000411extern int debug, followfork, followvfork;
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000412extern int dtime, cflag, xflag, qflag;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000413extern int acolumn;
Roland McGrathee9d4352002-12-18 04:16:10 +0000414extern unsigned int nprocs, tcbtabsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000415extern int max_strlen;
416extern struct tcb *tcp_last;
417
418#ifdef __STDC__
419#define P(args) args
420#else
421#define P(args) ()
422#endif
423
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000424enum bitness_t { BITNESS_CURRENT = 0, BITNESS_32 };
425
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000426extern int set_personality P((int personality));
Roland McGrathd9f816f2004-09-04 03:39:20 +0000427extern char *xlookup P((const struct xlat *, int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428extern struct tcb *alloctcb P((int));
Roland McGrath923f7502003-01-09 06:53:27 +0000429extern struct tcb *pid2tcb P((int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000430extern void droptcb P((struct tcb *));
Roland McGrath7b54a7a2004-06-04 01:50:45 +0000431extern int expand_tcbtab P((void));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000432
433extern void set_sortby P((char *));
434extern void set_overhead P((int));
435extern void qualify P((char *));
436extern void newoutf P((struct tcb *));
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000437extern int get_scno P((struct tcb *));
Roland McGrath76989d72005-06-07 23:21:31 +0000438extern long known_scno P((struct tcb *));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000439extern int trace_syscall P((struct tcb *));
Roland McGrathb2dee132005-06-01 19:02:36 +0000440extern void printxval P((const struct xlat *, int, const char *));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000441extern int printargs P((struct tcb *));
Roland McGrathd9f816f2004-09-04 03:39:20 +0000442extern int addflags P((const struct xlat *, int));
Roland McGrathb2dee132005-06-01 19:02:36 +0000443extern int printflags P((const struct xlat *, int, const char *));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444extern int umoven P((struct tcb *, long, int, char *));
445extern int umovestr P((struct tcb *, long, int, char *));
446extern int upeek P((int, long, long *));
John Hughes1d08dcf2001-07-10 13:48:44 +0000447extern void dumpiov P((struct tcb *, int, long));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000448extern void dumpstr P((struct tcb *, long, int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449extern void printstr P((struct tcb *, long, int));
450extern void printnum P((struct tcb *, long, char *));
Roland McGrath9814a942005-07-04 23:28:10 +0000451extern void printnum_int P((struct tcb *, long, char *));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452extern void printpath P((struct tcb *, long));
453extern void printpathn P((struct tcb *, long, int));
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000454extern void printtv_bitness P((struct tcb *, long, enum bitness_t));
455extern void sprinttv P((struct tcb *, long, enum bitness_t, char *));
John Hughes58265892001-10-18 15:13:53 +0000456#ifdef HAVE_SIGINFO_T
457extern void printsiginfo P((siginfo_t *, int));
458#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000459extern void printsock P((struct tcb *, long, int));
John Hughes38ae88d2002-05-23 11:48:58 +0000460extern void print_sock_optmgmt P((struct tcb *, long, int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461extern void printrusage P((struct tcb *, long));
Roland McGrath6bc12202003-11-13 22:32:27 +0000462extern void printuid P((const char *, unsigned long));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463extern int clearbpt P((struct tcb *));
464extern int setbpt P((struct tcb *));
465extern int sigishandled P((struct tcb *, int));
466extern void printcall P((struct tcb *));
Roland McGrathee36ce12004-09-04 03:53:10 +0000467extern const char *signame P((int));
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000468extern void print_sigset P((struct tcb *, long, int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000469extern void printsignal P((int));
470extern void printleader P((struct tcb *));
471extern void printtrailer P((struct tcb *));
472extern void tabto P((int));
473extern void call_summary P((FILE *));
Roland McGrathaa524c82005-06-01 19:22:06 +0000474extern void tprint_iov P((struct tcb *, unsigned long, unsigned long));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000476#ifdef LINUX
477extern int internal_clone P((struct tcb *));
478#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000479extern int internal_fork P((struct tcb *));
480extern int internal_exec P((struct tcb *));
Roland McGrathc74c0b72004-09-01 19:39:46 +0000481extern int internal_wait P((struct tcb *, int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000482extern int internal_exit P((struct tcb *));
483
Roland McGrathee36ce12004-09-04 03:53:10 +0000484extern const struct ioctlent *ioctl_lookup P((long));
485extern const struct ioctlent *ioctl_next_match P((const struct ioctlent *));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000486extern int ioctl_decode P((struct tcb *, long, long));
487extern int term_ioctl P((struct tcb *, long, long));
488extern int sock_ioctl P((struct tcb *, long, long));
489extern int proc_ioctl P((struct tcb *, int, int));
490extern int stream_ioctl P((struct tcb *, int, int));
Roland McGrathd83c50b2004-10-06 22:27:43 +0000491#ifdef LINUX
492extern int rtc_ioctl P((struct tcb *, long, long));
493#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000494
495extern void tv_tv P((struct timeval *, int, int));
496extern int tv_nz P((struct timeval *));
497extern int tv_cmp P((struct timeval *, struct timeval *));
498extern double tv_float P((struct timeval *));
499extern void tv_add P((struct timeval *, struct timeval *, struct timeval *));
500extern void tv_sub P((struct timeval *, struct timeval *, struct timeval *));
501extern void tv_mul P((struct timeval *, struct timeval *, int));
502extern void tv_div P((struct timeval *, struct timeval *, int));
503
504#ifdef SUNOS4
505extern int fixvfork P((struct tcb *));
506#endif
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000507#if !(defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(IA64))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508extern long getrval2 P((struct tcb *));
509#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000510#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000511extern int proc_open P((struct tcb *tcp, int attaching));
512#endif
513
514#define umove(pid, addr, objp) \
515 umoven((pid), (addr), sizeof *(objp), (char *) (objp))
516
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000517#define printtv(tcp, addr) \
518 printtv_bitness((tcp), (addr), BITNESS_CURRENT)
519
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520#ifdef __STDC__
521#ifdef __GNUC__
522extern void tprintf(const char *fmt, ...)
523 __attribute__ ((format (printf, 1, 2)));
524#else
525extern void tprintf(const char *fmt, ...);
526#endif
527#else
528extern void tprintf();
529#endif
530
531#ifndef HAVE_STRERROR
532const char *strerror P((int));
533#endif
534#ifndef HAVE_STRSIGNAL
535const char *strsignal P((int));
536#endif
537
538extern int current_personality;
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000539extern const int personality_wordsize[];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000540
541struct sysent {
542 int nargs;
543 int sys_flags;
544 int (*sys_func)();
Roland McGrathee36ce12004-09-04 03:53:10 +0000545 const char *sys_name;
Roland McGrath76989d72005-06-07 23:21:31 +0000546 long native_scno; /* Match against SYS_* constants. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547};
548
Roland McGrathee36ce12004-09-04 03:53:10 +0000549extern const struct sysent *sysent;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550extern int nsyscalls;
551
Roland McGrathee36ce12004-09-04 03:53:10 +0000552extern const char *const *errnoent;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000553extern int nerrnos;
554
555struct ioctlent {
Roland McGrathee36ce12004-09-04 03:53:10 +0000556 const char *doth;
557 const char *symbol;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558 unsigned long code;
559};
560
Roland McGrathee36ce12004-09-04 03:53:10 +0000561extern const struct ioctlent *ioctlent;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562extern int nioctlents;
Roland McGrathee36ce12004-09-04 03:53:10 +0000563
564extern const char *const *signalent;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565extern int nsignals;
566
Roland McGrathee36ce12004-09-04 03:53:10 +0000567extern const struct ioctlent ioctlent0[];
568extern const int nioctlents0;
569extern const char *const signalent0[];
570extern const int nsignals0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571
572#if SUPPORTED_PERSONALITIES >= 2
Roland McGrathee36ce12004-09-04 03:53:10 +0000573extern const struct ioctlent ioctlent1[];
Michal Ludvig51d1ebc2004-09-07 14:06:03 +0000574extern const int nioctlents1;
Roland McGrathee36ce12004-09-04 03:53:10 +0000575extern const char *const signalent1[];
576extern const int nsignals1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000577#endif /* SUPPORTED_PERSONALITIES >= 2 */
578
579#if SUPPORTED_PERSONALITIES >= 3
Roland McGrathee36ce12004-09-04 03:53:10 +0000580extern const struct ioctlent ioctlent2[];
581extern const int nioctlents2;
582extern const char *const signalent2[];
Michal Ludvig51d1ebc2004-09-07 14:06:03 +0000583extern const int nsignals2;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000584#endif /* SUPPORTED_PERSONALITIES >= 3 */
John Hughesbdf48f52001-03-06 15:08:09 +0000585
Roland McGrathe6d3a292003-01-14 09:46:18 +0000586#if defined(FREEBSD) || (defined(LINUX) \
Roland McGrathc0f8bbd2003-08-21 09:58:00 +0000587 && defined(POWERPC) && !defined(__powerpc64__)) \
588 || (defined (LINUX) && defined (MIPS) && !defined(__mips64))
John Hughes5a826b82001-03-07 13:21:24 +0000589/* ARRGH! off_t args are aligned on 64 bit boundaries! */
590#define ALIGN64(tcp,arg) \
591do { \
592 if (arg % 2) \
593 memmove (&tcp->u_arg[arg], &tcp->u_arg[arg + 1], \
594 (tcp->u_nargs - arg - 1) * sizeof tcp->u_arg[0]); \
595} while (0)
596#else
597#define ALIGN64(tcp,arg) do { } while (0)
598#endif
599
John Hughes0c79e012001-03-08 14:40:06 +0000600#if HAVE_LONG_LONG
John Hughes5a826b82001-03-07 13:21:24 +0000601
John Hughesbdf48f52001-03-06 15:08:09 +0000602/* _l refers to the lower numbered u_arg,
603 * _h refers to the higher numbered u_arg
604 */
John Hughes5a826b82001-03-07 13:21:24 +0000605
John Hughesb8a85a42001-03-28 08:05:27 +0000606#if HAVE_LITTLE_ENDIAN_LONG_LONG
John Hughes0c79e012001-03-08 14:40:06 +0000607#define LONG_LONG(_l,_h) \
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000608 ((long long)((unsigned long long)(unsigned)(_l) | ((unsigned long long)(_h)<<32)))
John Hughesbdf48f52001-03-06 15:08:09 +0000609#else
John Hughes0c79e012001-03-08 14:40:06 +0000610#define LONG_LONG(_l,_h) \
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000611 ((long long)((unsigned long long)(unsigned)(_h) | ((unsigned long long)(_l)<<32)))
John Hughesbdf48f52001-03-06 15:08:09 +0000612#endif
613#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000614
615#ifdef IA64
616extern long ia32;
617#endif
Michal Ludvig17f8fb32002-11-06 13:17:21 +0000618
619extern int not_failing_only;