blob: 4138894e3274de6d329828ce0c83380f494772e8 [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
Wichert Akkermanb859bea1999-04-18 22:50:50 +000032#ifdef linux
33#include <features.h>
34#endif
35
Roland McGrathe6d3a292003-01-14 09:46:18 +000036#ifdef _LARGEFILE64_SOURCE
37/* This is the macro everything checks before using foo64 names. */
38# ifndef _LFS64_LARGEFILE
39# define _LFS64_LARGEFILE 1
40# endif
41#endif
42
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000043#ifdef HAVE_CONFIG_H
44#include "config.h"
45#endif
46
47/* 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)
88# if defined(SPARC)
89# 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 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000173#endif /* LINUX */
174
175#define SUPPORTED_PERSONALITIES 1
176#define DEFAULT_PERSONALITY 0
177
178#ifdef LINUXSPARC
179#include <linux/a.out.h>
180#include <asm/psr.h>
181#undef SUPPORTED_PERSONALITIES
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000182#define SUPPORTED_PERSONALITIES 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000183#endif /* LINUXSPARC */
184
Michal Ludvig0e035502002-09-23 15:41:01 +0000185#ifdef X86_64
186#undef SUPPORTED_PERSONALITIES
187#define SUPPORTED_PERSONALITIES 2
Roland McGrathee9d4352002-12-18 04:16:10 +0000188#endif
189
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000190#ifdef SVR4
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000191#ifdef HAVE_MP_PROCFS
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000192extern int mp_ioctl (int f, int c, void *a, int s);
193#define IOCTL(f,c,a) mp_ioctl (f, c, a, sizeof *a)
194#define IOCTL_STATUS(t) \
195 pread (t->pfd_stat, &t->status, sizeof t->status, 0)
196#define IOCTL_WSTOP(t) \
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000197 (IOCTL (t->pfd, PCWSTOP, (char *)NULL) < 0 ? -1 : \
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000198 IOCTL_STATUS (t))
199#define PR_WHY pr_lwp.pr_why
200#define PR_WHAT pr_lwp.pr_what
201#define PR_REG pr_lwp.pr_context.uc_mcontext.gregs
202#define PR_FLAGS pr_lwp.pr_flags
John Hughes25299712001-03-06 10:10:06 +0000203#define PR_SYSCALL pr_lwp.pr_syscall
John Hughes58265892001-10-18 15:13:53 +0000204#define PR_INFO pr_lwp.pr_info
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000205#define PIOCSTIP PCSTOP
206#define PIOCSET PCSET
207#define PIOCRESET PCRESET
208#define PIOCSTRACE PCSTRACE
209#define PIOCSFAULT PCSFAULT
210#define PIOCWSTOP PCWSTOP
211#define PIOCSTOP PCSTOP
212#define PIOCSENTRY PCSENTRY
213#define PIOCSEXIT PCSEXIT
214#define PIOCRUN PCRUN
215#else
216#define IOCTL ioctl
217#define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status)
Roland McGrathee9d4352002-12-18 04:16:10 +0000218#define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWSTOP, &t->status)
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000219#define PR_WHY pr_why
220#define PR_WHAT pr_what
221#define PR_REG pr_reg
222#define PR_FLAGS pr_flags
John Hughes25299712001-03-06 10:10:06 +0000223#define PR_SYSCALL pr_syscall
John Hughes58265892001-10-18 15:13:53 +0000224#define PR_INFO pr_info
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000225#endif
226#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000227#ifdef FREEBSD
228#define IOCTL ioctl
229#define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status)
230#define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWAIT, &t->status)
231#define PIOCRUN PIOCCONT
232#define PIOCWSTOP PIOCWAIT
233#define PR_WHY why
234#define PR_WHAT val
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000235#define PR_FLAGS state
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000236/* from /usr/src/sys/miscfs/procfs/procfs_vnops.c,
237 status.state = 0 for running, 1 for stopped */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000238#define PR_ASLEEP 1
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000239#define PR_SYSENTRY S_SCE
240#define PR_SYSEXIT S_SCX
241#define PR_SIGNALLED S_SIG
242#define PR_FAULTED S_CORE
243#endif
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000244
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000245/* Trace Control Block */
246struct tcb {
247 short flags; /* See below for TCB_ values */
248 int pid; /* Process Id of this entry */
249 long scno; /* System call number */
250 int u_nargs; /* System call arguments */
251 long u_arg[MAX_ARGS]; /* System call arguments */
252 int u_error; /* Error code */
253 long u_rval; /* (first) return value */
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000254#ifdef HAVE_LONG_LONG
255 long long u_lrval; /* long long return value */
256#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000257 FILE *outf; /* Output file for this process */
Wichert Akkerman43a74822000-06-27 17:33:32 +0000258 const char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000259 struct timeval stime; /* System time usage as of last process wait */
260 struct timeval dtime; /* Delta for system time usage */
261 struct timeval etime; /* Syscall entry time */
262 /* Support for tracing forked processes */
263 struct tcb *parent; /* Parent of this process */
264 int nchildren; /* # of traced children */
265 int waitpid; /* pid(s) this process is waiting for */
Roland McGrath09623452003-05-23 02:27:13 +0000266 int nzombies; /* # of formerly traced children now dead */
Roland McGrath923f7502003-01-09 06:53:27 +0000267#ifdef LINUX
268 int nclone_threads; /* # of nchildren with CLONE_THREAD */
269 int nclone_detached; /* # of nchildren with CLONE_DETACHED */
270 int nclone_waiting; /* clone threads in wait4 (TCB_SUSPENDED) */
271#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272 /* (1st arg of wait4()) */
273 long baddr; /* `Breakpoint' address */
274 long inst[2]; /* Instructions on above */
275 int pfd; /* proc file descriptor */
276#ifdef SVR4
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000277#ifdef HAVE_MP_PROCFS
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000278 int pfd_stat;
279 int pfd_as;
280 pstatus_t status;
281#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000282 prstatus_t status; /* procfs status structure */
283#endif
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000284#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000285#ifdef FREEBSD
286 struct procfs_status status;
287 int pfd_reg;
288 int pfd_status;
289#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000290};
291
292/* TCB flags */
293#define TCB_STARTUP 00001 /* We have just begun ptracing this process */
294#define TCB_INUSE 00002 /* This table entry is in use */
295#define TCB_INSYSCALL 00004 /* A system call is in progress */
296#define TCB_ATTACHED 00010 /* Process is not our own child */
297#define TCB_EXITING 00020 /* As far as we know, this process is exiting */
298#define TCB_SUSPENDED 00040 /* Process has done a wait(4), that can
299 not be allowed to complete just now */
300#define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */
301#define TCB_SIGTRAPPED 00200 /* Process wanted to block SIGTRAP */
302#define TCB_FOLLOWFORK 00400 /* Process should have forks followed */
303#define TCB_REPRINT 01000 /* We should reprint this syscall on exit */
304#ifdef LINUX
Roland McGrath96dc5142003-01-20 10:23:04 +0000305# if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH) || defined(S390) || defined(S390X)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000306# define TCB_WAITEXECVE 02000 /* ignore SIGTRAP after exceve */
307# endif
Roland McGrath923f7502003-01-09 06:53:27 +0000308# define TCB_CLONE_DETACHED 04000 /* CLONE_DETACHED set in creating syscall */
309# define TCB_CLONE_THREAD 010000 /* CLONE_THREAD set in creating syscall */
310# define TCB_GROUP_EXITING 020000 /* TCB_EXITING was exit_group, not _exit */
311# include <sys/syscall.h>
312# ifndef __NR_exit_group
313# /* Hack: Most headers around are too old to have __NR_exit_group. */
314# ifdef ALPHA
315# define __NR_exit_group 405
316# elif defined I386
317# define __NR_exit_group 252
318# elif defined IA64
319# define __NR_exit_group 1236
320# elif defined POWERPC
321# define __NR_exit_group 234
322# elif defined S390 || defined S390X
323# define __NR_exit_group 248
324# elif defined SPARC
325# define __NR_exit_group 188
326# endif /* ALPHA et al */
327# endif /* !__NR_exit_group */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000328#endif /* LINUX */
329
330/* qualifier flags */
331#define QUAL_TRACE 0001 /* this system call should be traced */
332#define QUAL_ABBREV 0002 /* abbreviate the structures of this syscall */
333#define QUAL_VERBOSE 0004 /* decode the structures of this syscall */
334#define QUAL_RAW 0010 /* print all args in hex for this syscall */
335#define QUAL_SIGNAL 0020 /* report events with this signal */
336#define QUAL_FAULT 0040 /* report events with this fault */
337#define QUAL_READ 0100 /* dump data read on this file descriptor */
338#define QUAL_WRITE 0200 /* dump data written to this file descriptor */
339
340#define entering(tcp) (!((tcp)->flags & TCB_INSYSCALL))
341#define exiting(tcp) ((tcp)->flags & TCB_INSYSCALL)
342#define syserror(tcp) ((tcp)->u_error != 0)
343#define verbose(tcp) (qual_flags[(tcp)->scno] & QUAL_VERBOSE)
344#define abbrev(tcp) (qual_flags[(tcp)->scno] & QUAL_ABBREV)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000345
346struct xlat {
347 int val;
348 char *str;
349};
350
351/* Format of syscall return values */
352#define RVAL_DECIMAL 000 /* decimal format */
353#define RVAL_HEX 001 /* hex format */
354#define RVAL_OCTAL 002 /* octal format */
355#define RVAL_UDECIMAL 003 /* unsigned decimal format */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000356#define RVAL_LDECIMAL 004 /* long decimal format */
357#define RVAL_LHEX 005 /* long hex format */
358#define RVAL_LOCTAL 006 /* long octal format */
359#define RVAL_LUDECIMAL 007 /* long unsigned decimal format */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000360#define RVAL_MASK 007 /* mask for these values */
361
362#define RVAL_STR 010 /* Print `auxstr' field after return val */
363#define RVAL_NONE 020 /* Print nothing */
364
365#ifndef offsetof
366#define offsetof(type, member) (((char *) &(((type *) NULL)->member)) - \
367 ((char *) (type *) NULL))
368#endif /* !offsetof */
369
370/* get offset of member within a user struct */
371#define uoff(member) offsetof(struct user, member)
372
373#define TRACE_FILE 001 /* Trace file-related syscalls. */
374#define TRACE_IPC 002 /* Trace IPC-related syscalls. */
375#define TRACE_NETWORK 004 /* Trace network-related syscalls. */
376#define TRACE_PROCESS 010 /* Trace process-related syscalls. */
377#define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */
378
Roland McGrathee9d4352002-12-18 04:16:10 +0000379extern struct tcb **tcbtab;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380extern int qual_flags[];
381extern int debug, followfork, followvfork;
382extern int rflag, tflag, dtime, cflag, xflag, qflag;
383extern int acolumn;
384extern char *outfname;
Roland McGrathee9d4352002-12-18 04:16:10 +0000385extern unsigned int nprocs, tcbtabsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000386extern int max_strlen;
387extern struct tcb *tcp_last;
388
389#ifdef __STDC__
390#define P(args) args
391#else
392#define P(args) ()
393#endif
394
395extern int set_personality P((int personality));
396extern char *xlookup P((struct xlat *, int));
397extern struct tcb *alloctcb P((int));
Roland McGrath923f7502003-01-09 06:53:27 +0000398extern struct tcb *pid2tcb P((int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399extern void droptcb P((struct tcb *));
400
401extern void set_sortby P((char *));
402extern void set_overhead P((int));
403extern void qualify P((char *));
404extern void newoutf P((struct tcb *));
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000405extern int get_scno P((struct tcb *));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406extern int trace_syscall P((struct tcb *));
407extern void printxval P((struct xlat *, int, char *));
408extern int printargs P((struct tcb *));
409extern int addflags P((struct xlat *, int));
410extern int printflags P((struct xlat *, int));
411extern int umoven P((struct tcb *, long, int, char *));
412extern int umovestr P((struct tcb *, long, int, char *));
413extern int upeek P((int, long, long *));
John Hughes1d08dcf2001-07-10 13:48:44 +0000414extern void dumpiov P((struct tcb *, int, long));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000415extern void dumpstr P((struct tcb *, long, int));
416extern void string_quote P((char *str));
417extern void printstr P((struct tcb *, long, int));
418extern void printnum P((struct tcb *, long, char *));
419extern void printpath P((struct tcb *, long));
420extern void printpathn P((struct tcb *, long, int));
421extern void printtv P((struct tcb *, long));
John Hughes58265892001-10-18 15:13:53 +0000422#ifdef HAVE_SIGINFO_T
423extern void printsiginfo P((siginfo_t *, int));
424#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000425extern void printsock P((struct tcb *, long, int));
John Hughes38ae88d2002-05-23 11:48:58 +0000426extern void print_sock_optmgmt P((struct tcb *, long, int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000427extern void printrusage P((struct tcb *, long));
428extern int clearbpt P((struct tcb *));
429extern int setbpt P((struct tcb *));
430extern int sigishandled P((struct tcb *, int));
431extern void printcall P((struct tcb *));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000432extern char *signame P((int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433extern void printsignal P((int));
434extern void printleader P((struct tcb *));
435extern void printtrailer P((struct tcb *));
436extern void tabto P((int));
437extern void call_summary P((FILE *));
438extern void fake_execve P((struct tcb *, char *, char *[], char *[]));
Wichert Akkerman221f54f1999-11-18 17:26:45 +0000439extern void printtv32 P((struct tcb*, long));
John Hughes1d08dcf2001-07-10 13:48:44 +0000440extern void tprint_iov P((struct tcb *, int, long));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000441
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000442#ifdef LINUX
443extern int internal_clone P((struct tcb *));
444#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000445extern int internal_fork P((struct tcb *));
446extern int internal_exec P((struct tcb *));
447extern int internal_wait P((struct tcb *));
448extern int internal_exit P((struct tcb *));
449
450extern char *ioctl_lookup P((long));
451extern int ioctl_decode P((struct tcb *, long, long));
452extern int term_ioctl P((struct tcb *, long, long));
453extern int sock_ioctl P((struct tcb *, long, long));
454extern int proc_ioctl P((struct tcb *, int, int));
455extern int stream_ioctl P((struct tcb *, int, int));
456
457extern void tv_tv P((struct timeval *, int, int));
458extern int tv_nz P((struct timeval *));
459extern int tv_cmp P((struct timeval *, struct timeval *));
460extern double tv_float P((struct timeval *));
461extern void tv_add P((struct timeval *, struct timeval *, struct timeval *));
462extern void tv_sub P((struct timeval *, struct timeval *, struct timeval *));
463extern void tv_mul P((struct timeval *, struct timeval *, int));
464extern void tv_div P((struct timeval *, struct timeval *, int));
465
466#ifdef SUNOS4
467extern int fixvfork P((struct tcb *));
468#endif
469#if !(defined(LINUX) && !defined(SPARC))
470extern long getrval2 P((struct tcb *));
471#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000472#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000473extern int proc_open P((struct tcb *tcp, int attaching));
474#endif
475
476#define umove(pid, addr, objp) \
477 umoven((pid), (addr), sizeof *(objp), (char *) (objp))
478
479#ifdef __STDC__
480#ifdef __GNUC__
481extern void tprintf(const char *fmt, ...)
482 __attribute__ ((format (printf, 1, 2)));
483#else
484extern void tprintf(const char *fmt, ...);
485#endif
486#else
487extern void tprintf();
488#endif
489
490#ifndef HAVE_STRERROR
491const char *strerror P((int));
492#endif
493#ifndef HAVE_STRSIGNAL
494const char *strsignal P((int));
495#endif
496
497extern int current_personality;
498
499struct sysent {
500 int nargs;
501 int sys_flags;
502 int (*sys_func)();
503 char *sys_name;
504};
505
506extern struct sysent *sysent;
507extern int nsyscalls;
508
509extern char **errnoent;
510extern int nerrnos;
511
512struct ioctlent {
513 char *doth;
514 char *symbol;
515 unsigned long code;
516};
517
518extern struct ioctlent *ioctlent;
519extern int nioctlent;
520
521extern char **signalent;
522extern int nsignals;
523
524extern struct ioctlent *ioctlent;
525extern int nioctlents;
526extern char **signalent;
527extern int nsignals;
528
529extern struct ioctlent ioctlent0[];
530extern int nioctlents0;
531extern char *signalent0[];
532extern int nsignals0;
533
534#if SUPPORTED_PERSONALITIES >= 2
535extern struct ioctlent ioctlent1[];
536extern int nioctlents1;
537extern char *signalent1[];
538extern int nsignals1;
539#endif /* SUPPORTED_PERSONALITIES >= 2 */
540
541#if SUPPORTED_PERSONALITIES >= 3
542extern struct ioctlent ioctlent2[];
543extern int nioctlents2;
544extern char *signalent2[];
545extern int nsignals2;
546#endif /* SUPPORTED_PERSONALITIES >= 3 */
John Hughesbdf48f52001-03-06 15:08:09 +0000547
Roland McGrathe6d3a292003-01-14 09:46:18 +0000548#if defined(FREEBSD) || (defined(LINUX) \
549 && defined(POWERPC) && !defined(__powerpc64__))
John Hughes5a826b82001-03-07 13:21:24 +0000550/* ARRGH! off_t args are aligned on 64 bit boundaries! */
551#define ALIGN64(tcp,arg) \
552do { \
553 if (arg % 2) \
554 memmove (&tcp->u_arg[arg], &tcp->u_arg[arg + 1], \
555 (tcp->u_nargs - arg - 1) * sizeof tcp->u_arg[0]); \
556} while (0)
557#else
558#define ALIGN64(tcp,arg) do { } while (0)
559#endif
560
John Hughes0c79e012001-03-08 14:40:06 +0000561#if HAVE_LONG_LONG
John Hughes5a826b82001-03-07 13:21:24 +0000562
John Hughesbdf48f52001-03-06 15:08:09 +0000563/* _l refers to the lower numbered u_arg,
564 * _h refers to the higher numbered u_arg
565 */
John Hughes5a826b82001-03-07 13:21:24 +0000566
John Hughesb8a85a42001-03-28 08:05:27 +0000567#if HAVE_LITTLE_ENDIAN_LONG_LONG
John Hughes0c79e012001-03-08 14:40:06 +0000568#define LONG_LONG(_l,_h) \
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000569 ((long long)((unsigned long long)(unsigned)(_l) | ((unsigned long long)(_h)<<32)))
John Hughesbdf48f52001-03-06 15:08:09 +0000570#else
John Hughes0c79e012001-03-08 14:40:06 +0000571#define LONG_LONG(_l,_h) \
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000572 ((long long)((unsigned long long)(unsigned)(_h) | ((unsigned long long)(_l)<<32)))
John Hughesbdf48f52001-03-06 15:08:09 +0000573#endif
574#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000575
576#ifdef IA64
577extern long ia32;
578#endif
Michal Ludvig17f8fb32002-11-06 13:17:21 +0000579
580extern int not_failing_only;