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