blob: 8c9065119950d52b1b17ff89f06abd4ff91b4b44 [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>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Linux for s390 port by D.J. Barrow
8 * <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com>
Wichert Akkermanccef6372002-05-01 16:39:22 +00009 * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
10 * port by Greg Banks <gbanks@pocketpenguins.com>
11
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +000012 *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000013 * All rights reserved.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. The name of the author may not be used to endorse or promote products
24 * derived from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * $Id$
38 */
39
40#include "defs.h"
41
42#include <fcntl.h>
43#include <sys/stat.h>
44#include <sys/time.h>
45#include <sys/wait.h>
46#include <sys/resource.h>
47#include <sys/utsname.h>
48#include <sys/user.h>
49#include <sys/syscall.h>
50#include <signal.h>
51#ifdef SUNOS4
52#include <machine/reg.h>
53#endif /* SUNOS4 */
54
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000055#ifdef FREEBSD
56#include <sys/ptrace.h>
57#endif
58
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000059#if HAVE_ASM_REG_H
60#ifdef SPARC
61# define fpq kernel_fpq
62# define fq kernel_fq
63# define fpu kernel_fpu
64#endif
65#include <asm/reg.h>
66#ifdef SPARC
67# undef fpq
68# undef fq
69# undef fpu
70#endif
71#endif /* HAVE_ASM_REG_H */
72
Wichert Akkerman36915a11999-07-13 15:45:02 +000073#ifdef HAVE_SYS_REG_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074# include <sys/reg.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000075#ifndef PTRACE_PEEKUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000076# define PTRACE_PEEKUSR PTRACE_PEEKUSER
Wichert Akkerman15dea971999-10-06 13:06:34 +000077#endif
78#ifndef PTRACE_POKEUSR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000079# define PTRACE_POKEUSR PTRACE_POKEUSER
80#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +000081#elif defined(HAVE_LINUX_PTRACE_H)
82#undef PTRACE_SYSCALL
83#include <linux/ptrace.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000084#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000085
Wichert Akkermanfaf72222000-02-19 23:59:03 +000086
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000087#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000088#include <asm/posix_types.h>
89#undef GETGROUPS_T
90#define GETGROUPS_T __kernel_gid_t
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000091#endif /* LINUX */
92
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000093#if defined(LINUX) && defined(IA64)
94# include <asm/ptrace_offsets.h>
95# include <asm/rse.h>
96#endif
97
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000098#ifdef HAVE_PRCTL
99#include <sys/prctl.h>
100#endif
101
102#ifndef WCOREDUMP
103#define WCOREDUMP(status) ((status) & 0200)
104#endif
105
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000106/* WTA: this was `&& !defined(LINUXSPARC)', this seems unneeded though? */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000107#if defined(HAVE_PRCTL)
108static struct xlat prctl_options[] = {
109#ifdef PR_MAXPROCS
110 { PR_MAXPROCS, "PR_MAXPROCS" },
111#endif
112#ifdef PR_ISBLOCKED
113 { PR_ISBLOCKED, "PR_ISBLOCKED" },
114#endif
115#ifdef PR_SETSTACKSIZE
116 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
117#endif
118#ifdef PR_GETSTACKSIZE
119 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
120#endif
121#ifdef PR_MAXPPROCS
122 { PR_MAXPPROCS, "PR_MAXPPROCS" },
123#endif
124#ifdef PR_UNBLKONEXEC
125 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
126#endif
127#ifdef PR_ATOMICSIM
128 { PR_ATOMICSIM, "PR_ATOMICSIM" },
129#endif
130#ifdef PR_SETEXITSIG
131 { PR_SETEXITSIG, "PR_SETEXITSIG" },
132#endif
133#ifdef PR_RESIDENT
134 { PR_RESIDENT, "PR_RESIDENT" },
135#endif
136#ifdef PR_ATTACHADDR
137 { PR_ATTACHADDR, "PR_ATTACHADDR" },
138#endif
139#ifdef PR_DETACHADDR
140 { PR_DETACHADDR, "PR_DETACHADDR" },
141#endif
142#ifdef PR_TERMCHILD
143 { PR_TERMCHILD, "PR_TERMCHILD" },
144#endif
145#ifdef PR_GETSHMASK
146 { PR_GETSHMASK, "PR_GETSHMASK" },
147#endif
148#ifdef PR_GETNSHARE
149 { PR_GETNSHARE, "PR_GETNSHARE" },
150#endif
151#if defined(PR_SET_PDEATHSIG)
152 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
153#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000154#ifdef PR_COREPID
155 { PR_COREPID, "PR_COREPID" },
156#endif
157#ifdef PR_ATTACHADDRPERM
158 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
159#endif
160#ifdef PR_PTHREADEXIT
161 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
162#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000163#ifdef PR_SET_PDEATHSIG
164 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
165#endif
166#ifdef PR_GET_PDEATHSIG
167 { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
168#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000169#ifdef PR_GET_UNALIGN
170 { PR_GET_UNALIGN, "PR_GET_UNALIGN" },
171#endif
172#ifdef PR_SET_UNALIGN
173 { PR_SET_UNALIGN, "PR_SET_UNALIGN" },
174#endif
175#ifdef PR_GET_KEEPCAPS
176 { PR_GET_KEEPCAPS, "PR_GET_KEEP_CAPS" },
177#endif
178#ifdef PR_SET_KEEPCAPS
179 { PR_SET_KEEPCAPS, "PR_SET_KEEP_CAPS" },
180#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181 { 0, NULL },
182};
183
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000184
185const char *
186unalignctl_string (unsigned int ctl)
187{
188 static char buf[16];
189
190 switch (ctl) {
191#ifdef PR_UNALIGN_NOPRINT
192 case PR_UNALIGN_NOPRINT:
193 return "NOPRINT";
194#endif
195#ifdef PR_UNALIGN_SIGBUS
196 case PR_UNALIGN_SIGBUS:
197 return "SIGBUS";
198#endif
199 default:
200 break;
201 }
202 sprintf(buf, "%x", ctl);
203 return buf;
204}
205
206
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000207int
208sys_prctl(tcp)
209struct tcb *tcp;
210{
211 int i;
212
213 if (entering(tcp)) {
214 printxval(prctl_options, tcp->u_arg[0], "PR_???");
215 switch (tcp->u_arg[0]) {
216#ifdef PR_GETNSHARE
217 case PR_GETNSHARE:
218 break;
219#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000220#ifdef PR_SET_DEATHSIG
221 case PR_GET_PDEATHSIG:
222 break;
223#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000224#ifdef PR_SET_UNALIGN
225 case PR_SET_UNALIGN:
226 tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
227 break;
228#endif
229#ifdef PR_GET_UNALIGN
230 case PR_GET_UNALIGN:
231 tprintf(", %#lx", tcp->u_arg[1]);
232 break;
233#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234 default:
235 for (i = 1; i < tcp->u_nargs; i++)
236 tprintf(", %#lx", tcp->u_arg[i]);
237 break;
238 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000239 } else {
240 switch (tcp->u_arg[0]) {
241#ifdef PR_GET_PDEATHSIG
242 case PR_GET_PDEATHSIG:
243 for (i=1; i<tcp->u_nargs; i++)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000244 tprintf(", %#lx", tcp->u_arg[i]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000245 break;
246#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000247#ifdef PR_SET_UNALIGN
248 case PR_SET_UNALIGN:
249 break;
250#endif
251#ifdef PR_GET_UNALIGN
252 case PR_GET_UNALIGN:
253 {
254 int ctl;
255
256 umove(tcp, tcp->u_arg[1], &ctl);
257 tcp->auxstr = unalignctl_string(ctl);
258 return RVAL_STR;
259 }
260#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000261 default:
262 break;
263 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000264 }
265 return 0;
266}
267
268#endif /* HAVE_PRCTL */
269
270int
271sys_gethostid(tcp)
272struct tcb *tcp;
273{
274 if (exiting(tcp))
275 return RVAL_HEX;
276 return 0;
277}
278
279int
280sys_sethostname(tcp)
281struct tcb *tcp;
282{
283 if (entering(tcp)) {
284 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
285 tprintf(", %lu", tcp->u_arg[1]);
286 }
287 return 0;
288}
289
290int
291sys_gethostname(tcp)
292struct tcb *tcp;
293{
294 if (exiting(tcp)) {
295 if (syserror(tcp))
296 tprintf("%#lx", tcp->u_arg[0]);
297 else
298 printpath(tcp, tcp->u_arg[0]);
299 tprintf(", %lu", tcp->u_arg[1]);
300 }
301 return 0;
302}
303
304int
305sys_setdomainname(tcp)
306struct tcb *tcp;
307{
308 if (entering(tcp)) {
309 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
310 tprintf(", %lu", tcp->u_arg[1]);
311 }
312 return 0;
313}
314
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000315#if !defined(LINUX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000316
317int
318sys_getdomainname(tcp)
319struct tcb *tcp;
320{
321 if (exiting(tcp)) {
322 if (syserror(tcp))
323 tprintf("%#lx", tcp->u_arg[0]);
324 else
325 printpath(tcp, tcp->u_arg[0]);
326 tprintf(", %lu", tcp->u_arg[1]);
327 }
328 return 0;
329}
330#endif /* !LINUX */
331
332int
333sys_exit(tcp)
334struct tcb *tcp;
335{
336 if (exiting(tcp)) {
337 fprintf(stderr, "_exit returned!\n");
338 return -1;
339 }
340 /* special case: we stop tracing this process, finish line now */
341 tprintf("%ld) ", tcp->u_arg[0]);
342 tabto(acolumn);
343 tprintf("= ?");
344 printtrailer(tcp);
345 return 0;
346}
347
348int
349internal_exit(tcp)
350struct tcb *tcp;
351{
352 if (entering(tcp))
353 tcp->flags |= TCB_EXITING;
354 return 0;
355}
356
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000357#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358
359int
360sys_fork(tcp)
361struct tcb *tcp;
362{
363 if (exiting(tcp)) {
364 if (getrval2(tcp)) {
365 tcp->auxstr = "child process";
366 return RVAL_UDECIMAL | RVAL_STR;
367 }
368 }
369 return 0;
370}
371
John Hughes4e36a812001-04-18 15:11:51 +0000372#if UNIXWARE > 2
373
374int
375sys_rfork(tcp)
376struct tcb *tcp;
377{
378 if (entering(tcp)) {
379 tprintf ("%ld", tcp->u_arg[0]);
380 }
381 else {
382 if (getrval2(tcp)) {
383 tcp->auxstr = "child process";
384 return RVAL_UDECIMAL | RVAL_STR;
385 }
386 }
387 return 0;
388}
389
390#endif
391
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392int
393internal_fork(tcp)
394struct tcb *tcp;
395{
396 struct tcb *tcpchild;
397
398 if (exiting(tcp)) {
399 if (getrval2(tcp))
400 return 0;
401 if (!followfork)
402 return 0;
403 if (nprocs == MAX_PROCS) {
404 tcp->flags &= ~TCB_FOLLOWFORK;
405 fprintf(stderr, "sys_fork: tcb table full\n");
406 return 0;
407 }
408 else
409 tcp->flags |= TCB_FOLLOWFORK;
410 if (syserror(tcp))
411 return 0;
412 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
413 fprintf(stderr, "sys_fork: tcb table full\n");
414 return 0;
415 }
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000416 if (proc_open(tcpchild, 2) < 0)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000417 droptcb(tcpchild);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000418 }
419 return 0;
420}
421
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000422#else /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000423
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000424#ifdef LINUX
425
426/* defines copied from linux/sched.h since we can't include that
427 * ourselves (it conflicts with *lots* of libc includes)
428 */
429#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
430#define CLONE_VM 0x00000100 /* set if VM shared between processes */
431#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
432#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
433#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
434#define CLONE_PID 0x00001000 /* set if pid shared */
435#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
436#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
437#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
438
439static struct xlat clone_flags[] = {
440 { CLONE_VM, "CLONE_VM" },
441 { CLONE_FS, "CLONE_FS" },
442 { CLONE_FILES, "CLONE_FILES" },
443 { CLONE_SIGHAND, "CLONE_SIGHAND" },
444 { CLONE_PID, "CLONE_PID" },
445 { CLONE_PTRACE, "CLONE_PTRACE" },
446 { CLONE_VFORK, "CLONE_VFORK" },
447 { CLONE_PARENT, "CLONE_PARENT" },
448 { 0, NULL },
449};
450
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000451int
452sys_clone(tcp)
453struct tcb *tcp;
454{
455 if (exiting(tcp)) {
456 tprintf("child_stack=%#lx, flags=", tcp->u_arg[1]);
457 if (printflags(clone_flags, tcp->u_arg[0]) == 0)
458 tprintf("0");
459 }
460 return 0;
461}
462
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000463int
464sys_clone2(tcp)
465struct tcb *tcp;
466{
467 if (exiting(tcp)) {
468 tprintf("child_stack=%#lx, stack_size=%#lx, flags=",
469 tcp->u_arg[1], tcp->u_arg[2]);
470 if (printflags(clone_flags, tcp->u_arg[0]) == 0)
471 tprintf("0");
472 }
473 return 0;
474}
475
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000476#endif
477
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000478int
479sys_fork(tcp)
480struct tcb *tcp;
481{
482 if (exiting(tcp))
483 return RVAL_UDECIMAL;
484 return 0;
485}
486
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000487int
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000488change_syscall(tcp, new)
489struct tcb *tcp;
490int new;
491{
492#if defined(LINUX)
493#if defined(I386)
494 /* Attempt to make vfork into fork, which we can follow. */
495 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
496 return -1;
497 return 0;
Michal Ludvig0e035502002-09-23 15:41:01 +0000498#elif defined(X86_64)
499 /* Attempt to make vfork into fork, which we can follow. */
500 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
501 return -1;
502 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000503#elif defined(POWERPC)
Wichert Akkerman5c4c69b2001-04-12 09:00:47 +0000504 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000505 return -1;
Michal Ludvig10a88d02002-10-07 14:31:00 +0000506#elif defined(S390) || defined(S390X)
507 /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
508 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new)<0)
509 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000510 return 0;
511#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000512 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000513 return -1;
514 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000515#elif defined(SPARC)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000516 struct regs regs;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000517 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
518 return -1;
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000519 regs.r_g1=new;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000520 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
521 return -1;
522 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000523#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000524 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000525 return -1;
526 return 0;
527#elif defined(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000528 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000529 return -1;
530 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000531#elif defined(IA64)
532 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new)<0)
533 return -1;
534 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000535#elif defined(HPPA)
536 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new)<0)
537 return -1;
538 return 0;
Wichert Akkermanccef6372002-05-01 16:39:22 +0000539#elif defined(SH)
540 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL), new)<0)
541 return -1;
542 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000543#else
544#warning Do not know how to handle change_syscall for this architecture
545#endif /* architecture */
546#endif /* LINUX */
547 return -1;
548}
549
550int
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000551setarg(tcp, argnum)
552 struct tcb *tcp;
553 int argnum;
554{
555#if defined (IA64)
556 {
557 unsigned long *bsp, *ap;
558
559 if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
560 return -1;
561
562 ap = ia64_rse_skip_regs(bsp, argnum);
563 errno = 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000564 ptrace(PTRACE_POKEDATA, tcp->pid, (char *) ap, tcp->u_arg[argnum]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000565 if (errno)
566 return -1;
567
568 }
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000569#elif defined(I386)
570 {
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000571 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*argnum), tcp->u_arg[argnum]);
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000572 if (errno)
573 return -1;
574 }
Michal Ludvig0e035502002-09-23 15:41:01 +0000575#elif defined(X86_64)
576 {
577 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(8*(long)argnum), tcp->u_arg[argnum]);
578 if (errno)
579 return -1;
580 }
Ralf Baechlee3816102000-08-01 00:06:06 +0000581#elif defined(MIPS)
582 {
583 errno = 0;
584 if (argnum < 4)
585 ptrace(PTRACE_POKEUSER, tcp->pid,
586 (char*)(REG_A0 + argnum), tcp->u_arg[argnum]);
587 else {
588 unsigned long *sp;
589
590 if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
591 return -1;
592
593 ptrace(PTRACE_POKEDATA, tcp->pid,
594 (char*)(sp + argnum - 4), tcp->u_arg[argnum]);
595 }
596 if (errno)
597 return -1;
598 }
Michal Ludvig10a88d02002-10-07 14:31:00 +0000599#elif defined(S390) || defined(S390X)
600 {
601 if(argnum <= 5)
602 ptrace(PTRACE_POKEUSER, tcp->pid,
603 (char *) (argnum==0 ? PT_ORIGGPR2 :
604 PT_GPR2 + argnum*sizeof(long)),
605 tcp->u_arg[argnum]);
606 else
607 return -E2BIG;
608 if (errno)
609 return -1;
610 }
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000611#else
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000612# warning Sorry, setargs not implemented for this architecture.
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000613#endif
614 return 0;
615}
616
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000617#ifdef SYS_clone
618int
619internal_clone(tcp)
620struct tcb *tcp;
621{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000622 struct tcb *tcpchild;
623 int pid;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000624 if (entering(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000625 if (!followfork)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000626 return 0;
627 if (nprocs == MAX_PROCS) {
628 tcp->flags &= ~TCB_FOLLOWFORK;
629 fprintf(stderr, "sys_fork: tcb table full\n");
630 return 0;
631 }
632 tcp->flags |= TCB_FOLLOWFORK;
633
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000634
635 if (setbpt(tcp) < 0)
636 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000637 } else {
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000638 int bpt = tcp->flags & TCB_BPTSET;
639
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000640 if (!(tcp->flags & TCB_FOLLOWFORK))
641 return 0;
642
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000643 if (syserror(tcp)) {
644 if (bpt)
645 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000646 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000647 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000648
649 pid = tcp->u_rval;
650 if ((tcpchild = alloctcb(pid)) == NULL) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000651 if (bpt)
652 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000653 fprintf(stderr, " [tcb table full]\n");
654 kill(pid, SIGKILL); /* XXX */
655 return 0;
656 }
657
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000658 /* Attach to the new child */
659 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000660 if (bpt)
661 clearbpt(tcp);
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000662 perror("PTRACE_ATTACH");
663 fprintf(stderr, "Too late?\n");
664 droptcb(tcpchild);
665 return 0;
666 }
667
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000668 if (bpt)
669 clearbpt(tcp);
670
Ulrich Drepper90512f01999-12-24 07:22:25 +0000671 tcpchild->flags |= TCB_ATTACHED;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000672 if (bpt) {
673 tcpchild->flags |= TCB_BPTSET;
674 tcpchild->baddr = tcp->baddr;
675 memcpy(tcpchild->inst, tcp->inst,
676 sizeof tcpchild->inst);
677 }
Ulrich Drepper90512f01999-12-24 07:22:25 +0000678 newoutf(tcpchild);
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000679 tcpchild->parent = tcp;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000680 tcp->nchildren++;
681 if (!qflag)
682 fprintf(stderr, "Process %d attached\n", pid);
683 }
684 return 0;
685}
686#endif
687
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688int
689internal_fork(tcp)
690struct tcb *tcp;
691{
692 struct tcb *tcpchild;
693 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000694 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695
696#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000697 if (tcp->scno == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000698 /* Attempt to make vfork into fork, which we can follow. */
699 if (!followvfork ||
Pavel Machek9a9f10b2000-02-01 16:22:52 +0000700 change_syscall(tcp, SYS_fork) < 0)
Nate Sammonsccd8f211999-03-29 22:57:54 +0000701 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000702 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000703#endif
704 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000705 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000706 return 0;
707 if (nprocs == MAX_PROCS) {
708 tcp->flags &= ~TCB_FOLLOWFORK;
709 fprintf(stderr, "sys_fork: tcb table full\n");
710 return 0;
711 }
712 tcp->flags |= TCB_FOLLOWFORK;
713 if (setbpt(tcp) < 0)
714 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000715 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000716 else {
717 int bpt = tcp->flags & TCB_BPTSET;
718
719 if (!(tcp->flags & TCB_FOLLOWFORK))
720 return 0;
721 if (bpt)
722 clearbpt(tcp);
723
724 if (syserror(tcp))
725 return 0;
726
727 pid = tcp->u_rval;
728 if ((tcpchild = alloctcb(pid)) == NULL) {
729 fprintf(stderr, " [tcb table full]\n");
730 kill(pid, SIGKILL); /* XXX */
731 return 0;
732 }
733#ifdef LINUX
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000734#ifdef HPPA
735 /* The child must have run before it can be attached. */
736 /* This must be a bug in the parisc kernel, but I havn't
737 * identified it yet. Seems to be an issue associated
738 * with attaching to a process (which sends it a signal)
739 * before that process has ever been scheduled. When
740 * debugging, I started seeing crashes in
741 * arch/parisc/kernel/signal.c:do_signal(), apparently
742 * caused by r8 getting corrupt over the dequeue_signal()
743 * call. Didn't make much sense though...
744 */
745 {
746 struct timeval tv;
747 tv.tv_sec = 0;
748 tv.tv_usec = 10000;
749 select(0, NULL, NULL, NULL, &tv);
750 }
751#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000752 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
753 perror("PTRACE_ATTACH");
754 fprintf(stderr, "Too late?\n");
755 droptcb(tcpchild);
756 return 0;
757 }
758#endif /* LINUX */
759#ifdef SUNOS4
760#ifdef oldway
761 /* The child must have run before it can be attached. */
762 {
763 struct timeval tv;
764 tv.tv_sec = 0;
765 tv.tv_usec = 10000;
766 select(0, NULL, NULL, NULL, &tv);
767 }
768 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
769 perror("PTRACE_ATTACH");
770 fprintf(stderr, "Too late?\n");
771 droptcb(tcpchild);
772 return 0;
773 }
774#else /* !oldway */
775 /* Try to catch the new process as soon as possible. */
776 {
777 int i;
778 for (i = 0; i < 1024; i++)
779 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
780 break;
781 if (i == 1024) {
782 perror("PTRACE_ATTACH");
783 fprintf(stderr, "Too late?\n");
784 droptcb(tcpchild);
785 return 0;
786 }
787 }
788#endif /* !oldway */
789#endif /* SUNOS4 */
790 tcpchild->flags |= TCB_ATTACHED;
791 /* Child has BPT too, must be removed on first occasion */
792 if (bpt) {
793 tcpchild->flags |= TCB_BPTSET;
794 tcpchild->baddr = tcp->baddr;
795 memcpy(tcpchild->inst, tcp->inst,
796 sizeof tcpchild->inst);
797 }
798 newoutf(tcpchild);
799 tcpchild->parent = tcp;
800 tcp->nchildren++;
801 if (!qflag)
802 fprintf(stderr, "Process %d attached\n", pid);
803 }
804 return 0;
805}
806
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000807#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000808
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000809#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000810
811int
812sys_vfork(tcp)
813struct tcb *tcp;
814{
815 if (exiting(tcp))
816 return RVAL_UDECIMAL;
817 return 0;
818}
819
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000820#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821
822#ifndef LINUX
823
824static char idstr[16];
825
826int
827sys_getpid(tcp)
828struct tcb *tcp;
829{
830 if (exiting(tcp)) {
831 sprintf(idstr, "ppid %lu", getrval2(tcp));
832 tcp->auxstr = idstr;
833 return RVAL_STR;
834 }
835 return 0;
836}
837
838int
839sys_getuid(tcp)
840struct tcb *tcp;
841{
842 if (exiting(tcp)) {
843 sprintf(idstr, "euid %lu", getrval2(tcp));
844 tcp->auxstr = idstr;
845 return RVAL_STR;
846 }
847 return 0;
848}
849
850int
851sys_getgid(tcp)
852struct tcb *tcp;
853{
854 if (exiting(tcp)) {
855 sprintf(idstr, "egid %lu", getrval2(tcp));
856 tcp->auxstr = idstr;
857 return RVAL_STR;
858 }
859 return 0;
860}
861
862#endif /* !LINUX */
863
864#ifdef LINUX
865
866int
867sys_setuid(tcp)
868struct tcb *tcp;
869{
870 if (entering(tcp)) {
871 tprintf("%u", (uid_t) tcp->u_arg[0]);
872 }
873 return 0;
874}
875
876int
877sys_setgid(tcp)
878struct tcb *tcp;
879{
880 if (entering(tcp)) {
881 tprintf("%u", (gid_t) tcp->u_arg[0]);
882 }
883 return 0;
884}
885
886int
887sys_getresuid(tcp)
888 struct tcb *tcp;
889{
890 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000891 __kernel_uid_t uid;
892 if (syserror(tcp))
893 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
894 tcp->u_arg[1], tcp->u_arg[2]);
895 else {
896 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
897 tprintf("%#lx, ", tcp->u_arg[0]);
898 else
899 tprintf("ruid %lu, ", (unsigned long) uid);
900 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
901 tprintf("%#lx, ", tcp->u_arg[0]);
902 else
903 tprintf("euid %lu, ", (unsigned long) uid);
904 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
905 tprintf("%#lx", tcp->u_arg[0]);
906 else
907 tprintf("suid %lu", (unsigned long) uid);
908 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000909 }
910 return 0;
911}
912
913int
914sys_getresgid(tcp)
915struct tcb *tcp;
916{
917 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000918 __kernel_gid_t gid;
919 if (syserror(tcp))
920 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
921 tcp->u_arg[1], tcp->u_arg[2]);
922 else {
923 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
924 tprintf("%#lx, ", tcp->u_arg[0]);
925 else
926 tprintf("rgid %lu, ", (unsigned long) gid);
927 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
928 tprintf("%#lx, ", tcp->u_arg[0]);
929 else
930 tprintf("egid %lu, ", (unsigned long) gid);
931 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
932 tprintf("%#lx", tcp->u_arg[0]);
933 else
934 tprintf("sgid %lu", (unsigned long) gid);
935 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000936 }
937 return 0;
938}
939
940#endif /* LINUX */
941
942int
943sys_setreuid(tcp)
944struct tcb *tcp;
945{
946 if (entering(tcp)) {
947 tprintf("%lu, %lu",
948 (unsigned long) (uid_t) tcp->u_arg[0],
949 (unsigned long) (uid_t) tcp->u_arg[1]);
950 }
951 return 0;
952}
953
954int
955sys_setregid(tcp)
956struct tcb *tcp;
957{
958 if (entering(tcp)) {
959 tprintf("%lu, %lu",
960 (unsigned long) (gid_t) tcp->u_arg[0],
961 (unsigned long) (gid_t) tcp->u_arg[1]);
962 }
963 return 0;
964}
965
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000966#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000967int
968sys_setresuid(tcp)
969 struct tcb *tcp;
970{
971 if (entering(tcp)) {
972 tprintf("ruid %u, euid %u, suid %u",
973 (uid_t) tcp->u_arg[0],
974 (uid_t) tcp->u_arg[1],
975 (uid_t) tcp->u_arg[2]);
976 }
977 return 0;
978}
979int
980sys_setresgid(tcp)
981 struct tcb *tcp;
982{
983 if (entering(tcp)) {
984 tprintf("rgid %u, egid %u, sgid %u",
985 (uid_t) tcp->u_arg[0],
986 (uid_t) tcp->u_arg[1],
987 (uid_t) tcp->u_arg[2]);
988 }
989 return 0;
990}
991
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000992#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000993
994int
995sys_setgroups(tcp)
996struct tcb *tcp;
997{
998 int i, len;
999 GETGROUPS_T *gidset;
1000
1001 if (entering(tcp)) {
1002 len = tcp->u_arg[0];
1003 tprintf("%u, ", len);
1004 if (len <= 0) {
1005 tprintf("[]");
1006 return 0;
1007 }
1008 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1009 if (gidset == NULL) {
1010 fprintf(stderr, "sys_setgroups: out of memory\n");
1011 return -1;
1012 }
1013 if (!verbose(tcp))
1014 tprintf("%#lx", tcp->u_arg[1]);
1015 else if (umoven(tcp, tcp->u_arg[1],
1016 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1017 tprintf("[?]");
1018 else {
1019 tprintf("[");
1020 for (i = 0; i < len; i++)
1021 tprintf("%s%lu", i ? ", " : "",
1022 (unsigned long) gidset[i]);
1023 tprintf("]");
1024 }
1025 free((char *) gidset);
1026 }
1027 return 0;
1028}
1029
1030int
1031sys_getgroups(tcp)
1032struct tcb *tcp;
1033{
1034 int i, len;
1035 GETGROUPS_T *gidset;
1036
1037 if (entering(tcp)) {
1038 len = tcp->u_arg[0];
1039 tprintf("%u, ", len);
1040 } else {
1041 len = tcp->u_rval;
1042 if (len <= 0) {
1043 tprintf("[]");
1044 return 0;
1045 }
1046 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1047 if (gidset == NULL) {
1048 fprintf(stderr, "sys_getgroups: out of memory\n");
1049 return -1;
1050 }
1051 if (!tcp->u_arg[1])
1052 tprintf("NULL");
1053 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
1054 tprintf("%#lx", tcp->u_arg[1]);
1055 else if (umoven(tcp, tcp->u_arg[1],
1056 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1057 tprintf("[?]");
1058 else {
1059 tprintf("[");
1060 for (i = 0; i < len; i++)
1061 tprintf("%s%lu", i ? ", " : "",
1062 (unsigned long) gidset[i]);
1063 tprintf("]");
1064 }
1065 free((char *)gidset);
1066 }
1067 return 0;
1068}
1069
1070int
1071sys_setpgrp(tcp)
1072struct tcb *tcp;
1073{
1074 if (entering(tcp)) {
1075#ifndef SVR4
1076 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1077#endif /* !SVR4 */
1078 }
1079 return 0;
1080}
1081
1082int
1083sys_getpgrp(tcp)
1084struct tcb *tcp;
1085{
1086 if (entering(tcp)) {
1087#ifndef SVR4
1088 tprintf("%lu", tcp->u_arg[0]);
1089#endif /* !SVR4 */
1090 }
1091 return 0;
1092}
1093
1094int
1095sys_getsid(tcp)
1096struct tcb *tcp;
1097{
1098 if (entering(tcp)) {
1099 tprintf("%lu", tcp->u_arg[0]);
1100 }
1101 return 0;
1102}
1103
1104int
1105sys_setsid(tcp)
1106struct tcb *tcp;
1107{
1108 return 0;
1109}
1110
1111int
1112sys_getpgid(tcp)
1113struct tcb *tcp;
1114{
1115 if (entering(tcp)) {
1116 tprintf("%lu", tcp->u_arg[0]);
1117 }
1118 return 0;
1119}
1120
1121int
1122sys_setpgid(tcp)
1123struct tcb *tcp;
1124{
1125 if (entering(tcp)) {
1126 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1127 }
1128 return 0;
1129}
1130
John Hughesc61eb3d2002-05-17 11:37:50 +00001131#if UNIXWARE >= 2
1132
1133#include <sys/privilege.h>
1134
1135
1136static struct xlat procpriv_cmds [] = {
1137 { SETPRV, "SETPRV" },
1138 { CLRPRV, "CLRPRV" },
1139 { PUTPRV, "PUTPRV" },
1140 { GETPRV, "GETPRV" },
1141 { CNTPRV, "CNTPRV" },
1142 { 0, NULL },
1143};
1144
1145
1146static struct xlat procpriv_priv [] = {
1147 { P_OWNER, "P_OWNER" },
1148 { P_AUDIT, "P_AUDIT" },
1149 { P_COMPAT, "P_COMPAT" },
1150 { P_DACREAD, "P_DACREAD" },
1151 { P_DACWRITE, "P_DACWRITE" },
1152 { P_DEV, "P_DEV" },
1153 { P_FILESYS, "P_FILESYS" },
1154 { P_MACREAD, "P_MACREAD" },
1155 { P_MACWRITE, "P_MACWRITE" },
1156 { P_MOUNT, "P_MOUNT" },
1157 { P_MULTIDIR, "P_MULTIDIR" },
1158 { P_SETPLEVEL, "P_SETPLEVEL" },
1159 { P_SETSPRIV, "P_SETSPRIV" },
1160 { P_SETUID, "P_SETUID" },
1161 { P_SYSOPS, "P_SYSOPS" },
1162 { P_SETUPRIV, "P_SETUPRIV" },
1163 { P_DRIVER, "P_DRIVER" },
1164 { P_RTIME, "P_RTIME" },
1165 { P_MACUPGRADE, "P_MACUPGRADE" },
1166 { P_FSYSRANGE, "P_FSYSRANGE" },
1167 { P_SETFLEVEL, "P_SETFLEVEL" },
1168 { P_AUDITWR, "P_AUDITWR" },
1169 { P_TSHAR, "P_TSHAR" },
1170 { P_PLOCK, "P_PLOCK" },
1171 { P_CORE, "P_CORE" },
1172 { P_LOADMOD, "P_LOADMOD" },
1173 { P_BIND, "P_BIND" },
1174 { P_ALLPRIVS, "P_ALLPRIVS" },
1175 { 0, NULL },
1176};
1177
1178
1179static struct xlat procpriv_type [] = {
1180 { PS_FIX, "PS_FIX" },
1181 { PS_INH, "PS_INH" },
1182 { PS_MAX, "PS_MAX" },
1183 { PS_WKG, "PS_WKG" },
1184 { 0, NULL },
1185};
1186
1187
1188static void
1189printpriv(tcp, addr, len, opt)
1190struct tcb *tcp;
1191long addr;
1192int len;
1193struct xlat *opt;
1194{
1195 priv_t buf [128];
1196 int max = verbose (tcp) ? sizeof buf / sizeof buf [0] : 10;
1197 int dots = len > max;
1198 int i;
1199
1200 if (len > max) len = max;
1201
1202 if (len <= 0 ||
1203 umoven (tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
1204 {
1205 tprintf ("%#lx", addr);
1206 return;
1207 }
1208
1209 tprintf ("[");
1210
1211 for (i = 0; i < len; ++i) {
1212 char *t, *p;
1213
1214 if (i) tprintf (", ");
1215
1216 if ((t = xlookup (procpriv_type, buf [i] & PS_TYPE)) &&
1217 (p = xlookup (procpriv_priv, buf [i] & ~PS_TYPE)))
1218 {
1219 tprintf ("%s|%s", t, p);
1220 }
1221 else {
1222 tprintf ("%#lx", buf [i]);
1223 }
1224 }
1225
1226 if (dots) tprintf (" ...");
1227
1228 tprintf ("]");
1229}
1230
1231
1232int
1233sys_procpriv(tcp)
1234struct tcb *tcp;
1235{
1236 if (entering(tcp)) {
1237 printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
1238 switch (tcp->u_arg[0]) {
1239 case CNTPRV:
1240 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1241 break;
1242
1243 case GETPRV:
1244 break;
1245
1246 default:
1247 tprintf (", ");
1248 printpriv (tcp, tcp->u_arg[1], tcp->u_arg[2]);
1249 tprintf (", %ld", tcp->u_arg[2]);
1250 }
1251 }
1252 else if (tcp->u_arg[0] == GETPRV) {
1253 if (syserror (tcp)) {
1254 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1255 }
1256 else {
1257 tprintf (", ");
1258 printpriv (tcp, tcp->u_arg[1], tcp->u_rval);
1259 tprintf (", %ld", tcp->u_arg[2]);
1260 }
1261 }
1262
1263 return 0;
1264}
1265
1266#endif
1267
1268
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001269void
1270fake_execve(tcp, program, argv, envp)
1271struct tcb *tcp;
1272char *program;
1273char *argv[];
1274char *envp[];
1275{
1276 int i;
1277
1278#ifdef ARM
1279 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
1280 return;
1281#else
1282 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
1283 return;
1284#endif /* !ARM */
1285 printleader(tcp);
1286 tprintf("execve(");
1287 string_quote(program);
1288 tprintf(", [");
1289 for (i = 0; argv[i] != NULL; i++) {
1290 if (i != 0)
1291 tprintf(", ");
1292 string_quote(argv[i]);
1293 }
1294 for (i = 0; envp[i] != NULL; i++)
1295 ;
1296 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
1297 tabto(acolumn);
1298 tprintf("= 0");
1299 printtrailer(tcp);
1300}
1301
1302static void
1303printargv(tcp, addr)
1304struct tcb *tcp;
1305long addr;
1306{
1307 char *cp;
1308 char *sep;
1309 int max = max_strlen / 2;
1310
1311 for (sep = ""; --max >= 0; sep = ", ") {
1312 if (!abbrev(tcp))
1313 max++;
1314 if (umove(tcp, addr, &cp) < 0) {
1315 tprintf("%#lx", addr);
1316 return;
1317 }
1318 if (cp == 0)
1319 break;
1320 tprintf(sep);
1321 printstr(tcp, (long) cp, -1);
1322 addr += sizeof(char *);
1323 }
1324 if (cp)
1325 tprintf(", ...");
1326}
1327
1328static void
1329printargc(fmt, tcp, addr)
1330char *fmt;
1331struct tcb *tcp;
1332long addr;
1333{
1334 int count;
1335 char *cp;
1336
1337 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1338 addr += sizeof(char *);
1339 }
1340 tprintf(fmt, count, count == 1 ? "" : "s");
1341}
1342
1343int
1344sys_execv(tcp)
1345struct tcb *tcp;
1346{
1347 if (entering(tcp)) {
1348 printpath(tcp, tcp->u_arg[0]);
1349 if (!verbose(tcp))
1350 tprintf(", %#lx", tcp->u_arg[1]);
1351#if 0
1352 else if (abbrev(tcp))
1353 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1354#endif
1355 else {
1356 tprintf(", [");
1357 printargv(tcp, tcp->u_arg[1]);
1358 tprintf("]");
1359 }
1360 }
1361 return 0;
1362}
1363
1364int
1365sys_execve(tcp)
1366struct tcb *tcp;
1367{
1368 if (entering(tcp)) {
1369 printpath(tcp, tcp->u_arg[0]);
1370 if (!verbose(tcp))
1371 tprintf(", %#lx", tcp->u_arg[1]);
1372#if 0
1373 else if (abbrev(tcp))
1374 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1375#endif
1376 else {
1377 tprintf(", [");
1378 printargv(tcp, tcp->u_arg[1]);
1379 tprintf("]");
1380 }
1381 if (!verbose(tcp))
1382 tprintf(", %#lx", tcp->u_arg[2]);
1383 else if (abbrev(tcp))
1384 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1385 else {
1386 tprintf(", [");
1387 printargv(tcp, tcp->u_arg[2]);
1388 tprintf("]");
1389 }
1390 }
1391#ifdef LINUX
Wichert Akkermanccef6372002-05-01 16:39:22 +00001392#if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393 tcp->flags |= TCB_WAITEXECVE;
Wichert Akkermanccef6372002-05-01 16:39:22 +00001394#endif /* ALPHA || SPARC || POWERPC || IA64 || HPPA || SH */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001395#endif /* LINUX */
1396 return 0;
1397}
1398
John Hughes4e36a812001-04-18 15:11:51 +00001399#if UNIXWARE > 2
1400
1401int sys_rexecve(tcp)
1402struct tcb *tcp;
1403{
1404 if (entering (tcp)) {
1405 sys_execve (tcp);
1406 tprintf (", %ld", tcp->u_arg[3]);
1407 }
1408 return 0;
1409}
1410
1411#endif
1412
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413int
1414internal_exec(tcp)
1415struct tcb *tcp;
1416{
1417#ifdef SUNOS4
1418 if (exiting(tcp) && !syserror(tcp) && followfork)
1419 fixvfork(tcp);
1420#endif /* SUNOS4 */
1421 return 0;
1422}
1423
1424#ifdef LINUX
1425#ifndef __WCLONE
1426#define __WCLONE 0x8000000
1427#endif
1428#endif /* LINUX */
1429
1430static struct xlat wait4_options[] = {
1431 { WNOHANG, "WNOHANG" },
1432#ifndef WSTOPPED
1433 { WUNTRACED, "WUNTRACED" },
1434#endif
1435#ifdef WEXITED
1436 { WEXITED, "WEXITED" },
1437#endif
1438#ifdef WTRAPPED
1439 { WTRAPPED, "WTRAPPED" },
1440#endif
1441#ifdef WSTOPPED
1442 { WSTOPPED, "WSTOPPED" },
1443#endif
1444#ifdef WCONTINUED
1445 { WCONTINUED, "WCONTINUED" },
1446#endif
1447#ifdef WNOWAIT
1448 { WNOWAIT, "WNOWAIT" },
1449#endif
1450#ifdef __WCLONE
1451 { __WCLONE, "__WCLONE" },
1452#endif
1453 { 0, NULL },
1454};
1455
1456static int
1457printstatus(status)
1458int status;
1459{
1460 int exited = 0;
1461
1462 /*
1463 * Here is a tricky presentation problem. This solution
1464 * is still not entirely satisfactory but since there
1465 * are no wait status constructors it will have to do.
1466 */
1467 if (WIFSTOPPED(status))
1468 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001469 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001470 else if WIFSIGNALED(status)
1471 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001472 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001473 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1474 else if WIFEXITED(status) {
1475 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1476 WEXITSTATUS(status));
1477 exited = 1;
1478 }
1479 else
1480 tprintf("[%#x]", status);
1481 return exited;
1482}
1483
1484static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001485printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001486struct tcb *tcp;
1487int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001488int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001489{
1490 int status;
1491 int exited = 0;
1492
1493 if (entering(tcp)) {
1494 tprintf("%ld, ", tcp->u_arg[0]);
1495 } else {
1496 /* status */
1497 if (!tcp->u_arg[1])
1498 tprintf("NULL");
1499 else if (syserror(tcp) || tcp->u_rval == 0)
1500 tprintf("%#lx", tcp->u_arg[1]);
1501 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1502 tprintf("[?]");
1503 else
1504 exited = printstatus(status);
1505 /* options */
1506 tprintf(", ");
1507 if (!printflags(wait4_options, tcp->u_arg[2]))
1508 tprintf("0");
1509 if (n == 4) {
1510 tprintf(", ");
1511 /* usage */
1512 if (!tcp->u_arg[3])
1513 tprintf("NULL");
1514#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001515 else if (tcp->u_rval > 0) {
1516#ifdef LINUX_64BIT
1517 if (bitness)
1518 printrusage32(tcp, tcp->u_arg[3]);
1519 else
1520#endif
1521 printrusage(tcp, tcp->u_arg[3]);
1522 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001523#endif /* LINUX */
1524#ifdef SUNOS4
1525 else if (tcp->u_rval > 0 && exited)
1526 printrusage(tcp, tcp->u_arg[3]);
1527#endif /* SUNOS4 */
1528 else
1529 tprintf("%#lx", tcp->u_arg[3]);
1530 }
1531 }
1532 return 0;
1533}
1534
1535int
1536internal_wait(tcp)
1537struct tcb *tcp;
1538{
1539 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +00001540 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001541 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
1542 /* There are traced children */
1543 tcp->flags |= TCB_SUSPENDED;
1544 tcp->waitpid = tcp->u_arg[0];
1545 }
1546 }
1547 return 0;
1548}
1549
1550#ifdef SVR4
1551
1552int
1553sys_wait(tcp)
1554struct tcb *tcp;
1555{
1556 if (exiting(tcp)) {
1557 /* The library wrapper stuffs this into the user variable. */
1558 if (!syserror(tcp))
1559 printstatus(getrval2(tcp));
1560 }
1561 return 0;
1562}
1563
1564#endif /* SVR4 */
1565
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001566#ifdef FREEBSD
1567int
1568sys_wait(tcp)
1569struct tcb *tcp;
1570{
1571 int status;
1572
1573 if (exiting(tcp)) {
1574 if (!syserror(tcp)) {
1575 if (umove(tcp, tcp->u_arg[0], &status) < 0)
1576 tprintf("%#lx", tcp->u_arg[0]);
1577 else
1578 printstatus(status);
1579 }
1580 }
1581 return 0;
1582}
1583#endif
1584
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001585int
1586sys_waitpid(tcp)
1587struct tcb *tcp;
1588{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001589 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001590}
1591
1592int
1593sys_wait4(tcp)
1594struct tcb *tcp;
1595{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001596 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001597}
1598
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001599#ifdef ALPHA
1600int
1601sys_osf_wait4(tcp)
1602struct tcb *tcp;
1603{
1604 return printwaitn(tcp, 4, 1);
1605}
1606#endif
1607
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001608#ifdef SVR4
1609
1610static struct xlat waitid_types[] = {
1611 { P_PID, "P_PID" },
1612 { P_PPID, "P_PPID" },
1613 { P_PGID, "P_PGID" },
1614 { P_SID, "P_SID" },
1615 { P_CID, "P_CID" },
1616 { P_UID, "P_UID" },
1617 { P_GID, "P_GID" },
1618 { P_ALL, "P_ALL" },
1619#ifdef P_LWPID
1620 { P_LWPID, "P_LWPID" },
1621#endif
1622 { 0, NULL },
1623};
1624
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625int
1626sys_waitid(tcp)
1627struct tcb *tcp;
1628{
1629 siginfo_t si;
1630 int exited;
1631
1632 if (entering(tcp)) {
1633 printxval(waitid_types, tcp->u_arg[0], "P_???");
1634 tprintf(", %ld, ", tcp->u_arg[1]);
1635 if (tcp->nchildren > 0) {
1636 /* There are traced children */
1637 tcp->flags |= TCB_SUSPENDED;
1638 tcp->waitpid = tcp->u_arg[0];
1639 }
1640 }
1641 else {
1642 /* siginfo */
1643 exited = 0;
1644 if (!tcp->u_arg[2])
1645 tprintf("NULL");
1646 else if (syserror(tcp))
1647 tprintf("%#lx", tcp->u_arg[2]);
1648 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1649 tprintf("{???}");
1650 else
John Hughes58265892001-10-18 15:13:53 +00001651 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001652 /* options */
1653 tprintf(", ");
1654 if (!printflags(wait4_options, tcp->u_arg[3]))
1655 tprintf("0");
1656 }
1657 return 0;
1658}
1659
1660#endif /* SVR4 */
1661
1662int
1663sys_alarm(tcp)
1664struct tcb *tcp;
1665{
1666 if (entering(tcp))
1667 tprintf("%lu", tcp->u_arg[0]);
1668 return 0;
1669}
1670
1671int
1672sys_uname(tcp)
1673struct tcb *tcp;
1674{
1675 struct utsname uname;
1676
1677 if (exiting(tcp)) {
1678 if (syserror(tcp) || !verbose(tcp))
1679 tprintf("%#lx", tcp->u_arg[0]);
1680 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1681 tprintf("{...}");
1682 else if (!abbrev(tcp)) {
1683
1684 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1685 uname.sysname, uname.nodename);
1686 tprintf("release=\"%s\", version=\"%s\", ",
1687 uname.release, uname.version);
1688 tprintf("machine=\"%s\"", uname.machine);
1689#ifdef LINUX
1690#ifndef __GLIBC__
1691 tprintf(", domainname=\"%s\"", uname.domainname);
1692#endif /* __GLIBC__ */
1693#endif /* LINUX */
1694 tprintf("}");
1695 }
1696 else
1697 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1698 uname.sysname, uname.nodename);
1699 }
1700 return 0;
1701}
1702
1703#ifndef SVR4
1704
1705static struct xlat ptrace_cmds[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001706#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001707 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1708 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1709 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1710 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1711 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1712 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1713 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1714 { PTRACE_CONT, "PTRACE_CONT" },
1715 { PTRACE_KILL, "PTRACE_KILL" },
1716 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1717 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1718 { PTRACE_DETACH, "PTRACE_DETACH" },
1719#ifdef SUNOS4
1720 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1721 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1722 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1723 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1724 { PTRACE_READDATA, "PTRACE_READDATA" },
1725 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1726 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1727 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1728 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1729 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1730#ifdef SPARC
1731 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1732 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1733#else /* !SPARC */
1734 { PTRACE_22, "PTRACE_PTRACE_22" },
1735 { PTRACE_23, "PTRACE_PTRACE_23" },
1736#endif /* !SPARC */
1737#endif /* SUNOS4 */
1738 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1739#ifdef SUNOS4
1740 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1741#ifdef I386
1742 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1743 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1744 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1745#else /* !I386 */
1746 { PTRACE_26, "PTRACE_26" },
1747 { PTRACE_27, "PTRACE_27" },
1748 { PTRACE_28, "PTRACE_28" },
1749#endif /* !I386 */
1750 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1751#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001752#else /* FREEBSD */
1753 { PT_TRACE_ME, "PT_TRACE_ME" },
1754 { PT_READ_I, "PT_READ_I" },
1755 { PT_READ_D, "PT_READ_D" },
1756 { PT_WRITE_I, "PT_WRITE_I" },
1757 { PT_WRITE_D, "PT_WRITE_D" },
John Hughesa2278142001-09-28 16:21:30 +00001758#ifdef PT_READ_U
1759 { PT_READ_U, "PT_READ_U" },
1760#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001761 { PT_CONTINUE, "PT_CONTINUE" },
1762 { PT_KILL, "PT_KILL" },
1763 { PT_STEP, "PT_STEP" },
1764 { PT_ATTACH, "PT_ATTACH" },
1765 { PT_DETACH, "PT_DETACH" },
1766 { PT_GETREGS, "PT_GETREGS" },
1767 { PT_SETREGS, "PT_SETREGS" },
1768 { PT_GETFPREGS, "PT_GETFPREGS" },
1769 { PT_SETFPREGS, "PT_SETFPREGS" },
1770 { PT_GETDBREGS, "PT_GETDBREGS" },
1771 { PT_SETDBREGS, "PT_SETDBREGS" },
1772#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001773 { 0, NULL },
1774};
1775
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001776#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001777#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1778static
1779#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1780struct xlat struct_user_offsets[] = {
1781#ifdef LINUX
Michal Ludvig10a88d02002-10-07 14:31:00 +00001782#if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001783 { PT_PSWMASK, "psw_mask" },
1784 { PT_PSWADDR, "psw_addr" },
1785 { PT_GPR0, "gpr0" },
1786 { PT_GPR1, "gpr1" },
1787 { PT_GPR2, "gpr2" },
1788 { PT_GPR3, "gpr3" },
1789 { PT_GPR4, "gpr4" },
1790 { PT_GPR5, "gpr5" },
1791 { PT_GPR6, "gpr6" },
1792 { PT_GPR7, "gpr7" },
1793 { PT_GPR8, "gpr8" },
1794 { PT_GPR9, "gpr9" },
1795 { PT_GPR10, "gpr10" },
1796 { PT_GPR11, "gpr11" },
1797 { PT_GPR12, "gpr12" },
1798 { PT_GPR13, "gpr13" },
1799 { PT_GPR14, "gpr14" },
1800 { PT_GPR15, "gpr15" },
1801 { PT_ACR0, "acr0" },
1802 { PT_ACR1, "acr1" },
1803 { PT_ACR2, "acr2" },
1804 { PT_ACR3, "acr3" },
1805 { PT_ACR4, "acr4" },
1806 { PT_ACR5, "acr5" },
1807 { PT_ACR6, "acr6" },
1808 { PT_ACR7, "acr7" },
1809 { PT_ACR8, "acr8" },
1810 { PT_ACR9, "acr9" },
1811 { PT_ACR10, "acr10" },
1812 { PT_ACR11, "acr11" },
1813 { PT_ACR12, "acr12" },
1814 { PT_ACR13, "acr13" },
1815 { PT_ACR14, "acr14" },
1816 { PT_ACR15, "acr15" },
1817 { PT_ORIGGPR2, "orig_gpr2" },
1818 { PT_FPC, "fpc" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00001819#if defined(S390)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001820 { PT_FPR0_HI, "fpr0.hi" },
1821 { PT_FPR0_LO, "fpr0.lo" },
1822 { PT_FPR1_HI, "fpr1.hi" },
1823 { PT_FPR1_LO, "fpr1.lo" },
1824 { PT_FPR2_HI, "fpr2.hi" },
1825 { PT_FPR2_LO, "fpr2.lo" },
1826 { PT_FPR3_HI, "fpr3.hi" },
1827 { PT_FPR3_LO, "fpr3.lo" },
1828 { PT_FPR4_HI, "fpr4.hi" },
1829 { PT_FPR4_LO, "fpr4.lo" },
1830 { PT_FPR5_HI, "fpr5.hi" },
1831 { PT_FPR5_LO, "fpr5.lo" },
1832 { PT_FPR6_HI, "fpr6.hi" },
1833 { PT_FPR6_LO, "fpr6.lo" },
1834 { PT_FPR7_HI, "fpr7.hi" },
1835 { PT_FPR7_LO, "fpr7.lo" },
1836 { PT_FPR8_HI, "fpr8.hi" },
1837 { PT_FPR8_LO, "fpr8.lo" },
1838 { PT_FPR9_HI, "fpr9.hi" },
1839 { PT_FPR9_LO, "fpr9.lo" },
1840 { PT_FPR10_HI, "fpr10.hi" },
1841 { PT_FPR10_LO, "fpr10.lo" },
1842 { PT_FPR11_HI, "fpr11.hi" },
1843 { PT_FPR11_LO, "fpr11.lo" },
1844 { PT_FPR12_HI, "fpr12.hi" },
1845 { PT_FPR12_LO, "fpr12.lo" },
1846 { PT_FPR13_HI, "fpr13.hi" },
1847 { PT_FPR13_LO, "fpr13.lo" },
1848 { PT_FPR14_HI, "fpr14.hi" },
1849 { PT_FPR14_LO, "fpr14.lo" },
1850 { PT_FPR15_HI, "fpr15.hi" },
1851 { PT_FPR15_LO, "fpr15.lo" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00001852#endif
1853#if defined(S390X)
1854 { PT_FPR0, "fpr0" },
1855 { PT_FPR1, "fpr1" },
1856 { PT_FPR2, "fpr2" },
1857 { PT_FPR3, "fpr3" },
1858 { PT_FPR4, "fpr4" },
1859 { PT_FPR5, "fpr5" },
1860 { PT_FPR6, "fpr6" },
1861 { PT_FPR7, "fpr7" },
1862 { PT_FPR8, "fpr8" },
1863 { PT_FPR9, "fpr9" },
1864 { PT_FPR10, "fpr10" },
1865 { PT_FPR11, "fpr11" },
1866 { PT_FPR12, "fpr12" },
1867 { PT_FPR13, "fpr13" },
1868 { PT_FPR14, "fpr14" },
1869 { PT_FPR15, "fpr15" },
1870#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001871 { PT_CR_9, "cr9" },
1872 { PT_CR_10, "cr10" },
1873 { PT_CR_11, "cr11" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00001874 { PT_IEEE_IP, "ieee_exception_ip" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001875#endif
1876#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001877 /* XXX No support for these offsets yet. */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001878#elif defined(HPPA)
1879 /* XXX No support for these offsets yet. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001880#elif defined(POWERPC)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001881 { 4*PT_R0, "4*PT_R0" },
1882 { 4*PT_R1, "4*PT_R1" },
1883 { 4*PT_R2, "4*PT_R2" },
1884 { 4*PT_R3, "4*PT_R3" },
1885 { 4*PT_R4, "4*PT_R4" },
1886 { 4*PT_R5, "4*PT_R5" },
1887 { 4*PT_R6, "4*PT_R6" },
1888 { 4*PT_R7, "4*PT_R7" },
1889 { 4*PT_R8, "4*PT_R8" },
1890 { 4*PT_R9, "4*PT_R9" },
1891 { 4*PT_R10, "4*PT_R10" },
1892 { 4*PT_R11, "4*PT_R11" },
1893 { 4*PT_R12, "4*PT_R12" },
1894 { 4*PT_R13, "4*PT_R13" },
1895 { 4*PT_R14, "4*PT_R14" },
1896 { 4*PT_R15, "4*PT_R15" },
1897 { 4*PT_R16, "4*PT_R16" },
1898 { 4*PT_R17, "4*PT_R17" },
1899 { 4*PT_R18, "4*PT_R18" },
1900 { 4*PT_R19, "4*PT_R19" },
1901 { 4*PT_R20, "4*PT_R20" },
1902 { 4*PT_R21, "4*PT_R21" },
1903 { 4*PT_R22, "4*PT_R22" },
1904 { 4*PT_R23, "4*PT_R23" },
1905 { 4*PT_R24, "4*PT_R24" },
1906 { 4*PT_R25, "4*PT_R25" },
1907 { 4*PT_R26, "4*PT_R26" },
1908 { 4*PT_R27, "4*PT_R27" },
1909 { 4*PT_R28, "4*PT_R28" },
1910 { 4*PT_R29, "4*PT_R29" },
1911 { 4*PT_R30, "4*PT_R30" },
1912 { 4*PT_R31, "4*PT_R31" },
1913 { 4*PT_NIP, "4*PT_NIP" },
1914 { 4*PT_MSR, "4*PT_MSR" },
1915 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1916 { 4*PT_CTR, "4*PT_CTR" },
1917 { 4*PT_LNK, "4*PT_LNK" },
1918 { 4*PT_XER, "4*PT_XER" },
1919 { 4*PT_CCR, "4*PT_CCR" },
1920 { 4*PT_FPR0, "4*PT_FPR0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001921#else
1922#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001923 { 0, "r0" },
1924 { 1, "r1" },
1925 { 2, "r2" },
1926 { 3, "r3" },
1927 { 4, "r4" },
1928 { 5, "r5" },
1929 { 6, "r6" },
1930 { 7, "r7" },
1931 { 8, "r8" },
1932 { 9, "r9" },
1933 { 10, "r10" },
1934 { 11, "r11" },
1935 { 12, "r12" },
1936 { 13, "r13" },
1937 { 14, "r14" },
1938 { 15, "r15" },
1939 { 16, "r16" },
1940 { 17, "r17" },
1941 { 18, "r18" },
1942 { 19, "r19" },
1943 { 20, "r20" },
1944 { 21, "r21" },
1945 { 22, "r22" },
1946 { 23, "r23" },
1947 { 24, "r24" },
1948 { 25, "r25" },
1949 { 26, "r26" },
1950 { 27, "r27" },
1951 { 28, "r28" },
1952 { 29, "gp" },
1953 { 30, "fp" },
1954 { 31, "zero" },
1955 { 32, "fp0" },
1956 { 33, "fp" },
1957 { 34, "fp2" },
1958 { 35, "fp3" },
1959 { 36, "fp4" },
1960 { 37, "fp5" },
1961 { 38, "fp6" },
1962 { 39, "fp7" },
1963 { 40, "fp8" },
1964 { 41, "fp9" },
1965 { 42, "fp10" },
1966 { 43, "fp11" },
1967 { 44, "fp12" },
1968 { 45, "fp13" },
1969 { 46, "fp14" },
1970 { 47, "fp15" },
1971 { 48, "fp16" },
1972 { 49, "fp17" },
1973 { 50, "fp18" },
1974 { 51, "fp19" },
1975 { 52, "fp20" },
1976 { 53, "fp21" },
1977 { 54, "fp22" },
1978 { 55, "fp23" },
1979 { 56, "fp24" },
1980 { 57, "fp25" },
1981 { 58, "fp26" },
1982 { 59, "fp27" },
1983 { 60, "fp28" },
1984 { 61, "fp29" },
1985 { 62, "fp30" },
1986 { 63, "fp31" },
1987 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001988#else /* !ALPHA */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001989#ifdef IA64
1990 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
1991 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
1992 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
1993 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
1994 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
1995 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
1996 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
1997 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
1998 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
1999 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
2000 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
2001 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
2002 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
2003 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
2004 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
2005 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
2006 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
2007 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
2008 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
2009 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
2010 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
2011 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
2012 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
2013 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
2014 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
2015 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
2016 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
2017 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
2018 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
2019 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
2020 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
2021 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
2022 /* switch stack: */
2023 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
2024 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
2025 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
2026 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
2027 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
2028 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
2029 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
2030 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2031 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2032 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002033 { PT_B0, "kb0" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002034 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2035 { PT_B4, "b4" }, { PT_B5, "b5" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002036 { PT_AR_PFS, "kar.pfs" },
2037 { PT_AR_LC, "ar.lc" }, { PT_AR_UNAT, "kar.unat" },
2038 { PT_AR_RNAT, "kar.rnat" }, { PT_AR_BSPSTORE, "kar.bspstore" },
2039 { PT_PR, "k.pr" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002040 /* pt_regs */
2041 { PT_CR_IPSR, "cr.ipsr" }, { PT_CR_IIP, "cr.iip" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002042 /*{ PT_CR_IFS, "cr.ifs" },*/ { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002043 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2044 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2045 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2046 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2047 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2048 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2049 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2050 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2051 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2052 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2053 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2054 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2055 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2056 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2057 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
2058#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002059#ifdef I386
2060 { 4*EBX, "4*EBX" },
2061 { 4*ECX, "4*ECX" },
2062 { 4*EDX, "4*EDX" },
2063 { 4*ESI, "4*ESI" },
2064 { 4*EDI, "4*EDI" },
2065 { 4*EBP, "4*EBP" },
2066 { 4*EAX, "4*EAX" },
2067 { 4*DS, "4*DS" },
2068 { 4*ES, "4*ES" },
2069 { 4*FS, "4*FS" },
2070 { 4*GS, "4*GS" },
2071 { 4*ORIG_EAX, "4*ORIG_EAX" },
2072 { 4*EIP, "4*EIP" },
2073 { 4*CS, "4*CS" },
2074 { 4*EFL, "4*EFL" },
2075 { 4*UESP, "4*UESP" },
2076 { 4*SS, "4*SS" },
2077#else /* !I386 */
Michal Ludvig0e035502002-09-23 15:41:01 +00002078#ifdef X86_64
2079 { 8*RDI, "8*RDI" },
2080 { 8*RSI, "8*RSI" },
2081 { 8*RDX, "8*RDX" },
2082 { 8*R10, "8*R10" },
2083 { 8*R8, "8*R8" },
2084 { 8*R9, "8*R9" },
2085 { 8*RBX, "8*RBX" },
2086 { 8*RCX, "8*RCX" },
2087 { 8*RBP, "8*RBP" },
2088 { 8*RAX, "8*RAX" },
2089#if 0
2090 { 8*DS, "8*DS" },
2091 { 8*ES, "8*ES" },
2092 { 8*FS, "8*FS" },
2093 { 8*GS, "8*GS" },
2094#endif
2095 { 8*ORIG_RAX, "8*ORIG_EAX" },
2096 { 8*RIP, "8*RIP" },
2097 { 8*CS, "8*CS" },
2098 { 8*EFLAGS, "8*EFL" },
2099 { 8*RSP, "8*RSP" },
2100 { 8*SS, "8*SS" },
2101 { 8*R11, "8*R11" },
2102 { 8*R12, "8*R12" },
2103 { 8*R13, "8*R13" },
2104 { 8*R14, "8*R14" },
2105 { 8*R15, "8*R15" },
2106#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002107#ifdef M68K
2108 { 4*PT_D1, "4*PT_D1" },
2109 { 4*PT_D2, "4*PT_D2" },
2110 { 4*PT_D3, "4*PT_D3" },
2111 { 4*PT_D4, "4*PT_D4" },
2112 { 4*PT_D5, "4*PT_D5" },
2113 { 4*PT_D6, "4*PT_D6" },
2114 { 4*PT_D7, "4*PT_D7" },
2115 { 4*PT_A0, "4*PT_A0" },
2116 { 4*PT_A1, "4*PT_A1" },
2117 { 4*PT_A2, "4*PT_A2" },
2118 { 4*PT_A3, "4*PT_A3" },
2119 { 4*PT_A4, "4*PT_A4" },
2120 { 4*PT_A5, "4*PT_A5" },
2121 { 4*PT_A6, "4*PT_A6" },
2122 { 4*PT_D0, "4*PT_D0" },
2123 { 4*PT_USP, "4*PT_USP" },
2124 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2125 { 4*PT_SR, "4*PT_SR" },
2126 { 4*PT_PC, "4*PT_PC" },
2127#endif /* M68K */
2128#endif /* !I386 */
Wichert Akkermanccef6372002-05-01 16:39:22 +00002129#ifdef SH
2130 { 4*REG_REG0, "4*REG_REG0" },
2131 { 4*(REG_REG0+1), "4*REG_REG1" },
2132 { 4*(REG_REG0+2), "4*REG_REG2" },
2133 { 4*(REG_REG0+3), "4*REG_REG3" },
2134 { 4*(REG_REG0+4), "4*REG_REG4" },
2135 { 4*(REG_REG0+5), "4*REG_REG5" },
2136 { 4*(REG_REG0+6), "4*REG_REG6" },
2137 { 4*(REG_REG0+7), "4*REG_REG7" },
2138 { 4*(REG_REG0+8), "4*REG_REG8" },
2139 { 4*(REG_REG0+9), "4*REG_REG9" },
2140 { 4*(REG_REG0+10), "4*REG_REG10" },
2141 { 4*(REG_REG0+11), "4*REG_REG11" },
2142 { 4*(REG_REG0+12), "4*REG_REG12" },
2143 { 4*(REG_REG0+13), "4*REG_REG13" },
2144 { 4*(REG_REG0+14), "4*REG_REG14" },
2145 { 4*REG_REG15, "4*REG_REG15" },
2146 { 4*REG_PC, "4*REG_PC" },
2147 { 4*REG_PR, "4*REG_PR" },
2148 { 4*REG_SR, "4*REG_SR" },
2149 { 4*REG_GBR, "4*REG_GBR" },
2150 { 4*REG_MACH, "4*REG_MACH" },
2151 { 4*REG_MACL, "4*REG_MACL" },
2152 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
2153 { 4*REG_FPUL, "4*REG_FPUL" },
2154 { 4*REG_FPREG0, "4*REG_FPREG0" },
2155 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
2156 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
2157 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
2158 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
2159 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
2160 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
2161 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
2162 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
2163 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
2164 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
2165 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
2166 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
2167 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
2168 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
2169 { 4*REG_FPREG15, "4*REG_FPREG15" },
2170 { 4*REG_XDREG0, "4*REG_XDREG0" },
2171 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
2172 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
2173 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
2174 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
2175 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
2176 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
2177 { 4*REG_XDREG14, "4*REG_XDREG14" },
2178 { 4*REG_FPSCR, "4*REG_FPSCR" },
2179#endif /* SH */
2180
Michal Ludvig10a88d02002-10-07 14:31:00 +00002181#if !defined(S390) && !defined(S390X) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002182 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002183#endif
Michal Ludvig0e035502002-09-23 15:41:01 +00002184#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002185 { uoff(i387), "offsetof(struct user, i387)" },
2186#else /* !I386 */
2187#ifdef M68K
2188 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
2189#endif /* M68K */
2190#endif /* !I386 */
2191 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2192 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2193 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
2194 { uoff(start_code), "offsetof(struct user, start_code)" },
2195 { uoff(start_stack), "offsetof(struct user, start_stack)" },
2196 { uoff(signal), "offsetof(struct user, signal)" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002197#if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002198 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002199#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002200 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002201#if !defined(ARM) && !defined(MIPS) && !defined(S390) && !defined(S390X)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002202 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
2203#endif
2204 { uoff(magic), "offsetof(struct user, magic)" },
2205 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002206#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002207 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
2208#endif /* I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002209#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002210#endif /* !ALPHA */
2211#endif /* !POWERPC/!SPARC */
2212#endif /* LINUX */
2213#ifdef SUNOS4
2214 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
2215 { uoff(u_procp), "offsetof(struct user, u_procp)" },
2216 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
2217 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
2218 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
2219 { uoff(u_ap), "offsetof(struct user, u_ap)" },
2220 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
2221 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
2222 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
2223 { uoff(u_error), "offsetof(struct user, u_error)" },
2224 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
2225 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
2226 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
2227 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
2228 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
2229 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
2230 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
2231 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
2232 { uoff(u_code), "offsetof(struct user, u_code)" },
2233 { uoff(u_addr), "offsetof(struct user, u_addr)" },
2234 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
2235 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
2236 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
2237 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
2238 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
2239 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
2240 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
2241 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
2242 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
2243 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
2244 { uoff(u_ru), "offsetof(struct user, u_ru)" },
2245 { uoff(u_cru), "offsetof(struct user, u_cru)" },
2246 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
2247 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
2248 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
2249 { uoff(u_start), "offsetof(struct user, u_start)" },
2250 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
2251 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
2252 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
2253 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
2254 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
2255 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
2256 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
2257 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
2258 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
2259#endif /* SUNOS4 */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002260#ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002261 { sizeof(struct user), "sizeof(struct user)" },
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002262#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002263 { 0, NULL },
2264};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002265#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002266
2267int
2268sys_ptrace(tcp)
2269struct tcb *tcp;
2270{
2271 char *cmd;
2272 struct xlat *x;
2273 long addr;
2274
2275 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
2276 if (!cmd)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002277#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002278 cmd = "PTRACE_???";
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002279#else
2280 cmd = "PT_???";
2281#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002282 if (entering(tcp)) {
2283 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
2284 addr = tcp->u_arg[2];
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002285#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002286 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2287 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2288 for (x = struct_user_offsets; x->str; x++) {
2289 if (x->val >= addr)
2290 break;
2291 }
2292 if (!x->str)
2293 tprintf("%#lx, ", addr);
2294 else if (x->val > addr && x != struct_user_offsets) {
2295 x--;
2296 tprintf("%s + %ld, ", x->str, addr - x->val);
2297 }
2298 else
2299 tprintf("%s, ", x->str);
2300 }
2301 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002302#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002303 tprintf("%#lx, ", tcp->u_arg[2]);
2304#ifdef LINUX
2305 switch (tcp->u_arg[0]) {
2306 case PTRACE_PEEKDATA:
2307 case PTRACE_PEEKTEXT:
2308 case PTRACE_PEEKUSER:
2309 break;
2310 case PTRACE_CONT:
2311 case PTRACE_SINGLESTEP:
2312 case PTRACE_SYSCALL:
2313 case PTRACE_DETACH:
2314 printsignal(tcp->u_arg[3]);
2315 break;
2316 default:
2317 tprintf("%#lx", tcp->u_arg[3]);
2318 break;
2319 }
2320 } else {
2321 switch (tcp->u_arg[0]) {
2322 case PTRACE_PEEKDATA:
2323 case PTRACE_PEEKTEXT:
2324 case PTRACE_PEEKUSER:
2325 printnum(tcp, tcp->u_arg[3], "%#x");
2326 break;
2327 }
2328 }
2329#endif /* LINUX */
2330#ifdef SUNOS4
2331 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
2332 tcp->u_arg[0] == PTRACE_WRITETEXT) {
2333 tprintf("%lu, ", tcp->u_arg[3]);
2334 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2335 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
2336 tcp->u_arg[0] != PTRACE_READTEXT) {
2337 tprintf("%#lx", tcp->u_arg[3]);
2338 }
2339 } else {
2340 if (tcp->u_arg[0] == PTRACE_READDATA ||
2341 tcp->u_arg[0] == PTRACE_READTEXT) {
2342 tprintf("%lu, ", tcp->u_arg[3]);
2343 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2344 }
2345 }
2346#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002347#ifdef FREEBSD
2348 tprintf("%lu", tcp->u_arg[3]);
2349 }
2350#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002351 return 0;
2352}
2353
2354#endif /* !SVR4 */