blob: c6d5ee2d95c722cc40e793b330607f4a12f27c2c [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
Roland McGrath5a223472002-12-15 23:58:26 +000069# undef fpu
Wichert Akkerman00a82ee2001-03-28 20:29:17 +000070#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
Roland McGrath5a223472002-12-15 23:58:26 +000086#ifdef HAVE_LINUX_FUTEX_H
87#include <linux/futex.h>
88#endif
89#if defined LINUX
90# ifndef FUTEX_WAIT
91# define FUTEX_WAIT 0
92# endif
93# ifndef FUTEX_WAKE
94# define FUTEX_WAKE 1
95# endif
96# ifndef FUTEX_FD
97# define FUTEX_FD 2
98# endif
99#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000100
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000101#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000102#include <asm/posix_types.h>
103#undef GETGROUPS_T
104#define GETGROUPS_T __kernel_gid_t
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000105#endif /* LINUX */
106
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000107#if defined(LINUX) && defined(IA64)
108# include <asm/ptrace_offsets.h>
109# include <asm/rse.h>
110#endif
111
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000112#ifdef HAVE_PRCTL
113#include <sys/prctl.h>
114#endif
115
116#ifndef WCOREDUMP
117#define WCOREDUMP(status) ((status) & 0200)
118#endif
119
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000120/* WTA: this was `&& !defined(LINUXSPARC)', this seems unneeded though? */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000121#if defined(HAVE_PRCTL)
122static struct xlat prctl_options[] = {
123#ifdef PR_MAXPROCS
124 { PR_MAXPROCS, "PR_MAXPROCS" },
125#endif
126#ifdef PR_ISBLOCKED
127 { PR_ISBLOCKED, "PR_ISBLOCKED" },
128#endif
129#ifdef PR_SETSTACKSIZE
130 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
131#endif
132#ifdef PR_GETSTACKSIZE
133 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
134#endif
135#ifdef PR_MAXPPROCS
136 { PR_MAXPPROCS, "PR_MAXPPROCS" },
137#endif
138#ifdef PR_UNBLKONEXEC
139 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
140#endif
141#ifdef PR_ATOMICSIM
142 { PR_ATOMICSIM, "PR_ATOMICSIM" },
143#endif
144#ifdef PR_SETEXITSIG
145 { PR_SETEXITSIG, "PR_SETEXITSIG" },
146#endif
147#ifdef PR_RESIDENT
148 { PR_RESIDENT, "PR_RESIDENT" },
149#endif
150#ifdef PR_ATTACHADDR
151 { PR_ATTACHADDR, "PR_ATTACHADDR" },
152#endif
153#ifdef PR_DETACHADDR
154 { PR_DETACHADDR, "PR_DETACHADDR" },
155#endif
156#ifdef PR_TERMCHILD
157 { PR_TERMCHILD, "PR_TERMCHILD" },
158#endif
159#ifdef PR_GETSHMASK
160 { PR_GETSHMASK, "PR_GETSHMASK" },
161#endif
162#ifdef PR_GETNSHARE
163 { PR_GETNSHARE, "PR_GETNSHARE" },
164#endif
165#if defined(PR_SET_PDEATHSIG)
166 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
167#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000168#ifdef PR_COREPID
169 { PR_COREPID, "PR_COREPID" },
170#endif
171#ifdef PR_ATTACHADDRPERM
172 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
173#endif
174#ifdef PR_PTHREADEXIT
175 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
176#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000177#ifdef PR_SET_PDEATHSIG
178 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
179#endif
180#ifdef PR_GET_PDEATHSIG
181 { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
182#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000183#ifdef PR_GET_UNALIGN
184 { PR_GET_UNALIGN, "PR_GET_UNALIGN" },
185#endif
186#ifdef PR_SET_UNALIGN
187 { PR_SET_UNALIGN, "PR_SET_UNALIGN" },
188#endif
189#ifdef PR_GET_KEEPCAPS
190 { PR_GET_KEEPCAPS, "PR_GET_KEEP_CAPS" },
191#endif
192#ifdef PR_SET_KEEPCAPS
193 { PR_SET_KEEPCAPS, "PR_SET_KEEP_CAPS" },
194#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195 { 0, NULL },
196};
197
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000198
199const char *
200unalignctl_string (unsigned int ctl)
201{
202 static char buf[16];
203
204 switch (ctl) {
205#ifdef PR_UNALIGN_NOPRINT
206 case PR_UNALIGN_NOPRINT:
207 return "NOPRINT";
208#endif
209#ifdef PR_UNALIGN_SIGBUS
210 case PR_UNALIGN_SIGBUS:
211 return "SIGBUS";
212#endif
213 default:
214 break;
215 }
216 sprintf(buf, "%x", ctl);
217 return buf;
218}
219
220
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000221int
222sys_prctl(tcp)
223struct tcb *tcp;
224{
225 int i;
226
227 if (entering(tcp)) {
228 printxval(prctl_options, tcp->u_arg[0], "PR_???");
229 switch (tcp->u_arg[0]) {
230#ifdef PR_GETNSHARE
231 case PR_GETNSHARE:
232 break;
233#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000234#ifdef PR_SET_DEATHSIG
235 case PR_GET_PDEATHSIG:
236 break;
237#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000238#ifdef PR_SET_UNALIGN
239 case PR_SET_UNALIGN:
240 tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
241 break;
242#endif
243#ifdef PR_GET_UNALIGN
244 case PR_GET_UNALIGN:
245 tprintf(", %#lx", tcp->u_arg[1]);
246 break;
247#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000248 default:
249 for (i = 1; i < tcp->u_nargs; i++)
250 tprintf(", %#lx", tcp->u_arg[i]);
251 break;
252 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000253 } else {
254 switch (tcp->u_arg[0]) {
255#ifdef PR_GET_PDEATHSIG
256 case PR_GET_PDEATHSIG:
257 for (i=1; i<tcp->u_nargs; i++)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000258 tprintf(", %#lx", tcp->u_arg[i]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000259 break;
260#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000261#ifdef PR_SET_UNALIGN
262 case PR_SET_UNALIGN:
263 break;
264#endif
265#ifdef PR_GET_UNALIGN
266 case PR_GET_UNALIGN:
267 {
268 int ctl;
269
270 umove(tcp, tcp->u_arg[1], &ctl);
271 tcp->auxstr = unalignctl_string(ctl);
272 return RVAL_STR;
273 }
274#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000275 default:
276 break;
277 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000278 }
279 return 0;
280}
281
282#endif /* HAVE_PRCTL */
283
284int
285sys_gethostid(tcp)
286struct tcb *tcp;
287{
288 if (exiting(tcp))
289 return RVAL_HEX;
290 return 0;
291}
292
293int
294sys_sethostname(tcp)
295struct tcb *tcp;
296{
297 if (entering(tcp)) {
298 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
299 tprintf(", %lu", tcp->u_arg[1]);
300 }
301 return 0;
302}
303
304int
305sys_gethostname(tcp)
306struct tcb *tcp;
307{
308 if (exiting(tcp)) {
309 if (syserror(tcp))
310 tprintf("%#lx", tcp->u_arg[0]);
311 else
312 printpath(tcp, tcp->u_arg[0]);
313 tprintf(", %lu", tcp->u_arg[1]);
314 }
315 return 0;
316}
317
318int
319sys_setdomainname(tcp)
320struct tcb *tcp;
321{
322 if (entering(tcp)) {
323 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
324 tprintf(", %lu", tcp->u_arg[1]);
325 }
326 return 0;
327}
328
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000329#if !defined(LINUX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000330
331int
332sys_getdomainname(tcp)
333struct tcb *tcp;
334{
335 if (exiting(tcp)) {
336 if (syserror(tcp))
337 tprintf("%#lx", tcp->u_arg[0]);
338 else
339 printpath(tcp, tcp->u_arg[0]);
340 tprintf(", %lu", tcp->u_arg[1]);
341 }
342 return 0;
343}
344#endif /* !LINUX */
345
346int
347sys_exit(tcp)
348struct tcb *tcp;
349{
350 if (exiting(tcp)) {
351 fprintf(stderr, "_exit returned!\n");
352 return -1;
353 }
354 /* special case: we stop tracing this process, finish line now */
355 tprintf("%ld) ", tcp->u_arg[0]);
356 tabto(acolumn);
357 tprintf("= ?");
358 printtrailer(tcp);
359 return 0;
360}
361
362int
363internal_exit(tcp)
364struct tcb *tcp;
365{
366 if (entering(tcp))
367 tcp->flags |= TCB_EXITING;
368 return 0;
369}
370
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000371#ifdef USE_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000372
373int
374sys_fork(tcp)
375struct tcb *tcp;
376{
377 if (exiting(tcp)) {
378 if (getrval2(tcp)) {
379 tcp->auxstr = "child process";
380 return RVAL_UDECIMAL | RVAL_STR;
381 }
382 }
383 return 0;
384}
385
John Hughes4e36a812001-04-18 15:11:51 +0000386#if UNIXWARE > 2
387
388int
389sys_rfork(tcp)
390struct tcb *tcp;
391{
392 if (entering(tcp)) {
393 tprintf ("%ld", tcp->u_arg[0]);
394 }
395 else {
396 if (getrval2(tcp)) {
397 tcp->auxstr = "child process";
398 return RVAL_UDECIMAL | RVAL_STR;
399 }
400 }
401 return 0;
402}
403
404#endif
405
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406int
407internal_fork(tcp)
408struct tcb *tcp;
409{
410 struct tcb *tcpchild;
411
412 if (exiting(tcp)) {
413 if (getrval2(tcp))
414 return 0;
415 if (!followfork)
416 return 0;
417 if (nprocs == MAX_PROCS) {
418 tcp->flags &= ~TCB_FOLLOWFORK;
419 fprintf(stderr, "sys_fork: tcb table full\n");
420 return 0;
421 }
422 else
423 tcp->flags |= TCB_FOLLOWFORK;
424 if (syserror(tcp))
425 return 0;
426 if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
427 fprintf(stderr, "sys_fork: tcb table full\n");
428 return 0;
429 }
Wichert Akkerman2e4ffe52000-09-03 23:57:48 +0000430 if (proc_open(tcpchild, 2) < 0)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000431 droptcb(tcpchild);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000432 }
433 return 0;
434}
435
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000436#else /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000438#ifdef LINUX
439
440/* defines copied from linux/sched.h since we can't include that
441 * ourselves (it conflicts with *lots* of libc includes)
442 */
443#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
444#define CLONE_VM 0x00000100 /* set if VM shared between processes */
445#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
446#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
447#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
448#define CLONE_PID 0x00001000 /* set if pid shared */
449#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
450#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
451#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
452
453static struct xlat clone_flags[] = {
454 { CLONE_VM, "CLONE_VM" },
455 { CLONE_FS, "CLONE_FS" },
456 { CLONE_FILES, "CLONE_FILES" },
457 { CLONE_SIGHAND, "CLONE_SIGHAND" },
458 { CLONE_PID, "CLONE_PID" },
459 { CLONE_PTRACE, "CLONE_PTRACE" },
460 { CLONE_VFORK, "CLONE_VFORK" },
461 { CLONE_PARENT, "CLONE_PARENT" },
462 { 0, NULL },
463};
464
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000465int
466sys_clone(tcp)
467struct tcb *tcp;
468{
469 if (exiting(tcp)) {
470 tprintf("child_stack=%#lx, flags=", tcp->u_arg[1]);
471 if (printflags(clone_flags, tcp->u_arg[0]) == 0)
472 tprintf("0");
473 }
474 return 0;
475}
476
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000477int
478sys_clone2(tcp)
479struct tcb *tcp;
480{
481 if (exiting(tcp)) {
482 tprintf("child_stack=%#lx, stack_size=%#lx, flags=",
483 tcp->u_arg[1], tcp->u_arg[2]);
484 if (printflags(clone_flags, tcp->u_arg[0]) == 0)
485 tprintf("0");
486 }
487 return 0;
488}
489
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000490#endif
491
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000492int
493sys_fork(tcp)
494struct tcb *tcp;
495{
496 if (exiting(tcp))
497 return RVAL_UDECIMAL;
498 return 0;
499}
500
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000501int
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000502change_syscall(tcp, new)
503struct tcb *tcp;
504int new;
505{
506#if defined(LINUX)
507#if defined(I386)
508 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000509 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000510 return -1;
511 return 0;
Michal Ludvig0e035502002-09-23 15:41:01 +0000512#elif defined(X86_64)
513 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000514 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
Michal Ludvig0e035502002-09-23 15:41:01 +0000515 return -1;
516 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000517#elif defined(POWERPC)
Wichert Akkerman5c4c69b2001-04-12 09:00:47 +0000518 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000519 return -1;
Michal Ludvig10a88d02002-10-07 14:31:00 +0000520#elif defined(S390) || defined(S390X)
521 /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
522 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new)<0)
523 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000524 return 0;
525#elif defined(M68K)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000526 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000527 return -1;
528 return 0;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000529#elif defined(SPARC)
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000530 struct regs regs;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000531 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0)<0)
532 return -1;
Wichert Akkerman00a82ee2001-03-28 20:29:17 +0000533 regs.r_g1=new;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000534 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0)<0)
535 return -1;
536 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000537#elif defined(MIPS)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000538 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000539 return -1;
540 return 0;
541#elif defined(ALPHA)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000542 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new)<0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000543 return -1;
544 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000545#elif defined(IA64)
546 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new)<0)
547 return -1;
548 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000549#elif defined(HPPA)
550 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new)<0)
551 return -1;
552 return 0;
Wichert Akkermanccef6372002-05-01 16:39:22 +0000553#elif defined(SH)
554 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL), new)<0)
555 return -1;
556 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000557#else
558#warning Do not know how to handle change_syscall for this architecture
559#endif /* architecture */
560#endif /* LINUX */
561 return -1;
562}
563
564int
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000565setarg(tcp, argnum)
566 struct tcb *tcp;
567 int argnum;
568{
569#if defined (IA64)
570 {
571 unsigned long *bsp, *ap;
572
573 if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
574 return -1;
575
576 ap = ia64_rse_skip_regs(bsp, argnum);
577 errno = 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000578 ptrace(PTRACE_POKEDATA, tcp->pid, (char *) ap, tcp->u_arg[argnum]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000579 if (errno)
580 return -1;
581
582 }
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000583#elif defined(I386)
584 {
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000585 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*argnum), tcp->u_arg[argnum]);
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000586 if (errno)
587 return -1;
588 }
Michal Ludvig0e035502002-09-23 15:41:01 +0000589#elif defined(X86_64)
590 {
591 ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(8*(long)argnum), tcp->u_arg[argnum]);
592 if (errno)
593 return -1;
594 }
Ralf Baechlee3816102000-08-01 00:06:06 +0000595#elif defined(MIPS)
596 {
597 errno = 0;
598 if (argnum < 4)
599 ptrace(PTRACE_POKEUSER, tcp->pid,
600 (char*)(REG_A0 + argnum), tcp->u_arg[argnum]);
601 else {
602 unsigned long *sp;
603
604 if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
605 return -1;
606
607 ptrace(PTRACE_POKEDATA, tcp->pid,
608 (char*)(sp + argnum - 4), tcp->u_arg[argnum]);
609 }
610 if (errno)
611 return -1;
612 }
Michal Ludvig10a88d02002-10-07 14:31:00 +0000613#elif defined(S390) || defined(S390X)
614 {
615 if(argnum <= 5)
616 ptrace(PTRACE_POKEUSER, tcp->pid,
Roland McGrath5a223472002-12-15 23:58:26 +0000617 (char *) (argnum==0 ? PT_ORIGGPR2 :
618 PT_GPR2 + argnum*sizeof(long)),
Michal Ludvig10a88d02002-10-07 14:31:00 +0000619 tcp->u_arg[argnum]);
620 else
621 return -E2BIG;
622 if (errno)
623 return -1;
624 }
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000625#else
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000626# warning Sorry, setargs not implemented for this architecture.
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000627#endif
628 return 0;
629}
630
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000631#ifdef SYS_clone
632int
633internal_clone(tcp)
634struct tcb *tcp;
635{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000636 struct tcb *tcpchild;
637 int pid;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000638 if (entering(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000639 if (!followfork)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000640 return 0;
641 if (nprocs == MAX_PROCS) {
642 tcp->flags &= ~TCB_FOLLOWFORK;
643 fprintf(stderr, "sys_fork: tcb table full\n");
644 return 0;
645 }
646 tcp->flags |= TCB_FOLLOWFORK;
647
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000648
649 if (setbpt(tcp) < 0)
650 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000651 } else {
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000652 int bpt = tcp->flags & TCB_BPTSET;
653
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000654 if (!(tcp->flags & TCB_FOLLOWFORK))
655 return 0;
656
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000657 if (syserror(tcp)) {
658 if (bpt)
659 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000660 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000661 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000662
663 pid = tcp->u_rval;
664 if ((tcpchild = alloctcb(pid)) == NULL) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000665 if (bpt)
666 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000667 fprintf(stderr, " [tcb table full]\n");
668 kill(pid, SIGKILL); /* XXX */
669 return 0;
670 }
671
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000672 /* Attach to the new child */
673 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000674 if (bpt)
675 clearbpt(tcp);
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000676 perror("PTRACE_ATTACH");
677 fprintf(stderr, "Too late?\n");
678 droptcb(tcpchild);
679 return 0;
680 }
681
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000682 if (bpt)
683 clearbpt(tcp);
684
Ulrich Drepper90512f01999-12-24 07:22:25 +0000685 tcpchild->flags |= TCB_ATTACHED;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000686 if (bpt) {
687 tcpchild->flags |= TCB_BPTSET;
688 tcpchild->baddr = tcp->baddr;
689 memcpy(tcpchild->inst, tcp->inst,
690 sizeof tcpchild->inst);
691 }
Ulrich Drepper90512f01999-12-24 07:22:25 +0000692 newoutf(tcpchild);
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000693 tcpchild->parent = tcp;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000694 tcp->nchildren++;
695 if (!qflag)
696 fprintf(stderr, "Process %d attached\n", pid);
697 }
698 return 0;
699}
700#endif
701
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000702int
703internal_fork(tcp)
704struct tcb *tcp;
705{
706 struct tcb *tcpchild;
707 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000708 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000709
710#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000711 if (tcp->scno == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000712 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000713 if (!followvfork ||
Pavel Machek9a9f10b2000-02-01 16:22:52 +0000714 change_syscall(tcp, SYS_fork) < 0)
Nate Sammonsccd8f211999-03-29 22:57:54 +0000715 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000716 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000717#endif
718 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000719 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720 return 0;
721 if (nprocs == MAX_PROCS) {
722 tcp->flags &= ~TCB_FOLLOWFORK;
723 fprintf(stderr, "sys_fork: tcb table full\n");
724 return 0;
725 }
726 tcp->flags |= TCB_FOLLOWFORK;
727 if (setbpt(tcp) < 0)
728 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000729 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000730 else {
731 int bpt = tcp->flags & TCB_BPTSET;
732
733 if (!(tcp->flags & TCB_FOLLOWFORK))
734 return 0;
735 if (bpt)
736 clearbpt(tcp);
737
738 if (syserror(tcp))
739 return 0;
740
741 pid = tcp->u_rval;
742 if ((tcpchild = alloctcb(pid)) == NULL) {
743 fprintf(stderr, " [tcb table full]\n");
744 kill(pid, SIGKILL); /* XXX */
745 return 0;
746 }
747#ifdef LINUX
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000748#ifdef HPPA
749 /* The child must have run before it can be attached. */
750 /* This must be a bug in the parisc kernel, but I havn't
751 * identified it yet. Seems to be an issue associated
752 * with attaching to a process (which sends it a signal)
753 * before that process has ever been scheduled. When
754 * debugging, I started seeing crashes in
755 * arch/parisc/kernel/signal.c:do_signal(), apparently
756 * caused by r8 getting corrupt over the dequeue_signal()
757 * call. Didn't make much sense though...
758 */
759 {
760 struct timeval tv;
761 tv.tv_sec = 0;
762 tv.tv_usec = 10000;
763 select(0, NULL, NULL, NULL, &tv);
764 }
765#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000766 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
767 perror("PTRACE_ATTACH");
768 fprintf(stderr, "Too late?\n");
769 droptcb(tcpchild);
770 return 0;
771 }
772#endif /* LINUX */
773#ifdef SUNOS4
774#ifdef oldway
775 /* The child must have run before it can be attached. */
776 {
777 struct timeval tv;
778 tv.tv_sec = 0;
779 tv.tv_usec = 10000;
780 select(0, NULL, NULL, NULL, &tv);
781 }
782 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
783 perror("PTRACE_ATTACH");
784 fprintf(stderr, "Too late?\n");
785 droptcb(tcpchild);
786 return 0;
787 }
788#else /* !oldway */
789 /* Try to catch the new process as soon as possible. */
790 {
791 int i;
792 for (i = 0; i < 1024; i++)
793 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
794 break;
795 if (i == 1024) {
796 perror("PTRACE_ATTACH");
797 fprintf(stderr, "Too late?\n");
798 droptcb(tcpchild);
799 return 0;
800 }
801 }
802#endif /* !oldway */
803#endif /* SUNOS4 */
804 tcpchild->flags |= TCB_ATTACHED;
805 /* Child has BPT too, must be removed on first occasion */
806 if (bpt) {
807 tcpchild->flags |= TCB_BPTSET;
808 tcpchild->baddr = tcp->baddr;
809 memcpy(tcpchild->inst, tcp->inst,
810 sizeof tcpchild->inst);
811 }
812 newoutf(tcpchild);
813 tcpchild->parent = tcp;
814 tcp->nchildren++;
815 if (!qflag)
816 fprintf(stderr, "Process %d attached\n", pid);
817 }
818 return 0;
819}
820
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000821#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000822
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000823#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000824
825int
826sys_vfork(tcp)
827struct tcb *tcp;
828{
829 if (exiting(tcp))
830 return RVAL_UDECIMAL;
831 return 0;
832}
833
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000834#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000835
836#ifndef LINUX
837
838static char idstr[16];
839
840int
841sys_getpid(tcp)
842struct tcb *tcp;
843{
844 if (exiting(tcp)) {
845 sprintf(idstr, "ppid %lu", getrval2(tcp));
846 tcp->auxstr = idstr;
847 return RVAL_STR;
848 }
849 return 0;
850}
851
852int
853sys_getuid(tcp)
854struct tcb *tcp;
855{
856 if (exiting(tcp)) {
857 sprintf(idstr, "euid %lu", getrval2(tcp));
858 tcp->auxstr = idstr;
859 return RVAL_STR;
860 }
861 return 0;
862}
863
864int
865sys_getgid(tcp)
866struct tcb *tcp;
867{
868 if (exiting(tcp)) {
869 sprintf(idstr, "egid %lu", getrval2(tcp));
870 tcp->auxstr = idstr;
871 return RVAL_STR;
872 }
873 return 0;
874}
875
876#endif /* !LINUX */
877
878#ifdef LINUX
879
880int
881sys_setuid(tcp)
882struct tcb *tcp;
883{
884 if (entering(tcp)) {
885 tprintf("%u", (uid_t) tcp->u_arg[0]);
886 }
887 return 0;
888}
889
890int
891sys_setgid(tcp)
892struct tcb *tcp;
893{
894 if (entering(tcp)) {
895 tprintf("%u", (gid_t) tcp->u_arg[0]);
896 }
897 return 0;
898}
899
900int
901sys_getresuid(tcp)
902 struct tcb *tcp;
903{
904 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000905 __kernel_uid_t uid;
906 if (syserror(tcp))
907 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
908 tcp->u_arg[1], tcp->u_arg[2]);
909 else {
910 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
911 tprintf("%#lx, ", tcp->u_arg[0]);
912 else
913 tprintf("ruid %lu, ", (unsigned long) uid);
914 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
915 tprintf("%#lx, ", tcp->u_arg[0]);
916 else
917 tprintf("euid %lu, ", (unsigned long) uid);
918 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
919 tprintf("%#lx", tcp->u_arg[0]);
920 else
921 tprintf("suid %lu", (unsigned long) uid);
922 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000923 }
924 return 0;
925}
926
927int
928sys_getresgid(tcp)
929struct tcb *tcp;
930{
931 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000932 __kernel_gid_t gid;
933 if (syserror(tcp))
934 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
935 tcp->u_arg[1], tcp->u_arg[2]);
936 else {
937 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
938 tprintf("%#lx, ", tcp->u_arg[0]);
939 else
940 tprintf("rgid %lu, ", (unsigned long) gid);
941 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
942 tprintf("%#lx, ", tcp->u_arg[0]);
943 else
944 tprintf("egid %lu, ", (unsigned long) gid);
945 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
946 tprintf("%#lx", tcp->u_arg[0]);
947 else
948 tprintf("sgid %lu", (unsigned long) gid);
949 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000950 }
951 return 0;
952}
953
954#endif /* LINUX */
955
956int
957sys_setreuid(tcp)
958struct tcb *tcp;
959{
960 if (entering(tcp)) {
961 tprintf("%lu, %lu",
962 (unsigned long) (uid_t) tcp->u_arg[0],
963 (unsigned long) (uid_t) tcp->u_arg[1]);
964 }
965 return 0;
966}
967
968int
969sys_setregid(tcp)
970struct tcb *tcp;
971{
972 if (entering(tcp)) {
973 tprintf("%lu, %lu",
974 (unsigned long) (gid_t) tcp->u_arg[0],
975 (unsigned long) (gid_t) tcp->u_arg[1]);
976 }
977 return 0;
978}
979
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000980#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000981int
982sys_setresuid(tcp)
983 struct tcb *tcp;
984{
985 if (entering(tcp)) {
986 tprintf("ruid %u, euid %u, suid %u",
987 (uid_t) tcp->u_arg[0],
988 (uid_t) tcp->u_arg[1],
989 (uid_t) tcp->u_arg[2]);
990 }
991 return 0;
992}
993int
994sys_setresgid(tcp)
995 struct tcb *tcp;
996{
997 if (entering(tcp)) {
998 tprintf("rgid %u, egid %u, sgid %u",
999 (uid_t) tcp->u_arg[0],
1000 (uid_t) tcp->u_arg[1],
1001 (uid_t) tcp->u_arg[2]);
1002 }
1003 return 0;
1004}
1005
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001006#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001007
1008int
1009sys_setgroups(tcp)
1010struct tcb *tcp;
1011{
1012 int i, len;
1013 GETGROUPS_T *gidset;
1014
1015 if (entering(tcp)) {
1016 len = tcp->u_arg[0];
1017 tprintf("%u, ", len);
1018 if (len <= 0) {
1019 tprintf("[]");
1020 return 0;
1021 }
1022 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1023 if (gidset == NULL) {
1024 fprintf(stderr, "sys_setgroups: out of memory\n");
1025 return -1;
1026 }
1027 if (!verbose(tcp))
1028 tprintf("%#lx", tcp->u_arg[1]);
1029 else if (umoven(tcp, tcp->u_arg[1],
1030 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1031 tprintf("[?]");
1032 else {
1033 tprintf("[");
1034 for (i = 0; i < len; i++)
1035 tprintf("%s%lu", i ? ", " : "",
1036 (unsigned long) gidset[i]);
1037 tprintf("]");
1038 }
1039 free((char *) gidset);
1040 }
1041 return 0;
1042}
1043
1044int
1045sys_getgroups(tcp)
1046struct tcb *tcp;
1047{
1048 int i, len;
1049 GETGROUPS_T *gidset;
1050
1051 if (entering(tcp)) {
1052 len = tcp->u_arg[0];
1053 tprintf("%u, ", len);
1054 } else {
1055 len = tcp->u_rval;
1056 if (len <= 0) {
1057 tprintf("[]");
1058 return 0;
1059 }
1060 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1061 if (gidset == NULL) {
1062 fprintf(stderr, "sys_getgroups: out of memory\n");
1063 return -1;
1064 }
1065 if (!tcp->u_arg[1])
1066 tprintf("NULL");
1067 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
1068 tprintf("%#lx", tcp->u_arg[1]);
1069 else if (umoven(tcp, tcp->u_arg[1],
1070 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1071 tprintf("[?]");
1072 else {
1073 tprintf("[");
1074 for (i = 0; i < len; i++)
1075 tprintf("%s%lu", i ? ", " : "",
1076 (unsigned long) gidset[i]);
1077 tprintf("]");
1078 }
1079 free((char *)gidset);
1080 }
1081 return 0;
1082}
1083
1084int
1085sys_setpgrp(tcp)
1086struct tcb *tcp;
1087{
1088 if (entering(tcp)) {
1089#ifndef SVR4
1090 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1091#endif /* !SVR4 */
1092 }
1093 return 0;
1094}
1095
1096int
1097sys_getpgrp(tcp)
1098struct tcb *tcp;
1099{
1100 if (entering(tcp)) {
1101#ifndef SVR4
1102 tprintf("%lu", tcp->u_arg[0]);
1103#endif /* !SVR4 */
1104 }
1105 return 0;
1106}
1107
1108int
1109sys_getsid(tcp)
1110struct tcb *tcp;
1111{
1112 if (entering(tcp)) {
1113 tprintf("%lu", tcp->u_arg[0]);
1114 }
1115 return 0;
1116}
1117
1118int
1119sys_setsid(tcp)
1120struct tcb *tcp;
1121{
1122 return 0;
1123}
1124
1125int
1126sys_getpgid(tcp)
1127struct tcb *tcp;
1128{
1129 if (entering(tcp)) {
1130 tprintf("%lu", tcp->u_arg[0]);
1131 }
1132 return 0;
1133}
1134
1135int
1136sys_setpgid(tcp)
1137struct tcb *tcp;
1138{
1139 if (entering(tcp)) {
1140 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1141 }
1142 return 0;
1143}
1144
John Hughesc61eb3d2002-05-17 11:37:50 +00001145#if UNIXWARE >= 2
1146
1147#include <sys/privilege.h>
1148
1149
1150static struct xlat procpriv_cmds [] = {
1151 { SETPRV, "SETPRV" },
1152 { CLRPRV, "CLRPRV" },
1153 { PUTPRV, "PUTPRV" },
1154 { GETPRV, "GETPRV" },
1155 { CNTPRV, "CNTPRV" },
1156 { 0, NULL },
1157};
1158
1159
1160static struct xlat procpriv_priv [] = {
1161 { P_OWNER, "P_OWNER" },
1162 { P_AUDIT, "P_AUDIT" },
1163 { P_COMPAT, "P_COMPAT" },
1164 { P_DACREAD, "P_DACREAD" },
1165 { P_DACWRITE, "P_DACWRITE" },
1166 { P_DEV, "P_DEV" },
1167 { P_FILESYS, "P_FILESYS" },
1168 { P_MACREAD, "P_MACREAD" },
1169 { P_MACWRITE, "P_MACWRITE" },
1170 { P_MOUNT, "P_MOUNT" },
1171 { P_MULTIDIR, "P_MULTIDIR" },
1172 { P_SETPLEVEL, "P_SETPLEVEL" },
1173 { P_SETSPRIV, "P_SETSPRIV" },
1174 { P_SETUID, "P_SETUID" },
1175 { P_SYSOPS, "P_SYSOPS" },
1176 { P_SETUPRIV, "P_SETUPRIV" },
1177 { P_DRIVER, "P_DRIVER" },
1178 { P_RTIME, "P_RTIME" },
1179 { P_MACUPGRADE, "P_MACUPGRADE" },
1180 { P_FSYSRANGE, "P_FSYSRANGE" },
1181 { P_SETFLEVEL, "P_SETFLEVEL" },
1182 { P_AUDITWR, "P_AUDITWR" },
1183 { P_TSHAR, "P_TSHAR" },
1184 { P_PLOCK, "P_PLOCK" },
1185 { P_CORE, "P_CORE" },
1186 { P_LOADMOD, "P_LOADMOD" },
1187 { P_BIND, "P_BIND" },
1188 { P_ALLPRIVS, "P_ALLPRIVS" },
1189 { 0, NULL },
1190};
1191
1192
1193static struct xlat procpriv_type [] = {
1194 { PS_FIX, "PS_FIX" },
1195 { PS_INH, "PS_INH" },
1196 { PS_MAX, "PS_MAX" },
1197 { PS_WKG, "PS_WKG" },
1198 { 0, NULL },
1199};
1200
1201
1202static void
1203printpriv(tcp, addr, len, opt)
1204struct tcb *tcp;
1205long addr;
1206int len;
1207struct xlat *opt;
1208{
1209 priv_t buf [128];
1210 int max = verbose (tcp) ? sizeof buf / sizeof buf [0] : 10;
1211 int dots = len > max;
1212 int i;
Roland McGrath5a223472002-12-15 23:58:26 +00001213
John Hughesc61eb3d2002-05-17 11:37:50 +00001214 if (len > max) len = max;
Roland McGrath5a223472002-12-15 23:58:26 +00001215
John Hughesc61eb3d2002-05-17 11:37:50 +00001216 if (len <= 0 ||
1217 umoven (tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
1218 {
1219 tprintf ("%#lx", addr);
1220 return;
1221 }
1222
1223 tprintf ("[");
1224
1225 for (i = 0; i < len; ++i) {
1226 char *t, *p;
1227
1228 if (i) tprintf (", ");
1229
1230 if ((t = xlookup (procpriv_type, buf [i] & PS_TYPE)) &&
1231 (p = xlookup (procpriv_priv, buf [i] & ~PS_TYPE)))
1232 {
1233 tprintf ("%s|%s", t, p);
1234 }
1235 else {
1236 tprintf ("%#lx", buf [i]);
1237 }
1238 }
1239
1240 if (dots) tprintf (" ...");
1241
1242 tprintf ("]");
1243}
1244
1245
1246int
1247sys_procpriv(tcp)
1248struct tcb *tcp;
1249{
1250 if (entering(tcp)) {
1251 printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
1252 switch (tcp->u_arg[0]) {
1253 case CNTPRV:
1254 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1255 break;
1256
1257 case GETPRV:
1258 break;
1259
1260 default:
1261 tprintf (", ");
1262 printpriv (tcp, tcp->u_arg[1], tcp->u_arg[2]);
1263 tprintf (", %ld", tcp->u_arg[2]);
1264 }
1265 }
1266 else if (tcp->u_arg[0] == GETPRV) {
1267 if (syserror (tcp)) {
1268 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1269 }
1270 else {
1271 tprintf (", ");
1272 printpriv (tcp, tcp->u_arg[1], tcp->u_rval);
1273 tprintf (", %ld", tcp->u_arg[2]);
1274 }
1275 }
Roland McGrath5a223472002-12-15 23:58:26 +00001276
John Hughesc61eb3d2002-05-17 11:37:50 +00001277 return 0;
1278}
1279
1280#endif
1281
1282
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001283void
1284fake_execve(tcp, program, argv, envp)
1285struct tcb *tcp;
1286char *program;
1287char *argv[];
1288char *envp[];
1289{
1290 int i;
1291
1292#ifdef ARM
1293 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
1294 return;
1295#else
1296 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
1297 return;
1298#endif /* !ARM */
1299 printleader(tcp);
1300 tprintf("execve(");
1301 string_quote(program);
1302 tprintf(", [");
1303 for (i = 0; argv[i] != NULL; i++) {
1304 if (i != 0)
1305 tprintf(", ");
1306 string_quote(argv[i]);
1307 }
1308 for (i = 0; envp[i] != NULL; i++)
1309 ;
1310 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
1311 tabto(acolumn);
1312 tprintf("= 0");
1313 printtrailer(tcp);
1314}
1315
1316static void
1317printargv(tcp, addr)
1318struct tcb *tcp;
1319long addr;
1320{
1321 char *cp;
1322 char *sep;
1323 int max = max_strlen / 2;
1324
1325 for (sep = ""; --max >= 0; sep = ", ") {
1326 if (!abbrev(tcp))
1327 max++;
1328 if (umove(tcp, addr, &cp) < 0) {
1329 tprintf("%#lx", addr);
1330 return;
1331 }
1332 if (cp == 0)
1333 break;
1334 tprintf(sep);
1335 printstr(tcp, (long) cp, -1);
1336 addr += sizeof(char *);
1337 }
1338 if (cp)
1339 tprintf(", ...");
1340}
1341
1342static void
1343printargc(fmt, tcp, addr)
1344char *fmt;
1345struct tcb *tcp;
1346long addr;
1347{
1348 int count;
1349 char *cp;
1350
1351 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1352 addr += sizeof(char *);
1353 }
1354 tprintf(fmt, count, count == 1 ? "" : "s");
1355}
1356
1357int
1358sys_execv(tcp)
1359struct tcb *tcp;
1360{
1361 if (entering(tcp)) {
1362 printpath(tcp, tcp->u_arg[0]);
1363 if (!verbose(tcp))
1364 tprintf(", %#lx", tcp->u_arg[1]);
1365#if 0
1366 else if (abbrev(tcp))
1367 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1368#endif
1369 else {
1370 tprintf(", [");
1371 printargv(tcp, tcp->u_arg[1]);
1372 tprintf("]");
1373 }
1374 }
1375 return 0;
1376}
1377
1378int
1379sys_execve(tcp)
1380struct tcb *tcp;
1381{
1382 if (entering(tcp)) {
1383 printpath(tcp, tcp->u_arg[0]);
1384 if (!verbose(tcp))
1385 tprintf(", %#lx", tcp->u_arg[1]);
1386#if 0
1387 else if (abbrev(tcp))
1388 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1389#endif
1390 else {
1391 tprintf(", [");
1392 printargv(tcp, tcp->u_arg[1]);
1393 tprintf("]");
1394 }
1395 if (!verbose(tcp))
1396 tprintf(", %#lx", tcp->u_arg[2]);
1397 else if (abbrev(tcp))
1398 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1399 else {
1400 tprintf(", [");
1401 printargv(tcp, tcp->u_arg[2]);
1402 tprintf("]");
1403 }
1404 }
1405#ifdef LINUX
Wichert Akkermanccef6372002-05-01 16:39:22 +00001406#if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001407 tcp->flags |= TCB_WAITEXECVE;
Wichert Akkermanccef6372002-05-01 16:39:22 +00001408#endif /* ALPHA || SPARC || POWERPC || IA64 || HPPA || SH */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001409#endif /* LINUX */
1410 return 0;
1411}
1412
John Hughes4e36a812001-04-18 15:11:51 +00001413#if UNIXWARE > 2
1414
1415int sys_rexecve(tcp)
1416struct tcb *tcp;
1417{
1418 if (entering (tcp)) {
1419 sys_execve (tcp);
1420 tprintf (", %ld", tcp->u_arg[3]);
1421 }
1422 return 0;
1423}
1424
1425#endif
1426
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001427int
1428internal_exec(tcp)
1429struct tcb *tcp;
1430{
1431#ifdef SUNOS4
1432 if (exiting(tcp) && !syserror(tcp) && followfork)
1433 fixvfork(tcp);
1434#endif /* SUNOS4 */
1435 return 0;
1436}
1437
1438#ifdef LINUX
1439#ifndef __WCLONE
1440#define __WCLONE 0x8000000
1441#endif
1442#endif /* LINUX */
1443
1444static struct xlat wait4_options[] = {
1445 { WNOHANG, "WNOHANG" },
1446#ifndef WSTOPPED
1447 { WUNTRACED, "WUNTRACED" },
1448#endif
1449#ifdef WEXITED
1450 { WEXITED, "WEXITED" },
1451#endif
1452#ifdef WTRAPPED
1453 { WTRAPPED, "WTRAPPED" },
1454#endif
1455#ifdef WSTOPPED
1456 { WSTOPPED, "WSTOPPED" },
1457#endif
1458#ifdef WCONTINUED
1459 { WCONTINUED, "WCONTINUED" },
1460#endif
1461#ifdef WNOWAIT
1462 { WNOWAIT, "WNOWAIT" },
1463#endif
1464#ifdef __WCLONE
1465 { __WCLONE, "__WCLONE" },
1466#endif
1467 { 0, NULL },
1468};
1469
1470static int
1471printstatus(status)
1472int status;
1473{
1474 int exited = 0;
1475
1476 /*
1477 * Here is a tricky presentation problem. This solution
1478 * is still not entirely satisfactory but since there
1479 * are no wait status constructors it will have to do.
1480 */
1481 if (WIFSTOPPED(status))
1482 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001483 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001484 else if WIFSIGNALED(status)
1485 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001486 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001487 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1488 else if WIFEXITED(status) {
1489 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1490 WEXITSTATUS(status));
1491 exited = 1;
1492 }
1493 else
1494 tprintf("[%#x]", status);
1495 return exited;
1496}
1497
1498static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001499printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001500struct tcb *tcp;
1501int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001502int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001503{
1504 int status;
1505 int exited = 0;
1506
1507 if (entering(tcp)) {
1508 tprintf("%ld, ", tcp->u_arg[0]);
1509 } else {
1510 /* status */
1511 if (!tcp->u_arg[1])
1512 tprintf("NULL");
1513 else if (syserror(tcp) || tcp->u_rval == 0)
1514 tprintf("%#lx", tcp->u_arg[1]);
1515 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1516 tprintf("[?]");
1517 else
1518 exited = printstatus(status);
1519 /* options */
1520 tprintf(", ");
1521 if (!printflags(wait4_options, tcp->u_arg[2]))
1522 tprintf("0");
1523 if (n == 4) {
1524 tprintf(", ");
1525 /* usage */
1526 if (!tcp->u_arg[3])
1527 tprintf("NULL");
1528#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001529 else if (tcp->u_rval > 0) {
1530#ifdef LINUX_64BIT
1531 if (bitness)
1532 printrusage32(tcp, tcp->u_arg[3]);
1533 else
1534#endif
1535 printrusage(tcp, tcp->u_arg[3]);
1536 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001537#endif /* LINUX */
1538#ifdef SUNOS4
1539 else if (tcp->u_rval > 0 && exited)
1540 printrusage(tcp, tcp->u_arg[3]);
1541#endif /* SUNOS4 */
1542 else
1543 tprintf("%#lx", tcp->u_arg[3]);
1544 }
1545 }
1546 return 0;
1547}
1548
1549int
1550internal_wait(tcp)
1551struct tcb *tcp;
1552{
1553 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +00001554 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001555 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
1556 /* There are traced children */
1557 tcp->flags |= TCB_SUSPENDED;
1558 tcp->waitpid = tcp->u_arg[0];
1559 }
1560 }
1561 return 0;
1562}
1563
1564#ifdef SVR4
1565
1566int
1567sys_wait(tcp)
1568struct tcb *tcp;
1569{
1570 if (exiting(tcp)) {
1571 /* The library wrapper stuffs this into the user variable. */
1572 if (!syserror(tcp))
1573 printstatus(getrval2(tcp));
1574 }
1575 return 0;
1576}
1577
1578#endif /* SVR4 */
1579
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001580#ifdef FREEBSD
1581int
1582sys_wait(tcp)
1583struct tcb *tcp;
1584{
1585 int status;
Roland McGrath5a223472002-12-15 23:58:26 +00001586
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001587 if (exiting(tcp)) {
1588 if (!syserror(tcp)) {
1589 if (umove(tcp, tcp->u_arg[0], &status) < 0)
1590 tprintf("%#lx", tcp->u_arg[0]);
1591 else
1592 printstatus(status);
1593 }
1594 }
1595 return 0;
1596}
1597#endif
1598
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001599int
1600sys_waitpid(tcp)
1601struct tcb *tcp;
1602{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001603 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001604}
1605
1606int
1607sys_wait4(tcp)
1608struct tcb *tcp;
1609{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001610 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001611}
1612
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001613#ifdef ALPHA
1614int
1615sys_osf_wait4(tcp)
1616struct tcb *tcp;
1617{
1618 return printwaitn(tcp, 4, 1);
1619}
1620#endif
1621
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001622#ifdef SVR4
1623
1624static struct xlat waitid_types[] = {
1625 { P_PID, "P_PID" },
1626 { P_PPID, "P_PPID" },
1627 { P_PGID, "P_PGID" },
1628 { P_SID, "P_SID" },
1629 { P_CID, "P_CID" },
1630 { P_UID, "P_UID" },
1631 { P_GID, "P_GID" },
1632 { P_ALL, "P_ALL" },
1633#ifdef P_LWPID
1634 { P_LWPID, "P_LWPID" },
1635#endif
1636 { 0, NULL },
1637};
1638
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001639int
1640sys_waitid(tcp)
1641struct tcb *tcp;
1642{
1643 siginfo_t si;
1644 int exited;
1645
1646 if (entering(tcp)) {
1647 printxval(waitid_types, tcp->u_arg[0], "P_???");
1648 tprintf(", %ld, ", tcp->u_arg[1]);
1649 if (tcp->nchildren > 0) {
1650 /* There are traced children */
1651 tcp->flags |= TCB_SUSPENDED;
1652 tcp->waitpid = tcp->u_arg[0];
1653 }
1654 }
1655 else {
1656 /* siginfo */
1657 exited = 0;
1658 if (!tcp->u_arg[2])
1659 tprintf("NULL");
1660 else if (syserror(tcp))
1661 tprintf("%#lx", tcp->u_arg[2]);
1662 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1663 tprintf("{???}");
1664 else
John Hughes58265892001-10-18 15:13:53 +00001665 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001666 /* options */
1667 tprintf(", ");
1668 if (!printflags(wait4_options, tcp->u_arg[3]))
1669 tprintf("0");
1670 }
1671 return 0;
1672}
1673
1674#endif /* SVR4 */
1675
1676int
1677sys_alarm(tcp)
1678struct tcb *tcp;
1679{
1680 if (entering(tcp))
1681 tprintf("%lu", tcp->u_arg[0]);
1682 return 0;
1683}
1684
1685int
1686sys_uname(tcp)
1687struct tcb *tcp;
1688{
1689 struct utsname uname;
1690
1691 if (exiting(tcp)) {
1692 if (syserror(tcp) || !verbose(tcp))
1693 tprintf("%#lx", tcp->u_arg[0]);
1694 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1695 tprintf("{...}");
1696 else if (!abbrev(tcp)) {
1697
1698 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1699 uname.sysname, uname.nodename);
1700 tprintf("release=\"%s\", version=\"%s\", ",
1701 uname.release, uname.version);
1702 tprintf("machine=\"%s\"", uname.machine);
1703#ifdef LINUX
1704#ifndef __GLIBC__
1705 tprintf(", domainname=\"%s\"", uname.domainname);
1706#endif /* __GLIBC__ */
1707#endif /* LINUX */
1708 tprintf("}");
1709 }
1710 else
1711 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1712 uname.sysname, uname.nodename);
1713 }
1714 return 0;
1715}
1716
1717#ifndef SVR4
1718
1719static struct xlat ptrace_cmds[] = {
Roland McGrath5a223472002-12-15 23:58:26 +00001720#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001721 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1722 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1723 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1724 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1725 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1726 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1727 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1728 { PTRACE_CONT, "PTRACE_CONT" },
1729 { PTRACE_KILL, "PTRACE_KILL" },
1730 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1731 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1732 { PTRACE_DETACH, "PTRACE_DETACH" },
1733#ifdef SUNOS4
1734 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1735 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1736 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1737 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1738 { PTRACE_READDATA, "PTRACE_READDATA" },
1739 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1740 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1741 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1742 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1743 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1744#ifdef SPARC
1745 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1746 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1747#else /* !SPARC */
1748 { PTRACE_22, "PTRACE_PTRACE_22" },
1749 { PTRACE_23, "PTRACE_PTRACE_23" },
1750#endif /* !SPARC */
1751#endif /* SUNOS4 */
1752 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1753#ifdef SUNOS4
1754 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1755#ifdef I386
1756 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1757 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1758 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1759#else /* !I386 */
1760 { PTRACE_26, "PTRACE_26" },
1761 { PTRACE_27, "PTRACE_27" },
1762 { PTRACE_28, "PTRACE_28" },
1763#endif /* !I386 */
1764 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1765#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001766#else /* FREEBSD */
1767 { PT_TRACE_ME, "PT_TRACE_ME" },
1768 { PT_READ_I, "PT_READ_I" },
1769 { PT_READ_D, "PT_READ_D" },
1770 { PT_WRITE_I, "PT_WRITE_I" },
1771 { PT_WRITE_D, "PT_WRITE_D" },
John Hughesa2278142001-09-28 16:21:30 +00001772#ifdef PT_READ_U
1773 { PT_READ_U, "PT_READ_U" },
1774#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001775 { PT_CONTINUE, "PT_CONTINUE" },
1776 { PT_KILL, "PT_KILL" },
1777 { PT_STEP, "PT_STEP" },
1778 { PT_ATTACH, "PT_ATTACH" },
1779 { PT_DETACH, "PT_DETACH" },
1780 { PT_GETREGS, "PT_GETREGS" },
1781 { PT_SETREGS, "PT_SETREGS" },
1782 { PT_GETFPREGS, "PT_GETFPREGS" },
1783 { PT_SETFPREGS, "PT_SETFPREGS" },
1784 { PT_GETDBREGS, "PT_GETDBREGS" },
1785 { PT_SETDBREGS, "PT_SETDBREGS" },
1786#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001787 { 0, NULL },
1788};
1789
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001790#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1792static
1793#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1794struct xlat struct_user_offsets[] = {
1795#ifdef LINUX
Michal Ludvig10a88d02002-10-07 14:31:00 +00001796#if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001797 { PT_PSWMASK, "psw_mask" },
1798 { PT_PSWADDR, "psw_addr" },
1799 { PT_GPR0, "gpr0" },
1800 { PT_GPR1, "gpr1" },
1801 { PT_GPR2, "gpr2" },
1802 { PT_GPR3, "gpr3" },
1803 { PT_GPR4, "gpr4" },
1804 { PT_GPR5, "gpr5" },
1805 { PT_GPR6, "gpr6" },
1806 { PT_GPR7, "gpr7" },
1807 { PT_GPR8, "gpr8" },
1808 { PT_GPR9, "gpr9" },
1809 { PT_GPR10, "gpr10" },
1810 { PT_GPR11, "gpr11" },
1811 { PT_GPR12, "gpr12" },
1812 { PT_GPR13, "gpr13" },
1813 { PT_GPR14, "gpr14" },
1814 { PT_GPR15, "gpr15" },
1815 { PT_ACR0, "acr0" },
1816 { PT_ACR1, "acr1" },
1817 { PT_ACR2, "acr2" },
1818 { PT_ACR3, "acr3" },
1819 { PT_ACR4, "acr4" },
1820 { PT_ACR5, "acr5" },
1821 { PT_ACR6, "acr6" },
1822 { PT_ACR7, "acr7" },
1823 { PT_ACR8, "acr8" },
1824 { PT_ACR9, "acr9" },
1825 { PT_ACR10, "acr10" },
1826 { PT_ACR11, "acr11" },
1827 { PT_ACR12, "acr12" },
1828 { PT_ACR13, "acr13" },
1829 { PT_ACR14, "acr14" },
1830 { PT_ACR15, "acr15" },
1831 { PT_ORIGGPR2, "orig_gpr2" },
1832 { PT_FPC, "fpc" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00001833#if defined(S390)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001834 { PT_FPR0_HI, "fpr0.hi" },
1835 { PT_FPR0_LO, "fpr0.lo" },
1836 { PT_FPR1_HI, "fpr1.hi" },
1837 { PT_FPR1_LO, "fpr1.lo" },
1838 { PT_FPR2_HI, "fpr2.hi" },
1839 { PT_FPR2_LO, "fpr2.lo" },
1840 { PT_FPR3_HI, "fpr3.hi" },
1841 { PT_FPR3_LO, "fpr3.lo" },
1842 { PT_FPR4_HI, "fpr4.hi" },
1843 { PT_FPR4_LO, "fpr4.lo" },
1844 { PT_FPR5_HI, "fpr5.hi" },
1845 { PT_FPR5_LO, "fpr5.lo" },
1846 { PT_FPR6_HI, "fpr6.hi" },
1847 { PT_FPR6_LO, "fpr6.lo" },
1848 { PT_FPR7_HI, "fpr7.hi" },
1849 { PT_FPR7_LO, "fpr7.lo" },
1850 { PT_FPR8_HI, "fpr8.hi" },
1851 { PT_FPR8_LO, "fpr8.lo" },
1852 { PT_FPR9_HI, "fpr9.hi" },
1853 { PT_FPR9_LO, "fpr9.lo" },
1854 { PT_FPR10_HI, "fpr10.hi" },
1855 { PT_FPR10_LO, "fpr10.lo" },
1856 { PT_FPR11_HI, "fpr11.hi" },
1857 { PT_FPR11_LO, "fpr11.lo" },
1858 { PT_FPR12_HI, "fpr12.hi" },
1859 { PT_FPR12_LO, "fpr12.lo" },
1860 { PT_FPR13_HI, "fpr13.hi" },
1861 { PT_FPR13_LO, "fpr13.lo" },
1862 { PT_FPR14_HI, "fpr14.hi" },
1863 { PT_FPR14_LO, "fpr14.lo" },
1864 { PT_FPR15_HI, "fpr15.hi" },
1865 { PT_FPR15_LO, "fpr15.lo" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00001866#endif
1867#if defined(S390X)
1868 { PT_FPR0, "fpr0" },
1869 { PT_FPR1, "fpr1" },
1870 { PT_FPR2, "fpr2" },
1871 { PT_FPR3, "fpr3" },
1872 { PT_FPR4, "fpr4" },
1873 { PT_FPR5, "fpr5" },
1874 { PT_FPR6, "fpr6" },
1875 { PT_FPR7, "fpr7" },
1876 { PT_FPR8, "fpr8" },
1877 { PT_FPR9, "fpr9" },
1878 { PT_FPR10, "fpr10" },
1879 { PT_FPR11, "fpr11" },
1880 { PT_FPR12, "fpr12" },
1881 { PT_FPR13, "fpr13" },
1882 { PT_FPR14, "fpr14" },
1883 { PT_FPR15, "fpr15" },
1884#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001885 { PT_CR_9, "cr9" },
1886 { PT_CR_10, "cr10" },
1887 { PT_CR_11, "cr11" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00001888 { PT_IEEE_IP, "ieee_exception_ip" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001889#endif
1890#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001891 /* XXX No support for these offsets yet. */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001892#elif defined(HPPA)
1893 /* XXX No support for these offsets yet. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001894#elif defined(POWERPC)
Roland McGrath5a223472002-12-15 23:58:26 +00001895#ifndef PT_ORIG_R3
1896#define PT_ORIG_R3 34
1897#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001898 { 4*PT_R0, "4*PT_R0" },
1899 { 4*PT_R1, "4*PT_R1" },
1900 { 4*PT_R2, "4*PT_R2" },
1901 { 4*PT_R3, "4*PT_R3" },
1902 { 4*PT_R4, "4*PT_R4" },
1903 { 4*PT_R5, "4*PT_R5" },
1904 { 4*PT_R6, "4*PT_R6" },
1905 { 4*PT_R7, "4*PT_R7" },
1906 { 4*PT_R8, "4*PT_R8" },
1907 { 4*PT_R9, "4*PT_R9" },
1908 { 4*PT_R10, "4*PT_R10" },
1909 { 4*PT_R11, "4*PT_R11" },
1910 { 4*PT_R12, "4*PT_R12" },
1911 { 4*PT_R13, "4*PT_R13" },
1912 { 4*PT_R14, "4*PT_R14" },
1913 { 4*PT_R15, "4*PT_R15" },
1914 { 4*PT_R16, "4*PT_R16" },
1915 { 4*PT_R17, "4*PT_R17" },
1916 { 4*PT_R18, "4*PT_R18" },
1917 { 4*PT_R19, "4*PT_R19" },
1918 { 4*PT_R20, "4*PT_R20" },
1919 { 4*PT_R21, "4*PT_R21" },
1920 { 4*PT_R22, "4*PT_R22" },
1921 { 4*PT_R23, "4*PT_R23" },
1922 { 4*PT_R24, "4*PT_R24" },
1923 { 4*PT_R25, "4*PT_R25" },
1924 { 4*PT_R26, "4*PT_R26" },
1925 { 4*PT_R27, "4*PT_R27" },
1926 { 4*PT_R28, "4*PT_R28" },
1927 { 4*PT_R29, "4*PT_R29" },
1928 { 4*PT_R30, "4*PT_R30" },
1929 { 4*PT_R31, "4*PT_R31" },
1930 { 4*PT_NIP, "4*PT_NIP" },
1931 { 4*PT_MSR, "4*PT_MSR" },
1932 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1933 { 4*PT_CTR, "4*PT_CTR" },
1934 { 4*PT_LNK, "4*PT_LNK" },
1935 { 4*PT_XER, "4*PT_XER" },
1936 { 4*PT_CCR, "4*PT_CCR" },
1937 { 4*PT_FPR0, "4*PT_FPR0" },
Roland McGrath5a223472002-12-15 23:58:26 +00001938#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001939#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001940 { 0, "r0" },
1941 { 1, "r1" },
1942 { 2, "r2" },
1943 { 3, "r3" },
1944 { 4, "r4" },
1945 { 5, "r5" },
1946 { 6, "r6" },
1947 { 7, "r7" },
1948 { 8, "r8" },
1949 { 9, "r9" },
1950 { 10, "r10" },
1951 { 11, "r11" },
1952 { 12, "r12" },
1953 { 13, "r13" },
1954 { 14, "r14" },
1955 { 15, "r15" },
1956 { 16, "r16" },
1957 { 17, "r17" },
1958 { 18, "r18" },
1959 { 19, "r19" },
1960 { 20, "r20" },
1961 { 21, "r21" },
1962 { 22, "r22" },
1963 { 23, "r23" },
1964 { 24, "r24" },
1965 { 25, "r25" },
1966 { 26, "r26" },
1967 { 27, "r27" },
1968 { 28, "r28" },
1969 { 29, "gp" },
1970 { 30, "fp" },
1971 { 31, "zero" },
1972 { 32, "fp0" },
1973 { 33, "fp" },
1974 { 34, "fp2" },
1975 { 35, "fp3" },
1976 { 36, "fp4" },
1977 { 37, "fp5" },
1978 { 38, "fp6" },
1979 { 39, "fp7" },
1980 { 40, "fp8" },
1981 { 41, "fp9" },
1982 { 42, "fp10" },
1983 { 43, "fp11" },
1984 { 44, "fp12" },
1985 { 45, "fp13" },
1986 { 46, "fp14" },
1987 { 47, "fp15" },
1988 { 48, "fp16" },
1989 { 49, "fp17" },
1990 { 50, "fp18" },
1991 { 51, "fp19" },
1992 { 52, "fp20" },
1993 { 53, "fp21" },
1994 { 54, "fp22" },
1995 { 55, "fp23" },
1996 { 56, "fp24" },
1997 { 57, "fp25" },
1998 { 58, "fp26" },
1999 { 59, "fp27" },
2000 { 60, "fp28" },
2001 { 61, "fp29" },
2002 { 62, "fp30" },
2003 { 63, "fp31" },
2004 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002005#else /* !ALPHA */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002006#ifdef IA64
2007 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
2008 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
2009 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
2010 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
2011 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
2012 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
2013 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
2014 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
2015 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
2016 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
2017 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
2018 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
2019 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
2020 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
2021 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
2022 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
2023 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
2024 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
2025 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
2026 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
2027 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
2028 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
2029 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
2030 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
2031 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
2032 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
2033 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
2034 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
2035 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
2036 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
2037 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
2038 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
2039 /* switch stack: */
2040 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
2041 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
2042 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
2043 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
2044 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
2045 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
2046 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
2047 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2048 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2049 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002050 { PT_B0, "kb0" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002051 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2052 { PT_B4, "b4" }, { PT_B5, "b5" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002053 { PT_AR_PFS, "kar.pfs" },
2054 { PT_AR_LC, "ar.lc" }, { PT_AR_UNAT, "kar.unat" },
2055 { PT_AR_RNAT, "kar.rnat" }, { PT_AR_BSPSTORE, "kar.bspstore" },
2056 { PT_PR, "k.pr" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002057 /* pt_regs */
2058 { PT_CR_IPSR, "cr.ipsr" }, { PT_CR_IIP, "cr.iip" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002059 /*{ PT_CR_IFS, "cr.ifs" },*/ { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002060 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2061 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2062 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2063 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2064 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2065 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2066 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2067 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2068 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2069 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2070 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2071 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2072 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2073 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2074 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
2075#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002076#ifdef I386
2077 { 4*EBX, "4*EBX" },
2078 { 4*ECX, "4*ECX" },
2079 { 4*EDX, "4*EDX" },
2080 { 4*ESI, "4*ESI" },
2081 { 4*EDI, "4*EDI" },
2082 { 4*EBP, "4*EBP" },
2083 { 4*EAX, "4*EAX" },
2084 { 4*DS, "4*DS" },
2085 { 4*ES, "4*ES" },
2086 { 4*FS, "4*FS" },
2087 { 4*GS, "4*GS" },
2088 { 4*ORIG_EAX, "4*ORIG_EAX" },
2089 { 4*EIP, "4*EIP" },
2090 { 4*CS, "4*CS" },
2091 { 4*EFL, "4*EFL" },
2092 { 4*UESP, "4*UESP" },
2093 { 4*SS, "4*SS" },
2094#else /* !I386 */
Michal Ludvig0e035502002-09-23 15:41:01 +00002095#ifdef X86_64
2096 { 8*RDI, "8*RDI" },
2097 { 8*RSI, "8*RSI" },
2098 { 8*RDX, "8*RDX" },
2099 { 8*R10, "8*R10" },
2100 { 8*R8, "8*R8" },
2101 { 8*R9, "8*R9" },
2102 { 8*RBX, "8*RBX" },
2103 { 8*RCX, "8*RCX" },
2104 { 8*RBP, "8*RBP" },
2105 { 8*RAX, "8*RAX" },
2106#if 0
2107 { 8*DS, "8*DS" },
2108 { 8*ES, "8*ES" },
2109 { 8*FS, "8*FS" },
2110 { 8*GS, "8*GS" },
2111#endif
2112 { 8*ORIG_RAX, "8*ORIG_EAX" },
2113 { 8*RIP, "8*RIP" },
2114 { 8*CS, "8*CS" },
2115 { 8*EFLAGS, "8*EFL" },
2116 { 8*RSP, "8*RSP" },
2117 { 8*SS, "8*SS" },
2118 { 8*R11, "8*R11" },
2119 { 8*R12, "8*R12" },
2120 { 8*R13, "8*R13" },
2121 { 8*R14, "8*R14" },
2122 { 8*R15, "8*R15" },
2123#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002124#ifdef M68K
2125 { 4*PT_D1, "4*PT_D1" },
2126 { 4*PT_D2, "4*PT_D2" },
2127 { 4*PT_D3, "4*PT_D3" },
2128 { 4*PT_D4, "4*PT_D4" },
2129 { 4*PT_D5, "4*PT_D5" },
2130 { 4*PT_D6, "4*PT_D6" },
2131 { 4*PT_D7, "4*PT_D7" },
2132 { 4*PT_A0, "4*PT_A0" },
2133 { 4*PT_A1, "4*PT_A1" },
2134 { 4*PT_A2, "4*PT_A2" },
2135 { 4*PT_A3, "4*PT_A3" },
2136 { 4*PT_A4, "4*PT_A4" },
2137 { 4*PT_A5, "4*PT_A5" },
2138 { 4*PT_A6, "4*PT_A6" },
2139 { 4*PT_D0, "4*PT_D0" },
2140 { 4*PT_USP, "4*PT_USP" },
2141 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2142 { 4*PT_SR, "4*PT_SR" },
2143 { 4*PT_PC, "4*PT_PC" },
2144#endif /* M68K */
2145#endif /* !I386 */
Wichert Akkermanccef6372002-05-01 16:39:22 +00002146#ifdef SH
2147 { 4*REG_REG0, "4*REG_REG0" },
2148 { 4*(REG_REG0+1), "4*REG_REG1" },
2149 { 4*(REG_REG0+2), "4*REG_REG2" },
2150 { 4*(REG_REG0+3), "4*REG_REG3" },
2151 { 4*(REG_REG0+4), "4*REG_REG4" },
2152 { 4*(REG_REG0+5), "4*REG_REG5" },
2153 { 4*(REG_REG0+6), "4*REG_REG6" },
2154 { 4*(REG_REG0+7), "4*REG_REG7" },
2155 { 4*(REG_REG0+8), "4*REG_REG8" },
2156 { 4*(REG_REG0+9), "4*REG_REG9" },
2157 { 4*(REG_REG0+10), "4*REG_REG10" },
2158 { 4*(REG_REG0+11), "4*REG_REG11" },
2159 { 4*(REG_REG0+12), "4*REG_REG12" },
2160 { 4*(REG_REG0+13), "4*REG_REG13" },
2161 { 4*(REG_REG0+14), "4*REG_REG14" },
2162 { 4*REG_REG15, "4*REG_REG15" },
2163 { 4*REG_PC, "4*REG_PC" },
2164 { 4*REG_PR, "4*REG_PR" },
2165 { 4*REG_SR, "4*REG_SR" },
2166 { 4*REG_GBR, "4*REG_GBR" },
2167 { 4*REG_MACH, "4*REG_MACH" },
2168 { 4*REG_MACL, "4*REG_MACL" },
2169 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
2170 { 4*REG_FPUL, "4*REG_FPUL" },
2171 { 4*REG_FPREG0, "4*REG_FPREG0" },
2172 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
2173 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
2174 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
2175 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
2176 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
2177 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
2178 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
2179 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
2180 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
2181 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
2182 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
2183 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
2184 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
2185 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
2186 { 4*REG_FPREG15, "4*REG_FPREG15" },
2187 { 4*REG_XDREG0, "4*REG_XDREG0" },
2188 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
2189 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
2190 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
2191 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
2192 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
2193 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
2194 { 4*REG_XDREG14, "4*REG_XDREG14" },
2195 { 4*REG_FPSCR, "4*REG_FPSCR" },
2196#endif /* SH */
2197
Michal Ludvig10a88d02002-10-07 14:31:00 +00002198#if !defined(S390) && !defined(S390X) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002199 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002200#endif
Michal Ludvig0e035502002-09-23 15:41:01 +00002201#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002202 { uoff(i387), "offsetof(struct user, i387)" },
2203#else /* !I386 */
2204#ifdef M68K
2205 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
2206#endif /* M68K */
2207#endif /* !I386 */
2208 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2209 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2210 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
2211 { uoff(start_code), "offsetof(struct user, start_code)" },
2212 { uoff(start_stack), "offsetof(struct user, start_stack)" },
2213 { uoff(signal), "offsetof(struct user, signal)" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002214#if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002215 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002216#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002217 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002218#if !defined(ARM) && !defined(MIPS) && !defined(S390) && !defined(S390X)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002219 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
2220#endif
2221 { uoff(magic), "offsetof(struct user, magic)" },
2222 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002223#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002224 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
2225#endif /* I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002226#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002227#endif /* !ALPHA */
2228#endif /* !POWERPC/!SPARC */
2229#endif /* LINUX */
2230#ifdef SUNOS4
2231 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
2232 { uoff(u_procp), "offsetof(struct user, u_procp)" },
2233 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
2234 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
2235 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
2236 { uoff(u_ap), "offsetof(struct user, u_ap)" },
2237 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
2238 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
2239 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
2240 { uoff(u_error), "offsetof(struct user, u_error)" },
2241 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
2242 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
2243 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
2244 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
2245 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
2246 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
2247 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
2248 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
2249 { uoff(u_code), "offsetof(struct user, u_code)" },
2250 { uoff(u_addr), "offsetof(struct user, u_addr)" },
2251 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
2252 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
2253 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
2254 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
2255 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
2256 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
2257 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
2258 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
2259 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
2260 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
2261 { uoff(u_ru), "offsetof(struct user, u_ru)" },
2262 { uoff(u_cru), "offsetof(struct user, u_cru)" },
2263 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
2264 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
2265 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
2266 { uoff(u_start), "offsetof(struct user, u_start)" },
2267 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
2268 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
2269 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
2270 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
2271 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
2272 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
2273 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
2274 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
2275 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
2276#endif /* SUNOS4 */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002277#ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002278 { sizeof(struct user), "sizeof(struct user)" },
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002279#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002280 { 0, NULL },
2281};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002282#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002283
2284int
2285sys_ptrace(tcp)
2286struct tcb *tcp;
2287{
2288 char *cmd;
2289 struct xlat *x;
2290 long addr;
2291
2292 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
2293 if (!cmd)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002294#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002295 cmd = "PTRACE_???";
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002296#else
2297 cmd = "PT_???";
Roland McGrath5a223472002-12-15 23:58:26 +00002298#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002299 if (entering(tcp)) {
2300 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
2301 addr = tcp->u_arg[2];
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002302#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002303 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2304 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2305 for (x = struct_user_offsets; x->str; x++) {
2306 if (x->val >= addr)
2307 break;
2308 }
2309 if (!x->str)
2310 tprintf("%#lx, ", addr);
2311 else if (x->val > addr && x != struct_user_offsets) {
2312 x--;
2313 tprintf("%s + %ld, ", x->str, addr - x->val);
2314 }
2315 else
2316 tprintf("%s, ", x->str);
2317 }
2318 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002319#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002320 tprintf("%#lx, ", tcp->u_arg[2]);
2321#ifdef LINUX
2322 switch (tcp->u_arg[0]) {
2323 case PTRACE_PEEKDATA:
2324 case PTRACE_PEEKTEXT:
2325 case PTRACE_PEEKUSER:
2326 break;
2327 case PTRACE_CONT:
2328 case PTRACE_SINGLESTEP:
2329 case PTRACE_SYSCALL:
2330 case PTRACE_DETACH:
2331 printsignal(tcp->u_arg[3]);
2332 break;
2333 default:
2334 tprintf("%#lx", tcp->u_arg[3]);
2335 break;
2336 }
2337 } else {
2338 switch (tcp->u_arg[0]) {
2339 case PTRACE_PEEKDATA:
2340 case PTRACE_PEEKTEXT:
2341 case PTRACE_PEEKUSER:
2342 printnum(tcp, tcp->u_arg[3], "%#x");
2343 break;
2344 }
2345 }
2346#endif /* LINUX */
2347#ifdef SUNOS4
2348 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
2349 tcp->u_arg[0] == PTRACE_WRITETEXT) {
2350 tprintf("%lu, ", tcp->u_arg[3]);
2351 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2352 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
2353 tcp->u_arg[0] != PTRACE_READTEXT) {
2354 tprintf("%#lx", tcp->u_arg[3]);
2355 }
2356 } else {
2357 if (tcp->u_arg[0] == PTRACE_READDATA ||
2358 tcp->u_arg[0] == PTRACE_READTEXT) {
2359 tprintf("%lu, ", tcp->u_arg[3]);
2360 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2361 }
2362 }
2363#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002364#ifdef FREEBSD
2365 tprintf("%lu", tcp->u_arg[3]);
2366 }
2367#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002368 return 0;
2369}
2370
2371#endif /* !SVR4 */
Roland McGrath5a223472002-12-15 23:58:26 +00002372
2373#ifdef LINUX
2374static struct xlat futexops[] = {
2375 { FUTEX_WAIT, "FUTEX_WAIT" },
2376 { FUTEX_WAKE, "FUTEX_WAKE" },
2377 { FUTEX_FD, "FUTEX_FD" },
2378 { 0, NULL }
2379};
2380
2381int
2382sys_futex(tcp)
2383struct tcb *tcp;
2384{
2385 if (entering(tcp)) {
2386 tprintf("%p, ", (void *) tcp->u_arg[0]);
2387 printflags(futexops, tcp->u_arg[1]);
2388 tprintf(", %ld, ", tcp->u_arg[2]);
2389 printtv(tcp, tcp->u_arg[3]);
2390 }
2391 return 0;
2392}
2393
2394static void
2395print_affinitylist(list, len)
2396unsigned long *list;
2397unsigned int len;
2398{
2399 int first = 1;
2400 tprintf(" {");
2401 while (len > sizeof (unsigned long)) {
2402 tprintf("%s %lx", first ? "" : ",", *list++);
2403 first = 0;
2404 len -= sizeof (unsigned long);
2405 }
2406 tprintf(" }");
2407}
2408
2409int
2410sys_sched_setaffinity(tcp)
2411struct tcb *tcp;
2412{
2413 if (entering(tcp)) {
2414 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2415 print_affinitylist((unsigned long *) tcp->u_arg[2], tcp->u_arg[1]);
2416 }
2417 return 0;
2418}
2419
2420int
2421sys_sched_getaffinity(tcp)
2422struct tcb *tcp;
2423{
2424 if (entering(tcp)) {
2425 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2426 } else {
2427 print_affinitylist((unsigned long *) tcp->u_arg[2], tcp->u_rval);
2428 }
2429 return 0;
2430}
2431#endif