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