]> granicus.if.org Git - strace/blob - defs.h
Change number of personalities for Linux sparc to 2
[strace] / defs.h
1 /*
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
32 #ifdef linux
33 #include <features.h>
34 #endif
35
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 /* configuration section */
41 #ifndef MAX_QUALS
42 #define MAX_QUALS       1024    /* maximum number of syscalls, signals, etc. */
43 #endif
44 #ifndef MAX_PROCS
45 #define MAX_PROCS       32      /* maximum number of processes tracable */
46 #endif
47 #ifndef DEFAULT_STRLEN
48 #define DEFAULT_STRLEN  32      /* default maximum # of bytes printed in
49                                   `printstr', change with `-s' switch */
50 #endif
51 #ifndef DEFAULT_ACOLUMN
52 #define DEFAULT_ACOLUMN 40      /* default alignment column for results */
53 #endif
54 #ifndef MAX_ARGS
55 #define MAX_ARGS        32      /* maximum number of args to a syscall */
56 #endif
57 #ifndef DEFAULT_SORTBY
58 #define DEFAULT_SORTBY "time"   /* default sorting method for call profiling */
59 #endif
60
61 #include <sys/types.h>
62 #include <unistd.h>
63 #include <stdlib.h>
64 #include <stdio.h>
65 #include <ctype.h>
66 #include <string.h>
67 #include <sys/time.h>
68 #include <errno.h>
69
70 #ifdef STDC_HEADERS
71 #include <stddef.h>
72 #endif /* STDC_HEADERS */
73
74 #if defined(LINUX) && defined(SPARC)
75 #define LINUXSPARC
76 #endif /* LINUX && SPARC */
77
78 #ifdef SVR4
79 #include <sys/procfs.h>
80 #else /* !SVR4 */
81 #if defined(LINUXSPARC) && defined(__GLIBC__)
82 #include <sys/ptrace.h>
83 #else
84 /* Work around awkward prototype in ptrace.h. */
85 #define ptrace xptrace
86 #include <sys/ptrace.h>
87 #undef ptrace
88 #ifdef POWERPC
89 #define __KERNEL__
90 #include <asm/ptrace.h>
91 #undef __KERNEL__
92 /* TEMP */
93 #define UESP    PT_R1
94 #define EIP     PT_NIP
95 #define EAX     PT_R3
96 #define ORIG_EAX PT_ORIG_R3
97 #endif
98 #ifdef __STDC__
99 #ifdef LINUX
100 extern long ptrace(int, int, char *, long);
101 #else /* !LINUX */
102 extern int ptrace(int, int, char *, int, ...);
103 #endif /* !LINUX */
104 #else /* !__STDC__ */
105 extern int ptrace();
106 #endif /* !__STDC__ */
107 #endif /* !LINUXSPARC */
108 #endif /* !SVR4 */
109
110 #ifdef LINUX
111 #if !defined(__GLIBC__)
112 #define PTRACE_PEEKUSER PTRACE_PEEKUSR
113 #define PTRACE_POKEUSER PTRACE_POKEUSR
114 #endif
115 #ifdef ALPHA
116 #define REG_R0 0
117 #define REG_A0 16
118 #define REG_A3 19
119 #define REG_FP 30
120 #define REG_PC 64
121 #endif /* ALPHA */
122 #endif /* LINUX */
123
124 #define SUPPORTED_PERSONALITIES 1
125 #define DEFAULT_PERSONALITY 0
126
127 #ifdef LINUXSPARC
128 #include <linux/a.out.h>
129 #include <asm/psr.h>
130 #undef  SUPPORTED_PERSONALITIES
131 #define SUPPORTED_PERSONALITIES 2
132 #endif /* LINUXSPARC */
133
134 /* Trace Control Block */
135 struct tcb {
136         short flags;            /* See below for TCB_ values */
137         int pid;                /* Process Id of this entry */
138         long scno;              /* System call number */
139         int u_nargs;            /* System call arguments */
140         long u_arg[MAX_ARGS];   /* System call arguments */
141         int u_error;            /* Error code */
142         long u_rval;            /* (first) return value */
143         FILE *outf;             /* Output file for this process */
144         char *auxstr;           /* Auxiliary info from syscall (see RVAL_STR) */
145         struct timeval stime;   /* System time usage as of last process wait */
146         struct timeval dtime;   /* Delta for system time usage */
147         struct timeval etime;   /* Syscall entry time */
148                                 /* Support for tracing forked processes */
149         struct tcb *parent;     /* Parent of this process */
150         int nchildren;          /* # of traced children */
151         int waitpid;            /* pid(s) this process is waiting for */
152                                 /* (1st arg of wait4()) */
153         long baddr;             /* `Breakpoint' address */
154         long inst[2];           /* Instructions on above */
155         int pfd;                /* proc file descriptor */
156 #ifdef SVR4
157         prstatus_t status;      /* procfs status structure */
158 #endif
159 };
160
161 /* TCB flags */
162 #define TCB_STARTUP     00001   /* We have just begun ptracing this process */
163 #define TCB_INUSE       00002   /* This table entry is in use */
164 #define TCB_INSYSCALL   00004   /* A system call is in progress */
165 #define TCB_ATTACHED    00010   /* Process is not our own child */
166 #define TCB_EXITING     00020   /* As far as we know, this process is exiting */
167 #define TCB_SUSPENDED   00040   /* Process has done a wait(4), that can
168                                    not be allowed to complete just now */
169 #define TCB_BPTSET      00100   /* "Breakpoint" set after fork(2) */
170 #define TCB_SIGTRAPPED  00200   /* Process wanted to block SIGTRAP */
171 #define TCB_FOLLOWFORK  00400   /* Process should have forks followed */
172 #define TCB_REPRINT     01000   /* We should reprint this syscall on exit */
173 #ifdef LINUX
174 #if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
175 #define TCB_WAITEXECVE  02000   /* ignore SIGTRAP after exceve */
176 #endif /* ALPHA */
177 #endif /* LINUX */
178
179 /* qualifier flags */
180 #define QUAL_TRACE      0001    /* this system call should be traced */
181 #define QUAL_ABBREV     0002    /* abbreviate the structures of this syscall */
182 #define QUAL_VERBOSE    0004    /* decode the structures of this syscall */
183 #define QUAL_RAW        0010    /* print all args in hex for this syscall */
184 #define QUAL_SIGNAL     0020    /* report events with this signal */
185 #define QUAL_FAULT      0040    /* report events with this fault */
186 #define QUAL_READ       0100    /* dump data read on this file descriptor */
187 #define QUAL_WRITE      0200    /* dump data written to this file descriptor */
188
189 #define entering(tcp)   (!((tcp)->flags & TCB_INSYSCALL))
190 #define exiting(tcp)    ((tcp)->flags & TCB_INSYSCALL)
191 #define syserror(tcp)   ((tcp)->u_error != 0)
192 #define verbose(tcp)    (qual_flags[(tcp)->scno] & QUAL_VERBOSE)
193 #define abbrev(tcp)     (qual_flags[(tcp)->scno] & QUAL_ABBREV)
194 #define waiting_parent(tcp) \
195                 (tcp->parent && \
196                 (tcp->parent->flags & TCB_SUSPENDED) && \
197                 (tcp->parent->waitpid <= 0 || tcp->parent->waitpid == tcp->pid))
198
199 struct xlat {
200         int val;
201         char *str;
202 };
203
204 /* Format of syscall return values */
205 #define RVAL_DECIMAL    000     /* decimal format */
206 #define RVAL_HEX        001     /* hex format */
207 #define RVAL_OCTAL      002     /* octal format */
208 #define RVAL_UDECIMAL   003     /* unsigned decimal format */
209 #define RVAL_MASK       007     /* mask for these values */
210
211 #define RVAL_STR        010     /* Print `auxstr' field after return val */
212 #define RVAL_NONE       020     /* Print nothing */
213
214 #ifndef offsetof
215 #define offsetof(type, member)  (((char *) &(((type *) NULL)->member)) - \
216                                  ((char *) (type *) NULL))
217 #endif /* !offsetof */
218
219 /* get offset of member within a user struct */
220 #define uoff(member)    offsetof(struct user, member)
221
222 #define TRACE_FILE      001     /* Trace file-related syscalls. */
223 #define TRACE_IPC       002     /* Trace IPC-related syscalls. */
224 #define TRACE_NETWORK   004     /* Trace network-related syscalls. */
225 #define TRACE_PROCESS   010     /* Trace process-related syscalls. */
226 #define TRACE_SIGNAL    020     /* Trace signal-related syscalls. */
227
228 extern struct tcb tcbtab[];
229 extern int qual_flags[];
230 extern int debug, followfork, followvfork;
231 extern int rflag, tflag, dtime, cflag, xflag, qflag;
232 extern int acolumn;
233 extern char *outfname;
234 extern int nprocs;
235 extern int max_strlen;
236 extern struct tcb *tcp_last;
237
238 #ifdef __STDC__
239 #define P(args) args
240 #else
241 #define P(args) ()
242 #endif
243
244 extern int set_personality P((int personality));
245 extern char *xlookup P((struct xlat *, int));
246 extern struct tcb *alloctcb P((int));
247 extern void droptcb P((struct tcb *));
248
249 extern void set_sortby P((char *));
250 extern void set_overhead P((int));
251 extern void qualify P((char *));
252 extern void newoutf P((struct tcb *));
253 extern int trace_syscall P((struct tcb *));
254 extern void printxval P((struct xlat *, int, char *));
255 extern int printargs P((struct tcb *));
256 extern int addflags P((struct xlat *, int));
257 extern int printflags P((struct xlat *, int));
258 extern int umoven P((struct tcb *, long, int, char *));
259 extern int umovestr P((struct tcb *, long, int, char *));
260 extern int upeek P((int, long, long *));
261 extern void dumpstr P((struct tcb *, long, int));
262 extern void string_quote P((char *str));
263 extern void printstr P((struct tcb *, long, int));
264 extern void printnum P((struct tcb *, long, char *));
265 extern void printpath P((struct tcb *, long));
266 extern void printpathn P((struct tcb *, long, int));
267 extern void printtv P((struct tcb *, long));
268 extern void printsock P((struct tcb *, long));
269 extern void printrusage P((struct tcb *, long));
270 extern int clearbpt P((struct tcb *));
271 extern int setbpt P((struct tcb *));
272 extern int sigishandled P((struct tcb *, int));
273 extern void printcall P((struct tcb *));
274 extern char *signame P((int));
275 extern void printsignal P((int));
276 extern void printleader P((struct tcb *));
277 extern void printtrailer P((struct tcb *));
278 extern void tabto P((int));
279 extern void call_summary P((FILE *));
280 extern void fake_execve P((struct tcb *, char *, char *[], char *[]));
281
282 extern int internal_fork P((struct tcb *));
283 extern int internal_exec P((struct tcb *));
284 extern int internal_wait P((struct tcb *));
285 extern int internal_exit P((struct tcb *));
286
287 extern char *ioctl_lookup P((long));
288 extern int ioctl_decode P((struct tcb *, long, long));
289 extern int term_ioctl P((struct tcb *, long, long));
290 extern int sock_ioctl P((struct tcb *, long, long));
291 extern int proc_ioctl P((struct tcb *, int, int));
292 extern int stream_ioctl P((struct tcb *, int, int));
293
294 extern void tv_tv P((struct timeval *, int, int));
295 extern int tv_nz P((struct timeval *));
296 extern int tv_cmp P((struct timeval *, struct timeval *));
297 extern double tv_float P((struct timeval *));
298 extern void tv_add P((struct timeval *, struct timeval *, struct timeval *));
299 extern void tv_sub P((struct timeval *, struct timeval *, struct timeval *));
300 extern void tv_mul P((struct timeval *, struct timeval *, int));
301 extern void tv_div P((struct timeval *, struct timeval *, int));
302
303 #ifdef SUNOS4
304 extern int fixvfork P((struct tcb *));
305 #endif
306 #if !(defined(LINUX) && !defined(SPARC))
307 extern long getrval2 P((struct tcb *));
308 #endif
309 #ifdef SVR4
310 extern int proc_open P((struct tcb *tcp, int attaching));
311 #endif
312
313 #define umove(pid, addr, objp)  \
314         umoven((pid), (addr), sizeof *(objp), (char *) (objp))
315
316 #ifdef __STDC__
317 #ifdef __GNUC__
318 extern void tprintf(const char *fmt, ...)
319         __attribute__ ((format (printf, 1, 2)));
320 #else
321 extern void tprintf(const char *fmt, ...);
322 #endif
323 #else
324 extern void tprintf();
325 #endif
326
327 #ifndef HAVE_STRERROR
328 const char *strerror P((int));
329 #endif
330 #ifndef HAVE_STRSIGNAL
331 const char *strsignal P((int));
332 #endif
333
334 extern int current_personality;
335
336 struct sysent {
337         int     nargs;
338         int     sys_flags;
339         int     (*sys_func)();
340         char    *sys_name;
341 };
342
343 extern struct sysent *sysent;
344 extern int nsyscalls;
345
346 extern char **errnoent;
347 extern int nerrnos;
348
349 struct ioctlent {
350         char *doth;
351         char *symbol;
352         unsigned long code;
353 };
354
355 extern struct ioctlent *ioctlent;
356 extern int nioctlent;
357
358 extern char **signalent;
359 extern int nsignals;
360
361 extern struct ioctlent *ioctlent;
362 extern int nioctlents;
363 extern char **signalent;
364 extern int nsignals;
365
366 extern struct ioctlent ioctlent0[];
367 extern int nioctlents0;
368 extern char *signalent0[];
369 extern int nsignals0;
370
371 #if SUPPORTED_PERSONALITIES >= 2
372 extern struct ioctlent ioctlent1[];
373 extern int nioctlents1;
374 extern char *signalent1[];
375 extern int nsignals1;
376 #endif /* SUPPORTED_PERSONALITIES >= 2 */
377
378 #if SUPPORTED_PERSONALITIES >= 3
379 extern struct ioctlent ioctlent2[];
380 extern int nioctlents2;
381 extern char *signalent2[];
382 extern int nsignals2;
383 #endif /* SUPPORTED_PERSONALITIES >= 3 */