blob: 43036852aef7dfed7174a544e136d417635ceb9e [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
Wichert Akkermanfd89ced2000-04-13 17:06:09 +000042#if defined(linux) && defined(MIPS)
43#define MAX_QUALS 4999 /* maximum number of syscalls, signals, etc. */
44#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 MAX_PROCS
Wichert Akkermanfaf72222000-02-19 23:59:03 +000049#define MAX_PROCS 64 /* maximum number of processes tracable */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000050#endif
51#ifndef DEFAULT_STRLEN
52#define DEFAULT_STRLEN 32 /* default maximum # of bytes printed in
53 `printstr', change with `-s' switch */
54#endif
55#ifndef DEFAULT_ACOLUMN
56#define DEFAULT_ACOLUMN 40 /* default alignment column for results */
57#endif
58#ifndef MAX_ARGS
59#define MAX_ARGS 32 /* maximum number of args to a syscall */
60#endif
61#ifndef DEFAULT_SORTBY
62#define DEFAULT_SORTBY "time" /* default sorting method for call profiling */
63#endif
64
65#include <sys/types.h>
66#include <unistd.h>
67#include <stdlib.h>
68#include <stdio.h>
69#include <ctype.h>
70#include <string.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000071#include <time.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000072#include <sys/time.h>
73#include <errno.h>
74
75#ifdef STDC_HEADERS
76#include <stddef.h>
77#endif /* STDC_HEADERS */
78
John Hughes58265892001-10-18 15:13:53 +000079#ifdef HAVE_SIGINFO_T
80#include <signal.h>
81#endif
82
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000083#if defined(LINUX)
84# if defined(SPARC)
85# define LINUXSPARC
86# endif
87# if defined(ALPHA)
88# define LINUX_64BIT
89# endif
Michal Ludvig0e035502002-09-23 15:41:01 +000090# if defined(X86_64)
91# define LINUX_X86_64
92# endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000093#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000094
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000095#if defined(SVR4) || defined(FREEBSD)
96#define USE_PROCFS
97#else
98#undef USE_PROCFS
99#endif
100
101#ifdef FREEBSD
102#ifndef I386
103#error "FreeBSD support is only for i386 arch right now."
104#endif
105#include <machine/psl.h>
106#include <machine/reg.h>
107#include <sys/syscall.h>
108#endif
109
110#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000111#include <sys/procfs.h>
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000112#ifdef HAVE_MP_PROCFS
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000113#include <sys/uio.h>
114#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000115#ifdef FREEBSD
116#include <sys/pioctl.h>
117#endif /* FREEBSD */
118#else /* !USE_PROCFS */
Michal Ludvig0e035502002-09-23 15:41:01 +0000119#if (defined(LINUXSPARC) || defined (LINUX_X86_64)) && defined(__GLIBC__)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000120#include <sys/ptrace.h>
121#else
122/* Work around awkward prototype in ptrace.h. */
123#define ptrace xptrace
124#include <sys/ptrace.h>
125#undef ptrace
126#ifdef POWERPC
127#define __KERNEL__
128#include <asm/ptrace.h>
129#undef __KERNEL__
130/* TEMP */
131#define UESP PT_R1
132#define EIP PT_NIP
133#define EAX PT_R3
134#define ORIG_EAX PT_ORIG_R3
135#endif
136#ifdef __STDC__
137#ifdef LINUX
138extern long ptrace(int, int, char *, long);
139#else /* !LINUX */
140extern int ptrace(int, int, char *, int, ...);
141#endif /* !LINUX */
142#else /* !__STDC__ */
143extern int ptrace();
144#endif /* !__STDC__ */
145#endif /* !LINUXSPARC */
146#endif /* !SVR4 */
147
148#ifdef LINUX
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000149#if !defined(__GLIBC__)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150#define PTRACE_PEEKUSER PTRACE_PEEKUSR
151#define PTRACE_POKEUSER PTRACE_POKEUSR
152#endif
153#ifdef ALPHA
Wichert Akkermanf90da011999-10-31 21:15:38 +0000154# define REG_R0 0
155# define REG_A0 16
156# define REG_A3 19
157# define REG_FP 30
158# define REG_PC 64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159#endif /* ALPHA */
Wichert Akkermanf90da011999-10-31 21:15:38 +0000160#ifdef MIPS
161# define REG_V0 2
162# define REG_A0 4
163# define REG_A3 7
164# define REG_SP 29
165# define REG_EPC 64
166#endif /* MIPS */
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000167#ifdef HPPA
168# define PT_GR20 (20*4)
169# define PT_GR26 (26*4)
170# define PT_GR28 (28*4)
171# define PT_IAOQ0 (106*4)
172# define PT_IAOQ1 (107*4)
173#endif /* HPPA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174#endif /* LINUX */
175
176#define SUPPORTED_PERSONALITIES 1
177#define DEFAULT_PERSONALITY 0
178
179#ifdef LINUXSPARC
180#include <linux/a.out.h>
181#include <asm/psr.h>
182#undef SUPPORTED_PERSONALITIES
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000183#define SUPPORTED_PERSONALITIES 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184#endif /* LINUXSPARC */
185
Michal Ludvig0e035502002-09-23 15:41:01 +0000186#ifdef X86_64
187#undef SUPPORTED_PERSONALITIES
188#define SUPPORTED_PERSONALITIES 2
189#endif
190
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000191#ifdef SVR4
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000192#ifdef HAVE_MP_PROCFS
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000193extern int mp_ioctl (int f, int c, void *a, int s);
194#define IOCTL(f,c,a) mp_ioctl (f, c, a, sizeof *a)
195#define IOCTL_STATUS(t) \
196 pread (t->pfd_stat, &t->status, sizeof t->status, 0)
197#define IOCTL_WSTOP(t) \
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000198 (IOCTL (t->pfd, PCWSTOP, (char *)NULL) < 0 ? -1 : \
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000199 IOCTL_STATUS (t))
200#define PR_WHY pr_lwp.pr_why
201#define PR_WHAT pr_lwp.pr_what
202#define PR_REG pr_lwp.pr_context.uc_mcontext.gregs
203#define PR_FLAGS pr_lwp.pr_flags
John Hughes25299712001-03-06 10:10:06 +0000204#define PR_SYSCALL pr_lwp.pr_syscall
John Hughes58265892001-10-18 15:13:53 +0000205#define PR_INFO pr_lwp.pr_info
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000206#define PIOCSTIP PCSTOP
207#define PIOCSET PCSET
208#define PIOCRESET PCRESET
209#define PIOCSTRACE PCSTRACE
210#define PIOCSFAULT PCSFAULT
211#define PIOCWSTOP PCWSTOP
212#define PIOCSTOP PCSTOP
213#define PIOCSENTRY PCSENTRY
214#define PIOCSEXIT PCSEXIT
215#define PIOCRUN PCRUN
216#else
217#define IOCTL ioctl
218#define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status)
219#define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWSTOP, &t->status)
220#define PR_WHY pr_why
221#define PR_WHAT pr_what
222#define PR_REG pr_reg
223#define PR_FLAGS pr_flags
John Hughes25299712001-03-06 10:10:06 +0000224#define PR_SYSCALL pr_syscall
John Hughes58265892001-10-18 15:13:53 +0000225#define PR_INFO pr_info
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000226#endif
227#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000228#ifdef FREEBSD
229#define IOCTL ioctl
230#define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status)
231#define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWAIT, &t->status)
232#define PIOCRUN PIOCCONT
233#define PIOCWSTOP PIOCWAIT
234#define PR_WHY why
235#define PR_WHAT val
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000236#define PR_FLAGS state
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000237/* from /usr/src/sys/miscfs/procfs/procfs_vnops.c,
238 status.state = 0 for running, 1 for stopped */
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000239#define PR_ASLEEP 1
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000240#define PR_SYSENTRY S_SCE
241#define PR_SYSEXIT S_SCX
242#define PR_SIGNALLED S_SIG
243#define PR_FAULTED S_CORE
244#endif
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000245
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000246/* Trace Control Block */
247struct tcb {
248 short flags; /* See below for TCB_ values */
249 int pid; /* Process Id of this entry */
250 long scno; /* System call number */
251 int u_nargs; /* System call arguments */
252 long u_arg[MAX_ARGS]; /* System call arguments */
253 int u_error; /* Error code */
254 long u_rval; /* (first) return value */
Wichert Akkerman16a03d22000-08-10 02:14:04 +0000255#ifdef HAVE_LONG_LONG
256 long long u_lrval; /* long long return value */
257#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000258 FILE *outf; /* Output file for this process */
Wichert Akkerman43a74822000-06-27 17:33:32 +0000259 const char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000260 struct timeval stime; /* System time usage as of last process wait */
261 struct timeval dtime; /* Delta for system time usage */
262 struct timeval etime; /* Syscall entry time */
263 /* Support for tracing forked processes */
264 struct tcb *parent; /* Parent of this process */
265 int nchildren; /* # of traced children */
266 int waitpid; /* pid(s) this process is waiting for */
267 /* (1st arg of wait4()) */
268 long baddr; /* `Breakpoint' address */
269 long inst[2]; /* Instructions on above */
270 int pfd; /* proc file descriptor */
271#ifdef SVR4
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000272#ifdef HAVE_MP_PROCFS
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000273 int pfd_stat;
274 int pfd_as;
275 pstatus_t status;
276#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277 prstatus_t status; /* procfs status structure */
278#endif
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000279#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000280#ifdef FREEBSD
281 struct procfs_status status;
282 int pfd_reg;
283 int pfd_status;
284#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000285};
286
287/* TCB flags */
288#define TCB_STARTUP 00001 /* We have just begun ptracing this process */
289#define TCB_INUSE 00002 /* This table entry is in use */
290#define TCB_INSYSCALL 00004 /* A system call is in progress */
291#define TCB_ATTACHED 00010 /* Process is not our own child */
292#define TCB_EXITING 00020 /* As far as we know, this process is exiting */
293#define TCB_SUSPENDED 00040 /* Process has done a wait(4), that can
294 not be allowed to complete just now */
295#define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */
296#define TCB_SIGTRAPPED 00200 /* Process wanted to block SIGTRAP */
297#define TCB_FOLLOWFORK 00400 /* Process should have forks followed */
298#define TCB_REPRINT 01000 /* We should reprint this syscall on exit */
299#ifdef LINUX
Wichert Akkermanccef6372002-05-01 16:39:22 +0000300# if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000301# define TCB_WAITEXECVE 02000 /* ignore SIGTRAP after exceve */
302# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000303#endif /* LINUX */
304
305/* qualifier flags */
306#define QUAL_TRACE 0001 /* this system call should be traced */
307#define QUAL_ABBREV 0002 /* abbreviate the structures of this syscall */
308#define QUAL_VERBOSE 0004 /* decode the structures of this syscall */
309#define QUAL_RAW 0010 /* print all args in hex for this syscall */
310#define QUAL_SIGNAL 0020 /* report events with this signal */
311#define QUAL_FAULT 0040 /* report events with this fault */
312#define QUAL_READ 0100 /* dump data read on this file descriptor */
313#define QUAL_WRITE 0200 /* dump data written to this file descriptor */
314
315#define entering(tcp) (!((tcp)->flags & TCB_INSYSCALL))
316#define exiting(tcp) ((tcp)->flags & TCB_INSYSCALL)
317#define syserror(tcp) ((tcp)->u_error != 0)
318#define verbose(tcp) (qual_flags[(tcp)->scno] & QUAL_VERBOSE)
319#define abbrev(tcp) (qual_flags[(tcp)->scno] & QUAL_ABBREV)
320#define waiting_parent(tcp) \
321 (tcp->parent && \
322 (tcp->parent->flags & TCB_SUSPENDED) && \
323 (tcp->parent->waitpid <= 0 || tcp->parent->waitpid == tcp->pid))
324
325struct xlat {
326 int val;
327 char *str;
328};
329
330/* Format of syscall return values */
331#define RVAL_DECIMAL 000 /* decimal format */
332#define RVAL_HEX 001 /* hex format */
333#define RVAL_OCTAL 002 /* octal format */
334#define RVAL_UDECIMAL 003 /* unsigned decimal format */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000335#define RVAL_LDECIMAL 004 /* long decimal format */
336#define RVAL_LHEX 005 /* long hex format */
337#define RVAL_LOCTAL 006 /* long octal format */
338#define RVAL_LUDECIMAL 007 /* long unsigned decimal format */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000339#define RVAL_MASK 007 /* mask for these values */
340
341#define RVAL_STR 010 /* Print `auxstr' field after return val */
342#define RVAL_NONE 020 /* Print nothing */
343
344#ifndef offsetof
345#define offsetof(type, member) (((char *) &(((type *) NULL)->member)) - \
346 ((char *) (type *) NULL))
347#endif /* !offsetof */
348
349/* get offset of member within a user struct */
350#define uoff(member) offsetof(struct user, member)
351
352#define TRACE_FILE 001 /* Trace file-related syscalls. */
353#define TRACE_IPC 002 /* Trace IPC-related syscalls. */
354#define TRACE_NETWORK 004 /* Trace network-related syscalls. */
355#define TRACE_PROCESS 010 /* Trace process-related syscalls. */
356#define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */
357
358extern struct tcb tcbtab[];
359extern int qual_flags[];
360extern int debug, followfork, followvfork;
361extern int rflag, tflag, dtime, cflag, xflag, qflag;
362extern int acolumn;
363extern char *outfname;
364extern int nprocs;
365extern int max_strlen;
366extern struct tcb *tcp_last;
367
368#ifdef __STDC__
369#define P(args) args
370#else
371#define P(args) ()
372#endif
373
374extern int set_personality P((int personality));
375extern char *xlookup P((struct xlat *, int));
376extern struct tcb *alloctcb P((int));
377extern void droptcb P((struct tcb *));
378
379extern void set_sortby P((char *));
380extern void set_overhead P((int));
381extern void qualify P((char *));
382extern void newoutf P((struct tcb *));
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000383extern int get_scno P((struct tcb *));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384extern int trace_syscall P((struct tcb *));
385extern void printxval P((struct xlat *, int, char *));
386extern int printargs P((struct tcb *));
387extern int addflags P((struct xlat *, int));
388extern int printflags P((struct xlat *, int));
389extern int umoven P((struct tcb *, long, int, char *));
390extern int umovestr P((struct tcb *, long, int, char *));
391extern int upeek P((int, long, long *));
John Hughes1d08dcf2001-07-10 13:48:44 +0000392extern void dumpiov P((struct tcb *, int, long));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000393extern void dumpstr P((struct tcb *, long, int));
394extern void string_quote P((char *str));
395extern void printstr P((struct tcb *, long, int));
396extern void printnum P((struct tcb *, long, char *));
397extern void printpath P((struct tcb *, long));
398extern void printpathn P((struct tcb *, long, int));
399extern void printtv P((struct tcb *, long));
John Hughes58265892001-10-18 15:13:53 +0000400#ifdef HAVE_SIGINFO_T
401extern void printsiginfo P((siginfo_t *, int));
402#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000403extern void printsock P((struct tcb *, long, int));
John Hughes38ae88d2002-05-23 11:48:58 +0000404extern void print_sock_optmgmt P((struct tcb *, long, int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000405extern void printrusage P((struct tcb *, long));
406extern int clearbpt P((struct tcb *));
407extern int setbpt P((struct tcb *));
408extern int sigishandled P((struct tcb *, int));
409extern void printcall P((struct tcb *));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000410extern char *signame P((int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000411extern void printsignal P((int));
412extern void printleader P((struct tcb *));
413extern void printtrailer P((struct tcb *));
414extern void tabto P((int));
415extern void call_summary P((FILE *));
416extern void fake_execve P((struct tcb *, char *, char *[], char *[]));
Wichert Akkerman221f54f1999-11-18 17:26:45 +0000417extern void printtv32 P((struct tcb*, long));
John Hughes1d08dcf2001-07-10 13:48:44 +0000418extern void tprint_iov P((struct tcb *, int, long));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000419
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000420#ifdef LINUX
421extern int internal_clone P((struct tcb *));
422#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000423extern int internal_fork P((struct tcb *));
424extern int internal_exec P((struct tcb *));
425extern int internal_wait P((struct tcb *));
426extern int internal_exit P((struct tcb *));
427
428extern char *ioctl_lookup P((long));
429extern int ioctl_decode P((struct tcb *, long, long));
430extern int term_ioctl P((struct tcb *, long, long));
431extern int sock_ioctl P((struct tcb *, long, long));
432extern int proc_ioctl P((struct tcb *, int, int));
433extern int stream_ioctl P((struct tcb *, int, int));
434
435extern void tv_tv P((struct timeval *, int, int));
436extern int tv_nz P((struct timeval *));
437extern int tv_cmp P((struct timeval *, struct timeval *));
438extern double tv_float P((struct timeval *));
439extern void tv_add P((struct timeval *, struct timeval *, struct timeval *));
440extern void tv_sub P((struct timeval *, struct timeval *, struct timeval *));
441extern void tv_mul P((struct timeval *, struct timeval *, int));
442extern void tv_div P((struct timeval *, struct timeval *, int));
443
444#ifdef SUNOS4
445extern int fixvfork P((struct tcb *));
446#endif
447#if !(defined(LINUX) && !defined(SPARC))
448extern long getrval2 P((struct tcb *));
449#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000450#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000451extern int proc_open P((struct tcb *tcp, int attaching));
452#endif
453
454#define umove(pid, addr, objp) \
455 umoven((pid), (addr), sizeof *(objp), (char *) (objp))
456
457#ifdef __STDC__
458#ifdef __GNUC__
459extern void tprintf(const char *fmt, ...)
460 __attribute__ ((format (printf, 1, 2)));
461#else
462extern void tprintf(const char *fmt, ...);
463#endif
464#else
465extern void tprintf();
466#endif
467
468#ifndef HAVE_STRERROR
469const char *strerror P((int));
470#endif
471#ifndef HAVE_STRSIGNAL
472const char *strsignal P((int));
473#endif
474
475extern int current_personality;
476
477struct sysent {
478 int nargs;
479 int sys_flags;
480 int (*sys_func)();
481 char *sys_name;
482};
483
484extern struct sysent *sysent;
485extern int nsyscalls;
486
487extern char **errnoent;
488extern int nerrnos;
489
490struct ioctlent {
491 char *doth;
492 char *symbol;
493 unsigned long code;
494};
495
496extern struct ioctlent *ioctlent;
497extern int nioctlent;
498
499extern char **signalent;
500extern int nsignals;
501
502extern struct ioctlent *ioctlent;
503extern int nioctlents;
504extern char **signalent;
505extern int nsignals;
506
507extern struct ioctlent ioctlent0[];
508extern int nioctlents0;
509extern char *signalent0[];
510extern int nsignals0;
511
512#if SUPPORTED_PERSONALITIES >= 2
513extern struct ioctlent ioctlent1[];
514extern int nioctlents1;
515extern char *signalent1[];
516extern int nsignals1;
517#endif /* SUPPORTED_PERSONALITIES >= 2 */
518
519#if SUPPORTED_PERSONALITIES >= 3
520extern struct ioctlent ioctlent2[];
521extern int nioctlents2;
522extern char *signalent2[];
523extern int nsignals2;
524#endif /* SUPPORTED_PERSONALITIES >= 3 */
John Hughesbdf48f52001-03-06 15:08:09 +0000525
John Hughes5a826b82001-03-07 13:21:24 +0000526#if FREEBSD
527/* ARRGH! off_t args are aligned on 64 bit boundaries! */
528#define ALIGN64(tcp,arg) \
529do { \
530 if (arg % 2) \
531 memmove (&tcp->u_arg[arg], &tcp->u_arg[arg + 1], \
532 (tcp->u_nargs - arg - 1) * sizeof tcp->u_arg[0]); \
533} while (0)
534#else
535#define ALIGN64(tcp,arg) do { } while (0)
536#endif
537
John Hughes0c79e012001-03-08 14:40:06 +0000538#if HAVE_LONG_LONG
John Hughes5a826b82001-03-07 13:21:24 +0000539
John Hughesbdf48f52001-03-06 15:08:09 +0000540/* _l refers to the lower numbered u_arg,
541 * _h refers to the higher numbered u_arg
542 */
John Hughes5a826b82001-03-07 13:21:24 +0000543
John Hughesb8a85a42001-03-28 08:05:27 +0000544#if HAVE_LITTLE_ENDIAN_LONG_LONG
John Hughes0c79e012001-03-08 14:40:06 +0000545#define LONG_LONG(_l,_h) \
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000546 ((long long)((unsigned long long)(unsigned)(_l) | ((unsigned long long)(_h)<<32)))
John Hughesbdf48f52001-03-06 15:08:09 +0000547#else
John Hughes0c79e012001-03-08 14:40:06 +0000548#define LONG_LONG(_l,_h) \
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000549 ((long long)((unsigned long long)(unsigned)(_h) | ((unsigned long long)(_l)<<32)))
John Hughesbdf48f52001-03-06 15:08:09 +0000550#endif
551#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000552
553#ifdef IA64
554extern long ia32;
555#endif
Michal Ludvig17f8fb32002-11-06 13:17:21 +0000556
557extern int not_failing_only;