blob: e6b3539ea26b1ec55d01b90001bd262a3bef16bf [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
90#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 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000116#if defined(LINUXSPARC) && defined(__GLIBC__)
117#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__
127/* TEMP */
128#define UESP PT_R1
129#define EIP PT_NIP
130#define EAX PT_R3
131#define ORIG_EAX PT_ORIG_R3
132#endif
133#ifdef __STDC__
134#ifdef LINUX
135extern long ptrace(int, int, char *, long);
136#else /* !LINUX */
137extern int ptrace(int, int, char *, int, ...);
138#endif /* !LINUX */
139#else /* !__STDC__ */
140extern int ptrace();
141#endif /* !__STDC__ */
142#endif /* !LINUXSPARC */
143#endif /* !SVR4 */
144
145#ifdef LINUX
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000146#if !defined(__GLIBC__)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000147#define PTRACE_PEEKUSER PTRACE_PEEKUSR
148#define PTRACE_POKEUSER PTRACE_POKEUSR
149#endif
150#ifdef ALPHA
Wichert Akkermanf90da011999-10-31 21:15:38 +0000151# define REG_R0 0
152# define REG_A0 16
153# define REG_A3 19
154# define REG_FP 30
155# define REG_PC 64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000156#endif /* ALPHA */
Wichert Akkermanf90da011999-10-31 21:15:38 +0000157#ifdef MIPS
158# define REG_V0 2
159# define REG_A0 4
160# define REG_A3 7
161# define REG_SP 29
162# define REG_EPC 64
163#endif /* MIPS */
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000164#ifdef HPPA
165# define PT_GR20 (20*4)
166# define PT_GR26 (26*4)
167# define PT_GR28 (28*4)
168# define PT_IAOQ0 (106*4)
169# define PT_IAOQ1 (107*4)
170#endif /* HPPA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000171#endif /* LINUX */
172
173#define SUPPORTED_PERSONALITIES 1
174#define DEFAULT_PERSONALITY 0
175
176#ifdef LINUXSPARC
177#include <linux/a.out.h>
178#include <asm/psr.h>
179#undef SUPPORTED_PERSONALITIES
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000180#define SUPPORTED_PERSONALITIES 2
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181#endif /* LINUXSPARC */
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)
211#define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWSTOP, &t->status)
212#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 */
259 /* (1st arg of wait4()) */
260 long baddr; /* `Breakpoint' address */
261 long inst[2]; /* Instructions on above */
262 int pfd; /* proc file descriptor */
263#ifdef SVR4
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000264#ifdef HAVE_MP_PROCFS
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000265 int pfd_stat;
266 int pfd_as;
267 pstatus_t status;
268#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000269 prstatus_t status; /* procfs status structure */
270#endif
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000271#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000272#ifdef FREEBSD
273 struct procfs_status status;
274 int pfd_reg;
275 int pfd_status;
276#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277};
278
279/* TCB flags */
280#define TCB_STARTUP 00001 /* We have just begun ptracing this process */
281#define TCB_INUSE 00002 /* This table entry is in use */
282#define TCB_INSYSCALL 00004 /* A system call is in progress */
283#define TCB_ATTACHED 00010 /* Process is not our own child */
284#define TCB_EXITING 00020 /* As far as we know, this process is exiting */
285#define TCB_SUSPENDED 00040 /* Process has done a wait(4), that can
286 not be allowed to complete just now */
287#define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */
288#define TCB_SIGTRAPPED 00200 /* Process wanted to block SIGTRAP */
289#define TCB_FOLLOWFORK 00400 /* Process should have forks followed */
290#define TCB_REPRINT 01000 /* We should reprint this syscall on exit */
291#ifdef LINUX
Wichert Akkermanccef6372002-05-01 16:39:22 +0000292# if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000293# define TCB_WAITEXECVE 02000 /* ignore SIGTRAP after exceve */
294# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000295#endif /* LINUX */
296
297/* qualifier flags */
298#define QUAL_TRACE 0001 /* this system call should be traced */
299#define QUAL_ABBREV 0002 /* abbreviate the structures of this syscall */
300#define QUAL_VERBOSE 0004 /* decode the structures of this syscall */
301#define QUAL_RAW 0010 /* print all args in hex for this syscall */
302#define QUAL_SIGNAL 0020 /* report events with this signal */
303#define QUAL_FAULT 0040 /* report events with this fault */
304#define QUAL_READ 0100 /* dump data read on this file descriptor */
305#define QUAL_WRITE 0200 /* dump data written to this file descriptor */
306
307#define entering(tcp) (!((tcp)->flags & TCB_INSYSCALL))
308#define exiting(tcp) ((tcp)->flags & TCB_INSYSCALL)
309#define syserror(tcp) ((tcp)->u_error != 0)
310#define verbose(tcp) (qual_flags[(tcp)->scno] & QUAL_VERBOSE)
311#define abbrev(tcp) (qual_flags[(tcp)->scno] & QUAL_ABBREV)
312#define waiting_parent(tcp) \
313 (tcp->parent && \
314 (tcp->parent->flags & TCB_SUSPENDED) && \
315 (tcp->parent->waitpid <= 0 || tcp->parent->waitpid == tcp->pid))
316
317struct xlat {
318 int val;
319 char *str;
320};
321
322/* Format of syscall return values */
323#define RVAL_DECIMAL 000 /* decimal format */
324#define RVAL_HEX 001 /* hex format */
325#define RVAL_OCTAL 002 /* octal format */
326#define RVAL_UDECIMAL 003 /* unsigned decimal format */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000327#define RVAL_LDECIMAL 004 /* long decimal format */
328#define RVAL_LHEX 005 /* long hex format */
329#define RVAL_LOCTAL 006 /* long octal format */
330#define RVAL_LUDECIMAL 007 /* long unsigned decimal format */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331#define RVAL_MASK 007 /* mask for these values */
332
333#define RVAL_STR 010 /* Print `auxstr' field after return val */
334#define RVAL_NONE 020 /* Print nothing */
335
336#ifndef offsetof
337#define offsetof(type, member) (((char *) &(((type *) NULL)->member)) - \
338 ((char *) (type *) NULL))
339#endif /* !offsetof */
340
341/* get offset of member within a user struct */
342#define uoff(member) offsetof(struct user, member)
343
344#define TRACE_FILE 001 /* Trace file-related syscalls. */
345#define TRACE_IPC 002 /* Trace IPC-related syscalls. */
346#define TRACE_NETWORK 004 /* Trace network-related syscalls. */
347#define TRACE_PROCESS 010 /* Trace process-related syscalls. */
348#define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */
349
350extern struct tcb tcbtab[];
351extern int qual_flags[];
352extern int debug, followfork, followvfork;
353extern int rflag, tflag, dtime, cflag, xflag, qflag;
354extern int acolumn;
355extern char *outfname;
356extern int nprocs;
357extern int max_strlen;
358extern struct tcb *tcp_last;
359
360#ifdef __STDC__
361#define P(args) args
362#else
363#define P(args) ()
364#endif
365
366extern int set_personality P((int personality));
367extern char *xlookup P((struct xlat *, int));
368extern struct tcb *alloctcb P((int));
369extern void droptcb P((struct tcb *));
370
371extern void set_sortby P((char *));
372extern void set_overhead P((int));
373extern void qualify P((char *));
374extern void newoutf P((struct tcb *));
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000375extern int get_scno P((struct tcb *));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376extern int trace_syscall P((struct tcb *));
377extern void printxval P((struct xlat *, int, char *));
378extern int printargs P((struct tcb *));
379extern int addflags P((struct xlat *, int));
380extern int printflags P((struct xlat *, int));
381extern int umoven P((struct tcb *, long, int, char *));
382extern int umovestr P((struct tcb *, long, int, char *));
383extern int upeek P((int, long, long *));
John Hughes1d08dcf2001-07-10 13:48:44 +0000384extern void dumpiov P((struct tcb *, int, long));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000385extern void dumpstr P((struct tcb *, long, int));
386extern void string_quote P((char *str));
387extern void printstr P((struct tcb *, long, int));
388extern void printnum P((struct tcb *, long, char *));
389extern void printpath P((struct tcb *, long));
390extern void printpathn P((struct tcb *, long, int));
391extern void printtv P((struct tcb *, long));
John Hughes58265892001-10-18 15:13:53 +0000392#ifdef HAVE_SIGINFO_T
393extern void printsiginfo P((siginfo_t *, int));
394#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000395extern void printsock P((struct tcb *, long, int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000396extern void printrusage P((struct tcb *, long));
397extern int clearbpt P((struct tcb *));
398extern int setbpt P((struct tcb *));
399extern int sigishandled P((struct tcb *, int));
400extern void printcall P((struct tcb *));
Nate Sammonsce780fc1999-03-29 23:23:13 +0000401extern char *signame P((int));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402extern void printsignal P((int));
403extern void printleader P((struct tcb *));
404extern void printtrailer P((struct tcb *));
405extern void tabto P((int));
406extern void call_summary P((FILE *));
407extern void fake_execve P((struct tcb *, char *, char *[], char *[]));
Wichert Akkerman221f54f1999-11-18 17:26:45 +0000408extern void printtv32 P((struct tcb*, long));
John Hughes1d08dcf2001-07-10 13:48:44 +0000409extern void tprint_iov P((struct tcb *, int, long));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000410
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000411#ifdef LINUX
412extern int internal_clone P((struct tcb *));
413#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000414extern int internal_fork P((struct tcb *));
415extern int internal_exec P((struct tcb *));
416extern int internal_wait P((struct tcb *));
417extern int internal_exit P((struct tcb *));
418
419extern char *ioctl_lookup P((long));
420extern int ioctl_decode P((struct tcb *, long, long));
421extern int term_ioctl P((struct tcb *, long, long));
422extern int sock_ioctl P((struct tcb *, long, long));
423extern int proc_ioctl P((struct tcb *, int, int));
424extern int stream_ioctl P((struct tcb *, int, int));
425
426extern void tv_tv P((struct timeval *, int, int));
427extern int tv_nz P((struct timeval *));
428extern int tv_cmp P((struct timeval *, struct timeval *));
429extern double tv_float P((struct timeval *));
430extern void tv_add P((struct timeval *, struct timeval *, struct timeval *));
431extern void tv_sub P((struct timeval *, struct timeval *, struct timeval *));
432extern void tv_mul P((struct timeval *, struct timeval *, int));
433extern void tv_div P((struct timeval *, struct timeval *, int));
434
435#ifdef SUNOS4
436extern int fixvfork P((struct tcb *));
437#endif
438#if !(defined(LINUX) && !defined(SPARC))
439extern long getrval2 P((struct tcb *));
440#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000441#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442extern int proc_open P((struct tcb *tcp, int attaching));
443#endif
444
445#define umove(pid, addr, objp) \
446 umoven((pid), (addr), sizeof *(objp), (char *) (objp))
447
448#ifdef __STDC__
449#ifdef __GNUC__
450extern void tprintf(const char *fmt, ...)
451 __attribute__ ((format (printf, 1, 2)));
452#else
453extern void tprintf(const char *fmt, ...);
454#endif
455#else
456extern void tprintf();
457#endif
458
459#ifndef HAVE_STRERROR
460const char *strerror P((int));
461#endif
462#ifndef HAVE_STRSIGNAL
463const char *strsignal P((int));
464#endif
465
466extern int current_personality;
467
468struct sysent {
469 int nargs;
470 int sys_flags;
471 int (*sys_func)();
472 char *sys_name;
473};
474
475extern struct sysent *sysent;
476extern int nsyscalls;
477
478extern char **errnoent;
479extern int nerrnos;
480
481struct ioctlent {
482 char *doth;
483 char *symbol;
484 unsigned long code;
485};
486
487extern struct ioctlent *ioctlent;
488extern int nioctlent;
489
490extern char **signalent;
491extern int nsignals;
492
493extern struct ioctlent *ioctlent;
494extern int nioctlents;
495extern char **signalent;
496extern int nsignals;
497
498extern struct ioctlent ioctlent0[];
499extern int nioctlents0;
500extern char *signalent0[];
501extern int nsignals0;
502
503#if SUPPORTED_PERSONALITIES >= 2
504extern struct ioctlent ioctlent1[];
505extern int nioctlents1;
506extern char *signalent1[];
507extern int nsignals1;
508#endif /* SUPPORTED_PERSONALITIES >= 2 */
509
510#if SUPPORTED_PERSONALITIES >= 3
511extern struct ioctlent ioctlent2[];
512extern int nioctlents2;
513extern char *signalent2[];
514extern int nsignals2;
515#endif /* SUPPORTED_PERSONALITIES >= 3 */
John Hughesbdf48f52001-03-06 15:08:09 +0000516
John Hughes5a826b82001-03-07 13:21:24 +0000517#if FREEBSD
518/* ARRGH! off_t args are aligned on 64 bit boundaries! */
519#define ALIGN64(tcp,arg) \
520do { \
521 if (arg % 2) \
522 memmove (&tcp->u_arg[arg], &tcp->u_arg[arg + 1], \
523 (tcp->u_nargs - arg - 1) * sizeof tcp->u_arg[0]); \
524} while (0)
525#else
526#define ALIGN64(tcp,arg) do { } while (0)
527#endif
528
John Hughes0c79e012001-03-08 14:40:06 +0000529#if HAVE_LONG_LONG
John Hughes5a826b82001-03-07 13:21:24 +0000530
John Hughesbdf48f52001-03-06 15:08:09 +0000531/* _l refers to the lower numbered u_arg,
532 * _h refers to the higher numbered u_arg
533 */
John Hughes5a826b82001-03-07 13:21:24 +0000534
John Hughesb8a85a42001-03-28 08:05:27 +0000535#if HAVE_LITTLE_ENDIAN_LONG_LONG
John Hughes0c79e012001-03-08 14:40:06 +0000536#define LONG_LONG(_l,_h) \
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000537 ((long long)((unsigned long long)(unsigned)(_l) | ((unsigned long long)(_h)<<32)))
John Hughesbdf48f52001-03-06 15:08:09 +0000538#else
John Hughes0c79e012001-03-08 14:40:06 +0000539#define LONG_LONG(_l,_h) \
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000540 ((long long)((unsigned long long)(unsigned)(_h) | ((unsigned long long)(_l)<<32)))
John Hughesbdf48f52001-03-06 15:08:09 +0000541#endif
542#endif
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000543
544#ifdef IA64
545extern long ia32;
546#endif