]> granicus.if.org Git - strace/blob - process.c
20cfe206b0847ad96c040d073cae5c24611a29f4
[strace] / process.c
1 /*
2  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5  * 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>
9  * Copyright (c) 2000 PocketPenguins Inc.  Linux for Hitachi SuperH
10  *                    port by Greg Banks <gbanks@pocketpenguins.com>
11
12  *
13  * 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
52
53 #ifdef HAVE_SYS_REG_H
54 # include <sys/reg.h>
55 # ifndef PTRACE_PEEKUSR
56 #  define PTRACE_PEEKUSR PTRACE_PEEKUSER
57 # endif
58 # ifndef PTRACE_POKEUSR
59 #  define PTRACE_POKEUSR PTRACE_POKEUSER
60 # endif
61 #endif
62
63 #ifdef HAVE_LINUX_PTRACE_H
64 # undef PTRACE_SYSCALL
65 # ifdef HAVE_STRUCT_IA64_FPREG
66 #  define ia64_fpreg XXX_ia64_fpreg
67 # endif
68 # ifdef HAVE_STRUCT_PT_ALL_USER_REGS
69 #  define pt_all_user_regs XXX_pt_all_user_regs
70 # endif
71 # include <linux/ptrace.h>
72 # undef ia64_fpreg
73 # undef pt_all_user_regs
74 #endif
75
76 #if defined(SPARC64)
77 # define r_pc r_tpc
78 # undef PTRACE_GETREGS
79 # define PTRACE_GETREGS PTRACE_GETREGS64
80 # undef PTRACE_SETREGS
81 # define PTRACE_SETREGS PTRACE_SETREGS64
82 #endif
83
84 #ifdef HAVE_LINUX_FUTEX_H
85 # include <linux/futex.h>
86 #endif
87 #ifndef FUTEX_WAIT
88 # define FUTEX_WAIT 0
89 #endif
90 #ifndef FUTEX_WAKE
91 # define FUTEX_WAKE 1
92 #endif
93 #ifndef FUTEX_FD
94 # define FUTEX_FD 2
95 #endif
96 #ifndef FUTEX_REQUEUE
97 # define FUTEX_REQUEUE 3
98 #endif
99
100 #include <sched.h>
101 #include <asm/posix_types.h>
102 #undef GETGROUPS_T
103 #define GETGROUPS_T __kernel_gid_t
104 #undef GETGROUPS32_T
105 #define GETGROUPS32_T __kernel_gid32_t
106
107 #if defined(IA64)
108 # include <asm/ptrace_offsets.h>
109 # include <asm/rse.h>
110 #endif
111
112 #ifdef HAVE_PRCTL
113 # include <sys/prctl.h>
114
115 static const struct xlat prctl_options[] = {
116 #ifdef PR_MAXPROCS
117         { PR_MAXPROCS,          "PR_MAXPROCS"           },
118 #endif
119 #ifdef PR_ISBLOCKED
120         { PR_ISBLOCKED,         "PR_ISBLOCKED"          },
121 #endif
122 #ifdef PR_SETSTACKSIZE
123         { PR_SETSTACKSIZE,      "PR_SETSTACKSIZE"       },
124 #endif
125 #ifdef PR_GETSTACKSIZE
126         { PR_GETSTACKSIZE,      "PR_GETSTACKSIZE"       },
127 #endif
128 #ifdef PR_MAXPPROCS
129         { PR_MAXPPROCS,         "PR_MAXPPROCS"          },
130 #endif
131 #ifdef PR_UNBLKONEXEC
132         { PR_UNBLKONEXEC,       "PR_UNBLKONEXEC"        },
133 #endif
134 #ifdef PR_ATOMICSIM
135         { PR_ATOMICSIM,         "PR_ATOMICSIM"          },
136 #endif
137 #ifdef PR_SETEXITSIG
138         { PR_SETEXITSIG,        "PR_SETEXITSIG"         },
139 #endif
140 #ifdef PR_RESIDENT
141         { PR_RESIDENT,          "PR_RESIDENT"           },
142 #endif
143 #ifdef PR_ATTACHADDR
144         { PR_ATTACHADDR,        "PR_ATTACHADDR"         },
145 #endif
146 #ifdef PR_DETACHADDR
147         { PR_DETACHADDR,        "PR_DETACHADDR"         },
148 #endif
149 #ifdef PR_TERMCHILD
150         { PR_TERMCHILD,         "PR_TERMCHILD"          },
151 #endif
152 #ifdef PR_GETSHMASK
153         { PR_GETSHMASK,         "PR_GETSHMASK"          },
154 #endif
155 #ifdef PR_GETNSHARE
156         { PR_GETNSHARE,         "PR_GETNSHARE"          },
157 #endif
158 #ifdef PR_COREPID
159         { PR_COREPID,           "PR_COREPID"            },
160 #endif
161 #ifdef PR_ATTACHADDRPERM
162         { PR_ATTACHADDRPERM,    "PR_ATTACHADDRPERM"     },
163 #endif
164 #ifdef PR_PTHREADEXIT
165         { PR_PTHREADEXIT,       "PR_PTHREADEXIT"        },
166 #endif
167 #ifdef PR_SET_PDEATHSIG
168         { PR_SET_PDEATHSIG,     "PR_SET_PDEATHSIG"      },
169 #endif
170 #ifdef PR_GET_PDEATHSIG
171         { PR_GET_PDEATHSIG,     "PR_GET_PDEATHSIG"      },
172 #endif
173 #ifdef PR_GET_DUMPABLE
174         { PR_GET_DUMPABLE,      "PR_GET_DUMPABLE"       },
175 #endif
176 #ifdef PR_SET_DUMPABLE
177         { PR_SET_DUMPABLE,      "PR_SET_DUMPABLE"       },
178 #endif
179 #ifdef PR_GET_UNALIGN
180         { PR_GET_UNALIGN,       "PR_GET_UNALIGN"        },
181 #endif
182 #ifdef PR_SET_UNALIGN
183         { PR_SET_UNALIGN,       "PR_SET_UNALIGN"        },
184 #endif
185 #ifdef PR_GET_KEEPCAPS
186         { PR_GET_KEEPCAPS,      "PR_GET_KEEPCAPS"       },
187 #endif
188 #ifdef PR_SET_KEEPCAPS
189         { PR_SET_KEEPCAPS,      "PR_SET_KEEPCAPS"       },
190 #endif
191 #ifdef PR_GET_FPEMU
192         { PR_GET_FPEMU,         "PR_GET_FPEMU"          },
193 #endif
194 #ifdef PR_SET_FPEMU
195         { PR_SET_FPEMU,         "PR_SET_FPEMU"          },
196 #endif
197 #ifdef PR_GET_FPEXC
198         { PR_GET_FPEXC,         "PR_GET_FPEXC"          },
199 #endif
200 #ifdef PR_SET_FPEXC
201         { PR_SET_FPEXC,         "PR_SET_FPEXC"          },
202 #endif
203 #ifdef PR_GET_TIMING
204         { PR_GET_TIMING,        "PR_GET_TIMING"         },
205 #endif
206 #ifdef PR_SET_TIMING
207         { PR_SET_TIMING,        "PR_SET_TIMING"         },
208 #endif
209 #ifdef PR_SET_NAME
210         { PR_SET_NAME,          "PR_SET_NAME"           },
211 #endif
212 #ifdef PR_GET_NAME
213         { PR_GET_NAME,          "PR_GET_NAME"           },
214 #endif
215 #ifdef PR_GET_ENDIAN
216         { PR_GET_ENDIAN,        "PR_GET_ENDIAN"         },
217 #endif
218 #ifdef PR_SET_ENDIAN
219         { PR_SET_ENDIAN,        "PR_SET_ENDIAN"         },
220 #endif
221 #ifdef PR_GET_SECCOMP
222         { PR_GET_SECCOMP,       "PR_GET_SECCOMP"        },
223 #endif
224 #ifdef PR_SET_SECCOMP
225         { PR_SET_SECCOMP,       "PR_SET_SECCOMP"        },
226 #endif
227 #ifdef PR_GET_TSC
228         { PR_GET_TSC,           "PR_GET_TSC"            },
229 #endif
230 #ifdef PR_SET_TSC
231         { PR_SET_TSC,           "PR_SET_TSC"            },
232 #endif
233 #ifdef PR_GET_SECUREBITS
234         { PR_GET_SECUREBITS,    "PR_GET_SECUREBITS"     },
235 #endif
236 #ifdef PR_SET_SECUREBITS
237         { PR_SET_SECUREBITS,    "PR_SET_SECUREBITS"     },
238 #endif
239         { 0,                    NULL                    },
240 };
241
242
243 static const char *
244 unalignctl_string(unsigned int ctl)
245 {
246         static char buf[16];
247
248         switch (ctl) {
249 #ifdef PR_UNALIGN_NOPRINT
250               case PR_UNALIGN_NOPRINT:
251                 return "NOPRINT";
252 #endif
253 #ifdef PR_UNALIGN_SIGBUS
254               case PR_UNALIGN_SIGBUS:
255                 return "SIGBUS";
256 #endif
257               default:
258                 break;
259         }
260         sprintf(buf, "%x", ctl);
261         return buf;
262 }
263
264
265 int
266 sys_prctl(struct tcb *tcp)
267 {
268         int i;
269
270         if (entering(tcp)) {
271                 printxval(prctl_options, tcp->u_arg[0], "PR_???");
272                 switch (tcp->u_arg[0]) {
273 #ifdef PR_GETNSHARE
274                 case PR_GETNSHARE:
275                         break;
276 #endif
277 #ifdef PR_SET_PDEATHSIG
278                 case PR_SET_PDEATHSIG:
279                         tprintf(", %lu", tcp->u_arg[1]);
280                         break;
281 #endif
282 #ifdef PR_GET_PDEATHSIG
283                 case PR_GET_PDEATHSIG:
284                         break;
285 #endif
286 #ifdef PR_SET_DUMPABLE
287                 case PR_SET_DUMPABLE:
288                         tprintf(", %lu", tcp->u_arg[1]);
289                         break;
290 #endif
291 #ifdef PR_GET_DUMPABLE
292                 case PR_GET_DUMPABLE:
293                         break;
294 #endif
295 #ifdef PR_SET_UNALIGN
296                 case PR_SET_UNALIGN:
297                         tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
298                         break;
299 #endif
300 #ifdef PR_GET_UNALIGN
301                 case PR_GET_UNALIGN:
302                         tprintf(", %#lx", tcp->u_arg[1]);
303                         break;
304 #endif
305 #ifdef PR_SET_KEEPCAPS
306                 case PR_SET_KEEPCAPS:
307                         tprintf(", %lu", tcp->u_arg[1]);
308                         break;
309 #endif
310 #ifdef PR_GET_KEEPCAPS
311                 case PR_GET_KEEPCAPS:
312                         break;
313 #endif
314                 default:
315                         for (i = 1; i < tcp->u_nargs; i++)
316                                 tprintf(", %#lx", tcp->u_arg[i]);
317                         break;
318                 }
319         } else {
320                 switch (tcp->u_arg[0]) {
321 #ifdef PR_GET_PDEATHSIG
322                 case PR_GET_PDEATHSIG:
323                         if (umove(tcp, tcp->u_arg[1], &i) < 0)
324                                 tprintf(", %#lx", tcp->u_arg[1]);
325                         else
326                                 tprintf(", {%u}", i);
327                         break;
328 #endif
329 #ifdef PR_GET_DUMPABLE
330                 case PR_GET_DUMPABLE:
331                         return RVAL_UDECIMAL;
332 #endif
333 #ifdef PR_GET_UNALIGN
334                 case PR_GET_UNALIGN:
335                         if (syserror(tcp) || umove(tcp, tcp->u_arg[1], &i) < 0)
336                                 break;
337                         tcp->auxstr = unalignctl_string(i);
338                         return RVAL_STR;
339 #endif
340 #ifdef PR_GET_KEEPCAPS
341                 case PR_GET_KEEPCAPS:
342                         return RVAL_UDECIMAL;
343 #endif
344                 default:
345                         break;
346                 }
347         }
348         return 0;
349 }
350 #endif /* HAVE_PRCTL */
351
352
353 int
354 sys_sethostname(struct tcb *tcp)
355 {
356         if (entering(tcp)) {
357                 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
358                 tprintf(", %lu", tcp->u_arg[1]);
359         }
360         return 0;
361 }
362
363 #if defined(ALPHA)
364 int
365 sys_gethostname(struct tcb *tcp)
366 {
367         if (exiting(tcp)) {
368                 if (syserror(tcp))
369                         tprintf("%#lx", tcp->u_arg[0]);
370                 else
371                         printpath(tcp, tcp->u_arg[0]);
372                 tprintf(", %lu", tcp->u_arg[1]);
373         }
374         return 0;
375 }
376 #endif
377
378 int
379 sys_setdomainname(struct tcb *tcp)
380 {
381         if (entering(tcp)) {
382                 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
383                 tprintf(", %lu", tcp->u_arg[1]);
384         }
385         return 0;
386 }
387
388
389 int
390 sys_exit(struct tcb *tcp)
391 {
392         if (exiting(tcp)) {
393                 fprintf(stderr, "_exit returned!\n");
394                 return -1;
395         }
396         /* special case: we stop tracing this process, finish line now */
397         tprintf("%ld) ", tcp->u_arg[0]);
398         tabto();
399         tprints("= ?\n");
400         printing_tcp = NULL;
401         return 0;
402 }
403
404
405
406 /* defines copied from linux/sched.h since we can't include that
407  * ourselves (it conflicts with *lots* of libc includes)
408  */
409 #define CSIGNAL         0x000000ff      /* signal mask to be sent at exit */
410 #define CLONE_VM        0x00000100      /* set if VM shared between processes */
411 #define CLONE_FS        0x00000200      /* set if fs info shared between processes */
412 #define CLONE_FILES     0x00000400      /* set if open files shared between processes */
413 #define CLONE_SIGHAND   0x00000800      /* set if signal handlers shared */
414 #define CLONE_IDLETASK  0x00001000      /* kernel-only flag */
415 #define CLONE_PTRACE    0x00002000      /* set if we want to let tracing continue on the child too */
416 #define CLONE_VFORK     0x00004000      /* set if the parent wants the child to wake it up on mm_release */
417 #define CLONE_PARENT    0x00008000      /* set if we want to have the same parent as the cloner */
418 #define CLONE_THREAD    0x00010000      /* Same thread group? */
419 #define CLONE_NEWNS     0x00020000      /* New namespace group? */
420 #define CLONE_SYSVSEM   0x00040000      /* share system V SEM_UNDO semantics */
421 #define CLONE_SETTLS    0x00080000      /* create a new TLS for the child */
422 #define CLONE_PARENT_SETTID     0x00100000      /* set the TID in the parent */
423 #define CLONE_CHILD_CLEARTID    0x00200000      /* clear the TID in the child */
424 #define CLONE_UNTRACED          0x00800000      /* set if the tracing process can't force CLONE_PTRACE on this clone */
425 #define CLONE_CHILD_SETTID      0x01000000      /* set the TID in the child */
426 #define CLONE_STOPPED           0x02000000      /* Start in stopped state */
427 #define CLONE_NEWUTS            0x04000000      /* New utsname group? */
428 #define CLONE_NEWIPC            0x08000000      /* New ipcs */
429 #define CLONE_NEWUSER           0x10000000      /* New user namespace */
430 #define CLONE_NEWPID            0x20000000      /* New pid namespace */
431 #define CLONE_NEWNET            0x40000000      /* New network namespace */
432 #define CLONE_IO                0x80000000      /* Clone io context */
433
434 static const struct xlat clone_flags[] = {
435     { CLONE_VM,         "CLONE_VM"      },
436     { CLONE_FS,         "CLONE_FS"      },
437     { CLONE_FILES,      "CLONE_FILES"   },
438     { CLONE_SIGHAND,    "CLONE_SIGHAND" },
439     { CLONE_IDLETASK,   "CLONE_IDLETASK"},
440     { CLONE_PTRACE,     "CLONE_PTRACE"  },
441     { CLONE_VFORK,      "CLONE_VFORK"   },
442     { CLONE_PARENT,     "CLONE_PARENT"  },
443     { CLONE_THREAD,     "CLONE_THREAD" },
444     { CLONE_NEWNS,      "CLONE_NEWNS" },
445     { CLONE_SYSVSEM,    "CLONE_SYSVSEM" },
446     { CLONE_SETTLS,     "CLONE_SETTLS" },
447     { CLONE_PARENT_SETTID,"CLONE_PARENT_SETTID" },
448     { CLONE_CHILD_CLEARTID,"CLONE_CHILD_CLEARTID" },
449     { CLONE_UNTRACED,   "CLONE_UNTRACED" },
450     { CLONE_CHILD_SETTID,"CLONE_CHILD_SETTID" },
451     { CLONE_STOPPED,    "CLONE_STOPPED" },
452     { CLONE_NEWUTS,     "CLONE_NEWUTS" },
453     { CLONE_NEWIPC,     "CLONE_NEWIPC" },
454     { CLONE_NEWUSER,    "CLONE_NEWUSER" },
455     { CLONE_NEWPID,     "CLONE_NEWPID" },
456     { CLONE_NEWNET,     "CLONE_NEWNET" },
457     { CLONE_IO,         "CLONE_IO" },
458     { 0,                NULL            },
459 };
460
461 # ifdef I386
462 #  include <asm/ldt.h>
463 #   ifdef HAVE_STRUCT_USER_DESC
464 #    define modify_ldt_ldt_s user_desc
465 #   endif
466 extern void print_ldt_entry();
467 # endif
468
469 # if defined IA64
470 #  define ARG_FLAGS     0
471 #  define ARG_STACK     1
472 #  define ARG_STACKSIZE (tcp->scno == SYS_clone2 ? 2 : -1)
473 #  define ARG_PTID      (tcp->scno == SYS_clone2 ? 3 : 2)
474 #  define ARG_CTID      (tcp->scno == SYS_clone2 ? 4 : 3)
475 #  define ARG_TLS       (tcp->scno == SYS_clone2 ? 5 : 4)
476 # elif defined S390 || defined S390X || defined CRISV10 || defined CRISV32
477 #  define ARG_STACK     0
478 #  define ARG_FLAGS     1
479 #  define ARG_PTID      2
480 #  define ARG_CTID      3
481 #  define ARG_TLS       4
482 # elif defined X86_64 || defined ALPHA
483 #  define ARG_FLAGS     0
484 #  define ARG_STACK     1
485 #  define ARG_PTID      2
486 #  define ARG_CTID      3
487 #  define ARG_TLS       4
488 # else
489 #  define ARG_FLAGS     0
490 #  define ARG_STACK     1
491 #  define ARG_PTID      2
492 #  define ARG_TLS       3
493 #  define ARG_CTID      4
494 # endif
495
496 int
497 sys_clone(struct tcb *tcp)
498 {
499         if (exiting(tcp)) {
500                 const char *sep = "|";
501                 unsigned long flags = tcp->u_arg[ARG_FLAGS];
502                 tprintf("child_stack=%#lx, ", tcp->u_arg[ARG_STACK]);
503 # ifdef ARG_STACKSIZE
504                 if (ARG_STACKSIZE != -1)
505                         tprintf("stack_size=%#lx, ",
506                                 tcp->u_arg[ARG_STACKSIZE]);
507 # endif
508                 tprints("flags=");
509                 if (!printflags(clone_flags, flags &~ CSIGNAL, NULL))
510                         sep = "";
511                 if ((flags & CSIGNAL) != 0)
512                         tprintf("%s%s", sep, signame(flags & CSIGNAL));
513                 if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
514                               |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
515                         return 0;
516                 if (flags & CLONE_PARENT_SETTID)
517                         tprintf(", parent_tidptr=%#lx", tcp->u_arg[ARG_PTID]);
518                 if (flags & CLONE_SETTLS) {
519 # ifdef I386
520                         struct modify_ldt_ldt_s copy;
521                         if (umove(tcp, tcp->u_arg[ARG_TLS], &copy) != -1) {
522                                 tprintf(", {entry_number:%d, ",
523                                         copy.entry_number);
524                                 if (!verbose(tcp))
525                                         tprints("...}");
526                                 else
527                                         print_ldt_entry(&copy);
528                         }
529                         else
530 # endif
531                                 tprintf(", tls=%#lx", tcp->u_arg[ARG_TLS]);
532                 }
533                 if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID))
534                         tprintf(", child_tidptr=%#lx", tcp->u_arg[ARG_CTID]);
535         }
536         return 0;
537 }
538
539 int
540 sys_unshare(struct tcb *tcp)
541 {
542         if (entering(tcp))
543                 printflags(clone_flags, tcp->u_arg[0], "CLONE_???");
544         return 0;
545 }
546
547 int
548 sys_fork(struct tcb *tcp)
549 {
550         if (exiting(tcp))
551                 return RVAL_UDECIMAL;
552         return 0;
553 }
554
555 int
556 change_syscall(struct tcb *tcp, int new)
557 {
558 #if defined(I386)
559         /* Attempt to make vfork into fork, which we can follow. */
560         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
561                 return -1;
562         return 0;
563 #elif defined(X86_64)
564         /* Attempt to make vfork into fork, which we can follow. */
565         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
566                 return -1;
567         return 0;
568 #elif defined(POWERPC)
569         if (ptrace(PTRACE_POKEUSER, tcp->pid,
570                    (char*)(sizeof(unsigned long)*PT_R0), new) < 0)
571                 return -1;
572         return 0;
573 #elif defined(S390) || defined(S390X)
574         /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
575         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new) < 0)
576                 return -1;
577         return 0;
578 #elif defined(M68K)
579         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new) < 0)
580                 return -1;
581         return 0;
582 #elif defined(SPARC) || defined(SPARC64)
583         struct pt_regs regs;
584         if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0) < 0)
585                 return -1;
586         regs.u_regs[U_REG_G1] = new;
587         if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0) < 0)
588                 return -1;
589         return 0;
590 #elif defined(MIPS)
591         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new) < 0)
592                 return -1;
593         return 0;
594 #elif defined(ALPHA)
595         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new) < 0)
596                 return -1;
597         return 0;
598 #elif defined(AVR32)
599         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_R8), new) < 0)
600                 return -1;
601         return 0;
602 #elif defined(BFIN)
603         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_P0), new) < 0)
604                 return -1;
605         return 0;
606 #elif defined(IA64)
607         if (ia32) {
608                 switch (new) {
609                 case 2:
610                         break;  /* x86 SYS_fork */
611                 case SYS_clone:
612                         new = 120;
613                         break;
614                 default:
615                         fprintf(stderr, "%s: unexpected syscall %d\n",
616                                 __FUNCTION__, new);
617                         return -1;
618                 }
619                 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R1), new) < 0)
620                         return -1;
621         } else if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new) < 0)
622                 return -1;
623         return 0;
624 #elif defined(HPPA)
625         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new) < 0)
626                 return -1;
627         return 0;
628 #elif defined(SH)
629         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*(REG_REG0+3)), new) < 0)
630                 return -1;
631         return 0;
632 #elif defined(SH64)
633         /* Top half of reg encodes the no. of args n as 0x1n.
634            Assume 0 args as kernel never actually checks... */
635         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL),
636                                 0x100000 | new) < 0)
637                 return -1;
638         return 0;
639 #elif defined(CRISV10) || defined(CRISV32)
640         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R9), new) < 0)
641                 return -1;
642         return 0;
643 #elif defined(ARM)
644         /* Some kernels support this, some (pre-2.6.16 or so) don't.  */
645 # ifndef PTRACE_SET_SYSCALL
646 #  define PTRACE_SET_SYSCALL 23
647 # endif
648
649         if (ptrace(PTRACE_SET_SYSCALL, tcp->pid, 0, new & 0xffff) != 0)
650                 return -1;
651
652         return 0;
653 #elif defined(TILE)
654         if (ptrace(PTRACE_POKEUSER, tcp->pid,
655                    (char*)PTREGS_OFFSET_REG(0),
656                    new) != 0)
657                 return -1;
658         return 0;
659 #elif defined(MICROBLAZE)
660         if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR(0)), new) < 0)
661                 return -1;
662         return 0;
663 #else
664 #warning Do not know how to handle change_syscall for this architecture
665 #endif /* architecture */
666         return -1;
667 }
668
669
670 int
671 internal_fork(struct tcb *tcp)
672 {
673         if ((ptrace_setoptions
674             & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
675            == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
676                 return 0;
677
678         if (!followfork)
679                 return 0;
680
681         if (entering(tcp)) {
682                 /*
683                  * We won't see the new child if clone is called with
684                  * CLONE_UNTRACED, so we keep the same logic with that option
685                  * and don't trace it.
686                  */
687                 if ((sysent[tcp->scno].sys_func == sys_clone) &&
688                     (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED))
689                         return 0;
690                 setbpt(tcp);
691         } else {
692                 if (tcp->flags & TCB_BPTSET)
693                         clearbpt(tcp);
694         }
695         return 0;
696 }
697
698
699
700
701 int
702 sys_vfork(struct tcb *tcp)
703 {
704         if (exiting(tcp))
705                 return RVAL_UDECIMAL;
706         return 0;
707 }
708
709
710
711
712 int sys_getuid(struct tcb *tcp)
713 {
714         if (exiting(tcp))
715                 tcp->u_rval = (uid_t) tcp->u_rval;
716         return RVAL_UDECIMAL;
717 }
718
719 int sys_setfsuid(struct tcb *tcp)
720 {
721         if (entering(tcp))
722                 tprintf("%u", (uid_t) tcp->u_arg[0]);
723         else
724                 tcp->u_rval = (uid_t) tcp->u_rval;
725         return RVAL_UDECIMAL;
726 }
727
728 int
729 sys_setuid(struct tcb *tcp)
730 {
731         if (entering(tcp)) {
732                 tprintf("%u", (uid_t) tcp->u_arg[0]);
733         }
734         return 0;
735 }
736
737 int
738 sys_setgid(struct tcb *tcp)
739 {
740         if (entering(tcp)) {
741                 tprintf("%u", (gid_t) tcp->u_arg[0]);
742         }
743         return 0;
744 }
745
746 int
747 sys_getresuid(struct tcb *tcp)
748 {
749         if (exiting(tcp)) {
750                 __kernel_uid_t uid;
751                 if (syserror(tcp))
752                         tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
753                                 tcp->u_arg[1], tcp->u_arg[2]);
754                 else {
755                         if (umove(tcp, tcp->u_arg[0], &uid) < 0)
756                                 tprintf("%#lx, ", tcp->u_arg[0]);
757                         else
758                                 tprintf("[%lu], ", (unsigned long) uid);
759                         if (umove(tcp, tcp->u_arg[1], &uid) < 0)
760                                 tprintf("%#lx, ", tcp->u_arg[1]);
761                         else
762                                 tprintf("[%lu], ", (unsigned long) uid);
763                         if (umove(tcp, tcp->u_arg[2], &uid) < 0)
764                                 tprintf("%#lx", tcp->u_arg[2]);
765                         else
766                                 tprintf("[%lu]", (unsigned long) uid);
767                 }
768         }
769         return 0;
770 }
771
772 int
773 sys_getresgid(struct tcb *tcp)
774 {
775         if (exiting(tcp)) {
776                 __kernel_gid_t gid;
777                 if (syserror(tcp))
778                         tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
779                                 tcp->u_arg[1], tcp->u_arg[2]);
780                 else {
781                         if (umove(tcp, tcp->u_arg[0], &gid) < 0)
782                                 tprintf("%#lx, ", tcp->u_arg[0]);
783                         else
784                                 tprintf("[%lu], ", (unsigned long) gid);
785                         if (umove(tcp, tcp->u_arg[1], &gid) < 0)
786                                 tprintf("%#lx, ", tcp->u_arg[1]);
787                         else
788                                 tprintf("[%lu], ", (unsigned long) gid);
789                         if (umove(tcp, tcp->u_arg[2], &gid) < 0)
790                                 tprintf("%#lx", tcp->u_arg[2]);
791                         else
792                                 tprintf("[%lu]", (unsigned long) gid);
793                 }
794         }
795         return 0;
796 }
797
798
799 int
800 sys_setreuid(struct tcb *tcp)
801 {
802         if (entering(tcp)) {
803                 printuid("", tcp->u_arg[0]);
804                 printuid(", ", tcp->u_arg[1]);
805         }
806         return 0;
807 }
808
809 int
810 sys_setregid(struct tcb *tcp)
811 {
812         if (entering(tcp)) {
813                 printuid("", tcp->u_arg[0]);
814                 printuid(", ", tcp->u_arg[1]);
815         }
816         return 0;
817 }
818
819 int
820 sys_setresuid(struct tcb *tcp)
821 {
822         if (entering(tcp)) {
823                 printuid("", tcp->u_arg[0]);
824                 printuid(", ", tcp->u_arg[1]);
825                 printuid(", ", tcp->u_arg[2]);
826         }
827         return 0;
828 }
829 int
830 sys_setresgid(struct tcb *tcp)
831 {
832         if (entering(tcp)) {
833                 printuid("", tcp->u_arg[0]);
834                 printuid(", ", tcp->u_arg[1]);
835                 printuid(", ", tcp->u_arg[2]);
836         }
837         return 0;
838 }
839
840
841 int
842 sys_setgroups(struct tcb *tcp)
843 {
844         if (entering(tcp)) {
845                 unsigned long len, size, start, cur, end, abbrev_end;
846                 GETGROUPS_T gid;
847                 int failed = 0;
848
849                 len = tcp->u_arg[0];
850                 tprintf("%lu, ", len);
851                 if (len == 0) {
852                         tprints("[]");
853                         return 0;
854                 }
855                 start = tcp->u_arg[1];
856                 if (start == 0) {
857                         tprints("NULL");
858                         return 0;
859                 }
860                 size = len * sizeof(gid);
861                 end = start + size;
862                 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
863                         tprintf("%#lx", start);
864                         return 0;
865                 }
866                 if (abbrev(tcp)) {
867                         abbrev_end = start + max_strlen * sizeof(gid);
868                         if (abbrev_end < start)
869                                 abbrev_end = end;
870                 } else {
871                         abbrev_end = end;
872                 }
873                 tprints("[");
874                 for (cur = start; cur < end; cur += sizeof(gid)) {
875                         if (cur > start)
876                                 tprints(", ");
877                         if (cur >= abbrev_end) {
878                                 tprints("...");
879                                 break;
880                         }
881                         if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
882                                 tprints("?");
883                                 failed = 1;
884                                 break;
885                         }
886                         tprintf("%lu", (unsigned long) gid);
887                 }
888                 tprints("]");
889                 if (failed)
890                         tprintf(" %#lx", tcp->u_arg[1]);
891         }
892         return 0;
893 }
894
895 int
896 sys_getgroups(struct tcb *tcp)
897 {
898         unsigned long len;
899
900         if (entering(tcp)) {
901                 len = tcp->u_arg[0];
902                 tprintf("%lu, ", len);
903         } else {
904                 unsigned long size, start, cur, end, abbrev_end;
905                 GETGROUPS_T gid;
906                 int failed = 0;
907
908                 len = tcp->u_rval;
909                 if (len == 0) {
910                         tprints("[]");
911                         return 0;
912                 }
913                 start = tcp->u_arg[1];
914                 if (start == 0) {
915                         tprints("NULL");
916                         return 0;
917                 }
918                 if (tcp->u_arg[0] == 0) {
919                         tprintf("%#lx", start);
920                         return 0;
921                 }
922                 size = len * sizeof(gid);
923                 end = start + size;
924                 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
925                     size / sizeof(gid) != len || end < start) {
926                         tprintf("%#lx", start);
927                         return 0;
928                 }
929                 if (abbrev(tcp)) {
930                         abbrev_end = start + max_strlen * sizeof(gid);
931                         if (abbrev_end < start)
932                                 abbrev_end = end;
933                 } else {
934                         abbrev_end = end;
935                 }
936                 tprints("[");
937                 for (cur = start; cur < end; cur += sizeof(gid)) {
938                         if (cur > start)
939                                 tprints(", ");
940                         if (cur >= abbrev_end) {
941                                 tprints("...");
942                                 break;
943                         }
944                         if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
945                                 tprints("?");
946                                 failed = 1;
947                                 break;
948                         }
949                         tprintf("%lu", (unsigned long) gid);
950                 }
951                 tprints("]");
952                 if (failed)
953                         tprintf(" %#lx", tcp->u_arg[1]);
954         }
955         return 0;
956 }
957
958 int
959 sys_setgroups32(struct tcb *tcp)
960 {
961         if (entering(tcp)) {
962                 unsigned long len, size, start, cur, end, abbrev_end;
963                 GETGROUPS32_T gid;
964                 int failed = 0;
965
966                 len = tcp->u_arg[0];
967                 tprintf("%lu, ", len);
968                 if (len == 0) {
969                         tprints("[]");
970                         return 0;
971                 }
972                 start = tcp->u_arg[1];
973                 if (start == 0) {
974                         tprints("NULL");
975                         return 0;
976                 }
977                 size = len * sizeof(gid);
978                 end = start + size;
979                 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
980                         tprintf("%#lx", start);
981                         return 0;
982                 }
983                 if (abbrev(tcp)) {
984                         abbrev_end = start + max_strlen * sizeof(gid);
985                         if (abbrev_end < start)
986                                 abbrev_end = end;
987                 } else {
988                         abbrev_end = end;
989                 }
990                 tprints("[");
991                 for (cur = start; cur < end; cur += sizeof(gid)) {
992                         if (cur > start)
993                                 tprints(", ");
994                         if (cur >= abbrev_end) {
995                                 tprints("...");
996                                 break;
997                         }
998                         if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
999                                 tprints("?");
1000                                 failed = 1;
1001                                 break;
1002                         }
1003                         tprintf("%lu", (unsigned long) gid);
1004                 }
1005                 tprints("]");
1006                 if (failed)
1007                         tprintf(" %#lx", tcp->u_arg[1]);
1008         }
1009         return 0;
1010 }
1011
1012 int
1013 sys_getgroups32(struct tcb *tcp)
1014 {
1015         unsigned long len;
1016
1017         if (entering(tcp)) {
1018                 len = tcp->u_arg[0];
1019                 tprintf("%lu, ", len);
1020         } else {
1021                 unsigned long size, start, cur, end, abbrev_end;
1022                 GETGROUPS32_T gid;
1023                 int failed = 0;
1024
1025                 len = tcp->u_rval;
1026                 if (len == 0) {
1027                         tprints("[]");
1028                         return 0;
1029                 }
1030                 start = tcp->u_arg[1];
1031                 if (start == 0) {
1032                         tprints("NULL");
1033                         return 0;
1034                 }
1035                 size = len * sizeof(gid);
1036                 end = start + size;
1037                 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
1038                     size / sizeof(gid) != len || end < start) {
1039                         tprintf("%#lx", start);
1040                         return 0;
1041                 }
1042                 if (abbrev(tcp)) {
1043                         abbrev_end = start + max_strlen * sizeof(gid);
1044                         if (abbrev_end < start)
1045                                 abbrev_end = end;
1046                 } else {
1047                         abbrev_end = end;
1048                 }
1049                 tprints("[");
1050                 for (cur = start; cur < end; cur += sizeof(gid)) {
1051                         if (cur > start)
1052                                 tprints(", ");
1053                         if (cur >= abbrev_end) {
1054                                 tprints("...");
1055                                 break;
1056                         }
1057                         if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
1058                                 tprints("?");
1059                                 failed = 1;
1060                                 break;
1061                         }
1062                         tprintf("%lu", (unsigned long) gid);
1063                 }
1064                 tprints("]");
1065                 if (failed)
1066                         tprintf(" %#lx", tcp->u_arg[1]);
1067         }
1068         return 0;
1069 }
1070
1071 #if defined(ALPHA)
1072 int
1073 sys_setpgrp(struct tcb *tcp)
1074 {
1075         if (entering(tcp)) {
1076                 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1077         }
1078         return 0;
1079 }
1080 #endif
1081
1082 int
1083 sys_getpgrp(struct tcb *tcp)
1084 {
1085         if (entering(tcp)) {
1086                 tprintf("%lu", tcp->u_arg[0]);
1087         }
1088         return 0;
1089 }
1090
1091 int
1092 sys_getsid(struct tcb *tcp)
1093 {
1094         if (entering(tcp)) {
1095                 tprintf("%lu", tcp->u_arg[0]);
1096         }
1097         return 0;
1098 }
1099
1100 int
1101 sys_setsid(struct tcb *tcp)
1102 {
1103         return 0;
1104 }
1105
1106 int
1107 sys_getpgid(struct tcb *tcp)
1108 {
1109         if (entering(tcp)) {
1110                 tprintf("%lu", tcp->u_arg[0]);
1111         }
1112         return 0;
1113 }
1114
1115 int
1116 sys_setpgid(struct tcb *tcp)
1117 {
1118         if (entering(tcp)) {
1119                 tprintf("%lu, %lu", tcp->u_arg[0], tcp->u_arg[1]);
1120         }
1121         return 0;
1122 }
1123
1124
1125
1126 static void
1127 printargv(struct tcb *tcp, long addr)
1128 {
1129         union {
1130                 unsigned int p32;
1131                 unsigned long p64;
1132                 char data[sizeof(long)];
1133         } cp;
1134         const char *sep;
1135         int n = 0;
1136
1137         cp.p64 = 1;
1138         for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
1139                 if (umoven(tcp, addr, personality_wordsize[current_personality],
1140                            cp.data) < 0) {
1141                         tprintf("%#lx", addr);
1142                         return;
1143                 }
1144                 if (personality_wordsize[current_personality] == 4)
1145                         cp.p64 = cp.p32;
1146                 if (cp.p64 == 0)
1147                         break;
1148                 tprints(sep);
1149                 printstr(tcp, cp.p64, -1);
1150                 addr += personality_wordsize[current_personality];
1151         }
1152         if (cp.p64)
1153                 tprintf("%s...", sep);
1154 }
1155
1156 static void
1157 printargc(const char *fmt, struct tcb *tcp, long addr)
1158 {
1159         int count;
1160         char *cp;
1161
1162         for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1163                 addr += sizeof(char *);
1164         }
1165         tprintf(fmt, count, count == 1 ? "" : "s");
1166 }
1167
1168 #if defined(SPARC) || defined(SPARC64)
1169 int
1170 sys_execv(struct tcb *tcp)
1171 {
1172         if (entering(tcp)) {
1173                 printpath(tcp, tcp->u_arg[0]);
1174                 if (!verbose(tcp))
1175                         tprintf(", %#lx", tcp->u_arg[1]);
1176                 else {
1177                         tprints(", [");
1178                         printargv(tcp, tcp->u_arg[1]);
1179                         tprints("]");
1180                 }
1181         }
1182         return 0;
1183 }
1184 #endif
1185
1186 int
1187 sys_execve(struct tcb *tcp)
1188 {
1189         if (entering(tcp)) {
1190                 printpath(tcp, tcp->u_arg[0]);
1191                 if (!verbose(tcp))
1192                         tprintf(", %#lx", tcp->u_arg[1]);
1193                 else {
1194                         tprints(", [");
1195                         printargv(tcp, tcp->u_arg[1]);
1196                         tprints("]");
1197                 }
1198                 if (!verbose(tcp))
1199                         tprintf(", %#lx", tcp->u_arg[2]);
1200                 else if (abbrev(tcp))
1201                         printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1202                 else {
1203                         tprints(", [");
1204                         printargv(tcp, tcp->u_arg[2]);
1205                         tprints("]");
1206                 }
1207         }
1208         return 0;
1209 }
1210
1211
1212 #if defined(TCB_WAITEXECVE)
1213 int
1214 internal_exec(struct tcb *tcp)
1215 {
1216         if (exiting(tcp) && syserror(tcp))
1217                 tcp->flags &= ~TCB_WAITEXECVE;
1218         else {
1219                 /* Maybe we have post-execve SIGTRAP suppressed? */
1220                 if (!(ptrace_setoptions & PTRACE_O_TRACEEXEC))
1221                         tcp->flags |= TCB_WAITEXECVE; /* no */
1222         }
1223         return 0;
1224 }
1225 #endif
1226
1227 #ifndef __WNOTHREAD
1228 #define __WNOTHREAD     0x20000000
1229 #endif
1230 #ifndef __WALL
1231 #define __WALL          0x40000000
1232 #endif
1233 #ifndef __WCLONE
1234 #define __WCLONE        0x80000000
1235 #endif
1236
1237 static const struct xlat wait4_options[] = {
1238         { WNOHANG,      "WNOHANG"       },
1239 #ifndef WSTOPPED
1240         { WUNTRACED,    "WUNTRACED"     },
1241 #endif
1242 #ifdef WEXITED
1243         { WEXITED,      "WEXITED"       },
1244 #endif
1245 #ifdef WTRAPPED
1246         { WTRAPPED,     "WTRAPPED"      },
1247 #endif
1248 #ifdef WSTOPPED
1249         { WSTOPPED,     "WSTOPPED"      },
1250 #endif
1251 #ifdef WCONTINUED
1252         { WCONTINUED,   "WCONTINUED"    },
1253 #endif
1254 #ifdef WNOWAIT
1255         { WNOWAIT,      "WNOWAIT"       },
1256 #endif
1257 #ifdef __WCLONE
1258         { __WCLONE,     "__WCLONE"      },
1259 #endif
1260 #ifdef __WALL
1261         { __WALL,       "__WALL"        },
1262 #endif
1263 #ifdef __WNOTHREAD
1264         { __WNOTHREAD,  "__WNOTHREAD"   },
1265 #endif
1266         { 0,            NULL            },
1267 };
1268
1269 #if !defined WCOREFLAG && defined WCOREFLG
1270 # define WCOREFLAG WCOREFLG
1271 #endif
1272 #ifndef WCOREFLAG
1273 # define WCOREFLAG 0x80
1274 #endif
1275 #ifndef WCOREDUMP
1276 # define WCOREDUMP(status) ((status) & 0200)
1277 #endif
1278
1279
1280 #ifndef W_STOPCODE
1281 #define W_STOPCODE(sig)         ((sig) << 8 | 0x7f)
1282 #endif
1283 #ifndef W_EXITCODE
1284 #define W_EXITCODE(ret, sig)    ((ret) << 8 | (sig))
1285 #endif
1286
1287 static int
1288 printstatus(int status)
1289 {
1290         int exited = 0;
1291
1292         /*
1293          * Here is a tricky presentation problem.  This solution
1294          * is still not entirely satisfactory but since there
1295          * are no wait status constructors it will have to do.
1296          */
1297         if (WIFSTOPPED(status)) {
1298                 tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s}",
1299                         signame(WSTOPSIG(status)));
1300                 status &= ~W_STOPCODE(WSTOPSIG(status));
1301         }
1302         else if (WIFSIGNALED(status)) {
1303                 tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
1304                         signame(WTERMSIG(status)),
1305                         WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1306                 status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
1307         }
1308         else if (WIFEXITED(status)) {
1309                 tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
1310                         WEXITSTATUS(status));
1311                 exited = 1;
1312                 status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
1313         }
1314         else {
1315                 tprintf("[%#x]", status);
1316                 return 0;
1317         }
1318
1319         if (status == 0)
1320                 tprints("]");
1321         else
1322                 tprintf(" | %#x]", status);
1323
1324         return exited;
1325 }
1326
1327 static int
1328 printwaitn(struct tcb *tcp, int n, int bitness)
1329 {
1330         int status;
1331
1332         if (entering(tcp)) {
1333                 /* On Linux, kernel-side pid_t is typedef'ed to int
1334                  * on all arches. Also, glibc-2.8 truncates wait3 and wait4
1335                  * pid argument to int on 64bit arches, producing,
1336                  * for example, wait4(4294967295, ...) instead of -1
1337                  * in strace. We have to use int here, not long.
1338                  */
1339                 int pid = tcp->u_arg[0];
1340                 tprintf("%d, ", pid);
1341         } else {
1342                 /* status */
1343                 if (!tcp->u_arg[1])
1344                         tprints("NULL");
1345                 else if (syserror(tcp) || tcp->u_rval == 0)
1346                         tprintf("%#lx", tcp->u_arg[1]);
1347                 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1348                         tprints("[?]");
1349                 else
1350                         printstatus(status);
1351                 /* options */
1352                 tprints(", ");
1353                 printflags(wait4_options, tcp->u_arg[2], "W???");
1354                 if (n == 4) {
1355                         tprints(", ");
1356                         /* usage */
1357                         if (!tcp->u_arg[3])
1358                                 tprints("NULL");
1359                         else if (tcp->u_rval > 0) {
1360 #ifdef ALPHA
1361                                 if (bitness)
1362                                         printrusage32(tcp, tcp->u_arg[3]);
1363                                 else
1364 #endif
1365                                         printrusage(tcp, tcp->u_arg[3]);
1366                         }
1367                         else
1368                                 tprintf("%#lx", tcp->u_arg[3]);
1369                 }
1370         }
1371         return 0;
1372 }
1373
1374
1375
1376 int
1377 sys_waitpid(struct tcb *tcp)
1378 {
1379         return printwaitn(tcp, 3, 0);
1380 }
1381
1382 int
1383 sys_wait4(struct tcb *tcp)
1384 {
1385         return printwaitn(tcp, 4, 0);
1386 }
1387
1388 #ifdef ALPHA
1389 int
1390 sys_osf_wait4(struct tcb *tcp)
1391 {
1392         return printwaitn(tcp, 4, 1);
1393 }
1394 #endif
1395
1396
1397 static const struct xlat waitid_types[] = {
1398         { P_PID,        "P_PID"         },
1399 #ifdef P_PPID
1400         { P_PPID,       "P_PPID"        },
1401 #endif
1402         { P_PGID,       "P_PGID"        },
1403 #ifdef P_SID
1404         { P_SID,        "P_SID"         },
1405 #endif
1406 #ifdef P_CID
1407         { P_CID,        "P_CID"         },
1408 #endif
1409 #ifdef P_UID
1410         { P_UID,        "P_UID"         },
1411 #endif
1412 #ifdef P_GID
1413         { P_GID,        "P_GID"         },
1414 #endif
1415         { P_ALL,        "P_ALL"         },
1416 #ifdef P_LWPID
1417         { P_LWPID,      "P_LWPID"       },
1418 #endif
1419         { 0,            NULL            },
1420 };
1421
1422 int
1423 sys_waitid(struct tcb *tcp)
1424 {
1425         siginfo_t si;
1426
1427         if (entering(tcp)) {
1428                 printxval(waitid_types, tcp->u_arg[0], "P_???");
1429                 tprintf(", %ld, ", tcp->u_arg[1]);
1430         }
1431         else {
1432                 /* siginfo */
1433                 if (!tcp->u_arg[2])
1434                         tprints("NULL");
1435                 else if (syserror(tcp))
1436                         tprintf("%#lx", tcp->u_arg[2]);
1437                 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
1438                         tprints("{???}");
1439                 else
1440                         printsiginfo(&si, verbose(tcp));
1441                 /* options */
1442                 tprints(", ");
1443                 printflags(wait4_options, tcp->u_arg[3], "W???");
1444                 if (tcp->u_nargs > 4) {
1445                         /* usage */
1446                         tprints(", ");
1447                         if (!tcp->u_arg[4])
1448                                 tprints("NULL");
1449                         else if (tcp->u_error)
1450                                 tprintf("%#lx", tcp->u_arg[4]);
1451                         else
1452                                 printrusage(tcp, tcp->u_arg[4]);
1453                 }
1454         }
1455         return 0;
1456 }
1457
1458
1459 int
1460 sys_alarm(struct tcb *tcp)
1461 {
1462         if (entering(tcp))
1463                 tprintf("%lu", tcp->u_arg[0]);
1464         return 0;
1465 }
1466
1467 int
1468 sys_uname(struct tcb *tcp)
1469 {
1470         struct utsname uname;
1471
1472         if (exiting(tcp)) {
1473                 if (syserror(tcp) || !verbose(tcp))
1474                         tprintf("%#lx", tcp->u_arg[0]);
1475                 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1476                         tprints("{...}");
1477                 else if (!abbrev(tcp)) {
1478
1479                         tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1480                                 uname.sysname, uname.nodename);
1481                         tprintf("release=\"%s\", version=\"%s\", ",
1482                                 uname.release, uname.version);
1483                         tprintf("machine=\"%s\"", uname.machine);
1484 #ifndef __GLIBC__
1485                         tprintf(", domainname=\"%s\"", uname.domainname);
1486 #endif
1487                         tprints("}");
1488                 }
1489                 else
1490                         tprintf("{sys=\"%s\", node=\"%s\", ...}",
1491                                 uname.sysname, uname.nodename);
1492         }
1493         return 0;
1494 }
1495
1496
1497 static const struct xlat ptrace_cmds[] = {
1498         { PTRACE_TRACEME,       "PTRACE_TRACEME"        },
1499         { PTRACE_PEEKTEXT,      "PTRACE_PEEKTEXT"       },
1500         { PTRACE_PEEKDATA,      "PTRACE_PEEKDATA"       },
1501         { PTRACE_PEEKUSER,      "PTRACE_PEEKUSER"       },
1502         { PTRACE_POKETEXT,      "PTRACE_POKETEXT"       },
1503         { PTRACE_POKEDATA,      "PTRACE_POKEDATA"       },
1504         { PTRACE_POKEUSER,      "PTRACE_POKEUSER"       },
1505         { PTRACE_CONT,          "PTRACE_CONT"           },
1506         { PTRACE_KILL,          "PTRACE_KILL"           },
1507         { PTRACE_SINGLESTEP,    "PTRACE_SINGLESTEP"     },
1508         { PTRACE_ATTACH,        "PTRACE_ATTACH"         },
1509         { PTRACE_DETACH,        "PTRACE_DETACH"         },
1510 #  ifdef PTRACE_GETREGS
1511         { PTRACE_GETREGS,       "PTRACE_GETREGS"        },
1512 #  endif
1513 #  ifdef PTRACE_SETREGS
1514         { PTRACE_SETREGS,       "PTRACE_SETREGS"        },
1515 #  endif
1516 #  ifdef PTRACE_GETFPREGS
1517         { PTRACE_GETFPREGS,     "PTRACE_GETFPREGS"      },
1518 #  endif
1519 #  ifdef PTRACE_SETFPREGS
1520         { PTRACE_SETFPREGS,     "PTRACE_SETFPREGS"      },
1521 #  endif
1522 #  ifdef PTRACE_GETFPXREGS
1523         { PTRACE_GETFPXREGS,    "PTRACE_GETFPXREGS"     },
1524 #  endif
1525 #  ifdef PTRACE_SETFPXREGS
1526         { PTRACE_SETFPXREGS,    "PTRACE_SETFPXREGS"     },
1527 #  endif
1528 #  ifdef PTRACE_GETVRREGS
1529         { PTRACE_GETVRREGS,     "PTRACE_GETVRREGS"      },
1530 #  endif
1531 #  ifdef PTRACE_SETVRREGS
1532         { PTRACE_SETVRREGS,     "PTRACE_SETVRREGS"      },
1533 #  endif
1534 #  ifdef PTRACE_SETOPTIONS
1535         { PTRACE_SETOPTIONS,    "PTRACE_SETOPTIONS"     },
1536 #  endif
1537 #  ifdef PTRACE_GETEVENTMSG
1538         { PTRACE_GETEVENTMSG,   "PTRACE_GETEVENTMSG"    },
1539 #  endif
1540 #  ifdef PTRACE_GETSIGINFO
1541         { PTRACE_GETSIGINFO,    "PTRACE_GETSIGINFO"     },
1542 #  endif
1543 #  ifdef PTRACE_SETSIGINFO
1544         { PTRACE_SETSIGINFO,    "PTRACE_SETSIGINFO"     },
1545 #  endif
1546 #  ifdef PTRACE_GETREGSET
1547         { PTRACE_GETREGSET,     "PTRACE_GETREGSET"      },
1548 #  endif
1549 #  ifdef PTRACE_SETREGSET
1550         { PTRACE_SETREGSET,     "PTRACE_SETREGSET"      },
1551 #  endif
1552 #  ifdef PTRACE_SET_SYSCALL
1553         { PTRACE_SET_SYSCALL,   "PTRACE_SET_SYSCALL"    },
1554 #  endif
1555 #  ifdef PTRACE_SEIZE
1556         { PTRACE_SEIZE,         "PTRACE_SEIZE"          },
1557 #  endif
1558 #  ifdef PTRACE_INTERRUPT
1559         { PTRACE_INTERRUPT,     "PTRACE_INTERRUPT"      },
1560 #  endif
1561 #  ifdef PTRACE_LISTEN
1562         { PTRACE_LISTEN,        "PTRACE_LISTEN"         },
1563 #  endif
1564         { PTRACE_SYSCALL,       "PTRACE_SYSCALL"        },
1565
1566         { 0,                    NULL                    },
1567 };
1568
1569 #  ifdef PTRACE_SETOPTIONS
1570 static const struct xlat ptrace_setoptions_flags[] = {
1571 #   ifdef PTRACE_O_TRACESYSGOOD
1572         { PTRACE_O_TRACESYSGOOD,"PTRACE_O_TRACESYSGOOD" },
1573 #   endif
1574 #   ifdef PTRACE_O_TRACEFORK
1575         { PTRACE_O_TRACEFORK,   "PTRACE_O_TRACEFORK"    },
1576 #   endif
1577 #   ifdef PTRACE_O_TRACEVFORK
1578         { PTRACE_O_TRACEVFORK,  "PTRACE_O_TRACEVFORK"   },
1579 #   endif
1580 #   ifdef PTRACE_O_TRACECLONE
1581         { PTRACE_O_TRACECLONE,  "PTRACE_O_TRACECLONE"   },
1582 #   endif
1583 #   ifdef PTRACE_O_TRACEEXEC
1584         { PTRACE_O_TRACEEXEC,   "PTRACE_O_TRACEEXEC"    },
1585 #   endif
1586 #   ifdef PTRACE_O_TRACEVFORKDONE
1587         { PTRACE_O_TRACEVFORKDONE,"PTRACE_O_TRACEVFORKDONE"},
1588 #   endif
1589 #   ifdef PTRACE_O_TRACEEXIT
1590         { PTRACE_O_TRACEEXIT,   "PTRACE_O_TRACEEXIT"    },
1591 #   endif
1592         { 0,                    NULL                    },
1593 };
1594 #  endif /* PTRACE_SETOPTIONS */
1595
1596 const struct xlat struct_user_offsets[] = {
1597 #   if defined(S390) || defined(S390X)
1598         { PT_PSWMASK,           "psw_mask"                              },
1599         { PT_PSWADDR,           "psw_addr"                              },
1600         { PT_GPR0,              "gpr0"                                  },
1601         { PT_GPR1,              "gpr1"                                  },
1602         { PT_GPR2,              "gpr2"                                  },
1603         { PT_GPR3,              "gpr3"                                  },
1604         { PT_GPR4,              "gpr4"                                  },
1605         { PT_GPR5,              "gpr5"                                  },
1606         { PT_GPR6,              "gpr6"                                  },
1607         { PT_GPR7,              "gpr7"                                  },
1608         { PT_GPR8,              "gpr8"                                  },
1609         { PT_GPR9,              "gpr9"                                  },
1610         { PT_GPR10,             "gpr10"                                 },
1611         { PT_GPR11,             "gpr11"                                 },
1612         { PT_GPR12,             "gpr12"                                 },
1613         { PT_GPR13,             "gpr13"                                 },
1614         { PT_GPR14,             "gpr14"                                 },
1615         { PT_GPR15,             "gpr15"                                 },
1616         { PT_ACR0,              "acr0"                                  },
1617         { PT_ACR1,              "acr1"                                  },
1618         { PT_ACR2,              "acr2"                                  },
1619         { PT_ACR3,              "acr3"                                  },
1620         { PT_ACR4,              "acr4"                                  },
1621         { PT_ACR5,              "acr5"                                  },
1622         { PT_ACR6,              "acr6"                                  },
1623         { PT_ACR7,              "acr7"                                  },
1624         { PT_ACR8,              "acr8"                                  },
1625         { PT_ACR9,              "acr9"                                  },
1626         { PT_ACR10,             "acr10"                                 },
1627         { PT_ACR11,             "acr11"                                 },
1628         { PT_ACR12,             "acr12"                                 },
1629         { PT_ACR13,             "acr13"                                 },
1630         { PT_ACR14,             "acr14"                                 },
1631         { PT_ACR15,             "acr15"                                 },
1632         { PT_ORIGGPR2,          "orig_gpr2"                             },
1633         { PT_FPC,               "fpc"                                   },
1634 #    if defined(S390)
1635         { PT_FPR0_HI,           "fpr0.hi"                               },
1636         { PT_FPR0_LO,           "fpr0.lo"                               },
1637         { PT_FPR1_HI,           "fpr1.hi"                               },
1638         { PT_FPR1_LO,           "fpr1.lo"                               },
1639         { PT_FPR2_HI,           "fpr2.hi"                               },
1640         { PT_FPR2_LO,           "fpr2.lo"                               },
1641         { PT_FPR3_HI,           "fpr3.hi"                               },
1642         { PT_FPR3_LO,           "fpr3.lo"                               },
1643         { PT_FPR4_HI,           "fpr4.hi"                               },
1644         { PT_FPR4_LO,           "fpr4.lo"                               },
1645         { PT_FPR5_HI,           "fpr5.hi"                               },
1646         { PT_FPR5_LO,           "fpr5.lo"                               },
1647         { PT_FPR6_HI,           "fpr6.hi"                               },
1648         { PT_FPR6_LO,           "fpr6.lo"                               },
1649         { PT_FPR7_HI,           "fpr7.hi"                               },
1650         { PT_FPR7_LO,           "fpr7.lo"                               },
1651         { PT_FPR8_HI,           "fpr8.hi"                               },
1652         { PT_FPR8_LO,           "fpr8.lo"                               },
1653         { PT_FPR9_HI,           "fpr9.hi"                               },
1654         { PT_FPR9_LO,           "fpr9.lo"                               },
1655         { PT_FPR10_HI,          "fpr10.hi"                              },
1656         { PT_FPR10_LO,          "fpr10.lo"                              },
1657         { PT_FPR11_HI,          "fpr11.hi"                              },
1658         { PT_FPR11_LO,          "fpr11.lo"                              },
1659         { PT_FPR12_HI,          "fpr12.hi"                              },
1660         { PT_FPR12_LO,          "fpr12.lo"                              },
1661         { PT_FPR13_HI,          "fpr13.hi"                              },
1662         { PT_FPR13_LO,          "fpr13.lo"                              },
1663         { PT_FPR14_HI,          "fpr14.hi"                              },
1664         { PT_FPR14_LO,          "fpr14.lo"                              },
1665         { PT_FPR15_HI,          "fpr15.hi"                              },
1666         { PT_FPR15_LO,          "fpr15.lo"                              },
1667 #    endif
1668 #    if defined(S390X)
1669         { PT_FPR0,              "fpr0"                                  },
1670         { PT_FPR1,              "fpr1"                                  },
1671         { PT_FPR2,              "fpr2"                                  },
1672         { PT_FPR3,              "fpr3"                                  },
1673         { PT_FPR4,              "fpr4"                                  },
1674         { PT_FPR5,              "fpr5"                                  },
1675         { PT_FPR6,              "fpr6"                                  },
1676         { PT_FPR7,              "fpr7"                                  },
1677         { PT_FPR8,              "fpr8"                                  },
1678         { PT_FPR9,              "fpr9"                                  },
1679         { PT_FPR10,             "fpr10"                                 },
1680         { PT_FPR11,             "fpr11"                                 },
1681         { PT_FPR12,             "fpr12"                                 },
1682         { PT_FPR13,             "fpr13"                                 },
1683         { PT_FPR14,             "fpr14"                                 },
1684         { PT_FPR15,             "fpr15"                                 },
1685 #    endif
1686         { PT_CR_9,              "cr9"                                   },
1687         { PT_CR_10,             "cr10"                                  },
1688         { PT_CR_11,             "cr11"                                  },
1689         { PT_IEEE_IP,           "ieee_exception_ip"                     },
1690 #   elif defined(SPARC)
1691         /* XXX No support for these offsets yet. */
1692 #   elif defined(HPPA)
1693         /* XXX No support for these offsets yet. */
1694 #   elif defined(POWERPC)
1695 #    ifndef PT_ORIG_R3
1696 #     define PT_ORIG_R3 34
1697 #    endif
1698 #    define REGSIZE (sizeof(unsigned long))
1699         { REGSIZE*PT_R0,                "r0"                            },
1700         { REGSIZE*PT_R1,                "r1"                            },
1701         { REGSIZE*PT_R2,                "r2"                            },
1702         { REGSIZE*PT_R3,                "r3"                            },
1703         { REGSIZE*PT_R4,                "r4"                            },
1704         { REGSIZE*PT_R5,                "r5"                            },
1705         { REGSIZE*PT_R6,                "r6"                            },
1706         { REGSIZE*PT_R7,                "r7"                            },
1707         { REGSIZE*PT_R8,                "r8"                            },
1708         { REGSIZE*PT_R9,                "r9"                            },
1709         { REGSIZE*PT_R10,               "r10"                           },
1710         { REGSIZE*PT_R11,               "r11"                           },
1711         { REGSIZE*PT_R12,               "r12"                           },
1712         { REGSIZE*PT_R13,               "r13"                           },
1713         { REGSIZE*PT_R14,               "r14"                           },
1714         { REGSIZE*PT_R15,               "r15"                           },
1715         { REGSIZE*PT_R16,               "r16"                           },
1716         { REGSIZE*PT_R17,               "r17"                           },
1717         { REGSIZE*PT_R18,               "r18"                           },
1718         { REGSIZE*PT_R19,               "r19"                           },
1719         { REGSIZE*PT_R20,               "r20"                           },
1720         { REGSIZE*PT_R21,               "r21"                           },
1721         { REGSIZE*PT_R22,               "r22"                           },
1722         { REGSIZE*PT_R23,               "r23"                           },
1723         { REGSIZE*PT_R24,               "r24"                           },
1724         { REGSIZE*PT_R25,               "r25"                           },
1725         { REGSIZE*PT_R26,               "r26"                           },
1726         { REGSIZE*PT_R27,               "r27"                           },
1727         { REGSIZE*PT_R28,               "r28"                           },
1728         { REGSIZE*PT_R29,               "r29"                           },
1729         { REGSIZE*PT_R30,               "r30"                           },
1730         { REGSIZE*PT_R31,               "r31"                           },
1731         { REGSIZE*PT_NIP,               "NIP"                           },
1732         { REGSIZE*PT_MSR,               "MSR"                           },
1733         { REGSIZE*PT_ORIG_R3,           "ORIG_R3"                       },
1734         { REGSIZE*PT_CTR,               "CTR"                           },
1735         { REGSIZE*PT_LNK,               "LNK"                           },
1736         { REGSIZE*PT_XER,               "XER"                           },
1737         { REGSIZE*PT_CCR,               "CCR"                           },
1738         { REGSIZE*PT_FPR0,              "FPR0"                          },
1739 #    undef REGSIZE
1740 #   elif defined(ALPHA)
1741         { 0,                    "r0"                                    },
1742         { 1,                    "r1"                                    },
1743         { 2,                    "r2"                                    },
1744         { 3,                    "r3"                                    },
1745         { 4,                    "r4"                                    },
1746         { 5,                    "r5"                                    },
1747         { 6,                    "r6"                                    },
1748         { 7,                    "r7"                                    },
1749         { 8,                    "r8"                                    },
1750         { 9,                    "r9"                                    },
1751         { 10,                   "r10"                                   },
1752         { 11,                   "r11"                                   },
1753         { 12,                   "r12"                                   },
1754         { 13,                   "r13"                                   },
1755         { 14,                   "r14"                                   },
1756         { 15,                   "r15"                                   },
1757         { 16,                   "r16"                                   },
1758         { 17,                   "r17"                                   },
1759         { 18,                   "r18"                                   },
1760         { 19,                   "r19"                                   },
1761         { 20,                   "r20"                                   },
1762         { 21,                   "r21"                                   },
1763         { 22,                   "r22"                                   },
1764         { 23,                   "r23"                                   },
1765         { 24,                   "r24"                                   },
1766         { 25,                   "r25"                                   },
1767         { 26,                   "r26"                                   },
1768         { 27,                   "r27"                                   },
1769         { 28,                   "r28"                                   },
1770         { 29,                   "gp"                                    },
1771         { 30,                   "fp"                                    },
1772         { 31,                   "zero"                                  },
1773         { 32,                   "fp0"                                   },
1774         { 33,                   "fp"                                    },
1775         { 34,                   "fp2"                                   },
1776         { 35,                   "fp3"                                   },
1777         { 36,                   "fp4"                                   },
1778         { 37,                   "fp5"                                   },
1779         { 38,                   "fp6"                                   },
1780         { 39,                   "fp7"                                   },
1781         { 40,                   "fp8"                                   },
1782         { 41,                   "fp9"                                   },
1783         { 42,                   "fp10"                                  },
1784         { 43,                   "fp11"                                  },
1785         { 44,                   "fp12"                                  },
1786         { 45,                   "fp13"                                  },
1787         { 46,                   "fp14"                                  },
1788         { 47,                   "fp15"                                  },
1789         { 48,                   "fp16"                                  },
1790         { 49,                   "fp17"                                  },
1791         { 50,                   "fp18"                                  },
1792         { 51,                   "fp19"                                  },
1793         { 52,                   "fp20"                                  },
1794         { 53,                   "fp21"                                  },
1795         { 54,                   "fp22"                                  },
1796         { 55,                   "fp23"                                  },
1797         { 56,                   "fp24"                                  },
1798         { 57,                   "fp25"                                  },
1799         { 58,                   "fp26"                                  },
1800         { 59,                   "fp27"                                  },
1801         { 60,                   "fp28"                                  },
1802         { 61,                   "fp29"                                  },
1803         { 62,                   "fp30"                                  },
1804         { 63,                   "fp31"                                  },
1805         { 64,                   "pc"                                    },
1806 #   elif defined(IA64)
1807         { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
1808         { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
1809         { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
1810         { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
1811         { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
1812         { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
1813         { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
1814         { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
1815         { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
1816         { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
1817         { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
1818         { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
1819         { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
1820         { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
1821         { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
1822         { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
1823         { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
1824         { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
1825         { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
1826         { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
1827         { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
1828         { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
1829         { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
1830         { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
1831         { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
1832         { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
1833         { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
1834         { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
1835         { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
1836         { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
1837         { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
1838         { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
1839         /* switch stack: */
1840         { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
1841         { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
1842         { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
1843         { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
1844         { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
1845         { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
1846         { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
1847         { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
1848         { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
1849         { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
1850         { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
1851         { PT_B4, "b4" }, { PT_B5, "b5" },
1852         { PT_AR_EC, "ar.ec" }, { PT_AR_LC, "ar.lc" },
1853         /* pt_regs */
1854         { PT_CR_IPSR, "psr" }, { PT_CR_IIP, "ip" },
1855         { PT_CFM, "cfm" }, { PT_AR_UNAT, "ar.unat" },
1856         { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
1857         { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
1858         { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
1859         { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
1860         { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
1861         { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
1862         { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
1863         { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
1864         { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
1865         { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
1866         { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
1867         { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
1868         { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
1869         { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
1870         { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
1871 #    ifdef PT_AR_CSD
1872         { PT_AR_CSD, "ar.csd" },
1873 #    endif
1874 #    ifdef PT_AR_SSD
1875         { PT_AR_SSD, "ar.ssd" },
1876 #    endif
1877         { PT_DBR, "dbr" }, { PT_IBR, "ibr" }, { PT_PMD, "pmd" },
1878 #   elif defined(I386)
1879         { 4*EBX,                "4*EBX"                                 },
1880         { 4*ECX,                "4*ECX"                                 },
1881         { 4*EDX,                "4*EDX"                                 },
1882         { 4*ESI,                "4*ESI"                                 },
1883         { 4*EDI,                "4*EDI"                                 },
1884         { 4*EBP,                "4*EBP"                                 },
1885         { 4*EAX,                "4*EAX"                                 },
1886         { 4*DS,                 "4*DS"                                  },
1887         { 4*ES,                 "4*ES"                                  },
1888         { 4*FS,                 "4*FS"                                  },
1889         { 4*GS,                 "4*GS"                                  },
1890         { 4*ORIG_EAX,           "4*ORIG_EAX"                            },
1891         { 4*EIP,                "4*EIP"                                 },
1892         { 4*CS,                 "4*CS"                                  },
1893         { 4*EFL,                "4*EFL"                                 },
1894         { 4*UESP,               "4*UESP"                                },
1895         { 4*SS,                 "4*SS"                                  },
1896 #   elif defined(X86_64)
1897         { 8*R15,                "8*R15"                                 },
1898         { 8*R14,                "8*R14"                                 },
1899         { 8*R13,                "8*R13"                                 },
1900         { 8*R12,                "8*R12"                                 },
1901         { 8*RBP,                "8*RBP"                                 },
1902         { 8*RBX,                "8*RBX"                                 },
1903         { 8*R11,                "8*R11"                                 },
1904         { 8*R10,                "8*R10"                                 },
1905         { 8*R9,                 "8*R9"                                  },
1906         { 8*R8,                 "8*R8"                                  },
1907         { 8*RAX,                "8*RAX"                                 },
1908         { 8*RCX,                "8*RCX"                                 },
1909         { 8*RDX,                "8*RDX"                                 },
1910         { 8*RSI,                "8*RSI"                                 },
1911         { 8*RDI,                "8*RDI"                                 },
1912         { 8*ORIG_RAX,           "8*ORIG_RAX"                            },
1913         { 8*RIP,                "8*RIP"                                 },
1914         { 8*CS,                 "8*CS"                                  },
1915         { 8*EFLAGS,             "8*EFL"                                 },
1916         { 8*RSP,                "8*RSP"                                 },
1917         { 8*SS,                 "8*SS"                                  },
1918 #   elif defined(M68K)
1919         { 4*PT_D1,              "4*PT_D1"                               },
1920         { 4*PT_D2,              "4*PT_D2"                               },
1921         { 4*PT_D3,              "4*PT_D3"                               },
1922         { 4*PT_D4,              "4*PT_D4"                               },
1923         { 4*PT_D5,              "4*PT_D5"                               },
1924         { 4*PT_D6,              "4*PT_D6"                               },
1925         { 4*PT_D7,              "4*PT_D7"                               },
1926         { 4*PT_A0,              "4*PT_A0"                               },
1927         { 4*PT_A1,              "4*PT_A1"                               },
1928         { 4*PT_A2,              "4*PT_A2"                               },
1929         { 4*PT_A3,              "4*PT_A3"                               },
1930         { 4*PT_A4,              "4*PT_A4"                               },
1931         { 4*PT_A5,              "4*PT_A5"                               },
1932         { 4*PT_A6,              "4*PT_A6"                               },
1933         { 4*PT_D0,              "4*PT_D0"                               },
1934         { 4*PT_USP,             "4*PT_USP"                              },
1935         { 4*PT_ORIG_D0,         "4*PT_ORIG_D0"                          },
1936         { 4*PT_SR,              "4*PT_SR"                               },
1937         { 4*PT_PC,              "4*PT_PC"                               },
1938 #   elif defined(SH)
1939         { 4*REG_REG0,           "4*REG_REG0"                            },
1940         { 4*(REG_REG0+1),       "4*REG_REG1"                            },
1941         { 4*(REG_REG0+2),       "4*REG_REG2"                            },
1942         { 4*(REG_REG0+3),       "4*REG_REG3"                            },
1943         { 4*(REG_REG0+4),       "4*REG_REG4"                            },
1944         { 4*(REG_REG0+5),       "4*REG_REG5"                            },
1945         { 4*(REG_REG0+6),       "4*REG_REG6"                            },
1946         { 4*(REG_REG0+7),       "4*REG_REG7"                            },
1947         { 4*(REG_REG0+8),       "4*REG_REG8"                            },
1948         { 4*(REG_REG0+9),       "4*REG_REG9"                            },
1949         { 4*(REG_REG0+10),      "4*REG_REG10"                           },
1950         { 4*(REG_REG0+11),      "4*REG_REG11"                           },
1951         { 4*(REG_REG0+12),      "4*REG_REG12"                           },
1952         { 4*(REG_REG0+13),      "4*REG_REG13"                           },
1953         { 4*(REG_REG0+14),      "4*REG_REG14"                           },
1954         { 4*REG_REG15,          "4*REG_REG15"                           },
1955         { 4*REG_PC,             "4*REG_PC"                              },
1956         { 4*REG_PR,             "4*REG_PR"                              },
1957         { 4*REG_SR,             "4*REG_SR"                              },
1958         { 4*REG_GBR,            "4*REG_GBR"                             },
1959         { 4*REG_MACH,           "4*REG_MACH"                            },
1960         { 4*REG_MACL,           "4*REG_MACL"                            },
1961         { 4*REG_SYSCALL,        "4*REG_SYSCALL"                         },
1962         { 4*REG_FPUL,           "4*REG_FPUL"                            },
1963         { 4*REG_FPREG0,         "4*REG_FPREG0"                          },
1964         { 4*(REG_FPREG0+1),     "4*REG_FPREG1"                          },
1965         { 4*(REG_FPREG0+2),     "4*REG_FPREG2"                          },
1966         { 4*(REG_FPREG0+3),     "4*REG_FPREG3"                          },
1967         { 4*(REG_FPREG0+4),     "4*REG_FPREG4"                          },
1968         { 4*(REG_FPREG0+5),     "4*REG_FPREG5"                          },
1969         { 4*(REG_FPREG0+6),     "4*REG_FPREG6"                          },
1970         { 4*(REG_FPREG0+7),     "4*REG_FPREG7"                          },
1971         { 4*(REG_FPREG0+8),     "4*REG_FPREG8"                          },
1972         { 4*(REG_FPREG0+9),     "4*REG_FPREG9"                          },
1973         { 4*(REG_FPREG0+10),    "4*REG_FPREG10"                         },
1974         { 4*(REG_FPREG0+11),    "4*REG_FPREG11"                         },
1975         { 4*(REG_FPREG0+12),    "4*REG_FPREG12"                         },
1976         { 4*(REG_FPREG0+13),    "4*REG_FPREG13"                         },
1977         { 4*(REG_FPREG0+14),    "4*REG_FPREG14"                         },
1978         { 4*REG_FPREG15,        "4*REG_FPREG15"                         },
1979 #    ifdef REG_XDREG0
1980         { 4*REG_XDREG0,         "4*REG_XDREG0"                          },
1981         { 4*(REG_XDREG0+2),     "4*REG_XDREG2"                          },
1982         { 4*(REG_XDREG0+4),     "4*REG_XDREG4"                          },
1983         { 4*(REG_XDREG0+6),     "4*REG_XDREG6"                          },
1984         { 4*(REG_XDREG0+8),     "4*REG_XDREG8"                          },
1985         { 4*(REG_XDREG0+10),    "4*REG_XDREG10"                         },
1986         { 4*(REG_XDREG0+12),    "4*REG_XDREG12"                         },
1987         { 4*REG_XDREG14,        "4*REG_XDREG14"                         },
1988 #    endif
1989         { 4*REG_FPSCR,          "4*REG_FPSCR"                           },
1990 #   elif defined(SH64)
1991         { 0,                    "PC(L)"                                 },
1992         { 4,                    "PC(U)"                                 },
1993         { 8,                    "SR(L)"                                 },
1994         { 12,                   "SR(U)"                                 },
1995         { 16,                   "syscall no.(L)"                        },
1996         { 20,                   "syscall_no.(U)"                        },
1997         { 24,                   "R0(L)"                                 },
1998         { 28,                   "R0(U)"                                 },
1999         { 32,                   "R1(L)"                                 },
2000         { 36,                   "R1(U)"                                 },
2001         { 40,                   "R2(L)"                                 },
2002         { 44,                   "R2(U)"                                 },
2003         { 48,                   "R3(L)"                                 },
2004         { 52,                   "R3(U)"                                 },
2005         { 56,                   "R4(L)"                                 },
2006         { 60,                   "R4(U)"                                 },
2007         { 64,                   "R5(L)"                                 },
2008         { 68,                   "R5(U)"                                 },
2009         { 72,                   "R6(L)"                                 },
2010         { 76,                   "R6(U)"                                 },
2011         { 80,                   "R7(L)"                                 },
2012         { 84,                   "R7(U)"                                 },
2013         { 88,                   "R8(L)"                                 },
2014         { 92,                   "R8(U)"                                 },
2015         { 96,                   "R9(L)"                                 },
2016         { 100,                  "R9(U)"                                 },
2017         { 104,                  "R10(L)"                                },
2018         { 108,                  "R10(U)"                                },
2019         { 112,                  "R11(L)"                                },
2020         { 116,                  "R11(U)"                                },
2021         { 120,                  "R12(L)"                                },
2022         { 124,                  "R12(U)"                                },
2023         { 128,                  "R13(L)"                                },
2024         { 132,                  "R13(U)"                                },
2025         { 136,                  "R14(L)"                                },
2026         { 140,                  "R14(U)"                                },
2027         { 144,                  "R15(L)"                                },
2028         { 148,                  "R15(U)"                                },
2029         { 152,                  "R16(L)"                                },
2030         { 156,                  "R16(U)"                                },
2031         { 160,                  "R17(L)"                                },
2032         { 164,                  "R17(U)"                                },
2033         { 168,                  "R18(L)"                                },
2034         { 172,                  "R18(U)"                                },
2035         { 176,                  "R19(L)"                                },
2036         { 180,                  "R19(U)"                                },
2037         { 184,                  "R20(L)"                                },
2038         { 188,                  "R20(U)"                                },
2039         { 192,                  "R21(L)"                                },
2040         { 196,                  "R21(U)"                                },
2041         { 200,                  "R22(L)"                                },
2042         { 204,                  "R22(U)"                                },
2043         { 208,                  "R23(L)"                                },
2044         { 212,                  "R23(U)"                                },
2045         { 216,                  "R24(L)"                                },
2046         { 220,                  "R24(U)"                                },
2047         { 224,                  "R25(L)"                                },
2048         { 228,                  "R25(U)"                                },
2049         { 232,                  "R26(L)"                                },
2050         { 236,                  "R26(U)"                                },
2051         { 240,                  "R27(L)"                                },
2052         { 244,                  "R27(U)"                                },
2053         { 248,                  "R28(L)"                                },
2054         { 252,                  "R28(U)"                                },
2055         { 256,                  "R29(L)"                                },
2056         { 260,                  "R29(U)"                                },
2057         { 264,                  "R30(L)"                                },
2058         { 268,                  "R30(U)"                                },
2059         { 272,                  "R31(L)"                                },
2060         { 276,                  "R31(U)"                                },
2061         { 280,                  "R32(L)"                                },
2062         { 284,                  "R32(U)"                                },
2063         { 288,                  "R33(L)"                                },
2064         { 292,                  "R33(U)"                                },
2065         { 296,                  "R34(L)"                                },
2066         { 300,                  "R34(U)"                                },
2067         { 304,                  "R35(L)"                                },
2068         { 308,                  "R35(U)"                                },
2069         { 312,                  "R36(L)"                                },
2070         { 316,                  "R36(U)"                                },
2071         { 320,                  "R37(L)"                                },
2072         { 324,                  "R37(U)"                                },
2073         { 328,                  "R38(L)"                                },
2074         { 332,                  "R38(U)"                                },
2075         { 336,                  "R39(L)"                                },
2076         { 340,                  "R39(U)"                                },
2077         { 344,                  "R40(L)"                                },
2078         { 348,                  "R40(U)"                                },
2079         { 352,                  "R41(L)"                                },
2080         { 356,                  "R41(U)"                                },
2081         { 360,                  "R42(L)"                                },
2082         { 364,                  "R42(U)"                                },
2083         { 368,                  "R43(L)"                                },
2084         { 372,                  "R43(U)"                                },
2085         { 376,                  "R44(L)"                                },
2086         { 380,                  "R44(U)"                                },
2087         { 384,                  "R45(L)"                                },
2088         { 388,                  "R45(U)"                                },
2089         { 392,                  "R46(L)"                                },
2090         { 396,                  "R46(U)"                                },
2091         { 400,                  "R47(L)"                                },
2092         { 404,                  "R47(U)"                                },
2093         { 408,                  "R48(L)"                                },
2094         { 412,                  "R48(U)"                                },
2095         { 416,                  "R49(L)"                                },
2096         { 420,                  "R49(U)"                                },
2097         { 424,                  "R50(L)"                                },
2098         { 428,                  "R50(U)"                                },
2099         { 432,                  "R51(L)"                                },
2100         { 436,                  "R51(U)"                                },
2101         { 440,                  "R52(L)"                                },
2102         { 444,                  "R52(U)"                                },
2103         { 448,                  "R53(L)"                                },
2104         { 452,                  "R53(U)"                                },
2105         { 456,                  "R54(L)"                                },
2106         { 460,                  "R54(U)"                                },
2107         { 464,                  "R55(L)"                                },
2108         { 468,                  "R55(U)"                                },
2109         { 472,                  "R56(L)"                                },
2110         { 476,                  "R56(U)"                                },
2111         { 480,                  "R57(L)"                                },
2112         { 484,                  "R57(U)"                                },
2113         { 488,                  "R58(L)"                                },
2114         { 492,                  "R58(U)"                                },
2115         { 496,                  "R59(L)"                                },
2116         { 500,                  "R59(U)"                                },
2117         { 504,                  "R60(L)"                                },
2118         { 508,                  "R60(U)"                                },
2119         { 512,                  "R61(L)"                                },
2120         { 516,                  "R61(U)"                                },
2121         { 520,                  "R62(L)"                                },
2122         { 524,                  "R62(U)"                                },
2123         { 528,                  "TR0(L)"                                },
2124         { 532,                  "TR0(U)"                                },
2125         { 536,                  "TR1(L)"                                },
2126         { 540,                  "TR1(U)"                                },
2127         { 544,                  "TR2(L)"                                },
2128         { 548,                  "TR2(U)"                                },
2129         { 552,                  "TR3(L)"                                },
2130         { 556,                  "TR3(U)"                                },
2131         { 560,                  "TR4(L)"                                },
2132         { 564,                  "TR4(U)"                                },
2133         { 568,                  "TR5(L)"                                },
2134         { 572,                  "TR5(U)"                                },
2135         { 576,                  "TR6(L)"                                },
2136         { 580,                  "TR6(U)"                                },
2137         { 584,                  "TR7(L)"                                },
2138         { 588,                  "TR7(U)"                                },
2139         /* This entry is in case pt_regs contains dregs (depends on
2140            the kernel build options). */
2141         { uoff(regs),           "offsetof(struct user, regs)"           },
2142         { uoff(fpu),            "offsetof(struct user, fpu)"            },
2143 #   elif defined(ARM)
2144         { uoff(regs.ARM_r0),    "r0"                                    },
2145         { uoff(regs.ARM_r1),    "r1"                                    },
2146         { uoff(regs.ARM_r2),    "r2"                                    },
2147         { uoff(regs.ARM_r3),    "r3"                                    },
2148         { uoff(regs.ARM_r4),    "r4"                                    },
2149         { uoff(regs.ARM_r5),    "r5"                                    },
2150         { uoff(regs.ARM_r6),    "r6"                                    },
2151         { uoff(regs.ARM_r7),    "r7"                                    },
2152         { uoff(regs.ARM_r8),    "r8"                                    },
2153         { uoff(regs.ARM_r9),    "r9"                                    },
2154         { uoff(regs.ARM_r10),   "r10"                                   },
2155         { uoff(regs.ARM_fp),    "fp"                                    },
2156         { uoff(regs.ARM_ip),    "ip"                                    },
2157         { uoff(regs.ARM_sp),    "sp"                                    },
2158         { uoff(regs.ARM_lr),    "lr"                                    },
2159         { uoff(regs.ARM_pc),    "pc"                                    },
2160         { uoff(regs.ARM_cpsr),  "cpsr"                                  },
2161 #   elif defined(AVR32)
2162         { uoff(regs.sr),        "sr"                                    },
2163         { uoff(regs.pc),        "pc"                                    },
2164         { uoff(regs.lr),        "lr"                                    },
2165         { uoff(regs.sp),        "sp"                                    },
2166         { uoff(regs.r12),       "r12"                                   },
2167         { uoff(regs.r11),       "r11"                                   },
2168         { uoff(regs.r10),       "r10"                                   },
2169         { uoff(regs.r9),        "r9"                                    },
2170         { uoff(regs.r8),        "r8"                                    },
2171         { uoff(regs.r7),        "r7"                                    },
2172         { uoff(regs.r6),        "r6"                                    },
2173         { uoff(regs.r5),        "r5"                                    },
2174         { uoff(regs.r4),        "r4"                                    },
2175         { uoff(regs.r3),        "r3"                                    },
2176         { uoff(regs.r2),        "r2"                                    },
2177         { uoff(regs.r1),        "r1"                                    },
2178         { uoff(regs.r0),        "r0"                                    },
2179         { uoff(regs.r12_orig),  "orig_r12"                              },
2180 #   elif defined(MIPS)
2181         { 0,                    "r0"                                    },
2182         { 1,                    "r1"                                    },
2183         { 2,                    "r2"                                    },
2184         { 3,                    "r3"                                    },
2185         { 4,                    "r4"                                    },
2186         { 5,                    "r5"                                    },
2187         { 6,                    "r6"                                    },
2188         { 7,                    "r7"                                    },
2189         { 8,                    "r8"                                    },
2190         { 9,                    "r9"                                    },
2191         { 10,                   "r10"                                   },
2192         { 11,                   "r11"                                   },
2193         { 12,                   "r12"                                   },
2194         { 13,                   "r13"                                   },
2195         { 14,                   "r14"                                   },
2196         { 15,                   "r15"                                   },
2197         { 16,                   "r16"                                   },
2198         { 17,                   "r17"                                   },
2199         { 18,                   "r18"                                   },
2200         { 19,                   "r19"                                   },
2201         { 20,                   "r20"                                   },
2202         { 21,                   "r21"                                   },
2203         { 22,                   "r22"                                   },
2204         { 23,                   "r23"                                   },
2205         { 24,                   "r24"                                   },
2206         { 25,                   "r25"                                   },
2207         { 26,                   "r26"                                   },
2208         { 27,                   "r27"                                   },
2209         { 28,                   "r28"                                   },
2210         { 29,                   "r29"                                   },
2211         { 30,                   "r30"                                   },
2212         { 31,                   "r31"                                   },
2213         { 32,                   "f0"                                    },
2214         { 33,                   "f1"                                    },
2215         { 34,                   "f2"                                    },
2216         { 35,                   "f3"                                    },
2217         { 36,                   "f4"                                    },
2218         { 37,                   "f5"                                    },
2219         { 38,                   "f6"                                    },
2220         { 39,                   "f7"                                    },
2221         { 40,                   "f8"                                    },
2222         { 41,                   "f9"                                    },
2223         { 42,                   "f10"                                   },
2224         { 43,                   "f11"                                   },
2225         { 44,                   "f12"                                   },
2226         { 45,                   "f13"                                   },
2227         { 46,                   "f14"                                   },
2228         { 47,                   "f15"                                   },
2229         { 48,                   "f16"                                   },
2230         { 49,                   "f17"                                   },
2231         { 50,                   "f18"                                   },
2232         { 51,                   "f19"                                   },
2233         { 52,                   "f20"                                   },
2234         { 53,                   "f21"                                   },
2235         { 54,                   "f22"                                   },
2236         { 55,                   "f23"                                   },
2237         { 56,                   "f24"                                   },
2238         { 57,                   "f25"                                   },
2239         { 58,                   "f26"                                   },
2240         { 59,                   "f27"                                   },
2241         { 60,                   "f28"                                   },
2242         { 61,                   "f29"                                   },
2243         { 62,                   "f30"                                   },
2244         { 63,                   "f31"                                   },
2245         { 64,                   "pc"                                    },
2246         { 65,                   "cause"                                 },
2247         { 66,                   "badvaddr"                              },
2248         { 67,                   "mmhi"                                  },
2249         { 68,                   "mmlo"                                  },
2250         { 69,                   "fpcsr"                                 },
2251         { 70,                   "fpeir"                                 },
2252 #   elif defined(TILE)
2253         { PTREGS_OFFSET_REG(0),  "r0"  },
2254         { PTREGS_OFFSET_REG(1),  "r1"  },
2255         { PTREGS_OFFSET_REG(2),  "r2"  },
2256         { PTREGS_OFFSET_REG(3),  "r3"  },
2257         { PTREGS_OFFSET_REG(4),  "r4"  },
2258         { PTREGS_OFFSET_REG(5),  "r5"  },
2259         { PTREGS_OFFSET_REG(6),  "r6"  },
2260         { PTREGS_OFFSET_REG(7),  "r7"  },
2261         { PTREGS_OFFSET_REG(8),  "r8"  },
2262         { PTREGS_OFFSET_REG(9),  "r9"  },
2263         { PTREGS_OFFSET_REG(10), "r10" },
2264         { PTREGS_OFFSET_REG(11), "r11" },
2265         { PTREGS_OFFSET_REG(12), "r12" },
2266         { PTREGS_OFFSET_REG(13), "r13" },
2267         { PTREGS_OFFSET_REG(14), "r14" },
2268         { PTREGS_OFFSET_REG(15), "r15" },
2269         { PTREGS_OFFSET_REG(16), "r16" },
2270         { PTREGS_OFFSET_REG(17), "r17" },
2271         { PTREGS_OFFSET_REG(18), "r18" },
2272         { PTREGS_OFFSET_REG(19), "r19" },
2273         { PTREGS_OFFSET_REG(20), "r20" },
2274         { PTREGS_OFFSET_REG(21), "r21" },
2275         { PTREGS_OFFSET_REG(22), "r22" },
2276         { PTREGS_OFFSET_REG(23), "r23" },
2277         { PTREGS_OFFSET_REG(24), "r24" },
2278         { PTREGS_OFFSET_REG(25), "r25" },
2279         { PTREGS_OFFSET_REG(26), "r26" },
2280         { PTREGS_OFFSET_REG(27), "r27" },
2281         { PTREGS_OFFSET_REG(28), "r28" },
2282         { PTREGS_OFFSET_REG(29), "r29" },
2283         { PTREGS_OFFSET_REG(30), "r30" },
2284         { PTREGS_OFFSET_REG(31), "r31" },
2285         { PTREGS_OFFSET_REG(32), "r32" },
2286         { PTREGS_OFFSET_REG(33), "r33" },
2287         { PTREGS_OFFSET_REG(34), "r34" },
2288         { PTREGS_OFFSET_REG(35), "r35" },
2289         { PTREGS_OFFSET_REG(36), "r36" },
2290         { PTREGS_OFFSET_REG(37), "r37" },
2291         { PTREGS_OFFSET_REG(38), "r38" },
2292         { PTREGS_OFFSET_REG(39), "r39" },
2293         { PTREGS_OFFSET_REG(40), "r40" },
2294         { PTREGS_OFFSET_REG(41), "r41" },
2295         { PTREGS_OFFSET_REG(42), "r42" },
2296         { PTREGS_OFFSET_REG(43), "r43" },
2297         { PTREGS_OFFSET_REG(44), "r44" },
2298         { PTREGS_OFFSET_REG(45), "r45" },
2299         { PTREGS_OFFSET_REG(46), "r46" },
2300         { PTREGS_OFFSET_REG(47), "r47" },
2301         { PTREGS_OFFSET_REG(48), "r48" },
2302         { PTREGS_OFFSET_REG(49), "r49" },
2303         { PTREGS_OFFSET_REG(50), "r50" },
2304         { PTREGS_OFFSET_REG(51), "r51" },
2305         { PTREGS_OFFSET_REG(52), "r52" },
2306         { PTREGS_OFFSET_TP, "tp" },
2307         { PTREGS_OFFSET_SP, "sp" },
2308         { PTREGS_OFFSET_LR, "lr" },
2309         { PTREGS_OFFSET_PC, "pc" },
2310         { PTREGS_OFFSET_EX1, "ex1" },
2311         { PTREGS_OFFSET_FAULTNUM, "faultnum" },
2312         { PTREGS_OFFSET_ORIG_R0, "orig_r0" },
2313         { PTREGS_OFFSET_FLAGS, "flags" },
2314 #   endif
2315 #   ifdef CRISV10
2316         { 4*PT_FRAMETYPE, "4*PT_FRAMETYPE" },
2317         { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
2318         { 4*PT_R13, "4*PT_R13" },
2319         { 4*PT_R12, "4*PT_R12" },
2320         { 4*PT_R11, "4*PT_R11" },
2321         { 4*PT_R10, "4*PT_R10" },
2322         { 4*PT_R9, "4*PT_R9" },
2323         { 4*PT_R8, "4*PT_R8" },
2324         { 4*PT_R7, "4*PT_R7" },
2325         { 4*PT_R6, "4*PT_R6" },
2326         { 4*PT_R5, "4*PT_R5" },
2327         { 4*PT_R4, "4*PT_R4" },
2328         { 4*PT_R3, "4*PT_R3" },
2329         { 4*PT_R2, "4*PT_R2" },
2330         { 4*PT_R1, "4*PT_R1" },
2331         { 4*PT_R0, "4*PT_R0" },
2332         { 4*PT_MOF, "4*PT_MOF" },
2333         { 4*PT_DCCR, "4*PT_DCCR" },
2334         { 4*PT_SRP, "4*PT_SRP" },
2335         { 4*PT_IRP, "4*PT_IRP" },
2336         { 4*PT_CSRINSTR, "4*PT_CSRINSTR" },
2337         { 4*PT_CSRADDR, "4*PT_CSRADDR" },
2338         { 4*PT_CSRDATA, "4*PT_CSRDATA" },
2339         { 4*PT_USP, "4*PT_USP" },
2340 #   endif
2341 #   ifdef CRISV32
2342         { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
2343         { 4*PT_R0, "4*PT_R0" },
2344         { 4*PT_R1, "4*PT_R1" },
2345         { 4*PT_R2, "4*PT_R2" },
2346         { 4*PT_R3, "4*PT_R3" },
2347         { 4*PT_R4, "4*PT_R4" },
2348         { 4*PT_R5, "4*PT_R5" },
2349         { 4*PT_R6, "4*PT_R6" },
2350         { 4*PT_R7, "4*PT_R7" },
2351         { 4*PT_R8, "4*PT_R8" },
2352         { 4*PT_R9, "4*PT_R9" },
2353         { 4*PT_R10, "4*PT_R10" },
2354         { 4*PT_R11, "4*PT_R11" },
2355         { 4*PT_R12, "4*PT_R12" },
2356         { 4*PT_R13, "4*PT_R13" },
2357         { 4*PT_ACR, "4*PT_ACR" },
2358         { 4*PT_SRS, "4*PT_SRS" },
2359         { 4*PT_MOF, "4*PT_MOF" },
2360         { 4*PT_SPC, "4*PT_SPC" },
2361         { 4*PT_CCS, "4*PT_CCS" },
2362         { 4*PT_SRP, "4*PT_SRP" },
2363         { 4*PT_ERP, "4*PT_ERP" },
2364         { 4*PT_EXS, "4*PT_EXS" },
2365         { 4*PT_EDA, "4*PT_EDA" },
2366         { 4*PT_USP, "4*PT_USP" },
2367         { 4*PT_PPC, "4*PT_PPC" },
2368         { 4*PT_BP_CTRL, "4*PT_BP_CTRL" },
2369         { 4*PT_BP+4, "4*PT_BP+4" },
2370         { 4*PT_BP+8, "4*PT_BP+8" },
2371         { 4*PT_BP+12, "4*PT_BP+12" },
2372         { 4*PT_BP+16, "4*PT_BP+16" },
2373         { 4*PT_BP+20, "4*PT_BP+20" },
2374         { 4*PT_BP+24, "4*PT_BP+24" },
2375         { 4*PT_BP+28, "4*PT_BP+28" },
2376         { 4*PT_BP+32, "4*PT_BP+32" },
2377         { 4*PT_BP+36, "4*PT_BP+36" },
2378         { 4*PT_BP+40, "4*PT_BP+40" },
2379         { 4*PT_BP+44, "4*PT_BP+44" },
2380         { 4*PT_BP+48, "4*PT_BP+48" },
2381         { 4*PT_BP+52, "4*PT_BP+52" },
2382         { 4*PT_BP+56, "4*PT_BP+56" },
2383 #   endif
2384 #   ifdef MICROBLAZE
2385         { PT_GPR(0),            "r0"                                    },
2386         { PT_GPR(1),            "r1"                                    },
2387         { PT_GPR(2),            "r2"                                    },
2388         { PT_GPR(3),            "r3"                                    },
2389         { PT_GPR(4),            "r4"                                    },
2390         { PT_GPR(5),            "r5"                                    },
2391         { PT_GPR(6),            "r6"                                    },
2392         { PT_GPR(7),            "r7"                                    },
2393         { PT_GPR(8),            "r8"                                    },
2394         { PT_GPR(9),            "r9"                                    },
2395         { PT_GPR(10),           "r10"                                   },
2396         { PT_GPR(11),           "r11"                                   },
2397         { PT_GPR(12),           "r12"                                   },
2398         { PT_GPR(13),           "r13"                                   },
2399         { PT_GPR(14),           "r14"                                   },
2400         { PT_GPR(15),           "r15"                                   },
2401         { PT_GPR(16),           "r16"                                   },
2402         { PT_GPR(17),           "r17"                                   },
2403         { PT_GPR(18),           "r18"                                   },
2404         { PT_GPR(19),           "r19"                                   },
2405         { PT_GPR(20),           "r20"                                   },
2406         { PT_GPR(21),           "r21"                                   },
2407         { PT_GPR(22),           "r22"                                   },
2408         { PT_GPR(23),           "r23"                                   },
2409         { PT_GPR(24),           "r24"                                   },
2410         { PT_GPR(25),           "r25"                                   },
2411         { PT_GPR(26),           "r26"                                   },
2412         { PT_GPR(27),           "r27"                                   },
2413         { PT_GPR(28),           "r28"                                   },
2414         { PT_GPR(29),           "r29"                                   },
2415         { PT_GPR(30),           "r30"                                   },
2416         { PT_GPR(31),           "r31"                                   },
2417         { PT_PC,                "rpc",                                  },
2418         { PT_MSR,               "rmsr",                                 },
2419         { PT_EAR,               "rear",                                 },
2420         { PT_ESR,               "resr",                                 },
2421         { PT_FSR,               "rfsr",                                 },
2422         { PT_KERNEL_MODE,       "kernel_mode",                          },
2423 #   endif
2424
2425 #   if !defined(SPARC) && !defined(HPPA) && !defined(POWERPC) \
2426                 && !defined(ALPHA) && !defined(IA64) \
2427                 && !defined(CRISV10) && !defined(CRISV32) && !defined(MICROBLAZE)
2428 #    if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SPARC64) && !defined(AVR32) && !defined(BFIN) && !defined(TILE)
2429         { uoff(u_fpvalid),      "offsetof(struct user, u_fpvalid)"      },
2430 #    endif
2431 #    if defined(I386) || defined(X86_64)
2432         { uoff(i387),           "offsetof(struct user, i387)"           },
2433 #    endif
2434 #    if defined(M68K)
2435         { uoff(m68kfp),         "offsetof(struct user, m68kfp)"         },
2436 #    endif
2437         { uoff(u_tsize),        "offsetof(struct user, u_tsize)"        },
2438         { uoff(u_dsize),        "offsetof(struct user, u_dsize)"        },
2439         { uoff(u_ssize),        "offsetof(struct user, u_ssize)"        },
2440 #    if !defined(SPARC64)
2441         { uoff(start_code),     "offsetof(struct user, start_code)"     },
2442 #    endif
2443 #    if defined(AVR32) || defined(SH64)
2444         { uoff(start_data),     "offsetof(struct user, start_data)"     },
2445 #    endif
2446 #    if !defined(SPARC64)
2447         { uoff(start_stack),    "offsetof(struct user, start_stack)"    },
2448 #    endif
2449         { uoff(signal),         "offsetof(struct user, signal)"         },
2450 #    if !defined(AVR32) && !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH) && !defined(SH64) && !defined(SPARC64) && !defined(TILE)
2451         { uoff(reserved),       "offsetof(struct user, reserved)"       },
2452 #    endif
2453 #    if !defined(SPARC64)
2454         { uoff(u_ar0),          "offsetof(struct user, u_ar0)"          },
2455 #    endif
2456 #    if !defined(ARM) && !defined(AVR32) && !defined(MIPS) && !defined(S390) && !defined(S390X) && !defined(SPARC64) && !defined(BFIN) && !defined(TILE)
2457         { uoff(u_fpstate),      "offsetof(struct user, u_fpstate)"      },
2458 #    endif
2459         { uoff(magic),          "offsetof(struct user, magic)"          },
2460         { uoff(u_comm),         "offsetof(struct user, u_comm)"         },
2461 #    if defined(I386) || defined(X86_64)
2462         { uoff(u_debugreg),     "offsetof(struct user, u_debugreg)"     },
2463 #    endif
2464 #   endif /* !defined(many arches) */
2465
2466
2467 #  ifndef HPPA
2468         { sizeof(struct user),  "sizeof(struct user)"                   },
2469 #  endif
2470         { 0,                    NULL                                    },
2471 };
2472
2473 int
2474 sys_ptrace(struct tcb *tcp)
2475 {
2476         const struct xlat *x;
2477         long addr;
2478
2479         if (entering(tcp)) {
2480                 printxval(ptrace_cmds, tcp->u_arg[0],
2481                           "PTRACE_???"
2482                         );
2483                 tprintf(", %lu, ", tcp->u_arg[1]);
2484                 addr = tcp->u_arg[2];
2485                 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2486                         || tcp->u_arg[0] == PTRACE_POKEUSER) {
2487                         for (x = struct_user_offsets; x->str; x++) {
2488                                 if (x->val >= addr)
2489                                         break;
2490                         }
2491                         if (!x->str)
2492                                 tprintf("%#lx, ", addr);
2493                         else if (x->val > addr && x != struct_user_offsets) {
2494                                 x--;
2495                                 tprintf("%s + %ld, ", x->str, addr - x->val);
2496                         }
2497                         else
2498                                 tprintf("%s, ", x->str);
2499                 }
2500                 else
2501                         tprintf("%#lx, ", tcp->u_arg[2]);
2502                 switch (tcp->u_arg[0]) {
2503 #  ifndef IA64
2504                 case PTRACE_PEEKDATA:
2505                 case PTRACE_PEEKTEXT:
2506                 case PTRACE_PEEKUSER:
2507                         break;
2508 #  endif
2509                 case PTRACE_CONT:
2510                 case PTRACE_SINGLESTEP:
2511                 case PTRACE_SYSCALL:
2512                 case PTRACE_DETACH:
2513                         printsignal(tcp->u_arg[3]);
2514                         break;
2515 #  ifdef PTRACE_SETOPTIONS
2516                 case PTRACE_SETOPTIONS:
2517                         printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???");
2518                         break;
2519 #  endif
2520 #  ifdef PTRACE_SETSIGINFO
2521                 case PTRACE_SETSIGINFO: {
2522                         siginfo_t si;
2523                         if (!tcp->u_arg[3])
2524                                 tprints("NULL");
2525                         else if (syserror(tcp))
2526                                 tprintf("%#lx", tcp->u_arg[3]);
2527                         else if (umove(tcp, tcp->u_arg[3], &si) < 0)
2528                                 tprints("{???}");
2529                         else
2530                                 printsiginfo(&si, verbose(tcp));
2531                         break;
2532                 }
2533 #  endif
2534 #  ifdef PTRACE_GETSIGINFO
2535                 case PTRACE_GETSIGINFO:
2536                         /* Don't print anything, do it at syscall return. */
2537                         break;
2538 #  endif
2539                 default:
2540                         tprintf("%#lx", tcp->u_arg[3]);
2541                         break;
2542                 }
2543         } else {
2544                 switch (tcp->u_arg[0]) {
2545                 case PTRACE_PEEKDATA:
2546                 case PTRACE_PEEKTEXT:
2547                 case PTRACE_PEEKUSER:
2548 #  ifdef IA64
2549                         return RVAL_HEX;
2550 #  else
2551                         printnum(tcp, tcp->u_arg[3], "%#lx");
2552                         break;
2553 #  endif
2554 #  ifdef PTRACE_GETSIGINFO
2555                 case PTRACE_GETSIGINFO: {
2556                         siginfo_t si;
2557                         if (!tcp->u_arg[3])
2558                                 tprints("NULL");
2559                         else if (syserror(tcp))
2560                                 tprintf("%#lx", tcp->u_arg[3]);
2561                         else if (umove(tcp, tcp->u_arg[3], &si) < 0)
2562                                 tprints("{???}");
2563                         else
2564                                 printsiginfo(&si, verbose(tcp));
2565                         break;
2566                 }
2567 #  endif
2568                 }
2569         }
2570         return 0;
2571 }
2572
2573
2574 # ifndef FUTEX_CMP_REQUEUE
2575 #  define FUTEX_CMP_REQUEUE 4
2576 # endif
2577 # ifndef FUTEX_WAKE_OP
2578 #  define FUTEX_WAKE_OP 5
2579 # endif
2580 # ifndef FUTEX_LOCK_PI
2581 #  define FUTEX_LOCK_PI 6
2582 #  define FUTEX_UNLOCK_PI 7
2583 #  define FUTEX_TRYLOCK_PI 8
2584 # endif
2585 # ifndef FUTEX_WAIT_BITSET
2586 #  define FUTEX_WAIT_BITSET 9
2587 # endif
2588 # ifndef FUTEX_WAKE_BITSET
2589 #  define FUTEX_WAKE_BITSET 10
2590 # endif
2591 # ifndef FUTEX_WAIT_REQUEUE_PI
2592 #  define FUTEX_WAIT_REQUEUE_PI 11
2593 # endif
2594 # ifndef FUTEX_CMP_REQUEUE_PI
2595 #  define FUTEX_CMP_REQUEUE_PI 12
2596 # endif
2597 # ifndef FUTEX_PRIVATE_FLAG
2598 #  define FUTEX_PRIVATE_FLAG 128
2599 # endif
2600 # ifndef FUTEX_CLOCK_REALTIME
2601 #  define FUTEX_CLOCK_REALTIME 256
2602 # endif
2603 static const struct xlat futexops[] = {
2604         { FUTEX_WAIT,                                   "FUTEX_WAIT" },
2605         { FUTEX_WAKE,                                   "FUTEX_WAKE" },
2606         { FUTEX_FD,                                     "FUTEX_FD" },
2607         { FUTEX_REQUEUE,                                "FUTEX_REQUEUE" },
2608         { FUTEX_CMP_REQUEUE,                            "FUTEX_CMP_REQUEUE" },
2609         { FUTEX_WAKE_OP,                                "FUTEX_WAKE_OP" },
2610         { FUTEX_LOCK_PI,                                "FUTEX_LOCK_PI" },
2611         { FUTEX_UNLOCK_PI,                              "FUTEX_UNLOCK_PI" },
2612         { FUTEX_TRYLOCK_PI,                             "FUTEX_TRYLOCK_PI" },
2613         { FUTEX_WAIT_BITSET,                            "FUTEX_WAIT_BITSET" },
2614         { FUTEX_WAKE_BITSET,                            "FUTEX_WAKE_BITSET" },
2615         { FUTEX_WAIT_REQUEUE_PI,                        "FUTEX_WAIT_REQUEUE_PI" },
2616         { FUTEX_CMP_REQUEUE_PI,                         "FUTEX_CMP_REQUEUE_PI" },
2617         { FUTEX_WAIT|FUTEX_PRIVATE_FLAG,                "FUTEX_WAIT_PRIVATE" },
2618         { FUTEX_WAKE|FUTEX_PRIVATE_FLAG,                "FUTEX_WAKE_PRIVATE" },
2619         { FUTEX_FD|FUTEX_PRIVATE_FLAG,                  "FUTEX_FD_PRIVATE" },
2620         { FUTEX_REQUEUE|FUTEX_PRIVATE_FLAG,             "FUTEX_REQUEUE_PRIVATE" },
2621         { FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG,         "FUTEX_CMP_REQUEUE_PRIVATE" },
2622         { FUTEX_WAKE_OP|FUTEX_PRIVATE_FLAG,             "FUTEX_WAKE_OP_PRIVATE" },
2623         { FUTEX_LOCK_PI|FUTEX_PRIVATE_FLAG,             "FUTEX_LOCK_PI_PRIVATE" },
2624         { FUTEX_UNLOCK_PI|FUTEX_PRIVATE_FLAG,           "FUTEX_UNLOCK_PI_PRIVATE" },
2625         { FUTEX_TRYLOCK_PI|FUTEX_PRIVATE_FLAG,          "FUTEX_TRYLOCK_PI_PRIVATE" },
2626         { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG,         "FUTEX_WAIT_BITSET_PRIVATE" },
2627         { FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG,         "FUTEX_WAKE_BITSET_PRIVATE" },
2628         { FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG,     "FUTEX_WAIT_REQUEUE_PI_PRIVATE" },
2629         { FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG,      "FUTEX_CMP_REQUEUE_PI_PRIVATE" },
2630         { FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME,       "FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME" },
2631         { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME,    "FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME" },
2632         { FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME,   "FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME" },
2633         { FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME,        "FUTEX_WAIT_REQUEUE_PI_PRIVATE|FUTEX_CLOCK_REALTIME" },
2634         { 0,                                            NULL }
2635 };
2636 # ifndef FUTEX_OP_SET
2637 #  define FUTEX_OP_SET          0
2638 #  define FUTEX_OP_ADD          1
2639 #  define FUTEX_OP_OR           2
2640 #  define FUTEX_OP_ANDN         3
2641 #  define FUTEX_OP_XOR          4
2642 #  define FUTEX_OP_CMP_EQ       0
2643 #  define FUTEX_OP_CMP_NE       1
2644 #  define FUTEX_OP_CMP_LT       2
2645 #  define FUTEX_OP_CMP_LE       3
2646 #  define FUTEX_OP_CMP_GT       4
2647 #  define FUTEX_OP_CMP_GE       5
2648 # endif
2649 static const struct xlat futexwakeops[] = {
2650         { FUTEX_OP_SET,         "FUTEX_OP_SET" },
2651         { FUTEX_OP_ADD,         "FUTEX_OP_ADD" },
2652         { FUTEX_OP_OR,          "FUTEX_OP_OR" },
2653         { FUTEX_OP_ANDN,        "FUTEX_OP_ANDN" },
2654         { FUTEX_OP_XOR,         "FUTEX_OP_XOR" },
2655         { 0,                    NULL }
2656 };
2657 static const struct xlat futexwakecmps[] = {
2658         { FUTEX_OP_CMP_EQ,      "FUTEX_OP_CMP_EQ" },
2659         { FUTEX_OP_CMP_NE,      "FUTEX_OP_CMP_NE" },
2660         { FUTEX_OP_CMP_LT,      "FUTEX_OP_CMP_LT" },
2661         { FUTEX_OP_CMP_LE,      "FUTEX_OP_CMP_LE" },
2662         { FUTEX_OP_CMP_GT,      "FUTEX_OP_CMP_GT" },
2663         { FUTEX_OP_CMP_GE,      "FUTEX_OP_CMP_GE" },
2664         { 0,                    NULL }
2665 };
2666
2667 int
2668 sys_futex(struct tcb *tcp)
2669 {
2670         if (entering(tcp)) {
2671                 long int cmd = tcp->u_arg[1] & 127;
2672                 tprintf("%p, ", (void *) tcp->u_arg[0]);
2673                 printxval(futexops, tcp->u_arg[1], "FUTEX_???");
2674                 tprintf(", %ld", tcp->u_arg[2]);
2675                 if (cmd == FUTEX_WAKE_BITSET)
2676                         tprintf(", %lx", tcp->u_arg[5]);
2677                 else if (cmd == FUTEX_WAIT) {
2678                         tprints(", ");
2679                         printtv(tcp, tcp->u_arg[3]);
2680                 } else if (cmd == FUTEX_WAIT_BITSET) {
2681                         tprints(", ");
2682                         printtv(tcp, tcp->u_arg[3]);
2683                         tprintf(", %lx", tcp->u_arg[5]);
2684                 } else if (cmd == FUTEX_REQUEUE)
2685                         tprintf(", %ld, %p", tcp->u_arg[3], (void *) tcp->u_arg[4]);
2686                 else if (cmd == FUTEX_CMP_REQUEUE || cmd == FUTEX_CMP_REQUEUE_PI)
2687                         tprintf(", %ld, %p, %ld", tcp->u_arg[3], (void *) tcp->u_arg[4], tcp->u_arg[5]);
2688                 else if (cmd == FUTEX_WAKE_OP) {
2689                         tprintf(", %ld, %p, {", tcp->u_arg[3], (void *) tcp->u_arg[4]);
2690                         if ((tcp->u_arg[5] >> 28) & 8)
2691                                 tprints("FUTEX_OP_OPARG_SHIFT|");
2692                         printxval(futexwakeops, (tcp->u_arg[5] >> 28) & 0x7, "FUTEX_OP_???");
2693                         tprintf(", %ld, ", (tcp->u_arg[5] >> 12) & 0xfff);
2694                         if ((tcp->u_arg[5] >> 24) & 8)
2695                                 tprints("FUTEX_OP_OPARG_SHIFT|");
2696                         printxval(futexwakecmps, (tcp->u_arg[5] >> 24) & 0x7, "FUTEX_OP_CMP_???");
2697                         tprintf(", %ld}", tcp->u_arg[5] & 0xfff);
2698                 } else if (cmd == FUTEX_WAIT_REQUEUE_PI) {
2699                         tprints(", ");
2700                         printtv(tcp, tcp->u_arg[3]);
2701                         tprintf(", %p", (void *) tcp->u_arg[4]);
2702                 }
2703         }
2704         return 0;
2705 }
2706
2707 static void
2708 print_affinitylist(struct tcb *tcp, long list, unsigned int len)
2709 {
2710         int first = 1;
2711         unsigned long w, min_len;
2712
2713         if (abbrev(tcp) && len / sizeof(w) > max_strlen)
2714                 min_len = len - max_strlen * sizeof(w);
2715         else
2716                 min_len = 0;
2717         for (; len >= sizeof(w) && len > min_len;
2718              len -= sizeof(w), list += sizeof(w)) {
2719                 if (umove(tcp, list, &w) < 0)
2720                         break;
2721                 if (first)
2722                         tprints("{");
2723                 else
2724                         tprints(", ");
2725                 first = 0;
2726                 tprintf("%lx", w);
2727         }
2728         if (len) {
2729                 if (first)
2730                         tprintf("%#lx", list);
2731                 else
2732                         tprintf(", %s}", (len >= sizeof(w) && len > min_len ?
2733                                 "???" : "..."));
2734         } else {
2735                 tprints(first ? "{}" : "}");
2736         }
2737 }
2738
2739 int
2740 sys_sched_setaffinity(struct tcb *tcp)
2741 {
2742         if (entering(tcp)) {
2743                 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2744                 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2745         }
2746         return 0;
2747 }
2748
2749 int
2750 sys_sched_getaffinity(struct tcb *tcp)
2751 {
2752         if (entering(tcp)) {
2753                 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2754         } else {
2755                 if (tcp->u_rval == -1)
2756                         tprintf("%#lx", tcp->u_arg[2]);
2757                 else
2758                         print_affinitylist(tcp, tcp->u_arg[2], tcp->u_rval);
2759         }
2760         return 0;
2761 }
2762
2763 static const struct xlat schedulers[] = {
2764         { SCHED_OTHER,  "SCHED_OTHER" },
2765         { SCHED_RR,     "SCHED_RR" },
2766         { SCHED_FIFO,   "SCHED_FIFO" },
2767         { 0,            NULL }
2768 };
2769
2770 int
2771 sys_sched_getscheduler(struct tcb *tcp)
2772 {
2773         if (entering(tcp)) {
2774                 tprintf("%d", (int) tcp->u_arg[0]);
2775         } else if (! syserror(tcp)) {
2776                 tcp->auxstr = xlookup(schedulers, tcp->u_rval);
2777                 if (tcp->auxstr != NULL)
2778                         return RVAL_STR;
2779         }
2780         return 0;
2781 }
2782
2783 int
2784 sys_sched_setscheduler(struct tcb *tcp)
2785 {
2786         if (entering(tcp)) {
2787                 struct sched_param p;
2788                 tprintf("%d, ", (int) tcp->u_arg[0]);
2789                 printxval(schedulers, tcp->u_arg[1], "SCHED_???");
2790                 if (umove(tcp, tcp->u_arg[2], &p) < 0)
2791                         tprintf(", %#lx", tcp->u_arg[2]);
2792                 else
2793                         tprintf(", { %d }", p.__sched_priority);
2794         }
2795         return 0;
2796 }
2797
2798 int
2799 sys_sched_getparam(struct tcb *tcp)
2800 {
2801         if (entering(tcp)) {
2802                 tprintf("%d, ", (int) tcp->u_arg[0]);
2803         } else {
2804                 struct sched_param p;
2805                 if (umove(tcp, tcp->u_arg[1], &p) < 0)
2806                         tprintf("%#lx", tcp->u_arg[1]);
2807                 else
2808                         tprintf("{ %d }", p.__sched_priority);
2809         }
2810         return 0;
2811 }
2812
2813 int
2814 sys_sched_setparam(struct tcb *tcp)
2815 {
2816         if (entering(tcp)) {
2817                 struct sched_param p;
2818                 if (umove(tcp, tcp->u_arg[1], &p) < 0)
2819                         tprintf("%d, %#lx", (int) tcp->u_arg[0], tcp->u_arg[1]);
2820                 else
2821                         tprintf("%d, { %d }", (int) tcp->u_arg[0], p.__sched_priority);
2822         }
2823         return 0;
2824 }
2825
2826 int
2827 sys_sched_get_priority_min(struct tcb *tcp)
2828 {
2829         if (entering(tcp)) {
2830                 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
2831         }
2832         return 0;
2833 }
2834
2835 # ifdef X86_64
2836 # include <asm/prctl.h>
2837
2838 static const struct xlat archvals[] = {
2839         { ARCH_SET_GS,          "ARCH_SET_GS"           },
2840         { ARCH_SET_FS,          "ARCH_SET_FS"           },
2841         { ARCH_GET_FS,          "ARCH_GET_FS"           },
2842         { ARCH_GET_GS,          "ARCH_GET_GS"           },
2843         { 0,                    NULL                    },
2844 };
2845
2846 int
2847 sys_arch_prctl(struct tcb *tcp)
2848 {
2849         if (entering(tcp)) {
2850                 printxval(archvals, tcp->u_arg[0], "ARCH_???");
2851                 if (tcp->u_arg[0] == ARCH_SET_GS
2852                  || tcp->u_arg[0] == ARCH_SET_FS
2853                 ) {
2854                         tprintf(", %#lx", tcp->u_arg[1]);
2855                 }
2856         } else {
2857                 if (tcp->u_arg[0] == ARCH_GET_GS
2858                  || tcp->u_arg[0] == ARCH_GET_FS
2859                 ) {
2860                         long int v;
2861                         if (!syserror(tcp) && umove(tcp, tcp->u_arg[1], &v) != -1)
2862                                 tprintf(", [%#lx]", v);
2863                         else
2864                                 tprintf(", %#lx", tcp->u_arg[1]);
2865                 }
2866         }
2867         return 0;
2868 }
2869 # endif /* X86_64 */
2870
2871
2872 int
2873 sys_getcpu(struct tcb *tcp)
2874 {
2875         if (exiting(tcp)) {
2876                 unsigned u;
2877                 if (tcp->u_arg[0] == 0)
2878                         tprints("NULL, ");
2879                 else if (umove(tcp, tcp->u_arg[0], &u) < 0)
2880                         tprintf("%#lx, ", tcp->u_arg[0]);
2881                 else
2882                         tprintf("[%u], ", u);
2883                 if (tcp->u_arg[1] == 0)
2884                         tprints("NULL, ");
2885                 else if (umove(tcp, tcp->u_arg[1], &u) < 0)
2886                         tprintf("%#lx, ", tcp->u_arg[1]);
2887                 else
2888                         tprintf("[%u], ", u);
2889                 tprintf("%#lx", tcp->u_arg[2]);
2890         }
2891         return 0;
2892 }
2893
2894 int
2895 sys_process_vm_readv(struct tcb *tcp)
2896 {
2897         if (entering(tcp)) {
2898                 /* arg 1: pid */
2899                 tprintf("%ld, ", tcp->u_arg[0]);
2900         } else {
2901                 /* args 2,3: local iov,cnt */
2902                 if (syserror(tcp)) {
2903                         tprintf("%#lx, %lu",
2904                                         tcp->u_arg[1], tcp->u_arg[2]);
2905                 } else {
2906                         tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
2907                 }
2908                 tprints(", ");
2909                 /* args 4,5: remote iov,cnt */
2910                 if (syserror(tcp)) {
2911                         tprintf("%#lx, %lu", tcp->u_arg[3], tcp->u_arg[4]);
2912                 } else {
2913                         tprint_iov(tcp, tcp->u_arg[4], tcp->u_arg[3], 0);
2914                 }
2915                 /* arg 6: flags */
2916                 tprintf(", %lu", tcp->u_arg[5]);
2917         }
2918         return 0;
2919 }