blob: 3c20dd1d0596f17dfb3bdd41244dfb93dd94fd02 [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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036#ifdef HAVE_CONFIG_H
37#include "config.h"
38#endif
39
40/* configuration section */
41#ifndef MAX_QUALS
Roland McGrath63d01462002-12-30 00:25:36 +000042#if defined(LINUX) && defined(MIPS)
43#define MAX_QUALS 5000 /* maximum number of syscalls, signals, etc. */
Wichert Akkermanfd89ced2000-04-13 17:06:09 +000044#else
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000045#define MAX_QUALS 2048 /* maximum number of syscalls, signals, etc. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +000047#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048#ifndef DEFAULT_STRLEN
49#define DEFAULT_STRLEN 32 /* default maximum # of bytes printed in
50 `printstr', change with `-s' switch */
51#endif
52#ifndef DEFAULT_ACOLUMN
53#define DEFAULT_ACOLUMN 40 /* default alignment column for results */
54#endif
55#ifndef MAX_ARGS
56#define MAX_ARGS 32 /* maximum number of args to a syscall */
57#endif
58#ifndef DEFAULT_SORTBY
59#define DEFAULT_SORTBY "time" /* default sorting method for call profiling */
60#endif
61
62#include <sys/types.h>
63#include <unistd.h>
64#include <stdlib.h>
65#include <stdio.h>
66#include <ctype.h>
67#include <string.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000068#include <time.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000069#include <sys/time.h>
70#include <errno.h>
71
72#ifdef STDC_HEADERS
73#include <stddef.h>
74#endif /* STDC_HEADERS */
75
John Hughes58265892001-10-18 15:13:53 +000076#ifdef HAVE_SIGINFO_T
77#include <signal.h>
78#endif
79
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000080#if defined(LINUX)
81# if defined(SPARC)
82# define LINUXSPARC
83# endif
84# if defined(ALPHA)
85# define LINUX_64BIT
86# endif
Michal Ludvig0e035502002-09-23 15:41:01 +000087# if defined(X86_64)
88# define LINUX_X86_64
89# endif
Roland McGrathee9d4352002-12-18 04:16:10 +000090#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000091
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000092#if defined(SVR4) || defined(FREEBSD)
93#define USE_PROCFS
94#else
95#undef USE_PROCFS
96#endif
97
98#ifdef FREEBSD
99#ifndef I386
100#error "FreeBSD support is only for i386 arch right now."
101#endif
102#include <machine/psl.h>
103#include <machine/reg.h>
104#include <sys/syscall.h>
105#endif
106
107#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000108#include <sys/procfs.h>
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000109#ifdef HAVE_MP_PROCFS
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000110#include <sys/uio.h>
111#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000112#ifdef FREEBSD
113#include <sys/pioctl.h>
114#endif /* FREEBSD */
115#else /* !USE_PROCFS */
Michal Ludvig0e035502002-09-23 15:41:01 +0000116#if (defined(LINUXSPARC) || defined (LINUX_X86_64)) && defined(__GLIBC__)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000117#include <sys/ptrace.h>
118#else
119/* Work around awkward prototype in ptrace.h. */
120#define ptrace xptrace
121#include <sys/ptrace.h>
122#undef ptrace
123#ifdef POWERPC
124#define __KERNEL__
125#include <asm/ptrace.h>
126#undef __KERNEL__
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000127#endif
128#ifdef __STDC__
129#ifdef LINUX
130extern long ptrace(int, int, char *, long);
131#else /* !LINUX */
132extern int ptrace(int, int, char *, int, ...);
133#endif /* !LINUX */
134#else /* !__STDC__ */
135extern int ptrace();
136#endif /* !__STDC__ */
137#endif /* !LINUXSPARC */
138#endif /* !SVR4 */
139
140#ifdef LINUX
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000141#if !defined(__GLIBC__)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000142#define PTRACE_PEEKUSER PTRACE_PEEKUSR
143#define PTRACE_POKEUSER PTRACE_POKEUSR
144#endif
145#ifdef ALPHA
Wichert Akkermanf90da011999-10-31 21:15:38 +0000146# define REG_R0 0
147# define REG_A0 16
148# define REG_A3 19
149# define REG_FP 30
150# define REG_PC 64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151#endif /* ALPHA */
Wichert Akkermanf90da011999-10-31 21:15:38 +0000152#ifdef MIPS
153# define REG_V0 2
154# define REG_A0 4
155# define REG_A3 7
156# define REG_SP 29
157# define REG_EPC 64
158#endif /* MIPS */
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000159#ifdef HPPA
160# define PT_GR20 (20*4)
161# define PT_GR26 (26*4)
162# define PT_GR28 (28*4)
163# define PT_IAOQ0 (106*4)
164# define PT_IAOQ1 (107*4)
165#endif /* HPPA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166#endif /* LINUX */
167
168#define SUPPORTED_PERSONALITIES 1
169#define DEFAULT_PERSONALITY 0
170
171#ifdef LINUXSPARC
172#include <linux/a.out.h>
173#include <asm/psr.h>
174#undef SUPPORTED_PERSONALITIES
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000175#define SUPPORTED_PERSONALITIES 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176#endif /* LINUXSPARC */
177
Michal Ludvig0e035502002-09-23 15:41:01 +0000178#ifdef X86_64
179#undef SUPPORTED_PERSONALITIES
180#define SUPPORTED_PERSONALITIES 2
Roland McGrathee9d4352002-12-18 04:16:10 +0000181#endif
182
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000183#ifdef SVR4
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000184#ifdef HAVE_MP_PROCFS
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000185extern int mp_ioctl (int f, int c, void *a, int s);
186#define IOCTL(f,c,a) mp_ioctl (f, c, a, sizeof *a)
187#define IOCTL_STATUS(t) \
188 pread (t->pfd_stat, &t->status, sizeof t->status, 0)
189#define IOCTL_WSTOP(t) \
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000190 (IOCTL (t->pfd, PCWSTOP, (char *)NULL) < 0 ? -1 : \
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000191 IOCTL_STATUS (t))
192#define PR_WHY pr_lwp.pr_why
193#define PR_WHAT pr_lwp.pr_what
194#define PR_REG pr_lwp.pr_context.uc_mcontext.gregs
195#define PR_FLAGS pr_lwp.pr_flags
John Hughes25299712001-03-06 10:10:06 +0000196#define PR_SYSCALL pr_lwp.pr_syscall
John Hughes58265892001-10-18 15:13:53 +0000197#define PR_INFO pr_lwp.pr_info
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000198#define PIOCSTIP PCSTOP
199#define PIOCSET PCSET
200#define PIOCRESET PCRESET
201#define PIOCSTRACE PCSTRACE
202#define PIOCSFAULT PCSFAULT
203#define PIOCWSTOP PCWSTOP
204#define PIOCSTOP PCSTOP
205#define PIOCSENTRY PCSENTRY
206#define PIOCSEXIT PCSEXIT
207#define PIOCRUN PCRUN
208#else
209#define IOCTL ioctl
210#define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status)
Roland McGrathee9d4352002-12-18 04:16:10 +0000211#define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWSTOP, &t->status)
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000212#define PR_WHY pr_why
213#define PR_WHAT pr_what
214#define PR_REG pr_reg
215#define PR_FLAGS pr_flags
John Hughes25299712001-03-06 10:10:06 +0000216#define PR_SYSCALL pr_syscall
John Hughes58265892001-10-18 15:13:53 +0000217#define PR_INFO pr_info
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000218#endif
219#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000220#ifdef FREEBSD
221#define IOCTL ioctl
222#define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status)
223#define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWAIT, &t->status)
224#define PIOCRUN PIOCCONT
225#define PIOCWSTOP PIOCWAIT
226#define PR_WHY why
227#define PR_WHAT val
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000228#define PR_FLAGS state
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000229/* from /usr/src/sys/miscfs/procfs/procfs_vnops.c,
230 status.state = 0 for running, 1 for stopped */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000231#define PR_ASLEEP 1
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000232#define PR_SYSENTRY S_SCE
233#define PR_SYSEXIT S_SCX
234#define PR_SIGNALLED S_SIG
235#define PR_FAULTED S_CORE
236#endif
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000237
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000238/* Trace Control Block */
239struct tcb {
240 short flags; /* See below for TCB_ values */
241 int pid; /* Process Id of this entry */
242 long scno; /* System call number */
243 int u_nargs; /* System call arguments */
244 long u_arg[MAX_ARGS]; /* System call arguments */
245 int u_error; /* Error code */
246 long u_rval; /* (first) return value */
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000247#ifdef HAVE_LONG_LONG
248 long long u_lrval; /* long long return value */
249#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000250 FILE *outf; /* Output file for this process */
Wichert Akkerman43a74822000-06-27 17:33:32 +0000251 const char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000252 struct timeval stime; /* System time usage as of last process wait */
253 struct timeval dtime; /* Delta for system time usage */
254 struct timeval etime; /* Syscall entry time */
255 /* Support for tracing forked processes */
256 struct tcb *parent; /* Parent of this process */
257 int nchildren; /* # of traced children */
258 int waitpid; /* pid(s) this process is waiting for */
Roland McGrath923f7502003-01-09 06:53:27 +0000259#ifdef LINUX
260 int nclone_threads; /* # of nchildren with CLONE_THREAD */
261 int nclone_detached; /* # of nchildren with CLONE_DETACHED */
262 int nclone_waiting; /* clone threads in wait4 (TCB_SUSPENDED) */
263#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000264 /* (1st arg of wait4()) */
265 long baddr; /* `Breakpoint' address */
266 long inst[2]; /* Instructions on above */
267 int pfd; /* proc file descriptor */
268#ifdef SVR4
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000269#ifdef HAVE_MP_PROCFS
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000270 int pfd_stat;
271 int pfd_as;
272 pstatus_t status;
273#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274 prstatus_t status; /* procfs status structure */
275#endif
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000276#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000277#ifdef FREEBSD
278 struct procfs_status status;
279 int pfd_reg;
280 int pfd_status;
281#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000282};
283
284/* TCB flags */
285#define TCB_STARTUP 00001 /* We have just begun ptracing this process */
286#define TCB_INUSE 00002 /* This table entry is in use */
287#define TCB_INSYSCALL 00004 /* A system call is in progress */
288#define TCB_ATTACHED 00010 /* Process is not our own child */
289#define TCB_EXITING 00020 /* As far as we know, this process is exiting */
290#define TCB_SUSPENDED 00040 /* Process has done a wait(4), that can
291 not be allowed to complete just now */
292#define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */
293#define TCB_SIGTRAPPED 00200 /* Process wanted to block SIGTRAP */
294#define TCB_FOLLOWFORK 00400 /* Process should have forks followed */
295#define TCB_REPRINT 01000 /* We should reprint this syscall on exit */
296#ifdef LINUX
Wichert Akkermanccef6372002-05-01 16:39:22 +0000297# if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000298# define TCB_WAITEXECVE 02000 /* ignore SIGTRAP after exceve */
299# endif
Roland McGrath923f7502003-01-09 06:53:27 +0000300# define TCB_CLONE_DETACHED 04000 /* CLONE_DETACHED set in creating syscall */
301# define TCB_CLONE_THREAD 010000 /* CLONE_THREAD set in creating syscall */
302# define TCB_GROUP_EXITING 020000 /* TCB_EXITING was exit_group, not _exit */
303# include <sys/syscall.h>
304# ifndef __NR_exit_group
305# /* Hack: Most headers around are too old to have __NR_exit_group. */
306# ifdef ALPHA
307# define __NR_exit_group 405
308# elif defined I386
309# define __NR_exit_group 252
310# elif defined IA64
311# define __NR_exit_group 1236
312# elif defined POWERPC
313# define __NR_exit_group 234
314# elif defined S390 || defined S390X
315# define __NR_exit_group 248
316# elif defined SPARC
317# define __NR_exit_group 188
318# endif /* ALPHA et al */
319# endif /* !__NR_exit_group */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000320#endif /* LINUX */
321
322/* qualifier flags */
323#define QUAL_TRACE 0001 /* this system call should be traced */
324#define QUAL_ABBREV 0002 /* abbreviate the structures of this syscall */
325#define QUAL_VERBOSE 0004 /* decode the structures of this syscall */
326#define QUAL_RAW 0010 /* print all args in hex for this syscall */
327#define QUAL_SIGNAL 0020 /* report events with this signal */
328#define QUAL_FAULT 0040 /* report events with this fault */
329#define QUAL_READ 0100 /* dump data read on this file descriptor */
330#define QUAL_WRITE 0200 /* dump data written to this file descriptor */
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) (qual_flags[(tcp)->scno] & QUAL_VERBOSE)
336#define abbrev(tcp) (qual_flags[(tcp)->scno] & QUAL_ABBREV)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000337
338struct xlat {
339 int val;
340 char *str;
341};
342
343/* Format of syscall return values */
344#define RVAL_DECIMAL 000 /* decimal format */
345#define RVAL_HEX 001 /* hex format */
346#define RVAL_OCTAL 002 /* octal format */
347#define RVAL_UDECIMAL 003 /* unsigned decimal format */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000348#define RVAL_LDECIMAL 004 /* long decimal format */
349#define RVAL_LHEX 005 /* long hex format */
350#define RVAL_LOCTAL 006 /* long octal format */
351#define RVAL_LUDECIMAL 007 /* long unsigned decimal format */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000352#define RVAL_MASK 007 /* mask for these values */
353
354#define RVAL_STR 010 /* Print `auxstr' field after return val */
355#define RVAL_NONE 020 /* Print nothing */
356
357#ifndef offsetof
358#define offsetof(type, member) (((char *) &(((type *) NULL)->member)) - \
359 ((char *) (type *) NULL))
360#endif /* !offsetof */
361
362/* get offset of member within a user struct */
363#define uoff(member) offsetof(struct user, member)
364
365#define TRACE_FILE 001 /* Trace file-related syscalls. */
366#define TRACE_IPC 002 /* Trace IPC-related syscalls. */
367#define TRACE_NETWORK 004 /* Trace network-related syscalls. */
368#define TRACE_PROCESS 010 /* Trace process-related syscalls. */
369#define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */
370
Roland McGrathee9d4352002-12-18 04:16:10 +0000371extern struct tcb **tcbtab;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000372extern int qual_flags[];
373extern int debug, followfork, followvfork;
374extern int rflag, tflag, dtime, cflag, xflag, qflag;
375extern int acolumn;
376extern char *outfname;
Roland McGrathee9d4352002-12-18 04:16:10 +0000377extern unsigned int nprocs, tcbtabsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378extern int max_strlen;
379extern struct tcb *tcp_last;
380
381#ifdef __STDC__
382#define P(args) args
383#else
384#define P(args) ()
385#endif
386
387extern int set_personality P((int personality));
388extern char *xlookup P((struct xlat *, int));
389extern struct tcb *alloctcb P((int));
Roland McGrath923f7502003-01-09 06:53:27 +0000390extern struct tcb *pid2tcb P((int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391extern void droptcb P((struct tcb *));
392
393extern void set_sortby P((char *));
394extern void set_overhead P((int));
395extern void qualify P((char *));
396extern void newoutf P((struct tcb *));
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000397extern int get_scno P((struct tcb *));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000398extern int trace_syscall P((struct tcb *));
399extern void printxval P((struct xlat *, int, char *));
400extern int printargs P((struct tcb *));
401extern int addflags P((struct xlat *, int));
402extern int printflags P((struct xlat *, int));
403extern int umoven P((struct tcb *, long, int, char *));
404extern int umovestr P((struct tcb *, long, int, char *));
405extern int upeek P((int, long, long *));
John Hughes1d08dcf2001-07-10 13:48:44 +0000406extern void dumpiov P((struct tcb *, int, long));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000407extern void dumpstr P((struct tcb *, long, int));
408extern void string_quote P((char *str));
409extern void printstr P((struct tcb *, long, int));
410extern void printnum P((struct tcb *, long, char *));
411extern void printpath P((struct tcb *, long));
412extern void printpathn P((struct tcb *, long, int));
413extern void printtv P((struct tcb *, long));
John Hughes58265892001-10-18 15:13:53 +0000414#ifdef HAVE_SIGINFO_T
415extern void printsiginfo P((siginfo_t *, int));
416#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000417extern void printsock P((struct tcb *, long, int));
John Hughes38ae88d2002-05-23 11:48:58 +0000418extern void print_sock_optmgmt P((struct tcb *, long, int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000419extern void printrusage P((struct tcb *, long));
420extern int clearbpt P((struct tcb *));
421extern int setbpt P((struct tcb *));
422extern int sigishandled P((struct tcb *, int));
423extern void printcall P((struct tcb *));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000424extern char *signame P((int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425extern void printsignal P((int));
426extern void printleader P((struct tcb *));
427extern void printtrailer P((struct tcb *));
428extern void tabto P((int));
429extern void call_summary P((FILE *));
430extern void fake_execve P((struct tcb *, char *, char *[], char *[]));
Wichert Akkerman221f54f1999-11-18 17:26:45 +0000431extern void printtv32 P((struct tcb*, long));
John Hughes1d08dcf2001-07-10 13:48:44 +0000432extern void tprint_iov P((struct tcb *, int, long));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000434#ifdef LINUX
435extern int internal_clone P((struct tcb *));
436#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437extern int internal_fork P((struct tcb *));
438extern int internal_exec P((struct tcb *));
439extern int internal_wait P((struct tcb *));
440extern int internal_exit P((struct tcb *));
441
442extern char *ioctl_lookup P((long));
443extern int ioctl_decode P((struct tcb *, long, long));
444extern int term_ioctl P((struct tcb *, long, long));
445extern int sock_ioctl P((struct tcb *, long, long));
446extern int proc_ioctl P((struct tcb *, int, int));
447extern int stream_ioctl P((struct tcb *, int, int));
448
449extern void tv_tv P((struct timeval *, int, int));
450extern int tv_nz P((struct timeval *));
451extern int tv_cmp P((struct timeval *, struct timeval *));
452extern double tv_float P((struct timeval *));
453extern void tv_add P((struct timeval *, struct timeval *, struct timeval *));
454extern void tv_sub P((struct timeval *, struct timeval *, struct timeval *));
455extern void tv_mul P((struct timeval *, struct timeval *, int));
456extern void tv_div P((struct timeval *, struct timeval *, int));
457
458#ifdef SUNOS4
459extern int fixvfork P((struct tcb *));
460#endif
461#if !(defined(LINUX) && !defined(SPARC))
462extern long getrval2 P((struct tcb *));
463#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000464#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465extern int proc_open P((struct tcb *tcp, int attaching));
466#endif
467
468#define umove(pid, addr, objp) \
469 umoven((pid), (addr), sizeof *(objp), (char *) (objp))
470
471#ifdef __STDC__
472#ifdef __GNUC__
473extern void tprintf(const char *fmt, ...)
474 __attribute__ ((format (printf, 1, 2)));
475#else
476extern void tprintf(const char *fmt, ...);
477#endif
478#else
479extern void tprintf();
480#endif
481
482#ifndef HAVE_STRERROR
483const char *strerror P((int));
484#endif
485#ifndef HAVE_STRSIGNAL
486const char *strsignal P((int));
487#endif
488
489extern int current_personality;
490
491struct sysent {
492 int nargs;
493 int sys_flags;
494 int (*sys_func)();
495 char *sys_name;
496};
497
498extern struct sysent *sysent;
499extern int nsyscalls;
500
501extern char **errnoent;
502extern int nerrnos;
503
504struct ioctlent {
505 char *doth;
506 char *symbol;
507 unsigned long code;
508};
509
510extern struct ioctlent *ioctlent;
511extern int nioctlent;
512
513extern char **signalent;
514extern int nsignals;
515
516extern struct ioctlent *ioctlent;
517extern int nioctlents;
518extern char **signalent;
519extern int nsignals;
520
521extern struct ioctlent ioctlent0[];
522extern int nioctlents0;
523extern char *signalent0[];
524extern int nsignals0;
525
526#if SUPPORTED_PERSONALITIES >= 2
527extern struct ioctlent ioctlent1[];
528extern int nioctlents1;
529extern char *signalent1[];
530extern int nsignals1;
531#endif /* SUPPORTED_PERSONALITIES >= 2 */
532
533#if SUPPORTED_PERSONALITIES >= 3
534extern struct ioctlent ioctlent2[];
535extern int nioctlents2;
536extern char *signalent2[];
537extern int nsignals2;
538#endif /* SUPPORTED_PERSONALITIES >= 3 */
John Hughesbdf48f52001-03-06 15:08:09 +0000539
John Hughes5a826b82001-03-07 13:21:24 +0000540#if FREEBSD
541/* ARRGH! off_t args are aligned on 64 bit boundaries! */
542#define ALIGN64(tcp,arg) \
543do { \
544 if (arg % 2) \
545 memmove (&tcp->u_arg[arg], &tcp->u_arg[arg + 1], \
546 (tcp->u_nargs - arg - 1) * sizeof tcp->u_arg[0]); \
547} while (0)
Roland McGrathf5c450d2003-01-14 07:53:41 +0000548#elif defined(LINUX) && defined(POWERPC) && !defined(__powerpc64__)
549#define ALIGN64(tcp,arg) \
550do { \
551 if (!(arg % 2)) \
552 memmove (&tcp->u_arg[arg], &tcp->u_arg[arg + 1], \
553 (tcp->u_nargs - arg - 1) * sizeof tcp->u_arg[0]); \
554} while (0)
John Hughes5a826b82001-03-07 13:21:24 +0000555#else
556#define ALIGN64(tcp,arg) do { } while (0)
557#endif
558
John Hughes0c79e012001-03-08 14:40:06 +0000559#if HAVE_LONG_LONG
John Hughes5a826b82001-03-07 13:21:24 +0000560
John Hughesbdf48f52001-03-06 15:08:09 +0000561/* _l refers to the lower numbered u_arg,
562 * _h refers to the higher numbered u_arg
563 */
John Hughes5a826b82001-03-07 13:21:24 +0000564
John Hughesb8a85a42001-03-28 08:05:27 +0000565#if HAVE_LITTLE_ENDIAN_LONG_LONG
John Hughes0c79e012001-03-08 14:40:06 +0000566#define LONG_LONG(_l,_h) \
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000567 ((long long)((unsigned long long)(unsigned)(_l) | ((unsigned long long)(_h)<<32)))
John Hughesbdf48f52001-03-06 15:08:09 +0000568#else
John Hughes0c79e012001-03-08 14:40:06 +0000569#define LONG_LONG(_l,_h) \
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000570 ((long long)((unsigned long long)(unsigned)(_h) | ((unsigned long long)(_l)<<32)))
John Hughesbdf48f52001-03-06 15:08:09 +0000571#endif
572#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000573
574#ifdef IA64
575extern long ia32;
576#endif
Michal Ludvig17f8fb32002-11-06 13:17:21 +0000577
578extern int not_failing_only;