blob: 6a68316d0d13245f0323b71eb6d4a7dc133f1949 [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 }
Roland McGrath3bb9c3d2002-12-16 20:40:48 +0000595#elif defined(POWERPC)
596#ifndef PT_ORIG_R3
597#define PT_ORIG_R3 34
598#endif
599 {
600 ptrace(PTRACE_POKEUSER, tcp->pid,
601 (char*)((argnum==0 ? PT_ORIG_R3 : argnum+PT_R3)*4),
602 tcp->u_arg[argnum]);
603 if (errno)
604 return -1;
605 }
Ralf Baechlee3816102000-08-01 00:06:06 +0000606#elif defined(MIPS)
607 {
608 errno = 0;
609 if (argnum < 4)
610 ptrace(PTRACE_POKEUSER, tcp->pid,
611 (char*)(REG_A0 + argnum), tcp->u_arg[argnum]);
612 else {
613 unsigned long *sp;
614
615 if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
616 return -1;
617
618 ptrace(PTRACE_POKEDATA, tcp->pid,
619 (char*)(sp + argnum - 4), tcp->u_arg[argnum]);
620 }
621 if (errno)
622 return -1;
623 }
Michal Ludvig10a88d02002-10-07 14:31:00 +0000624#elif defined(S390) || defined(S390X)
625 {
626 if(argnum <= 5)
627 ptrace(PTRACE_POKEUSER, tcp->pid,
Roland McGrath5a223472002-12-15 23:58:26 +0000628 (char *) (argnum==0 ? PT_ORIGGPR2 :
629 PT_GPR2 + argnum*sizeof(long)),
Michal Ludvig10a88d02002-10-07 14:31:00 +0000630 tcp->u_arg[argnum]);
631 else
632 return -E2BIG;
633 if (errno)
634 return -1;
635 }
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000636#else
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000637# warning Sorry, setargs not implemented for this architecture.
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000638#endif
639 return 0;
640}
641
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000642#ifdef SYS_clone
643int
644internal_clone(tcp)
645struct tcb *tcp;
646{
Ulrich Drepper90512f01999-12-24 07:22:25 +0000647 struct tcb *tcpchild;
648 int pid;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000649 if (entering(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000650 if (!followfork)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000651 return 0;
652 if (nprocs == MAX_PROCS) {
653 tcp->flags &= ~TCB_FOLLOWFORK;
654 fprintf(stderr, "sys_fork: tcb table full\n");
655 return 0;
656 }
657 tcp->flags |= TCB_FOLLOWFORK;
658
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000659
660 if (setbpt(tcp) < 0)
661 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000662 } else {
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000663 int bpt = tcp->flags & TCB_BPTSET;
664
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000665 if (!(tcp->flags & TCB_FOLLOWFORK))
666 return 0;
667
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000668 if (syserror(tcp)) {
669 if (bpt)
670 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000671 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000672 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000673
674 pid = tcp->u_rval;
675 if ((tcpchild = alloctcb(pid)) == NULL) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000676 if (bpt)
677 clearbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000678 fprintf(stderr, " [tcb table full]\n");
679 kill(pid, SIGKILL); /* XXX */
680 return 0;
681 }
682
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000683 /* Attach to the new child */
684 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000685 if (bpt)
686 clearbpt(tcp);
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000687 perror("PTRACE_ATTACH");
688 fprintf(stderr, "Too late?\n");
689 droptcb(tcpchild);
690 return 0;
691 }
692
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000693 if (bpt)
694 clearbpt(tcp);
695
Ulrich Drepper90512f01999-12-24 07:22:25 +0000696 tcpchild->flags |= TCB_ATTACHED;
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +0000697 if (bpt) {
698 tcpchild->flags |= TCB_BPTSET;
699 tcpchild->baddr = tcp->baddr;
700 memcpy(tcpchild->inst, tcp->inst,
701 sizeof tcpchild->inst);
702 }
Ulrich Drepper90512f01999-12-24 07:22:25 +0000703 newoutf(tcpchild);
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000704 tcpchild->parent = tcp;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000705 tcp->nchildren++;
706 if (!qflag)
707 fprintf(stderr, "Process %d attached\n", pid);
708 }
709 return 0;
710}
711#endif
712
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000713int
714internal_fork(tcp)
715struct tcb *tcp;
716{
717 struct tcb *tcpchild;
718 int pid;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000719 int dont_follow = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720
721#ifdef SYS_vfork
Nate Sammonsccd8f211999-03-29 22:57:54 +0000722 if (tcp->scno == SYS_vfork) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000723 /* Attempt to make vfork into fork, which we can follow. */
Roland McGrath5a223472002-12-15 23:58:26 +0000724 if (!followvfork ||
Pavel Machek9a9f10b2000-02-01 16:22:52 +0000725 change_syscall(tcp, SYS_fork) < 0)
Nate Sammonsccd8f211999-03-29 22:57:54 +0000726 dont_follow = 1;
Nate Sammonsccd8f211999-03-29 22:57:54 +0000727 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000728#endif
729 if (entering(tcp)) {
Nate Sammonsccd8f211999-03-29 22:57:54 +0000730 if (!followfork || dont_follow)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731 return 0;
732 if (nprocs == MAX_PROCS) {
733 tcp->flags &= ~TCB_FOLLOWFORK;
734 fprintf(stderr, "sys_fork: tcb table full\n");
735 return 0;
736 }
737 tcp->flags |= TCB_FOLLOWFORK;
738 if (setbpt(tcp) < 0)
739 return 0;
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000740 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000741 else {
742 int bpt = tcp->flags & TCB_BPTSET;
743
744 if (!(tcp->flags & TCB_FOLLOWFORK))
745 return 0;
746 if (bpt)
747 clearbpt(tcp);
748
749 if (syserror(tcp))
750 return 0;
751
752 pid = tcp->u_rval;
753 if ((tcpchild = alloctcb(pid)) == NULL) {
754 fprintf(stderr, " [tcb table full]\n");
755 kill(pid, SIGKILL); /* XXX */
756 return 0;
757 }
758#ifdef LINUX
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000759#ifdef HPPA
760 /* The child must have run before it can be attached. */
761 /* This must be a bug in the parisc kernel, but I havn't
762 * identified it yet. Seems to be an issue associated
763 * with attaching to a process (which sends it a signal)
764 * before that process has ever been scheduled. When
765 * debugging, I started seeing crashes in
766 * arch/parisc/kernel/signal.c:do_signal(), apparently
767 * caused by r8 getting corrupt over the dequeue_signal()
768 * call. Didn't make much sense though...
769 */
770 {
771 struct timeval tv;
772 tv.tv_sec = 0;
773 tv.tv_usec = 10000;
774 select(0, NULL, NULL, NULL, &tv);
775 }
776#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000777 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) < 0) {
778 perror("PTRACE_ATTACH");
779 fprintf(stderr, "Too late?\n");
780 droptcb(tcpchild);
781 return 0;
782 }
783#endif /* LINUX */
784#ifdef SUNOS4
785#ifdef oldway
786 /* The child must have run before it can be attached. */
787 {
788 struct timeval tv;
789 tv.tv_sec = 0;
790 tv.tv_usec = 10000;
791 select(0, NULL, NULL, NULL, &tv);
792 }
793 if (ptrace(PTRACE_ATTACH, pid, (char *)1, 0) < 0) {
794 perror("PTRACE_ATTACH");
795 fprintf(stderr, "Too late?\n");
796 droptcb(tcpchild);
797 return 0;
798 }
799#else /* !oldway */
800 /* Try to catch the new process as soon as possible. */
801 {
802 int i;
803 for (i = 0; i < 1024; i++)
804 if (ptrace(PTRACE_ATTACH, pid, (char *) 1, 0) >= 0)
805 break;
806 if (i == 1024) {
807 perror("PTRACE_ATTACH");
808 fprintf(stderr, "Too late?\n");
809 droptcb(tcpchild);
810 return 0;
811 }
812 }
813#endif /* !oldway */
814#endif /* SUNOS4 */
815 tcpchild->flags |= TCB_ATTACHED;
816 /* Child has BPT too, must be removed on first occasion */
817 if (bpt) {
818 tcpchild->flags |= TCB_BPTSET;
819 tcpchild->baddr = tcp->baddr;
820 memcpy(tcpchild->inst, tcp->inst,
821 sizeof tcpchild->inst);
822 }
823 newoutf(tcpchild);
824 tcpchild->parent = tcp;
825 tcp->nchildren++;
826 if (!qflag)
827 fprintf(stderr, "Process %d attached\n", pid);
828 }
829 return 0;
830}
831
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000832#endif /* !USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000833
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000834#if defined(SUNOS4) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000835
836int
837sys_vfork(tcp)
838struct tcb *tcp;
839{
840 if (exiting(tcp))
841 return RVAL_UDECIMAL;
842 return 0;
843}
844
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000845#endif /* SUNOS4 || LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000846
847#ifndef LINUX
848
849static char idstr[16];
850
851int
852sys_getpid(tcp)
853struct tcb *tcp;
854{
855 if (exiting(tcp)) {
856 sprintf(idstr, "ppid %lu", getrval2(tcp));
857 tcp->auxstr = idstr;
858 return RVAL_STR;
859 }
860 return 0;
861}
862
863int
864sys_getuid(tcp)
865struct tcb *tcp;
866{
867 if (exiting(tcp)) {
868 sprintf(idstr, "euid %lu", getrval2(tcp));
869 tcp->auxstr = idstr;
870 return RVAL_STR;
871 }
872 return 0;
873}
874
875int
876sys_getgid(tcp)
877struct tcb *tcp;
878{
879 if (exiting(tcp)) {
880 sprintf(idstr, "egid %lu", getrval2(tcp));
881 tcp->auxstr = idstr;
882 return RVAL_STR;
883 }
884 return 0;
885}
886
887#endif /* !LINUX */
888
889#ifdef LINUX
890
891int
892sys_setuid(tcp)
893struct tcb *tcp;
894{
895 if (entering(tcp)) {
896 tprintf("%u", (uid_t) tcp->u_arg[0]);
897 }
898 return 0;
899}
900
901int
902sys_setgid(tcp)
903struct tcb *tcp;
904{
905 if (entering(tcp)) {
906 tprintf("%u", (gid_t) tcp->u_arg[0]);
907 }
908 return 0;
909}
910
911int
912sys_getresuid(tcp)
913 struct tcb *tcp;
914{
915 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000916 __kernel_uid_t uid;
917 if (syserror(tcp))
918 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
919 tcp->u_arg[1], tcp->u_arg[2]);
920 else {
921 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
922 tprintf("%#lx, ", tcp->u_arg[0]);
923 else
924 tprintf("ruid %lu, ", (unsigned long) uid);
925 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
926 tprintf("%#lx, ", tcp->u_arg[0]);
927 else
928 tprintf("euid %lu, ", (unsigned long) uid);
929 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
930 tprintf("%#lx", tcp->u_arg[0]);
931 else
932 tprintf("suid %lu", (unsigned long) uid);
933 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000934 }
935 return 0;
936}
937
938int
939sys_getresgid(tcp)
940struct tcb *tcp;
941{
942 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000943 __kernel_gid_t gid;
944 if (syserror(tcp))
945 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
946 tcp->u_arg[1], tcp->u_arg[2]);
947 else {
948 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
949 tprintf("%#lx, ", tcp->u_arg[0]);
950 else
951 tprintf("rgid %lu, ", (unsigned long) gid);
952 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
953 tprintf("%#lx, ", tcp->u_arg[0]);
954 else
955 tprintf("egid %lu, ", (unsigned long) gid);
956 if (umove(tcp, tcp->u_arg[0], &gid) < 0)
957 tprintf("%#lx", tcp->u_arg[0]);
958 else
959 tprintf("sgid %lu", (unsigned long) gid);
960 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000961 }
962 return 0;
963}
964
965#endif /* LINUX */
966
967int
968sys_setreuid(tcp)
969struct tcb *tcp;
970{
971 if (entering(tcp)) {
972 tprintf("%lu, %lu",
973 (unsigned long) (uid_t) tcp->u_arg[0],
974 (unsigned long) (uid_t) tcp->u_arg[1]);
975 }
976 return 0;
977}
978
979int
980sys_setregid(tcp)
981struct tcb *tcp;
982{
983 if (entering(tcp)) {
984 tprintf("%lu, %lu",
985 (unsigned long) (gid_t) tcp->u_arg[0],
986 (unsigned long) (gid_t) tcp->u_arg[1]);
987 }
988 return 0;
989}
990
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000991#if defined(LINUX) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992int
993sys_setresuid(tcp)
994 struct tcb *tcp;
995{
996 if (entering(tcp)) {
997 tprintf("ruid %u, euid %u, suid %u",
998 (uid_t) tcp->u_arg[0],
999 (uid_t) tcp->u_arg[1],
1000 (uid_t) tcp->u_arg[2]);
1001 }
1002 return 0;
1003}
1004int
1005sys_setresgid(tcp)
1006 struct tcb *tcp;
1007{
1008 if (entering(tcp)) {
1009 tprintf("rgid %u, egid %u, sgid %u",
1010 (uid_t) tcp->u_arg[0],
1011 (uid_t) tcp->u_arg[1],
1012 (uid_t) tcp->u_arg[2]);
1013 }
1014 return 0;
1015}
1016
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001017#endif /* LINUX || FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018
1019int
1020sys_setgroups(tcp)
1021struct tcb *tcp;
1022{
1023 int i, len;
1024 GETGROUPS_T *gidset;
1025
1026 if (entering(tcp)) {
1027 len = tcp->u_arg[0];
1028 tprintf("%u, ", len);
1029 if (len <= 0) {
1030 tprintf("[]");
1031 return 0;
1032 }
1033 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1034 if (gidset == NULL) {
1035 fprintf(stderr, "sys_setgroups: out of memory\n");
1036 return -1;
1037 }
1038 if (!verbose(tcp))
1039 tprintf("%#lx", tcp->u_arg[1]);
1040 else if (umoven(tcp, tcp->u_arg[1],
1041 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1042 tprintf("[?]");
1043 else {
1044 tprintf("[");
1045 for (i = 0; i < len; i++)
1046 tprintf("%s%lu", i ? ", " : "",
1047 (unsigned long) gidset[i]);
1048 tprintf("]");
1049 }
1050 free((char *) gidset);
1051 }
1052 return 0;
1053}
1054
1055int
1056sys_getgroups(tcp)
1057struct tcb *tcp;
1058{
1059 int i, len;
1060 GETGROUPS_T *gidset;
1061
1062 if (entering(tcp)) {
1063 len = tcp->u_arg[0];
1064 tprintf("%u, ", len);
1065 } else {
1066 len = tcp->u_rval;
1067 if (len <= 0) {
1068 tprintf("[]");
1069 return 0;
1070 }
1071 gidset = (GETGROUPS_T *) malloc(len * sizeof(GETGROUPS_T));
1072 if (gidset == NULL) {
1073 fprintf(stderr, "sys_getgroups: out of memory\n");
1074 return -1;
1075 }
1076 if (!tcp->u_arg[1])
1077 tprintf("NULL");
1078 else if (!verbose(tcp) || tcp->u_arg[0] == 0)
1079 tprintf("%#lx", tcp->u_arg[1]);
1080 else if (umoven(tcp, tcp->u_arg[1],
1081 len * sizeof(GETGROUPS_T), (char *) gidset) < 0)
1082 tprintf("[?]");
1083 else {
1084 tprintf("[");
1085 for (i = 0; i < len; i++)
1086 tprintf("%s%lu", i ? ", " : "",
1087 (unsigned long) gidset[i]);
1088 tprintf("]");
1089 }
1090 free((char *)gidset);
1091 }
1092 return 0;
1093}
1094
1095int
1096sys_setpgrp(tcp)
1097struct tcb *tcp;
1098{
1099 if (entering(tcp)) {
1100#ifndef SVR4
1101 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1102#endif /* !SVR4 */
1103 }
1104 return 0;
1105}
1106
1107int
1108sys_getpgrp(tcp)
1109struct tcb *tcp;
1110{
1111 if (entering(tcp)) {
1112#ifndef SVR4
1113 tprintf("%lu", tcp->u_arg[0]);
1114#endif /* !SVR4 */
1115 }
1116 return 0;
1117}
1118
1119int
1120sys_getsid(tcp)
1121struct tcb *tcp;
1122{
1123 if (entering(tcp)) {
1124 tprintf("%lu", tcp->u_arg[0]);
1125 }
1126 return 0;
1127}
1128
1129int
1130sys_setsid(tcp)
1131struct tcb *tcp;
1132{
1133 return 0;
1134}
1135
1136int
1137sys_getpgid(tcp)
1138struct tcb *tcp;
1139{
1140 if (entering(tcp)) {
1141 tprintf("%lu", tcp->u_arg[0]);
1142 }
1143 return 0;
1144}
1145
1146int
1147sys_setpgid(tcp)
1148struct tcb *tcp;
1149{
1150 if (entering(tcp)) {
1151 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1152 }
1153 return 0;
1154}
1155
John Hughesc61eb3d2002-05-17 11:37:50 +00001156#if UNIXWARE >= 2
1157
1158#include <sys/privilege.h>
1159
1160
1161static struct xlat procpriv_cmds [] = {
1162 { SETPRV, "SETPRV" },
1163 { CLRPRV, "CLRPRV" },
1164 { PUTPRV, "PUTPRV" },
1165 { GETPRV, "GETPRV" },
1166 { CNTPRV, "CNTPRV" },
1167 { 0, NULL },
1168};
1169
1170
1171static struct xlat procpriv_priv [] = {
1172 { P_OWNER, "P_OWNER" },
1173 { P_AUDIT, "P_AUDIT" },
1174 { P_COMPAT, "P_COMPAT" },
1175 { P_DACREAD, "P_DACREAD" },
1176 { P_DACWRITE, "P_DACWRITE" },
1177 { P_DEV, "P_DEV" },
1178 { P_FILESYS, "P_FILESYS" },
1179 { P_MACREAD, "P_MACREAD" },
1180 { P_MACWRITE, "P_MACWRITE" },
1181 { P_MOUNT, "P_MOUNT" },
1182 { P_MULTIDIR, "P_MULTIDIR" },
1183 { P_SETPLEVEL, "P_SETPLEVEL" },
1184 { P_SETSPRIV, "P_SETSPRIV" },
1185 { P_SETUID, "P_SETUID" },
1186 { P_SYSOPS, "P_SYSOPS" },
1187 { P_SETUPRIV, "P_SETUPRIV" },
1188 { P_DRIVER, "P_DRIVER" },
1189 { P_RTIME, "P_RTIME" },
1190 { P_MACUPGRADE, "P_MACUPGRADE" },
1191 { P_FSYSRANGE, "P_FSYSRANGE" },
1192 { P_SETFLEVEL, "P_SETFLEVEL" },
1193 { P_AUDITWR, "P_AUDITWR" },
1194 { P_TSHAR, "P_TSHAR" },
1195 { P_PLOCK, "P_PLOCK" },
1196 { P_CORE, "P_CORE" },
1197 { P_LOADMOD, "P_LOADMOD" },
1198 { P_BIND, "P_BIND" },
1199 { P_ALLPRIVS, "P_ALLPRIVS" },
1200 { 0, NULL },
1201};
1202
1203
1204static struct xlat procpriv_type [] = {
1205 { PS_FIX, "PS_FIX" },
1206 { PS_INH, "PS_INH" },
1207 { PS_MAX, "PS_MAX" },
1208 { PS_WKG, "PS_WKG" },
1209 { 0, NULL },
1210};
1211
1212
1213static void
1214printpriv(tcp, addr, len, opt)
1215struct tcb *tcp;
1216long addr;
1217int len;
1218struct xlat *opt;
1219{
1220 priv_t buf [128];
1221 int max = verbose (tcp) ? sizeof buf / sizeof buf [0] : 10;
1222 int dots = len > max;
1223 int i;
Roland McGrath5a223472002-12-15 23:58:26 +00001224
John Hughesc61eb3d2002-05-17 11:37:50 +00001225 if (len > max) len = max;
Roland McGrath5a223472002-12-15 23:58:26 +00001226
John Hughesc61eb3d2002-05-17 11:37:50 +00001227 if (len <= 0 ||
1228 umoven (tcp, addr, len * sizeof buf[0], (char *) buf) < 0)
1229 {
1230 tprintf ("%#lx", addr);
1231 return;
1232 }
1233
1234 tprintf ("[");
1235
1236 for (i = 0; i < len; ++i) {
1237 char *t, *p;
1238
1239 if (i) tprintf (", ");
1240
1241 if ((t = xlookup (procpriv_type, buf [i] & PS_TYPE)) &&
1242 (p = xlookup (procpriv_priv, buf [i] & ~PS_TYPE)))
1243 {
1244 tprintf ("%s|%s", t, p);
1245 }
1246 else {
1247 tprintf ("%#lx", buf [i]);
1248 }
1249 }
1250
1251 if (dots) tprintf (" ...");
1252
1253 tprintf ("]");
1254}
1255
1256
1257int
1258sys_procpriv(tcp)
1259struct tcb *tcp;
1260{
1261 if (entering(tcp)) {
1262 printxval(procpriv_cmds, tcp->u_arg[0], "???PRV");
1263 switch (tcp->u_arg[0]) {
1264 case CNTPRV:
1265 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1266 break;
1267
1268 case GETPRV:
1269 break;
1270
1271 default:
1272 tprintf (", ");
1273 printpriv (tcp, tcp->u_arg[1], tcp->u_arg[2]);
1274 tprintf (", %ld", tcp->u_arg[2]);
1275 }
1276 }
1277 else if (tcp->u_arg[0] == GETPRV) {
1278 if (syserror (tcp)) {
1279 tprintf(", %#lx, %ld", tcp->u_arg[1], tcp->u_arg[2]);
1280 }
1281 else {
1282 tprintf (", ");
1283 printpriv (tcp, tcp->u_arg[1], tcp->u_rval);
1284 tprintf (", %ld", tcp->u_arg[2]);
1285 }
1286 }
Roland McGrath5a223472002-12-15 23:58:26 +00001287
John Hughesc61eb3d2002-05-17 11:37:50 +00001288 return 0;
1289}
1290
1291#endif
1292
1293
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294void
1295fake_execve(tcp, program, argv, envp)
1296struct tcb *tcp;
1297char *program;
1298char *argv[];
1299char *envp[];
1300{
1301 int i;
1302
1303#ifdef ARM
1304 if (!(qual_flags[SYS_execve - __NR_SYSCALL_BASE] & QUAL_TRACE))
1305 return;
1306#else
1307 if (!(qual_flags[SYS_execve] & QUAL_TRACE))
1308 return;
1309#endif /* !ARM */
1310 printleader(tcp);
1311 tprintf("execve(");
1312 string_quote(program);
1313 tprintf(", [");
1314 for (i = 0; argv[i] != NULL; i++) {
1315 if (i != 0)
1316 tprintf(", ");
1317 string_quote(argv[i]);
1318 }
1319 for (i = 0; envp[i] != NULL; i++)
1320 ;
1321 tprintf("], [/* %d var%s */]) ", i, (i != 1) ? "s" : "");
1322 tabto(acolumn);
1323 tprintf("= 0");
1324 printtrailer(tcp);
1325}
1326
1327static void
1328printargv(tcp, addr)
1329struct tcb *tcp;
1330long addr;
1331{
1332 char *cp;
1333 char *sep;
1334 int max = max_strlen / 2;
1335
1336 for (sep = ""; --max >= 0; sep = ", ") {
1337 if (!abbrev(tcp))
1338 max++;
1339 if (umove(tcp, addr, &cp) < 0) {
1340 tprintf("%#lx", addr);
1341 return;
1342 }
1343 if (cp == 0)
1344 break;
1345 tprintf(sep);
1346 printstr(tcp, (long) cp, -1);
1347 addr += sizeof(char *);
1348 }
1349 if (cp)
1350 tprintf(", ...");
1351}
1352
1353static void
1354printargc(fmt, tcp, addr)
1355char *fmt;
1356struct tcb *tcp;
1357long addr;
1358{
1359 int count;
1360 char *cp;
1361
1362 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1363 addr += sizeof(char *);
1364 }
1365 tprintf(fmt, count, count == 1 ? "" : "s");
1366}
1367
1368int
1369sys_execv(tcp)
1370struct tcb *tcp;
1371{
1372 if (entering(tcp)) {
1373 printpath(tcp, tcp->u_arg[0]);
1374 if (!verbose(tcp))
1375 tprintf(", %#lx", tcp->u_arg[1]);
1376#if 0
1377 else if (abbrev(tcp))
1378 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1379#endif
1380 else {
1381 tprintf(", [");
1382 printargv(tcp, tcp->u_arg[1]);
1383 tprintf("]");
1384 }
1385 }
1386 return 0;
1387}
1388
1389int
1390sys_execve(tcp)
1391struct tcb *tcp;
1392{
1393 if (entering(tcp)) {
1394 printpath(tcp, tcp->u_arg[0]);
1395 if (!verbose(tcp))
1396 tprintf(", %#lx", tcp->u_arg[1]);
1397#if 0
1398 else if (abbrev(tcp))
1399 printargc(", [/* %d arg%s */]", tcp, tcp->u_arg[1]);
1400#endif
1401 else {
1402 tprintf(", [");
1403 printargv(tcp, tcp->u_arg[1]);
1404 tprintf("]");
1405 }
1406 if (!verbose(tcp))
1407 tprintf(", %#lx", tcp->u_arg[2]);
1408 else if (abbrev(tcp))
1409 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1410 else {
1411 tprintf(", [");
1412 printargv(tcp, tcp->u_arg[2]);
1413 tprintf("]");
1414 }
1415 }
1416#ifdef LINUX
Wichert Akkermanccef6372002-05-01 16:39:22 +00001417#if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001418 tcp->flags |= TCB_WAITEXECVE;
Wichert Akkermanccef6372002-05-01 16:39:22 +00001419#endif /* ALPHA || SPARC || POWERPC || IA64 || HPPA || SH */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001420#endif /* LINUX */
1421 return 0;
1422}
1423
John Hughes4e36a812001-04-18 15:11:51 +00001424#if UNIXWARE > 2
1425
1426int sys_rexecve(tcp)
1427struct tcb *tcp;
1428{
1429 if (entering (tcp)) {
1430 sys_execve (tcp);
1431 tprintf (", %ld", tcp->u_arg[3]);
1432 }
1433 return 0;
1434}
1435
1436#endif
1437
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001438int
1439internal_exec(tcp)
1440struct tcb *tcp;
1441{
1442#ifdef SUNOS4
1443 if (exiting(tcp) && !syserror(tcp) && followfork)
1444 fixvfork(tcp);
1445#endif /* SUNOS4 */
1446 return 0;
1447}
1448
1449#ifdef LINUX
1450#ifndef __WCLONE
1451#define __WCLONE 0x8000000
1452#endif
1453#endif /* LINUX */
1454
1455static struct xlat wait4_options[] = {
1456 { WNOHANG, "WNOHANG" },
1457#ifndef WSTOPPED
1458 { WUNTRACED, "WUNTRACED" },
1459#endif
1460#ifdef WEXITED
1461 { WEXITED, "WEXITED" },
1462#endif
1463#ifdef WTRAPPED
1464 { WTRAPPED, "WTRAPPED" },
1465#endif
1466#ifdef WSTOPPED
1467 { WSTOPPED, "WSTOPPED" },
1468#endif
1469#ifdef WCONTINUED
1470 { WCONTINUED, "WCONTINUED" },
1471#endif
1472#ifdef WNOWAIT
1473 { WNOWAIT, "WNOWAIT" },
1474#endif
1475#ifdef __WCLONE
1476 { __WCLONE, "__WCLONE" },
1477#endif
1478 { 0, NULL },
1479};
1480
1481static int
1482printstatus(status)
1483int status;
1484{
1485 int exited = 0;
1486
1487 /*
1488 * Here is a tricky presentation problem. This solution
1489 * is still not entirely satisfactory but since there
1490 * are no wait status constructors it will have to do.
1491 */
1492 if (WIFSTOPPED(status))
1493 tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001494 signame(WSTOPSIG(status)));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001495 else if WIFSIGNALED(status)
1496 tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001497 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001498 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1499 else if WIFEXITED(status) {
1500 tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
1501 WEXITSTATUS(status));
1502 exited = 1;
1503 }
1504 else
1505 tprintf("[%#x]", status);
1506 return exited;
1507}
1508
1509static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001510printwaitn(tcp, n, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001511struct tcb *tcp;
1512int n;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001513int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001514{
1515 int status;
1516 int exited = 0;
1517
1518 if (entering(tcp)) {
1519 tprintf("%ld, ", tcp->u_arg[0]);
1520 } else {
1521 /* status */
1522 if (!tcp->u_arg[1])
1523 tprintf("NULL");
1524 else if (syserror(tcp) || tcp->u_rval == 0)
1525 tprintf("%#lx", tcp->u_arg[1]);
1526 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1527 tprintf("[?]");
1528 else
1529 exited = printstatus(status);
1530 /* options */
1531 tprintf(", ");
1532 if (!printflags(wait4_options, tcp->u_arg[2]))
1533 tprintf("0");
1534 if (n == 4) {
1535 tprintf(", ");
1536 /* usage */
1537 if (!tcp->u_arg[3])
1538 tprintf("NULL");
1539#ifdef LINUX
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001540 else if (tcp->u_rval > 0) {
1541#ifdef LINUX_64BIT
1542 if (bitness)
1543 printrusage32(tcp, tcp->u_arg[3]);
1544 else
1545#endif
1546 printrusage(tcp, tcp->u_arg[3]);
1547 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001548#endif /* LINUX */
1549#ifdef SUNOS4
1550 else if (tcp->u_rval > 0 && exited)
1551 printrusage(tcp, tcp->u_arg[3]);
1552#endif /* SUNOS4 */
1553 else
1554 tprintf("%#lx", tcp->u_arg[3]);
1555 }
1556 }
1557 return 0;
1558}
1559
1560int
1561internal_wait(tcp)
1562struct tcb *tcp;
1563{
1564 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +00001565 /* WTA: fix bug with hanging children */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001566 if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
1567 /* There are traced children */
1568 tcp->flags |= TCB_SUSPENDED;
1569 tcp->waitpid = tcp->u_arg[0];
1570 }
1571 }
1572 return 0;
1573}
1574
1575#ifdef SVR4
1576
1577int
1578sys_wait(tcp)
1579struct tcb *tcp;
1580{
1581 if (exiting(tcp)) {
1582 /* The library wrapper stuffs this into the user variable. */
1583 if (!syserror(tcp))
1584 printstatus(getrval2(tcp));
1585 }
1586 return 0;
1587}
1588
1589#endif /* SVR4 */
1590
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001591#ifdef FREEBSD
1592int
1593sys_wait(tcp)
1594struct tcb *tcp;
1595{
1596 int status;
Roland McGrath5a223472002-12-15 23:58:26 +00001597
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001598 if (exiting(tcp)) {
1599 if (!syserror(tcp)) {
1600 if (umove(tcp, tcp->u_arg[0], &status) < 0)
1601 tprintf("%#lx", tcp->u_arg[0]);
1602 else
1603 printstatus(status);
1604 }
1605 }
1606 return 0;
1607}
1608#endif
1609
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001610int
1611sys_waitpid(tcp)
1612struct tcb *tcp;
1613{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001614 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615}
1616
1617int
1618sys_wait4(tcp)
1619struct tcb *tcp;
1620{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001621 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001622}
1623
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001624#ifdef ALPHA
1625int
1626sys_osf_wait4(tcp)
1627struct tcb *tcp;
1628{
1629 return printwaitn(tcp, 4, 1);
1630}
1631#endif
1632
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001633#ifdef SVR4
1634
1635static struct xlat waitid_types[] = {
1636 { P_PID, "P_PID" },
1637 { P_PPID, "P_PPID" },
1638 { P_PGID, "P_PGID" },
1639 { P_SID, "P_SID" },
1640 { P_CID, "P_CID" },
1641 { P_UID, "P_UID" },
1642 { P_GID, "P_GID" },
1643 { P_ALL, "P_ALL" },
1644#ifdef P_LWPID
1645 { P_LWPID, "P_LWPID" },
1646#endif
1647 { 0, NULL },
1648};
1649
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001650int
1651sys_waitid(tcp)
1652struct tcb *tcp;
1653{
1654 siginfo_t si;
1655 int exited;
1656
1657 if (entering(tcp)) {
1658 printxval(waitid_types, tcp->u_arg[0], "P_???");
1659 tprintf(", %ld, ", tcp->u_arg[1]);
1660 if (tcp->nchildren > 0) {
1661 /* There are traced children */
1662 tcp->flags |= TCB_SUSPENDED;
1663 tcp->waitpid = tcp->u_arg[0];
1664 }
1665 }
1666 else {
1667 /* siginfo */
1668 exited = 0;
1669 if (!tcp->u_arg[2])
1670 tprintf("NULL");
1671 else if (syserror(tcp))
1672 tprintf("%#lx", tcp->u_arg[2]);
1673 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1674 tprintf("{???}");
1675 else
John Hughes58265892001-10-18 15:13:53 +00001676 printsiginfo(&si, verbose (tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001677 /* options */
1678 tprintf(", ");
1679 if (!printflags(wait4_options, tcp->u_arg[3]))
1680 tprintf("0");
1681 }
1682 return 0;
1683}
1684
1685#endif /* SVR4 */
1686
1687int
1688sys_alarm(tcp)
1689struct tcb *tcp;
1690{
1691 if (entering(tcp))
1692 tprintf("%lu", tcp->u_arg[0]);
1693 return 0;
1694}
1695
1696int
1697sys_uname(tcp)
1698struct tcb *tcp;
1699{
1700 struct utsname uname;
1701
1702 if (exiting(tcp)) {
1703 if (syserror(tcp) || !verbose(tcp))
1704 tprintf("%#lx", tcp->u_arg[0]);
1705 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1706 tprintf("{...}");
1707 else if (!abbrev(tcp)) {
1708
1709 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1710 uname.sysname, uname.nodename);
1711 tprintf("release=\"%s\", version=\"%s\", ",
1712 uname.release, uname.version);
1713 tprintf("machine=\"%s\"", uname.machine);
1714#ifdef LINUX
1715#ifndef __GLIBC__
1716 tprintf(", domainname=\"%s\"", uname.domainname);
1717#endif /* __GLIBC__ */
1718#endif /* LINUX */
1719 tprintf("}");
1720 }
1721 else
1722 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1723 uname.sysname, uname.nodename);
1724 }
1725 return 0;
1726}
1727
1728#ifndef SVR4
1729
1730static struct xlat ptrace_cmds[] = {
Roland McGrath5a223472002-12-15 23:58:26 +00001731#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001732 { PTRACE_TRACEME, "PTRACE_TRACEME" },
1733 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT", },
1734 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA", },
1735 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER", },
1736 { PTRACE_POKETEXT, "PTRACE_POKETEXT", },
1737 { PTRACE_POKEDATA, "PTRACE_POKEDATA", },
1738 { PTRACE_POKEUSER, "PTRACE_POKEUSER", },
1739 { PTRACE_CONT, "PTRACE_CONT" },
1740 { PTRACE_KILL, "PTRACE_KILL" },
1741 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1742 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1743 { PTRACE_DETACH, "PTRACE_DETACH" },
1744#ifdef SUNOS4
1745 { PTRACE_GETREGS, "PTRACE_GETREGS" },
1746 { PTRACE_SETREGS, "PTRACE_SETREGS" },
1747 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS", },
1748 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS", },
1749 { PTRACE_READDATA, "PTRACE_READDATA" },
1750 { PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
1751 { PTRACE_READTEXT, "PTRACE_READTEXT" },
1752 { PTRACE_WRITETEXT, "PTRACE_WRITETEXT" },
1753 { PTRACE_GETFPAREGS, "PTRACE_GETFPAREGS" },
1754 { PTRACE_SETFPAREGS, "PTRACE_SETFPAREGS" },
1755#ifdef SPARC
1756 { PTRACE_GETWINDOW, "PTRACE_GETWINDOW" },
1757 { PTRACE_SETWINDOW, "PTRACE_SETWINDOW" },
1758#else /* !SPARC */
1759 { PTRACE_22, "PTRACE_PTRACE_22" },
1760 { PTRACE_23, "PTRACE_PTRACE_23" },
1761#endif /* !SPARC */
1762#endif /* SUNOS4 */
1763 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
1764#ifdef SUNOS4
1765 { PTRACE_DUMPCORE, "PTRACE_DUMPCORE" },
1766#ifdef I386
1767 { PTRACE_SETWRBKPT, "PTRACE_SETWRBKPT" },
1768 { PTRACE_SETACBKPT, "PTRACE_SETACBKPT" },
1769 { PTRACE_CLRDR7, "PTRACE_CLRDR7" },
1770#else /* !I386 */
1771 { PTRACE_26, "PTRACE_26" },
1772 { PTRACE_27, "PTRACE_27" },
1773 { PTRACE_28, "PTRACE_28" },
1774#endif /* !I386 */
1775 { PTRACE_GETUCODE, "PTRACE_GETUCODE" },
1776#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001777#else /* FREEBSD */
1778 { PT_TRACE_ME, "PT_TRACE_ME" },
1779 { PT_READ_I, "PT_READ_I" },
1780 { PT_READ_D, "PT_READ_D" },
1781 { PT_WRITE_I, "PT_WRITE_I" },
1782 { PT_WRITE_D, "PT_WRITE_D" },
John Hughesa2278142001-09-28 16:21:30 +00001783#ifdef PT_READ_U
1784 { PT_READ_U, "PT_READ_U" },
1785#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001786 { PT_CONTINUE, "PT_CONTINUE" },
1787 { PT_KILL, "PT_KILL" },
1788 { PT_STEP, "PT_STEP" },
1789 { PT_ATTACH, "PT_ATTACH" },
1790 { PT_DETACH, "PT_DETACH" },
1791 { PT_GETREGS, "PT_GETREGS" },
1792 { PT_SETREGS, "PT_SETREGS" },
1793 { PT_GETFPREGS, "PT_GETFPREGS" },
1794 { PT_SETFPREGS, "PT_SETFPREGS" },
1795 { PT_GETDBREGS, "PT_GETDBREGS" },
1796 { PT_SETDBREGS, "PT_SETDBREGS" },
1797#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001798 { 0, NULL },
1799};
1800
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001801#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001802#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
1803static
1804#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
1805struct xlat struct_user_offsets[] = {
1806#ifdef LINUX
Michal Ludvig10a88d02002-10-07 14:31:00 +00001807#if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001808 { PT_PSWMASK, "psw_mask" },
1809 { PT_PSWADDR, "psw_addr" },
1810 { PT_GPR0, "gpr0" },
1811 { PT_GPR1, "gpr1" },
1812 { PT_GPR2, "gpr2" },
1813 { PT_GPR3, "gpr3" },
1814 { PT_GPR4, "gpr4" },
1815 { PT_GPR5, "gpr5" },
1816 { PT_GPR6, "gpr6" },
1817 { PT_GPR7, "gpr7" },
1818 { PT_GPR8, "gpr8" },
1819 { PT_GPR9, "gpr9" },
1820 { PT_GPR10, "gpr10" },
1821 { PT_GPR11, "gpr11" },
1822 { PT_GPR12, "gpr12" },
1823 { PT_GPR13, "gpr13" },
1824 { PT_GPR14, "gpr14" },
1825 { PT_GPR15, "gpr15" },
1826 { PT_ACR0, "acr0" },
1827 { PT_ACR1, "acr1" },
1828 { PT_ACR2, "acr2" },
1829 { PT_ACR3, "acr3" },
1830 { PT_ACR4, "acr4" },
1831 { PT_ACR5, "acr5" },
1832 { PT_ACR6, "acr6" },
1833 { PT_ACR7, "acr7" },
1834 { PT_ACR8, "acr8" },
1835 { PT_ACR9, "acr9" },
1836 { PT_ACR10, "acr10" },
1837 { PT_ACR11, "acr11" },
1838 { PT_ACR12, "acr12" },
1839 { PT_ACR13, "acr13" },
1840 { PT_ACR14, "acr14" },
1841 { PT_ACR15, "acr15" },
1842 { PT_ORIGGPR2, "orig_gpr2" },
1843 { PT_FPC, "fpc" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00001844#if defined(S390)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001845 { PT_FPR0_HI, "fpr0.hi" },
1846 { PT_FPR0_LO, "fpr0.lo" },
1847 { PT_FPR1_HI, "fpr1.hi" },
1848 { PT_FPR1_LO, "fpr1.lo" },
1849 { PT_FPR2_HI, "fpr2.hi" },
1850 { PT_FPR2_LO, "fpr2.lo" },
1851 { PT_FPR3_HI, "fpr3.hi" },
1852 { PT_FPR3_LO, "fpr3.lo" },
1853 { PT_FPR4_HI, "fpr4.hi" },
1854 { PT_FPR4_LO, "fpr4.lo" },
1855 { PT_FPR5_HI, "fpr5.hi" },
1856 { PT_FPR5_LO, "fpr5.lo" },
1857 { PT_FPR6_HI, "fpr6.hi" },
1858 { PT_FPR6_LO, "fpr6.lo" },
1859 { PT_FPR7_HI, "fpr7.hi" },
1860 { PT_FPR7_LO, "fpr7.lo" },
1861 { PT_FPR8_HI, "fpr8.hi" },
1862 { PT_FPR8_LO, "fpr8.lo" },
1863 { PT_FPR9_HI, "fpr9.hi" },
1864 { PT_FPR9_LO, "fpr9.lo" },
1865 { PT_FPR10_HI, "fpr10.hi" },
1866 { PT_FPR10_LO, "fpr10.lo" },
1867 { PT_FPR11_HI, "fpr11.hi" },
1868 { PT_FPR11_LO, "fpr11.lo" },
1869 { PT_FPR12_HI, "fpr12.hi" },
1870 { PT_FPR12_LO, "fpr12.lo" },
1871 { PT_FPR13_HI, "fpr13.hi" },
1872 { PT_FPR13_LO, "fpr13.lo" },
1873 { PT_FPR14_HI, "fpr14.hi" },
1874 { PT_FPR14_LO, "fpr14.lo" },
1875 { PT_FPR15_HI, "fpr15.hi" },
1876 { PT_FPR15_LO, "fpr15.lo" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00001877#endif
1878#if defined(S390X)
1879 { PT_FPR0, "fpr0" },
1880 { PT_FPR1, "fpr1" },
1881 { PT_FPR2, "fpr2" },
1882 { PT_FPR3, "fpr3" },
1883 { PT_FPR4, "fpr4" },
1884 { PT_FPR5, "fpr5" },
1885 { PT_FPR6, "fpr6" },
1886 { PT_FPR7, "fpr7" },
1887 { PT_FPR8, "fpr8" },
1888 { PT_FPR9, "fpr9" },
1889 { PT_FPR10, "fpr10" },
1890 { PT_FPR11, "fpr11" },
1891 { PT_FPR12, "fpr12" },
1892 { PT_FPR13, "fpr13" },
1893 { PT_FPR14, "fpr14" },
1894 { PT_FPR15, "fpr15" },
1895#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001896 { PT_CR_9, "cr9" },
1897 { PT_CR_10, "cr10" },
1898 { PT_CR_11, "cr11" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00001899 { PT_IEEE_IP, "ieee_exception_ip" },
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001900#endif
1901#if defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001902 /* XXX No support for these offsets yet. */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001903#elif defined(HPPA)
1904 /* XXX No support for these offsets yet. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001905#elif defined(POWERPC)
Roland McGrath5a223472002-12-15 23:58:26 +00001906#ifndef PT_ORIG_R3
1907#define PT_ORIG_R3 34
1908#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001909 { 4*PT_R0, "4*PT_R0" },
1910 { 4*PT_R1, "4*PT_R1" },
1911 { 4*PT_R2, "4*PT_R2" },
1912 { 4*PT_R3, "4*PT_R3" },
1913 { 4*PT_R4, "4*PT_R4" },
1914 { 4*PT_R5, "4*PT_R5" },
1915 { 4*PT_R6, "4*PT_R6" },
1916 { 4*PT_R7, "4*PT_R7" },
1917 { 4*PT_R8, "4*PT_R8" },
1918 { 4*PT_R9, "4*PT_R9" },
1919 { 4*PT_R10, "4*PT_R10" },
1920 { 4*PT_R11, "4*PT_R11" },
1921 { 4*PT_R12, "4*PT_R12" },
1922 { 4*PT_R13, "4*PT_R13" },
1923 { 4*PT_R14, "4*PT_R14" },
1924 { 4*PT_R15, "4*PT_R15" },
1925 { 4*PT_R16, "4*PT_R16" },
1926 { 4*PT_R17, "4*PT_R17" },
1927 { 4*PT_R18, "4*PT_R18" },
1928 { 4*PT_R19, "4*PT_R19" },
1929 { 4*PT_R20, "4*PT_R20" },
1930 { 4*PT_R21, "4*PT_R21" },
1931 { 4*PT_R22, "4*PT_R22" },
1932 { 4*PT_R23, "4*PT_R23" },
1933 { 4*PT_R24, "4*PT_R24" },
1934 { 4*PT_R25, "4*PT_R25" },
1935 { 4*PT_R26, "4*PT_R26" },
1936 { 4*PT_R27, "4*PT_R27" },
1937 { 4*PT_R28, "4*PT_R28" },
1938 { 4*PT_R29, "4*PT_R29" },
1939 { 4*PT_R30, "4*PT_R30" },
1940 { 4*PT_R31, "4*PT_R31" },
1941 { 4*PT_NIP, "4*PT_NIP" },
1942 { 4*PT_MSR, "4*PT_MSR" },
1943 { 4*PT_ORIG_R3, "4*PT_ORIG_R3" },
1944 { 4*PT_CTR, "4*PT_CTR" },
1945 { 4*PT_LNK, "4*PT_LNK" },
1946 { 4*PT_XER, "4*PT_XER" },
1947 { 4*PT_CCR, "4*PT_CCR" },
1948 { 4*PT_FPR0, "4*PT_FPR0" },
Roland McGrath5a223472002-12-15 23:58:26 +00001949#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001950#ifdef ALPHA
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001951 { 0, "r0" },
1952 { 1, "r1" },
1953 { 2, "r2" },
1954 { 3, "r3" },
1955 { 4, "r4" },
1956 { 5, "r5" },
1957 { 6, "r6" },
1958 { 7, "r7" },
1959 { 8, "r8" },
1960 { 9, "r9" },
1961 { 10, "r10" },
1962 { 11, "r11" },
1963 { 12, "r12" },
1964 { 13, "r13" },
1965 { 14, "r14" },
1966 { 15, "r15" },
1967 { 16, "r16" },
1968 { 17, "r17" },
1969 { 18, "r18" },
1970 { 19, "r19" },
1971 { 20, "r20" },
1972 { 21, "r21" },
1973 { 22, "r22" },
1974 { 23, "r23" },
1975 { 24, "r24" },
1976 { 25, "r25" },
1977 { 26, "r26" },
1978 { 27, "r27" },
1979 { 28, "r28" },
1980 { 29, "gp" },
1981 { 30, "fp" },
1982 { 31, "zero" },
1983 { 32, "fp0" },
1984 { 33, "fp" },
1985 { 34, "fp2" },
1986 { 35, "fp3" },
1987 { 36, "fp4" },
1988 { 37, "fp5" },
1989 { 38, "fp6" },
1990 { 39, "fp7" },
1991 { 40, "fp8" },
1992 { 41, "fp9" },
1993 { 42, "fp10" },
1994 { 43, "fp11" },
1995 { 44, "fp12" },
1996 { 45, "fp13" },
1997 { 46, "fp14" },
1998 { 47, "fp15" },
1999 { 48, "fp16" },
2000 { 49, "fp17" },
2001 { 50, "fp18" },
2002 { 51, "fp19" },
2003 { 52, "fp20" },
2004 { 53, "fp21" },
2005 { 54, "fp22" },
2006 { 55, "fp23" },
2007 { 56, "fp24" },
2008 { 57, "fp25" },
2009 { 58, "fp26" },
2010 { 59, "fp27" },
2011 { 60, "fp28" },
2012 { 61, "fp29" },
2013 { 62, "fp30" },
2014 { 63, "fp31" },
2015 { 64, "pc" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002016#else /* !ALPHA */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002017#ifdef IA64
2018 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
2019 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
2020 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
2021 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
2022 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
2023 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
2024 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
2025 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
2026 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
2027 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
2028 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
2029 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
2030 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
2031 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
2032 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
2033 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
2034 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
2035 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
2036 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
2037 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
2038 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
2039 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
2040 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
2041 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
2042 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
2043 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
2044 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
2045 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
2046 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
2047 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
2048 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
2049 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
2050 /* switch stack: */
2051 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
2052 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
2053 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
2054 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
2055 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
2056 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
2057 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
2058 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
2059 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
2060 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002061 { PT_B0, "kb0" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002062 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
2063 { PT_B4, "b4" }, { PT_B5, "b5" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002064 { PT_AR_PFS, "kar.pfs" },
2065 { PT_AR_LC, "ar.lc" }, { PT_AR_UNAT, "kar.unat" },
2066 { PT_AR_RNAT, "kar.rnat" }, { PT_AR_BSPSTORE, "kar.bspstore" },
2067 { PT_PR, "k.pr" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002068 /* pt_regs */
2069 { PT_CR_IPSR, "cr.ipsr" }, { PT_CR_IIP, "cr.iip" },
Wichert Akkerman82b162e2001-08-03 11:51:28 +00002070 /*{ PT_CR_IFS, "cr.ifs" },*/ { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002071 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
2072 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
2073 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
2074 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
2075 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
2076 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
2077 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
2078 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
2079 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
2080 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
2081 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
2082 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
2083 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
2084 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
2085 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
2086#else /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002087#ifdef I386
2088 { 4*EBX, "4*EBX" },
2089 { 4*ECX, "4*ECX" },
2090 { 4*EDX, "4*EDX" },
2091 { 4*ESI, "4*ESI" },
2092 { 4*EDI, "4*EDI" },
2093 { 4*EBP, "4*EBP" },
2094 { 4*EAX, "4*EAX" },
2095 { 4*DS, "4*DS" },
2096 { 4*ES, "4*ES" },
2097 { 4*FS, "4*FS" },
2098 { 4*GS, "4*GS" },
2099 { 4*ORIG_EAX, "4*ORIG_EAX" },
2100 { 4*EIP, "4*EIP" },
2101 { 4*CS, "4*CS" },
2102 { 4*EFL, "4*EFL" },
2103 { 4*UESP, "4*UESP" },
2104 { 4*SS, "4*SS" },
2105#else /* !I386 */
Michal Ludvig0e035502002-09-23 15:41:01 +00002106#ifdef X86_64
2107 { 8*RDI, "8*RDI" },
2108 { 8*RSI, "8*RSI" },
2109 { 8*RDX, "8*RDX" },
2110 { 8*R10, "8*R10" },
2111 { 8*R8, "8*R8" },
2112 { 8*R9, "8*R9" },
2113 { 8*RBX, "8*RBX" },
2114 { 8*RCX, "8*RCX" },
2115 { 8*RBP, "8*RBP" },
2116 { 8*RAX, "8*RAX" },
2117#if 0
2118 { 8*DS, "8*DS" },
2119 { 8*ES, "8*ES" },
2120 { 8*FS, "8*FS" },
2121 { 8*GS, "8*GS" },
2122#endif
2123 { 8*ORIG_RAX, "8*ORIG_EAX" },
2124 { 8*RIP, "8*RIP" },
2125 { 8*CS, "8*CS" },
2126 { 8*EFLAGS, "8*EFL" },
2127 { 8*RSP, "8*RSP" },
2128 { 8*SS, "8*SS" },
2129 { 8*R11, "8*R11" },
2130 { 8*R12, "8*R12" },
2131 { 8*R13, "8*R13" },
2132 { 8*R14, "8*R14" },
2133 { 8*R15, "8*R15" },
2134#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002135#ifdef M68K
2136 { 4*PT_D1, "4*PT_D1" },
2137 { 4*PT_D2, "4*PT_D2" },
2138 { 4*PT_D3, "4*PT_D3" },
2139 { 4*PT_D4, "4*PT_D4" },
2140 { 4*PT_D5, "4*PT_D5" },
2141 { 4*PT_D6, "4*PT_D6" },
2142 { 4*PT_D7, "4*PT_D7" },
2143 { 4*PT_A0, "4*PT_A0" },
2144 { 4*PT_A1, "4*PT_A1" },
2145 { 4*PT_A2, "4*PT_A2" },
2146 { 4*PT_A3, "4*PT_A3" },
2147 { 4*PT_A4, "4*PT_A4" },
2148 { 4*PT_A5, "4*PT_A5" },
2149 { 4*PT_A6, "4*PT_A6" },
2150 { 4*PT_D0, "4*PT_D0" },
2151 { 4*PT_USP, "4*PT_USP" },
2152 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
2153 { 4*PT_SR, "4*PT_SR" },
2154 { 4*PT_PC, "4*PT_PC" },
2155#endif /* M68K */
2156#endif /* !I386 */
Wichert Akkermanccef6372002-05-01 16:39:22 +00002157#ifdef SH
2158 { 4*REG_REG0, "4*REG_REG0" },
2159 { 4*(REG_REG0+1), "4*REG_REG1" },
2160 { 4*(REG_REG0+2), "4*REG_REG2" },
2161 { 4*(REG_REG0+3), "4*REG_REG3" },
2162 { 4*(REG_REG0+4), "4*REG_REG4" },
2163 { 4*(REG_REG0+5), "4*REG_REG5" },
2164 { 4*(REG_REG0+6), "4*REG_REG6" },
2165 { 4*(REG_REG0+7), "4*REG_REG7" },
2166 { 4*(REG_REG0+8), "4*REG_REG8" },
2167 { 4*(REG_REG0+9), "4*REG_REG9" },
2168 { 4*(REG_REG0+10), "4*REG_REG10" },
2169 { 4*(REG_REG0+11), "4*REG_REG11" },
2170 { 4*(REG_REG0+12), "4*REG_REG12" },
2171 { 4*(REG_REG0+13), "4*REG_REG13" },
2172 { 4*(REG_REG0+14), "4*REG_REG14" },
2173 { 4*REG_REG15, "4*REG_REG15" },
2174 { 4*REG_PC, "4*REG_PC" },
2175 { 4*REG_PR, "4*REG_PR" },
2176 { 4*REG_SR, "4*REG_SR" },
2177 { 4*REG_GBR, "4*REG_GBR" },
2178 { 4*REG_MACH, "4*REG_MACH" },
2179 { 4*REG_MACL, "4*REG_MACL" },
2180 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
2181 { 4*REG_FPUL, "4*REG_FPUL" },
2182 { 4*REG_FPREG0, "4*REG_FPREG0" },
2183 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
2184 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
2185 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
2186 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
2187 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
2188 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
2189 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
2190 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
2191 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
2192 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
2193 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
2194 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
2195 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
2196 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
2197 { 4*REG_FPREG15, "4*REG_FPREG15" },
2198 { 4*REG_XDREG0, "4*REG_XDREG0" },
2199 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
2200 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
2201 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
2202 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
2203 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
2204 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
2205 { 4*REG_XDREG14, "4*REG_XDREG14" },
2206 { 4*REG_FPSCR, "4*REG_FPSCR" },
2207#endif /* SH */
2208
Michal Ludvig10a88d02002-10-07 14:31:00 +00002209#if !defined(S390) && !defined(S390X) && !defined(MIPS)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002210 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002211#endif
Michal Ludvig0e035502002-09-23 15:41:01 +00002212#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002213 { uoff(i387), "offsetof(struct user, i387)" },
2214#else /* !I386 */
2215#ifdef M68K
2216 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
2217#endif /* M68K */
2218#endif /* !I386 */
2219 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2220 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2221 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
2222 { uoff(start_code), "offsetof(struct user, start_code)" },
2223 { uoff(start_stack), "offsetof(struct user, start_stack)" },
2224 { uoff(signal), "offsetof(struct user, signal)" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002225#if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002226 { uoff(reserved), "offsetof(struct user, reserved)" },
Wichert Akkermanf90da011999-10-31 21:15:38 +00002227#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002228 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Michal Ludvig10a88d02002-10-07 14:31:00 +00002229#if !defined(ARM) && !defined(MIPS) && !defined(S390) && !defined(S390X)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002230 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
2231#endif
2232 { uoff(magic), "offsetof(struct user, magic)" },
2233 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Michal Ludvig0e035502002-09-23 15:41:01 +00002234#if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002235 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
2236#endif /* I386 */
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00002237#endif /* !IA64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002238#endif /* !ALPHA */
2239#endif /* !POWERPC/!SPARC */
2240#endif /* LINUX */
2241#ifdef SUNOS4
2242 { uoff(u_pcb), "offsetof(struct user, u_pcb)" },
2243 { uoff(u_procp), "offsetof(struct user, u_procp)" },
2244 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
2245 { uoff(u_comm[0]), "offsetof(struct user, u_comm[0])" },
2246 { uoff(u_arg[0]), "offsetof(struct user, u_arg[0])" },
2247 { uoff(u_ap), "offsetof(struct user, u_ap)" },
2248 { uoff(u_qsave), "offsetof(struct user, u_qsave)" },
2249 { uoff(u_rval1), "offsetof(struct user, u_rval1)" },
2250 { uoff(u_rval2), "offsetof(struct user, u_rval2)" },
2251 { uoff(u_error), "offsetof(struct user, u_error)" },
2252 { uoff(u_eosys), "offsetof(struct user, u_eosys)" },
2253 { uoff(u_ssave), "offsetof(struct user, u_ssave)" },
2254 { uoff(u_signal[0]), "offsetof(struct user, u_signal)" },
2255 { uoff(u_sigmask[0]), "offsetof(struct user, u_sigmask)" },
2256 { uoff(u_sigonstack), "offsetof(struct user, u_sigonstack)" },
2257 { uoff(u_sigintr), "offsetof(struct user, u_sigintr)" },
2258 { uoff(u_sigreset), "offsetof(struct user, u_sigreset)" },
2259 { uoff(u_oldmask), "offsetof(struct user, u_oldmask)" },
2260 { uoff(u_code), "offsetof(struct user, u_code)" },
2261 { uoff(u_addr), "offsetof(struct user, u_addr)" },
2262 { uoff(u_sigstack), "offsetof(struct user, u_sigstack)" },
2263 { uoff(u_ofile), "offsetof(struct user, u_ofile)" },
2264 { uoff(u_pofile), "offsetof(struct user, u_pofile)" },
2265 { uoff(u_ofile_arr[0]), "offsetof(struct user, u_ofile_arr[0])" },
2266 { uoff(u_pofile_arr[0]),"offsetof(struct user, u_pofile_arr[0])"},
2267 { uoff(u_lastfile), "offsetof(struct user, u_lastfile)" },
2268 { uoff(u_cwd), "offsetof(struct user, u_cwd)" },
2269 { uoff(u_cdir), "offsetof(struct user, u_cdir)" },
2270 { uoff(u_rdir), "offsetof(struct user, u_rdir)" },
2271 { uoff(u_cmask), "offsetof(struct user, u_cmask)" },
2272 { uoff(u_ru), "offsetof(struct user, u_ru)" },
2273 { uoff(u_cru), "offsetof(struct user, u_cru)" },
2274 { uoff(u_timer[0]), "offsetof(struct user, u_timer[0])" },
2275 { uoff(u_XXX[0]), "offsetof(struct user, u_XXX[0])" },
2276 { uoff(u_ioch), "offsetof(struct user, u_ioch)" },
2277 { uoff(u_start), "offsetof(struct user, u_start)" },
2278 { uoff(u_acflag), "offsetof(struct user, u_acflag)" },
2279 { uoff(u_prof.pr_base), "offsetof(struct user, u_prof.pr_base)" },
2280 { uoff(u_prof.pr_size), "offsetof(struct user, u_prof.pr_size)" },
2281 { uoff(u_prof.pr_off), "offsetof(struct user, u_prof.pr_off)" },
2282 { uoff(u_prof.pr_scale),"offsetof(struct user, u_prof.pr_scale)"},
2283 { uoff(u_rlimit[0]), "offsetof(struct user, u_rlimit)" },
2284 { uoff(u_exdata.Ux_A), "offsetof(struct user, u_exdata.Ux_A)" },
2285 { uoff(u_exdata.ux_shell[0]),"offsetof(struct user, u_exdata.ux_shell[0])"},
2286 { uoff(u_lofault), "offsetof(struct user, u_lofault)" },
2287#endif /* SUNOS4 */
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002288#ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002289 { sizeof(struct user), "sizeof(struct user)" },
Wichert Akkermanc1652e22001-03-27 12:17:16 +00002290#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002291 { 0, NULL },
2292};
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002293#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002294
2295int
2296sys_ptrace(tcp)
2297struct tcb *tcp;
2298{
2299 char *cmd;
2300 struct xlat *x;
2301 long addr;
2302
2303 cmd = xlookup(ptrace_cmds, tcp->u_arg[0]);
2304 if (!cmd)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002305#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002306 cmd = "PTRACE_???";
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002307#else
2308 cmd = "PT_???";
Roland McGrath5a223472002-12-15 23:58:26 +00002309#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002310 if (entering(tcp)) {
2311 tprintf("%s, %lu, ", cmd, tcp->u_arg[1]);
2312 addr = tcp->u_arg[2];
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002313#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002314 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2315 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2316 for (x = struct_user_offsets; x->str; x++) {
2317 if (x->val >= addr)
2318 break;
2319 }
2320 if (!x->str)
2321 tprintf("%#lx, ", addr);
2322 else if (x->val > addr && x != struct_user_offsets) {
2323 x--;
2324 tprintf("%s + %ld, ", x->str, addr - x->val);
2325 }
2326 else
2327 tprintf("%s, ", x->str);
2328 }
2329 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002330#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002331 tprintf("%#lx, ", tcp->u_arg[2]);
2332#ifdef LINUX
2333 switch (tcp->u_arg[0]) {
2334 case PTRACE_PEEKDATA:
2335 case PTRACE_PEEKTEXT:
2336 case PTRACE_PEEKUSER:
2337 break;
2338 case PTRACE_CONT:
2339 case PTRACE_SINGLESTEP:
2340 case PTRACE_SYSCALL:
2341 case PTRACE_DETACH:
2342 printsignal(tcp->u_arg[3]);
2343 break;
2344 default:
2345 tprintf("%#lx", tcp->u_arg[3]);
2346 break;
2347 }
2348 } else {
2349 switch (tcp->u_arg[0]) {
2350 case PTRACE_PEEKDATA:
2351 case PTRACE_PEEKTEXT:
2352 case PTRACE_PEEKUSER:
2353 printnum(tcp, tcp->u_arg[3], "%#x");
2354 break;
2355 }
2356 }
2357#endif /* LINUX */
2358#ifdef SUNOS4
2359 if (tcp->u_arg[0] == PTRACE_WRITEDATA ||
2360 tcp->u_arg[0] == PTRACE_WRITETEXT) {
2361 tprintf("%lu, ", tcp->u_arg[3]);
2362 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2363 } else if (tcp->u_arg[0] != PTRACE_READDATA &&
2364 tcp->u_arg[0] != PTRACE_READTEXT) {
2365 tprintf("%#lx", tcp->u_arg[3]);
2366 }
2367 } else {
2368 if (tcp->u_arg[0] == PTRACE_READDATA ||
2369 tcp->u_arg[0] == PTRACE_READTEXT) {
2370 tprintf("%lu, ", tcp->u_arg[3]);
2371 printstr(tcp, tcp->u_arg[4], tcp->u_arg[3]);
2372 }
2373 }
2374#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002375#ifdef FREEBSD
2376 tprintf("%lu", tcp->u_arg[3]);
2377 }
2378#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002379 return 0;
2380}
2381
2382#endif /* !SVR4 */
Roland McGrath5a223472002-12-15 23:58:26 +00002383
2384#ifdef LINUX
2385static struct xlat futexops[] = {
2386 { FUTEX_WAIT, "FUTEX_WAIT" },
2387 { FUTEX_WAKE, "FUTEX_WAKE" },
2388 { FUTEX_FD, "FUTEX_FD" },
2389 { 0, NULL }
2390};
2391
2392int
2393sys_futex(tcp)
2394struct tcb *tcp;
2395{
2396 if (entering(tcp)) {
2397 tprintf("%p, ", (void *) tcp->u_arg[0]);
2398 printflags(futexops, tcp->u_arg[1]);
2399 tprintf(", %ld, ", tcp->u_arg[2]);
2400 printtv(tcp, tcp->u_arg[3]);
2401 }
2402 return 0;
2403}
2404
2405static void
2406print_affinitylist(list, len)
2407unsigned long *list;
2408unsigned int len;
2409{
2410 int first = 1;
2411 tprintf(" {");
2412 while (len > sizeof (unsigned long)) {
2413 tprintf("%s %lx", first ? "" : ",", *list++);
2414 first = 0;
2415 len -= sizeof (unsigned long);
2416 }
2417 tprintf(" }");
2418}
2419
2420int
2421sys_sched_setaffinity(tcp)
2422struct tcb *tcp;
2423{
2424 if (entering(tcp)) {
2425 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2426 print_affinitylist((unsigned long *) tcp->u_arg[2], tcp->u_arg[1]);
2427 }
2428 return 0;
2429}
2430
2431int
2432sys_sched_getaffinity(tcp)
2433struct tcb *tcp;
2434{
2435 if (entering(tcp)) {
2436 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2437 } else {
2438 print_affinitylist((unsigned long *) tcp->u_arg[2], tcp->u_rval);
2439 }
2440 return 0;
2441}
2442#endif