defs.h revision 4b2dccaf943adf4ff2b6e15c1f51a59652f8da36
10ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/*
20ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
30ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
40ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
50ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * All rights reserved.
60ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *
70ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * Redistribution and use in source and binary forms, with or without
80ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * modification, are permitted provided that the following conditions
90ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * are met:
100ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * 1. Redistributions of source code must retain the above copyright
110ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *    notice, this list of conditions and the following disclaimer.
120ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * 2. Redistributions in binary form must reproduce the above copyright
130ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *    notice, this list of conditions and the following disclaimer in the
140ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *    documentation and/or other materials provided with the distribution.
150ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * 3. The name of the author may not be used to endorse or promote products
160ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *    derived from this software without specific prior written permission.
170ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *
180ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
190ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
200ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
210ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
220ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
230ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
240ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
250ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
260ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
270ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
280ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *
290ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *	$Id$
300ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong */
310ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
320ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifdef HAVE_CONFIG_H
330ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include "config.h"
340ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
350ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
360ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifdef linux
370ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <features.h>
380ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
390ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
400ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifdef _LARGEFILE64_SOURCE
410ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/* This is the macro everything checks before using foo64 names.  */
420ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong# ifndef _LFS64_LARGEFILE
431d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#  define _LFS64_LARGEFILE 1
441d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling# endif
450ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
461d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling
470ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/* configuration section */
480ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifndef MAX_QUALS
490ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#if defined(LINUX) && defined(MIPS)
500ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define MAX_QUALS	5000	/* maximum number of syscalls, signals, etc. */
510ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#else
520ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define MAX_QUALS	2048	/* maximum number of syscalls, signals, etc. */
530ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
540ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
550ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifndef DEFAULT_STRLEN
560ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define DEFAULT_STRLEN	32	/* default maximum # of bytes printed in
570ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong				  `printstr', change with `-s' switch */
580ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
590ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifndef DEFAULT_ACOLUMN
600ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define DEFAULT_ACOLUMN	40	/* default alignment column for results */
610ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
620ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifndef MAX_ARGS
630ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define MAX_ARGS	32	/* maximum number of args to a syscall */
640ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
650ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifndef DEFAULT_SORTBY
660ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define DEFAULT_SORTBY "time"	/* default sorting method for call profiling */
671d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#endif
680ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
691d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#include <sys/types.h>
701d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#include <unistd.h>
710ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <stdlib.h>
720ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <stdio.h>
730ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <ctype.h>
740ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <string.h>
751d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#include <time.h>
760ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <sys/time.h>
770ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <errno.h>
780ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
790ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifdef STDC_HEADERS
800ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <stddef.h>
811d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#endif /* STDC_HEADERS */
820ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
830ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifdef HAVE_SIGINFO_T
840ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <signal.h>
850ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
860ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
870ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#if defined(LINUX)
880ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#  if defined(SPARC) || defined(SPARC64)
890ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#     define LINUXSPARC
900ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#  endif
910ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#  if defined(ALPHA)
920ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#     define LINUX_64BIT
930ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#  endif
940ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#  if defined(X86_64)
950ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#     define LINUX_X86_64
960ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#  endif
9779397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez#endif
9879397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez
9979397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez#if defined(SVR4) || defined(FREEBSD)
1000ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define USE_PROCFS
1010ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#else
1020ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#undef USE_PROCFS
1030ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
1040ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
1050ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifdef FREEBSD
1060ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifndef I386
1070ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#error "FreeBSD support is only for i386 arch right now."
1080ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
1090ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <machine/psl.h>
1100ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <machine/reg.h>
1111d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#include <sys/syscall.h>
1121d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#endif
1130ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
1140ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifdef USE_PROCFS
1150ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <sys/procfs.h>
116399f7d09e0c45af54b77b4ab9508d6f23759b927Scott Ettinger#ifdef HAVE_MP_PROCFS
1170ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <sys/uio.h>
1180ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
1191d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#ifdef FREEBSD
1200ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <sys/pioctl.h>
1210ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif /* FREEBSD */
1221d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#else /* !USE_PROCFS */
1231d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#if (defined(LINUXSPARC) || defined (LINUX_X86_64)) && defined(__GLIBC__)
1240ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <sys/ptrace.h>
1250ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#else
1260ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/* Work around awkward prototype in ptrace.h. */
1270ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define ptrace xptrace
1280ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <sys/ptrace.h>
1290ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#undef ptrace
1300ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifdef POWERPC
1310ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define __KERNEL__
1320ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <asm/ptrace.h>
1330ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#undef __KERNEL__
1340ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif
1350ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifdef __STDC__
1360ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifdef LINUX
1370ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kongextern long ptrace(int, int, char *, long);
1380ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#else /* !LINUX */
1390ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kongextern 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
148#if !defined(__GLIBC__)
149#define	PTRACE_PEEKUSER	PTRACE_PEEKUSR
150#define	PTRACE_POKEUSER	PTRACE_POKEUSR
151#endif
152#ifdef ALPHA
153#  define REG_R0 0
154#  define REG_A0 16
155#  define REG_A3 19
156#  define REG_FP 30
157#  define REG_PC 64
158#endif /* ALPHA */
159#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 */
166#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 */
173#ifdef SH64
174   /* SH64 Linux - this code assumes the following kernel API for system calls:
175          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)
188#endif /* SH64 */
189#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>
197#define PERSONALITY0_WORDSIZE 4
198#define PERSONALITY1_WORDSIZE 4
199#undef  SUPPORTED_PERSONALITIES
200#if defined(SPARC64)
201#define SUPPORTED_PERSONALITIES 3
202#define PERSONALITY2_WORDSIZE 8
203#else
204#define SUPPORTED_PERSONALITIES 2
205#endif /* SPARC64 */
206#endif /* LINUXSPARC */
207
208#ifdef X86_64
209#undef SUPPORTED_PERSONALITIES
210#define SUPPORTED_PERSONALITIES 2
211#define PERSONALITY0_WORDSIZE 8
212#define PERSONALITY1_WORDSIZE 4
213#endif
214
215#ifdef SVR4
216#ifdef HAVE_MP_PROCFS
217extern 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)						\
222	(IOCTL (t->pfd, PCWSTOP, (char *)NULL) < 0 ? -1 :		\
223	 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
228#define PR_SYSCALL	pr_lwp.pr_syscall
229#define PR_INFO		pr_lwp.pr_info
230#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)
243#define IOCTL_WSTOP(t)	ioctl (t->pfd, PIOCWSTOP, &t->status)
244#define PR_WHY		pr_why
245#define PR_WHAT		pr_what
246#define PR_REG		pr_reg
247#define PR_FLAGS	pr_flags
248#define PR_SYSCALL	pr_syscall
249#define PR_INFO		pr_info
250#endif
251#endif
252#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
260#define PR_FLAGS	state
261/* from /usr/src/sys/miscfs/procfs/procfs_vnops.c,
262   status.state = 0 for running, 1 for stopped */
263#define PR_ASLEEP	1
264#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
269
270/* 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 */
279#ifdef HAVE_LONG_LONG
280	long long u_lrval;	/* long long return value */
281#endif
282	FILE *outf;		/* Output file for this process */
283	const char *auxstr;	/* Auxiliary info from syscall (see RVAL_STR) */
284	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 */
291	int nzombies;		/* # of formerly traced children now dead */
292#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
297				/* (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
302#ifdef HAVE_MP_PROCFS
303	int pfd_stat;
304	int pfd_as;
305	pstatus_t status;
306#else
307	prstatus_t status;	/* procfs status structure */
308#endif
309#endif
310#ifdef FREEBSD
311	struct procfs_status status;
312	int pfd_reg;
313	int pfd_status;
314#endif
315};
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
330# if defined(ALPHA) || defined(SPARC) || defined(SPARC64) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH) || defined(SH64) || defined(S390) || defined(S390X) || defined(ARM)
331#  define TCB_WAITEXECVE 02000	/* ignore SIGTRAP after exceve */
332# endif
333# 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
343#  elif defined IA64
344#   define __NR_exit_group 1236
345#  elif defined POWERPC
346#   define __NR_exit_group 234
347#  elif defined S390 || defined S390X
348#   define __NR_exit_group 248
349#  elif defined SPARC || defined SPARC64
350#   define __NR_exit_group 188
351#  elif defined M68K
352#   define __NR_exit_group 247
353#  endif /* ALPHA et al */
354# endif	/* !__NR_exit_group */
355#endif /* LINUX */
356
357/* qualifier flags */
358#define QUAL_TRACE	0001	/* this system call should be traced */
359#define QUAL_ABBREV	0002	/* abbreviate the structures of this syscall */
360#define QUAL_VERBOSE	0004	/* decode the structures of this syscall */
361#define QUAL_RAW	0010	/* print all args in hex for this syscall */
362#define QUAL_SIGNAL	0020	/* report events with this signal */
363#define QUAL_FAULT	0040	/* report events with this fault */
364#define QUAL_READ	0100	/* dump data read on this file descriptor */
365#define QUAL_WRITE	0200	/* dump data written to this file descriptor */
366
367#define entering(tcp)	(!((tcp)->flags & TCB_INSYSCALL))
368#define exiting(tcp)	((tcp)->flags & TCB_INSYSCALL)
369#define syserror(tcp)	((tcp)->u_error != 0)
370#define verbose(tcp)	(qual_flags[(tcp)->scno] & QUAL_VERBOSE)
371#define abbrev(tcp)	(qual_flags[(tcp)->scno] & QUAL_ABBREV)
372
373struct xlat {
374	int val;
375	char *str;
376};
377
378/* Format of syscall return values */
379#define RVAL_DECIMAL	000	/* decimal format */
380#define RVAL_HEX	001	/* hex format */
381#define RVAL_OCTAL	002	/* octal format */
382#define RVAL_UDECIMAL	003	/* unsigned decimal format */
383#define RVAL_LDECIMAL	004	/* long decimal format */
384#define RVAL_LHEX	005	/* long hex format */
385#define RVAL_LOCTAL	006	/* long octal format */
386#define RVAL_LUDECIMAL	007	/* long unsigned decimal format */
387#define RVAL_MASK	007	/* mask for these values */
388
389#define RVAL_STR	010	/* Print `auxstr' field after return val */
390#define RVAL_NONE	020	/* Print nothing */
391
392#ifndef offsetof
393#define offsetof(type, member)	(((char *) &(((type *) NULL)->member)) - \
394				 ((char *) (type *) NULL))
395#endif /* !offsetof */
396
397/* get offset of member within a user struct */
398#define uoff(member)	offsetof(struct user, member)
399
400#define TRACE_FILE	001	/* Trace file-related syscalls. */
401#define TRACE_IPC	002	/* Trace IPC-related syscalls. */
402#define TRACE_NETWORK	004	/* Trace network-related syscalls. */
403#define TRACE_PROCESS	010	/* Trace process-related syscalls. */
404#define TRACE_SIGNAL	020	/* Trace signal-related syscalls. */
405#define TRACE_DESC	040	/* Trace file descriptor-related syscalls. */
406
407extern struct tcb **tcbtab;
408extern int *qual_flags;
409extern int debug, followfork, followvfork;
410extern int rflag, tflag, dtime, cflag, xflag, qflag;
411extern int acolumn;
412extern char *outfname;
413extern unsigned int nprocs, tcbtabsize;
414extern int max_strlen;
415extern struct tcb *tcp_last;
416
417#ifdef __STDC__
418#define P(args) args
419#else
420#define P(args) ()
421#endif
422
423extern int set_personality P((int personality));
424extern char *xlookup P((const struct xlat *, int));
425extern struct tcb *alloctcb P((int));
426extern struct tcb *pid2tcb P((int));
427extern void droptcb P((struct tcb *));
428extern int expand_tcbtab P((void));
429
430extern void set_sortby P((char *));
431extern void set_overhead P((int));
432extern void qualify P((char *));
433extern void newoutf P((struct tcb *));
434extern int get_scno P((struct tcb *));
435extern long known_scno P((struct tcb *));
436extern int trace_syscall P((struct tcb *));
437extern void printxval P((const struct xlat *, int, const char *));
438extern int printargs P((struct tcb *));
439extern int addflags P((const struct xlat *, int));
440extern int printflags P((const struct xlat *, int, const char *));
441extern int umoven P((struct tcb *, long, int, char *));
442extern int umovestr P((struct tcb *, long, int, char *));
443extern int upeek P((int, long, long *));
444extern void dumpiov P((struct tcb *, int, long));
445extern void dumpstr P((struct tcb *, long, int));
446extern void printstr P((struct tcb *, long, int));
447extern void printnum P((struct tcb *, long, char *));
448extern void printnum_int P((struct tcb *, long, char *));
449extern void printpath P((struct tcb *, long));
450extern void printpathn P((struct tcb *, long, int));
451extern void printtv P((struct tcb *, long));
452#ifdef HAVE_SIGINFO_T
453extern void printsiginfo P((siginfo_t *, int));
454#endif
455extern void printsock P((struct tcb *, long, int));
456extern void print_sock_optmgmt P((struct tcb *, long, int));
457extern void printrusage P((struct tcb *, long));
458extern void printuid P((const char *, unsigned long));
459extern int clearbpt P((struct tcb *));
460extern int setbpt P((struct tcb *));
461extern int sigishandled P((struct tcb *, int));
462extern void printcall P((struct tcb *));
463extern const char *signame P((int));
464extern void printsignal P((int));
465extern void printleader P((struct tcb *));
466extern void printtrailer P((struct tcb *));
467extern void tabto P((int));
468extern void call_summary P((FILE *));
469extern void printtv32 P((struct tcb*, long));
470extern void tprint_iov P((struct tcb *, unsigned long, unsigned long));
471
472#ifdef LINUX
473extern int internal_clone P((struct tcb *));
474#endif
475extern int internal_fork P((struct tcb *));
476extern int internal_exec P((struct tcb *));
477extern int internal_wait P((struct tcb *, int));
478extern int internal_exit P((struct tcb *));
479
480extern const struct ioctlent *ioctl_lookup P((long));
481extern const struct ioctlent *ioctl_next_match P((const struct ioctlent *));
482extern int ioctl_decode P((struct tcb *, long, long));
483extern int term_ioctl P((struct tcb *, long, long));
484extern int sock_ioctl P((struct tcb *, long, long));
485extern int proc_ioctl P((struct tcb *, int, int));
486extern int stream_ioctl P((struct tcb *, int, int));
487#ifdef LINUX
488extern int rtc_ioctl P((struct tcb *, long, long));
489#endif
490
491extern void tv_tv P((struct timeval *, int, int));
492extern int tv_nz P((struct timeval *));
493extern int tv_cmp P((struct timeval *, struct timeval *));
494extern double tv_float P((struct timeval *));
495extern void tv_add P((struct timeval *, struct timeval *, struct timeval *));
496extern void tv_sub P((struct timeval *, struct timeval *, struct timeval *));
497extern void tv_mul P((struct timeval *, struct timeval *, int));
498extern void tv_div P((struct timeval *, struct timeval *, int));
499
500#ifdef SUNOS4
501extern int fixvfork P((struct tcb *));
502#endif
503#if !(defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(IA64))
504extern long getrval2 P((struct tcb *));
505#endif
506#ifdef USE_PROCFS
507extern int proc_open P((struct tcb *tcp, int attaching));
508#endif
509
510#define umove(pid, addr, objp)	\
511	umoven((pid), (addr), sizeof *(objp), (char *) (objp))
512
513#ifdef __STDC__
514#ifdef __GNUC__
515extern void tprintf(const char *fmt, ...)
516	__attribute__ ((format (printf, 1, 2)));
517#else
518extern void tprintf(const char *fmt, ...);
519#endif
520#else
521extern void tprintf();
522#endif
523
524#ifndef HAVE_STRERROR
525const char *strerror P((int));
526#endif
527#ifndef HAVE_STRSIGNAL
528const char *strsignal P((int));
529#endif
530
531extern int current_personality;
532
533struct sysent {
534	int	nargs;
535	int	sys_flags;
536	int	(*sys_func)();
537	const char *sys_name;
538	long	native_scno;	/* Match against SYS_* constants.  */
539};
540
541extern const struct sysent *sysent;
542extern int nsyscalls;
543
544extern const char *const *errnoent;
545extern int nerrnos;
546
547struct ioctlent {
548	const char *doth;
549	const char *symbol;
550	unsigned long code;
551};
552
553extern const struct ioctlent *ioctlent;
554extern int nioctlents;
555
556extern const char *const *signalent;
557extern int nsignals;
558
559extern const struct ioctlent ioctlent0[];
560extern const int nioctlents0;
561extern const char *const signalent0[];
562extern const int nsignals0;
563
564#if SUPPORTED_PERSONALITIES >= 2
565extern const struct ioctlent ioctlent1[];
566extern const int nioctlents1;
567extern const char *const signalent1[];
568extern const int nsignals1;
569#endif /* SUPPORTED_PERSONALITIES >= 2 */
570
571#if SUPPORTED_PERSONALITIES >= 3
572extern const struct ioctlent ioctlent2[];
573extern const int nioctlents2;
574extern const char *const signalent2[];
575extern const int nsignals2;
576#endif /* SUPPORTED_PERSONALITIES >= 3 */
577
578#if defined(FREEBSD) || (defined(LINUX) \
579			 && defined(POWERPC) && !defined(__powerpc64__)) \
580  || (defined (LINUX) && defined (MIPS) && !defined(__mips64))
581/* ARRGH!  off_t args are aligned on 64 bit boundaries! */
582#define ALIGN64(tcp,arg)						\
583do {									\
584	if (arg % 2)							\
585	    memmove (&tcp->u_arg[arg], &tcp->u_arg[arg + 1],		\
586		     (tcp->u_nargs - arg - 1) * sizeof tcp->u_arg[0]);	\
587} while (0)
588#else
589#define ALIGN64(tcp,arg) do { } while (0)
590#endif
591
592#if HAVE_LONG_LONG
593
594/* _l refers to the lower numbered u_arg,
595 * _h refers to the higher numbered u_arg
596 */
597
598#if HAVE_LITTLE_ENDIAN_LONG_LONG
599#define LONG_LONG(_l,_h) \
600    ((long long)((unsigned long long)(unsigned)(_l) | ((unsigned long long)(_h)<<32)))
601#else
602#define LONG_LONG(_l,_h) \
603    ((long long)((unsigned long long)(unsigned)(_h) | ((unsigned long long)(_l)<<32)))
604#endif
605#endif
606
607#ifdef IA64
608extern long ia32;
609#endif
610
611extern int not_failing_only;
612