blob: d44796312063b5b8d141758581cd74721c09efe6 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Linux for s390 port by D.J. Barrow
8 * <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com>
Wichert Akkermanccef6372002-05-01 16:39:22 +00009 * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
10 * port by Greg Banks <gbanks@pocketpenguins.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +000011 *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000012 * 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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035 */
36
37#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000038#include <fcntl.h>
39#include <sys/stat.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040#include <sys/wait.h>
41#include <sys/resource.h>
42#include <sys/utsname.h>
43#include <sys/user.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000044
Wichert Akkerman36915a11999-07-13 15:45:02 +000045#ifdef HAVE_SYS_REG_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046# include <sys/reg.h>
Denys Vlasenko84703742012-02-25 02:38:52 +010047# ifndef PTRACE_PEEKUSR
48# define PTRACE_PEEKUSR PTRACE_PEEKUSER
49# endif
50# ifndef PTRACE_POKEUSR
51# define PTRACE_POKEUSR PTRACE_POKEUSER
52# endif
Wichert Akkerman15dea971999-10-06 13:06:34 +000053#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054
Roland McGrath5bd7cf82003-01-24 04:31:18 +000055#ifdef HAVE_LINUX_PTRACE_H
Denys Vlasenko84703742012-02-25 02:38:52 +010056# undef PTRACE_SYSCALL
Roland McGrathfb1bc072004-03-01 21:29:24 +000057# ifdef HAVE_STRUCT_IA64_FPREG
58# define ia64_fpreg XXX_ia64_fpreg
59# endif
60# ifdef HAVE_STRUCT_PT_ALL_USER_REGS
61# define pt_all_user_regs XXX_pt_all_user_regs
62# endif
Denys Vlasenko84703742012-02-25 02:38:52 +010063# include <linux/ptrace.h>
Roland McGrathfb1bc072004-03-01 21:29:24 +000064# undef ia64_fpreg
65# undef pt_all_user_regs
Roland McGrath5bd7cf82003-01-24 04:31:18 +000066#endif
67
Denys Vlasenko84703742012-02-25 02:38:52 +010068#if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000069# define r_pc r_tpc
70# undef PTRACE_GETREGS
71# define PTRACE_GETREGS PTRACE_GETREGS64
72# undef PTRACE_SETREGS
73# define PTRACE_SETREGS PTRACE_SETREGS64
Denys Vlasenko84703742012-02-25 02:38:52 +010074#endif
Roland McGrath6d1a65c2004-07-12 07:44:08 +000075
Roland McGrath5a223472002-12-15 23:58:26 +000076#ifdef HAVE_LINUX_FUTEX_H
Dmitry V. Levine5e60852009-12-31 22:50:49 +000077# include <linux/futex.h>
Roland McGrath5a223472002-12-15 23:58:26 +000078#endif
Denys Vlasenko84703742012-02-25 02:38:52 +010079#ifndef FUTEX_WAIT
80# define FUTEX_WAIT 0
81#endif
82#ifndef FUTEX_WAKE
83# define FUTEX_WAKE 1
84#endif
85#ifndef FUTEX_FD
86# define FUTEX_FD 2
87#endif
88#ifndef FUTEX_REQUEUE
89# define FUTEX_REQUEUE 3
90#endif
Wichert Akkermanfaf72222000-02-19 23:59:03 +000091
Roland McGrath279d3782004-03-01 20:27:37 +000092#include <sched.h>
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000093#include <asm/posix_types.h>
94#undef GETGROUPS_T
95#define GETGROUPS_T __kernel_gid_t
Roland McGrath83bd47a2003-11-13 22:32:26 +000096#undef GETGROUPS32_T
97#define GETGROUPS32_T __kernel_gid32_t
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000098
Denys Vlasenko84703742012-02-25 02:38:52 +010099#if defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000100# include <asm/ptrace_offsets.h>
101# include <asm/rse.h>
102#endif
103
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000104#ifdef HAVE_PRCTL
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000105# include <sys/prctl.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000106
Roland McGrathd9f816f2004-09-04 03:39:20 +0000107static const struct xlat prctl_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000108#ifdef PR_MAXPROCS
109 { PR_MAXPROCS, "PR_MAXPROCS" },
110#endif
111#ifdef PR_ISBLOCKED
112 { PR_ISBLOCKED, "PR_ISBLOCKED" },
113#endif
114#ifdef PR_SETSTACKSIZE
115 { PR_SETSTACKSIZE, "PR_SETSTACKSIZE" },
116#endif
117#ifdef PR_GETSTACKSIZE
118 { PR_GETSTACKSIZE, "PR_GETSTACKSIZE" },
119#endif
120#ifdef PR_MAXPPROCS
121 { PR_MAXPPROCS, "PR_MAXPPROCS" },
122#endif
123#ifdef PR_UNBLKONEXEC
124 { PR_UNBLKONEXEC, "PR_UNBLKONEXEC" },
125#endif
126#ifdef PR_ATOMICSIM
127 { PR_ATOMICSIM, "PR_ATOMICSIM" },
128#endif
129#ifdef PR_SETEXITSIG
130 { PR_SETEXITSIG, "PR_SETEXITSIG" },
131#endif
132#ifdef PR_RESIDENT
133 { PR_RESIDENT, "PR_RESIDENT" },
134#endif
135#ifdef PR_ATTACHADDR
136 { PR_ATTACHADDR, "PR_ATTACHADDR" },
137#endif
138#ifdef PR_DETACHADDR
139 { PR_DETACHADDR, "PR_DETACHADDR" },
140#endif
141#ifdef PR_TERMCHILD
142 { PR_TERMCHILD, "PR_TERMCHILD" },
143#endif
144#ifdef PR_GETSHMASK
145 { PR_GETSHMASK, "PR_GETSHMASK" },
146#endif
147#ifdef PR_GETNSHARE
148 { PR_GETNSHARE, "PR_GETNSHARE" },
149#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000150#ifdef PR_COREPID
151 { PR_COREPID, "PR_COREPID" },
152#endif
153#ifdef PR_ATTACHADDRPERM
154 { PR_ATTACHADDRPERM, "PR_ATTACHADDRPERM" },
155#endif
156#ifdef PR_PTHREADEXIT
157 { PR_PTHREADEXIT, "PR_PTHREADEXIT" },
158#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000159#ifdef PR_SET_PDEATHSIG
160 { PR_SET_PDEATHSIG, "PR_SET_PDEATHSIG" },
161#endif
162#ifdef PR_GET_PDEATHSIG
163 { PR_GET_PDEATHSIG, "PR_GET_PDEATHSIG" },
164#endif
Dmitry V. Levinf02cf212008-09-03 00:54:40 +0000165#ifdef PR_GET_DUMPABLE
166 { PR_GET_DUMPABLE, "PR_GET_DUMPABLE" },
167#endif
168#ifdef PR_SET_DUMPABLE
169 { PR_SET_DUMPABLE, "PR_SET_DUMPABLE" },
170#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000171#ifdef PR_GET_UNALIGN
172 { PR_GET_UNALIGN, "PR_GET_UNALIGN" },
173#endif
174#ifdef PR_SET_UNALIGN
175 { PR_SET_UNALIGN, "PR_SET_UNALIGN" },
176#endif
177#ifdef PR_GET_KEEPCAPS
Dmitry V. Levin8dd31dd2008-11-11 00:25:22 +0000178 { PR_GET_KEEPCAPS, "PR_GET_KEEPCAPS" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000179#endif
180#ifdef PR_SET_KEEPCAPS
Dmitry V. Levin8dd31dd2008-11-11 00:25:22 +0000181 { PR_SET_KEEPCAPS, "PR_SET_KEEPCAPS" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000182#endif
Roland McGrathe5039fb2007-11-03 23:58:07 +0000183#ifdef PR_GET_FPEMU
184 { PR_GET_FPEMU, "PR_GET_FPEMU" },
185#endif
186#ifdef PR_SET_FPEMU
187 { PR_SET_FPEMU, "PR_SET_FPEMU" },
188#endif
189#ifdef PR_GET_FPEXC
190 { PR_GET_FPEXC, "PR_GET_FPEXC" },
191#endif
192#ifdef PR_SET_FPEXC
193 { PR_SET_FPEXC, "PR_SET_FPEXC" },
194#endif
195#ifdef PR_GET_TIMING
196 { PR_GET_TIMING, "PR_GET_TIMING" },
197#endif
198#ifdef PR_SET_TIMING
199 { PR_SET_TIMING, "PR_SET_TIMING" },
200#endif
201#ifdef PR_SET_NAME
202 { PR_SET_NAME, "PR_SET_NAME" },
203#endif
204#ifdef PR_GET_NAME
205 { PR_GET_NAME, "PR_GET_NAME" },
206#endif
207#ifdef PR_GET_ENDIAN
208 { PR_GET_ENDIAN, "PR_GET_ENDIAN" },
209#endif
210#ifdef PR_SET_ENDIAN
211 { PR_SET_ENDIAN, "PR_SET_ENDIAN" },
212#endif
213#ifdef PR_GET_SECCOMP
214 { PR_GET_SECCOMP, "PR_GET_SECCOMP" },
215#endif
216#ifdef PR_SET_SECCOMP
217 { PR_SET_SECCOMP, "PR_SET_SECCOMP" },
218#endif
Dmitry V. Levin8dd31dd2008-11-11 00:25:22 +0000219#ifdef PR_GET_TSC
220 { PR_GET_TSC, "PR_GET_TSC" },
221#endif
222#ifdef PR_SET_TSC
223 { PR_SET_TSC, "PR_SET_TSC" },
224#endif
225#ifdef PR_GET_SECUREBITS
226 { PR_GET_SECUREBITS, "PR_GET_SECUREBITS" },
227#endif
228#ifdef PR_SET_SECUREBITS
229 { PR_SET_SECUREBITS, "PR_SET_SECUREBITS" },
230#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000231 { 0, NULL },
232};
233
Roland McGratha4d48532005-06-08 20:45:28 +0000234static const char *
Denys Vlasenko12014262011-05-30 14:00:14 +0200235unalignctl_string(unsigned int ctl)
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000236{
Denys Vlasenkob237b1b2012-02-27 13:56:59 +0100237 static char buf[sizeof(int)*2 + 2];
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000238
239 switch (ctl) {
240#ifdef PR_UNALIGN_NOPRINT
Denys Vlasenkob237b1b2012-02-27 13:56:59 +0100241 case PR_UNALIGN_NOPRINT:
242 return "NOPRINT";
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000243#endif
244#ifdef PR_UNALIGN_SIGBUS
Denys Vlasenkob237b1b2012-02-27 13:56:59 +0100245 case PR_UNALIGN_SIGBUS:
246 return "SIGBUS";
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000247#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +0100248 default:
249 break;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000250 }
251 sprintf(buf, "%x", ctl);
252 return buf;
253}
254
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255int
Denys Vlasenko12014262011-05-30 14:00:14 +0200256sys_prctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000257{
258 int i;
259
260 if (entering(tcp)) {
261 printxval(prctl_options, tcp->u_arg[0], "PR_???");
262 switch (tcp->u_arg[0]) {
263#ifdef PR_GETNSHARE
264 case PR_GETNSHARE:
265 break;
266#endif
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000267#ifdef PR_SET_PDEATHSIG
268 case PR_SET_PDEATHSIG:
269 tprintf(", %lu", tcp->u_arg[1]);
270 break;
271#endif
272#ifdef PR_GET_PDEATHSIG
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000273 case PR_GET_PDEATHSIG:
274 break;
275#endif
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000276#ifdef PR_SET_DUMPABLE
277 case PR_SET_DUMPABLE:
278 tprintf(", %lu", tcp->u_arg[1]);
279 break;
280#endif
281#ifdef PR_GET_DUMPABLE
282 case PR_GET_DUMPABLE:
283 break;
284#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000285#ifdef PR_SET_UNALIGN
286 case PR_SET_UNALIGN:
287 tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
288 break;
289#endif
290#ifdef PR_GET_UNALIGN
291 case PR_GET_UNALIGN:
292 tprintf(", %#lx", tcp->u_arg[1]);
293 break;
294#endif
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000295#ifdef PR_SET_KEEPCAPS
296 case PR_SET_KEEPCAPS:
297 tprintf(", %lu", tcp->u_arg[1]);
298 break;
299#endif
300#ifdef PR_GET_KEEPCAPS
301 case PR_GET_KEEPCAPS:
302 break;
303#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000304 default:
305 for (i = 1; i < tcp->u_nargs; i++)
306 tprintf(", %#lx", tcp->u_arg[i]);
307 break;
308 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000309 } else {
310 switch (tcp->u_arg[0]) {
311#ifdef PR_GET_PDEATHSIG
312 case PR_GET_PDEATHSIG:
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000313 if (umove(tcp, tcp->u_arg[1], &i) < 0)
314 tprintf(", %#lx", tcp->u_arg[1]);
315 else
316 tprintf(", {%u}", i);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000317 break;
318#endif
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000319#ifdef PR_GET_DUMPABLE
320 case PR_GET_DUMPABLE:
321 return RVAL_UDECIMAL;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000322#endif
323#ifdef PR_GET_UNALIGN
324 case PR_GET_UNALIGN:
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000325 if (syserror(tcp) || umove(tcp, tcp->u_arg[1], &i) < 0)
326 break;
327 tcp->auxstr = unalignctl_string(i);
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000328 return RVAL_STR;
Dmitry V. Levin50f60132008-09-03 00:56:52 +0000329#endif
330#ifdef PR_GET_KEEPCAPS
331 case PR_GET_KEEPCAPS:
332 return RVAL_UDECIMAL;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000333#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000334 default:
335 break;
336 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000337 }
338 return 0;
339}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000340#endif /* HAVE_PRCTL */
341
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000342int
Denys Vlasenko12014262011-05-30 14:00:14 +0200343sys_sethostname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344{
345 if (entering(tcp)) {
346 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
347 tprintf(", %lu", tcp->u_arg[1]);
348 }
349 return 0;
350}
351
Denys Vlasenko84703742012-02-25 02:38:52 +0100352#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000353int
Denys Vlasenko12014262011-05-30 14:00:14 +0200354sys_gethostname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000355{
356 if (exiting(tcp)) {
357 if (syserror(tcp))
358 tprintf("%#lx", tcp->u_arg[0]);
359 else
360 printpath(tcp, tcp->u_arg[0]);
361 tprintf(", %lu", tcp->u_arg[1]);
362 }
363 return 0;
364}
Denys Vlasenko84703742012-02-25 02:38:52 +0100365#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366
367int
Denys Vlasenko12014262011-05-30 14:00:14 +0200368sys_setdomainname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369{
370 if (entering(tcp)) {
371 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
372 tprintf(", %lu", tcp->u_arg[1]);
373 }
374 return 0;
375}
376
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000377int
Denys Vlasenko12014262011-05-30 14:00:14 +0200378sys_exit(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000379{
380 if (exiting(tcp)) {
381 fprintf(stderr, "_exit returned!\n");
382 return -1;
383 }
384 /* special case: we stop tracing this process, finish line now */
385 tprintf("%ld) ", tcp->u_arg[0]);
Denys Vlasenko102ec492011-08-25 01:27:59 +0200386 tabto();
Denys Vlasenko000b6012012-01-28 01:25:03 +0100387 tprints("= ?\n");
Denys Vlasenko7de265d2012-03-13 11:44:31 +0100388 line_ended();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000389 return 0;
390}
391
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000392/* defines copied from linux/sched.h since we can't include that
393 * ourselves (it conflicts with *lots* of libc includes)
394 */
395#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
396#define CLONE_VM 0x00000100 /* set if VM shared between processes */
397#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
398#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
399#define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
Roland McGrath909875b2002-12-22 03:34:36 +0000400#define CLONE_IDLETASK 0x00001000 /* kernel-only flag */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000401#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
402#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
403#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
Roland McGrath909875b2002-12-22 03:34:36 +0000404#define CLONE_THREAD 0x00010000 /* Same thread group? */
405#define CLONE_NEWNS 0x00020000 /* New namespace group? */
406#define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */
407#define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */
408#define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */
409#define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */
Roland McGrath909875b2002-12-22 03:34:36 +0000410#define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */
411#define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */
Dmitry V. Levine3d4b682010-12-03 17:19:51 +0000412#define CLONE_STOPPED 0x02000000 /* Start in stopped state */
413#define CLONE_NEWUTS 0x04000000 /* New utsname group? */
414#define CLONE_NEWIPC 0x08000000 /* New ipcs */
415#define CLONE_NEWUSER 0x10000000 /* New user namespace */
416#define CLONE_NEWPID 0x20000000 /* New pid namespace */
417#define CLONE_NEWNET 0x40000000 /* New network namespace */
418#define CLONE_IO 0x80000000 /* Clone io context */
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000419
Roland McGrathd9f816f2004-09-04 03:39:20 +0000420static const struct xlat clone_flags[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100421 { CLONE_VM, "CLONE_VM" },
422 { CLONE_FS, "CLONE_FS" },
423 { CLONE_FILES, "CLONE_FILES" },
424 { CLONE_SIGHAND, "CLONE_SIGHAND" },
425 { CLONE_IDLETASK, "CLONE_IDLETASK" },
426 { CLONE_PTRACE, "CLONE_PTRACE" },
427 { CLONE_VFORK, "CLONE_VFORK" },
428 { CLONE_PARENT, "CLONE_PARENT" },
429 { CLONE_THREAD, "CLONE_THREAD" },
430 { CLONE_NEWNS, "CLONE_NEWNS" },
431 { CLONE_SYSVSEM, "CLONE_SYSVSEM" },
432 { CLONE_SETTLS, "CLONE_SETTLS" },
433 { CLONE_PARENT_SETTID, "CLONE_PARENT_SETTID" },
434 { CLONE_CHILD_CLEARTID, "CLONE_CHILD_CLEARTID" },
435 { CLONE_UNTRACED, "CLONE_UNTRACED" },
436 { CLONE_CHILD_SETTID, "CLONE_CHILD_SETTID" },
437 { CLONE_STOPPED, "CLONE_STOPPED" },
438 { CLONE_NEWUTS, "CLONE_NEWUTS" },
439 { CLONE_NEWIPC, "CLONE_NEWIPC" },
440 { CLONE_NEWUSER, "CLONE_NEWUSER" },
441 { CLONE_NEWPID, "CLONE_NEWPID" },
442 { CLONE_NEWNET, "CLONE_NEWNET" },
443 { CLONE_IO, "CLONE_IO" },
444 { 0, NULL },
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000445};
446
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100447#ifdef I386
448# include <asm/ldt.h>
449# ifdef HAVE_STRUCT_USER_DESC
450# define modify_ldt_ldt_s user_desc
451# endif
Roland McGrath909875b2002-12-22 03:34:36 +0000452extern void print_ldt_entry();
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100453#endif
Roland McGrath909875b2002-12-22 03:34:36 +0000454
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100455#if defined IA64
456# define ARG_FLAGS 0
457# define ARG_STACK 1
458# define ARG_STACKSIZE (tcp->scno == SYS_clone2 ? 2 : -1)
459# define ARG_PTID (tcp->scno == SYS_clone2 ? 3 : 2)
460# define ARG_CTID (tcp->scno == SYS_clone2 ? 4 : 3)
461# define ARG_TLS (tcp->scno == SYS_clone2 ? 5 : 4)
462#elif defined S390 || defined S390X || defined CRISV10 || defined CRISV32
463# define ARG_STACK 0
464# define ARG_FLAGS 1
465# define ARG_PTID 2
466# define ARG_CTID 3
467# define ARG_TLS 4
468#elif defined X86_64 || defined ALPHA
469# define ARG_FLAGS 0
470# define ARG_STACK 1
471# define ARG_PTID 2
472# define ARG_CTID 3
473# define ARG_TLS 4
474#else
475# define ARG_FLAGS 0
476# define ARG_STACK 1
477# define ARG_PTID 2
478# define ARG_TLS 3
479# define ARG_CTID 4
480#endif
Roland McGrath9677b3a2003-03-12 09:54:36 +0000481
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000482int
Denys Vlasenko12014262011-05-30 14:00:14 +0200483sys_clone(struct tcb *tcp)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000484{
485 if (exiting(tcp)) {
Wang Chaocbdd1902010-09-02 15:08:59 +0800486 const char *sep = "|";
Roland McGrath9677b3a2003-03-12 09:54:36 +0000487 unsigned long flags = tcp->u_arg[ARG_FLAGS];
488 tprintf("child_stack=%#lx, ", tcp->u_arg[ARG_STACK]);
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100489#ifdef ARG_STACKSIZE
Roland McGrath9677b3a2003-03-12 09:54:36 +0000490 if (ARG_STACKSIZE != -1)
491 tprintf("stack_size=%#lx, ",
492 tcp->u_arg[ARG_STACKSIZE]);
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100493#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200494 tprints("flags=");
Wang Chaocbdd1902010-09-02 15:08:59 +0800495 if (!printflags(clone_flags, flags &~ CSIGNAL, NULL))
496 sep = "";
Roland McGrath984154d2003-05-23 01:08:42 +0000497 if ((flags & CSIGNAL) != 0)
Wang Chaocbdd1902010-09-02 15:08:59 +0800498 tprintf("%s%s", sep, signame(flags & CSIGNAL));
Roland McGrathb4968be2003-01-20 09:04:33 +0000499 if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
Roland McGrath9677b3a2003-03-12 09:54:36 +0000500 |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
Roland McGrath909875b2002-12-22 03:34:36 +0000501 return 0;
Roland McGrath6f67a982003-03-21 07:33:15 +0000502 if (flags & CLONE_PARENT_SETTID)
503 tprintf(", parent_tidptr=%#lx", tcp->u_arg[ARG_PTID]);
Roland McGrathb4968be2003-01-20 09:04:33 +0000504 if (flags & CLONE_SETTLS) {
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100505#ifdef I386
Roland McGrath909875b2002-12-22 03:34:36 +0000506 struct modify_ldt_ldt_s copy;
Roland McGrath9677b3a2003-03-12 09:54:36 +0000507 if (umove(tcp, tcp->u_arg[ARG_TLS], &copy) != -1) {
Roland McGrath909875b2002-12-22 03:34:36 +0000508 tprintf(", {entry_number:%d, ",
509 copy.entry_number);
510 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200511 tprints("...}");
Roland McGrath909875b2002-12-22 03:34:36 +0000512 else
513 print_ldt_entry(&copy);
514 }
515 else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100516#endif
Roland McGrath43f2c842003-03-12 09:58:14 +0000517 tprintf(", tls=%#lx", tcp->u_arg[ARG_TLS]);
Roland McGrath909875b2002-12-22 03:34:36 +0000518 }
Roland McGrath9677b3a2003-03-12 09:54:36 +0000519 if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID))
520 tprintf(", child_tidptr=%#lx", tcp->u_arg[ARG_CTID]);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000521 }
522 return 0;
523}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000524
525int
526sys_unshare(struct tcb *tcp)
527{
528 if (entering(tcp))
529 printflags(clone_flags, tcp->u_arg[0], "CLONE_???");
530 return 0;
531}
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000532
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533int
Denys Vlasenko12014262011-05-30 14:00:14 +0200534sys_fork(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535{
536 if (exiting(tcp))
537 return RVAL_UDECIMAL;
538 return 0;
539}
540
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000541int
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000542change_syscall(struct tcb *tcp, int new)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000543{
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000544#if defined(I386)
Roland McGrath5a223472002-12-15 23:58:26 +0000545 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000546 return -1;
547 return 0;
Michal Ludvig0e035502002-09-23 15:41:01 +0000548#elif defined(X86_64)
Roland McGrath5a223472002-12-15 23:58:26 +0000549 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
Michal Ludvig0e035502002-09-23 15:41:01 +0000550 return -1;
551 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000552#elif defined(POWERPC)
Roland McGratheb285352003-01-14 09:59:00 +0000553 if (ptrace(PTRACE_POKEUSER, tcp->pid,
554 (char*)(sizeof(unsigned long)*PT_R0), new) < 0)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000555 return -1;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000556 return 0;
Michal Ludvig10a88d02002-10-07 14:31:00 +0000557#elif defined(S390) || defined(S390X)
558 /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200559 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000560 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000561 return 0;
562#elif defined(M68K)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200563 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000564 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000565 return 0;
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000566#elif defined(SPARC) || defined(SPARC64)
Mike Frysinger8566c502009-10-12 11:05:14 -0400567 struct pt_regs regs;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200568 if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0) < 0)
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000569 return -1;
Mike Frysinger8566c502009-10-12 11:05:14 -0400570 regs.u_regs[U_REG_G1] = new;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200571 if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000572 return -1;
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000573 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000574#elif defined(MIPS)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200575 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000576 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000577 return 0;
578#elif defined(ALPHA)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200579 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000580 return -1;
581 return 0;
582#elif defined(AVR32)
583 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_R8), new) < 0)
584 return -1;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000585 return 0;
Dmitry V. Levin87ea1f42008-11-10 22:21:41 +0000586#elif defined(BFIN)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200587 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_P0), new) < 0)
Dmitry V. Levin87ea1f42008-11-10 22:21:41 +0000588 return -1;
589 return 0;
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000590#elif defined(IA64)
Roland McGrath08267b82004-02-20 22:56:43 +0000591 if (ia32) {
592 switch (new) {
Denys Vlasenko418d66a2009-01-17 01:52:54 +0000593 case 2:
594 break; /* x86 SYS_fork */
595 case SYS_clone:
596 new = 120;
597 break;
598 default:
Roland McGrath08267b82004-02-20 22:56:43 +0000599 fprintf(stderr, "%s: unexpected syscall %d\n",
600 __FUNCTION__, new);
601 return -1;
602 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200603 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R1), new) < 0)
Roland McGrath08267b82004-02-20 22:56:43 +0000604 return -1;
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200605 } else if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new) < 0)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000606 return -1;
607 return 0;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000608#elif defined(HPPA)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200609 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new) < 0)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000610 return -1;
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000611 return 0;
Wichert Akkermanccef6372002-05-01 16:39:22 +0000612#elif defined(SH)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200613 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*(REG_REG0+3)), new) < 0)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000614 return -1;
615 return 0;
Roland McGrathf5a47772003-06-26 22:40:42 +0000616#elif defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000617 /* Top half of reg encodes the no. of args n as 0x1n.
618 Assume 0 args as kernel never actually checks... */
619 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL),
620 0x100000 | new) < 0)
621 return -1;
622 return 0;
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +0000623#elif defined(CRISV10) || defined(CRISV32)
624 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R9), new) < 0)
625 return -1;
626 return 0;
Roland McGrathf691bd22006-04-25 07:34:41 +0000627#elif defined(ARM)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000628 /* Some kernels support this, some (pre-2.6.16 or so) don't. */
Roland McGrathf691bd22006-04-25 07:34:41 +0000629# ifndef PTRACE_SET_SYSCALL
630# define PTRACE_SET_SYSCALL 23
631# endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200632 if (ptrace(PTRACE_SET_SYSCALL, tcp->pid, 0, new & 0xffff) != 0)
Roland McGrathf691bd22006-04-25 07:34:41 +0000633 return -1;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000634 return 0;
Chris Metcalfc8c66982009-12-28 10:00:15 -0500635#elif defined(TILE)
636 if (ptrace(PTRACE_POKEUSER, tcp->pid,
637 (char*)PTREGS_OFFSET_REG(0),
638 new) != 0)
639 return -1;
640 return 0;
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200641#elif defined(MICROBLAZE)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200642 if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR(0)), new) < 0)
Edgar E. Iglesias939caba2010-07-06 14:21:07 +0200643 return -1;
644 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000645#else
646#warning Do not know how to handle change_syscall for this architecture
647#endif /* architecture */
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000648 return -1;
649}
650
Wang Chaoca8ab8d2010-11-12 17:26:08 +0800651int
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000652internal_fork(struct tcb *tcp)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000653{
Denys Vlasenkof44cce42011-06-21 14:34:10 +0200654 if ((ptrace_setoptions
Wang Chaoca8ab8d2010-11-12 17:26:08 +0800655 & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
656 == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
657 return 0;
658
Denys Vlasenko65d7c4d2011-06-23 21:46:37 +0200659 if (!followfork)
660 return 0;
661
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000662 if (entering(tcp)) {
Wang Chaoe636c852010-09-16 11:20:56 +0800663 /*
Denys Vlasenko833fb132011-08-17 11:30:56 +0200664 * We won't see the new child if clone is called with
665 * CLONE_UNTRACED, so we keep the same logic with that option
666 * and don't trace it.
Wang Chaoe636c852010-09-16 11:20:56 +0800667 */
668 if ((sysent[tcp->scno].sys_func == sys_clone) &&
669 (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED))
670 return 0;
Denys Vlasenkoe7c90242011-06-22 00:09:25 +0200671 setbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000672 } else {
Denys Vlasenko833fb132011-08-17 11:30:56 +0200673 if (tcp->flags & TCB_BPTSET)
674 clearbpt(tcp);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000675 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000676 return 0;
677}
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000678
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000679int
Denys Vlasenko12014262011-05-30 14:00:14 +0200680sys_vfork(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000681{
682 if (exiting(tcp))
683 return RVAL_UDECIMAL;
684 return 0;
685}
686
Dmitry V. Levin50a218d2011-01-18 17:36:20 +0000687int sys_getuid(struct tcb *tcp)
688{
689 if (exiting(tcp))
690 tcp->u_rval = (uid_t) tcp->u_rval;
691 return RVAL_UDECIMAL;
692}
693
694int sys_setfsuid(struct tcb *tcp)
695{
696 if (entering(tcp))
697 tprintf("%u", (uid_t) tcp->u_arg[0]);
698 else
699 tcp->u_rval = (uid_t) tcp->u_rval;
700 return RVAL_UDECIMAL;
701}
702
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000703int
Denys Vlasenko12014262011-05-30 14:00:14 +0200704sys_setuid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705{
706 if (entering(tcp)) {
707 tprintf("%u", (uid_t) tcp->u_arg[0]);
708 }
709 return 0;
710}
711
712int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000713sys_getresuid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000714{
715 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000716 __kernel_uid_t uid;
717 if (syserror(tcp))
718 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
719 tcp->u_arg[1], tcp->u_arg[2]);
720 else {
721 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
722 tprintf("%#lx, ", tcp->u_arg[0]);
723 else
Roland McGrath83bd47a2003-11-13 22:32:26 +0000724 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +0000725 if (umove(tcp, tcp->u_arg[1], &uid) < 0)
726 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000727 else
Roland McGrath83bd47a2003-11-13 22:32:26 +0000728 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +0000729 if (umove(tcp, tcp->u_arg[2], &uid) < 0)
730 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000731 else
Roland McGrath83bd47a2003-11-13 22:32:26 +0000732 tprintf("[%lu]", (unsigned long) uid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000733 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000734 }
735 return 0;
736}
737
738int
Denys Vlasenko12014262011-05-30 14:00:14 +0200739sys_setreuid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000740{
741 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +0000742 printuid("", tcp->u_arg[0]);
743 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000744 }
745 return 0;
746}
747
748int
Denys Vlasenko12014262011-05-30 14:00:14 +0200749sys_setresuid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000750{
751 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +0000752 printuid("", tcp->u_arg[0]);
753 printuid(", ", tcp->u_arg[1]);
754 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000755 }
756 return 0;
757}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000758
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000759int
Denys Vlasenko12014262011-05-30 14:00:14 +0200760sys_setgroups(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000761{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000762 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +0000763 unsigned long len, size, start, cur, end, abbrev_end;
764 GETGROUPS_T gid;
765 int failed = 0;
766
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +0000768 tprintf("%lu, ", len);
769 if (len == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200770 tprints("[]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000771 return 0;
772 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000773 start = tcp->u_arg[1];
774 if (start == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200775 tprints("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +0000776 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000777 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000778 size = len * sizeof(gid);
779 end = start + size;
780 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
781 tprintf("%#lx", start);
782 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000783 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000784 if (abbrev(tcp)) {
785 abbrev_end = start + max_strlen * sizeof(gid);
786 if (abbrev_end < start)
787 abbrev_end = end;
788 } else {
789 abbrev_end = end;
790 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200791 tprints("[");
Roland McGrathaa524c82005-06-01 19:22:06 +0000792 for (cur = start; cur < end; cur += sizeof(gid)) {
793 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200794 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000795 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200796 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000797 break;
798 }
799 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200800 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000801 failed = 1;
802 break;
803 }
804 tprintf("%lu", (unsigned long) gid);
805 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200806 tprints("]");
Roland McGrathaa524c82005-06-01 19:22:06 +0000807 if (failed)
808 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000809 }
810 return 0;
811}
812
813int
Denys Vlasenko12014262011-05-30 14:00:14 +0200814sys_getgroups(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000815{
Roland McGrathaa524c82005-06-01 19:22:06 +0000816 unsigned long len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000817
818 if (entering(tcp)) {
819 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +0000820 tprintf("%lu, ", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +0000822 unsigned long size, start, cur, end, abbrev_end;
823 GETGROUPS_T gid;
824 int failed = 0;
825
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000826 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +0000827 if (len == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200828 tprints("[]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000829 return 0;
830 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000831 start = tcp->u_arg[1];
832 if (start == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200833 tprints("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +0000834 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000835 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000836 if (tcp->u_arg[0] == 0) {
837 tprintf("%#lx", start);
838 return 0;
839 }
840 size = len * sizeof(gid);
841 end = start + size;
842 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
843 size / sizeof(gid) != len || end < start) {
844 tprintf("%#lx", start);
845 return 0;
846 }
847 if (abbrev(tcp)) {
848 abbrev_end = start + max_strlen * sizeof(gid);
849 if (abbrev_end < start)
850 abbrev_end = end;
851 } else {
852 abbrev_end = end;
853 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200854 tprints("[");
Roland McGrathaa524c82005-06-01 19:22:06 +0000855 for (cur = start; cur < end; cur += sizeof(gid)) {
856 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200857 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000858 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200859 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000860 break;
861 }
862 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200863 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000864 failed = 1;
865 break;
866 }
867 tprintf("%lu", (unsigned long) gid);
868 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200869 tprints("]");
Roland McGrathaa524c82005-06-01 19:22:06 +0000870 if (failed)
871 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000872 }
873 return 0;
874}
875
Roland McGrath83bd47a2003-11-13 22:32:26 +0000876int
Denys Vlasenko12014262011-05-30 14:00:14 +0200877sys_setgroups32(struct tcb *tcp)
Roland McGrath83bd47a2003-11-13 22:32:26 +0000878{
Roland McGrath83bd47a2003-11-13 22:32:26 +0000879 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +0000880 unsigned long len, size, start, cur, end, abbrev_end;
881 GETGROUPS32_T gid;
882 int failed = 0;
883
Roland McGrath83bd47a2003-11-13 22:32:26 +0000884 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +0000885 tprintf("%lu, ", len);
886 if (len == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200887 tprints("[]");
Roland McGrath83bd47a2003-11-13 22:32:26 +0000888 return 0;
889 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000890 start = tcp->u_arg[1];
891 if (start == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200892 tprints("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +0000893 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +0000894 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000895 size = len * sizeof(gid);
896 end = start + size;
897 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
898 tprintf("%#lx", start);
899 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +0000900 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000901 if (abbrev(tcp)) {
902 abbrev_end = start + max_strlen * sizeof(gid);
903 if (abbrev_end < start)
904 abbrev_end = end;
905 } else {
906 abbrev_end = end;
907 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200908 tprints("[");
Roland McGrathaa524c82005-06-01 19:22:06 +0000909 for (cur = start; cur < end; cur += sizeof(gid)) {
910 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200911 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000912 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200913 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000914 break;
915 }
916 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200917 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000918 failed = 1;
919 break;
920 }
921 tprintf("%lu", (unsigned long) gid);
922 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200923 tprints("]");
Roland McGrathaa524c82005-06-01 19:22:06 +0000924 if (failed)
925 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +0000926 }
927 return 0;
928}
929
930int
Denys Vlasenko12014262011-05-30 14:00:14 +0200931sys_getgroups32(struct tcb *tcp)
Roland McGrath83bd47a2003-11-13 22:32:26 +0000932{
Roland McGrathaa524c82005-06-01 19:22:06 +0000933 unsigned long len;
Roland McGrath83bd47a2003-11-13 22:32:26 +0000934
935 if (entering(tcp)) {
936 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +0000937 tprintf("%lu, ", len);
Roland McGrath83bd47a2003-11-13 22:32:26 +0000938 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +0000939 unsigned long size, start, cur, end, abbrev_end;
940 GETGROUPS32_T gid;
941 int failed = 0;
942
Roland McGrath83bd47a2003-11-13 22:32:26 +0000943 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +0000944 if (len == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200945 tprints("[]");
Roland McGrath83bd47a2003-11-13 22:32:26 +0000946 return 0;
947 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000948 start = tcp->u_arg[1];
949 if (start == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200950 tprints("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +0000951 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +0000952 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000953 size = len * sizeof(gid);
954 end = start + size;
955 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
956 size / sizeof(gid) != len || end < start) {
957 tprintf("%#lx", start);
958 return 0;
959 }
960 if (abbrev(tcp)) {
961 abbrev_end = start + max_strlen * sizeof(gid);
962 if (abbrev_end < start)
963 abbrev_end = end;
964 } else {
965 abbrev_end = end;
966 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200967 tprints("[");
Roland McGrathaa524c82005-06-01 19:22:06 +0000968 for (cur = start; cur < end; cur += sizeof(gid)) {
969 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200970 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000971 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200972 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000973 break;
974 }
975 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200976 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000977 failed = 1;
978 break;
979 }
980 tprintf("%lu", (unsigned long) gid);
981 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200982 tprints("]");
Roland McGrathaa524c82005-06-01 19:22:06 +0000983 if (failed)
984 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +0000985 }
986 return 0;
987}
Roland McGrath83bd47a2003-11-13 22:32:26 +0000988
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000989static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000990printargv(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000991{
Roland McGrath85a3bc42007-08-02 02:13:05 +0000992 union {
Andreas Schwab99c85692009-08-28 19:36:20 +0200993 unsigned int p32;
994 unsigned long p64;
Roland McGrath85a3bc42007-08-02 02:13:05 +0000995 char data[sizeof(long)];
996 } cp;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000997 const char *sep;
Roland McGrath85a3bc42007-08-02 02:13:05 +0000998 int n = 0;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100999 unsigned wordsize = personality_wordsize[current_personality];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001000
Roland McGrath85a3bc42007-08-02 02:13:05 +00001001 cp.p64 = 1;
1002 for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001003 if (umoven(tcp, addr, wordsize, cp.data) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001004 tprintf("%#lx", addr);
1005 return;
1006 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001007 if (wordsize == 4)
Roland McGrath85a3bc42007-08-02 02:13:05 +00001008 cp.p64 = cp.p32;
1009 if (cp.p64 == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001010 break;
Denys Vlasenko5940e652011-09-01 09:55:05 +02001011 tprints(sep);
Roland McGrath85a3bc42007-08-02 02:13:05 +00001012 printstr(tcp, cp.p64, -1);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001013 addr += wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001014 }
Roland McGrath85a3bc42007-08-02 02:13:05 +00001015 if (cp.p64)
1016 tprintf("%s...", sep);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001017}
1018
1019static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +00001020printargc(const char *fmt, struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021{
1022 int count;
1023 char *cp;
1024
1025 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
1026 addr += sizeof(char *);
1027 }
1028 tprintf(fmt, count, count == 1 ? "" : "s");
1029}
1030
Denys Vlasenko84703742012-02-25 02:38:52 +01001031#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001033sys_execv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001034{
1035 if (entering(tcp)) {
1036 printpath(tcp, tcp->u_arg[0]);
1037 if (!verbose(tcp))
1038 tprintf(", %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001039 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001040 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041 printargv(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001042 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001043 }
1044 }
1045 return 0;
1046}
Denys Vlasenko84703742012-02-25 02:38:52 +01001047#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001048
1049int
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001050sys_execve(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001051{
1052 if (entering(tcp)) {
1053 printpath(tcp, tcp->u_arg[0]);
1054 if (!verbose(tcp))
1055 tprintf(", %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001056 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001057 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001058 printargv(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001059 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001060 }
1061 if (!verbose(tcp))
1062 tprintf(", %#lx", tcp->u_arg[2]);
1063 else if (abbrev(tcp))
1064 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
1065 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001066 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001067 printargv(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001068 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001069 }
1070 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071 return 0;
1072}
1073
Denys Vlasenko84703742012-02-25 02:38:52 +01001074#if defined(TCB_WAITEXECVE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001075int
Denys Vlasenkof8bc0652011-05-24 20:30:24 +02001076internal_exec(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077{
Roland McGrathfdb097f2004-07-12 07:38:55 +00001078 if (exiting(tcp) && syserror(tcp))
1079 tcp->flags &= ~TCB_WAITEXECVE;
Denys Vlasenkof8bc0652011-05-24 20:30:24 +02001080 else {
1081 /* Maybe we have post-execve SIGTRAP suppressed? */
Denys Vlasenkof44cce42011-06-21 14:34:10 +02001082 if (!(ptrace_setoptions & PTRACE_O_TRACEEXEC))
Denys Vlasenkof8bc0652011-05-24 20:30:24 +02001083 tcp->flags |= TCB_WAITEXECVE; /* no */
1084 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001085 return 0;
1086}
Denys Vlasenkoa7949742011-08-21 17:26:55 +02001087#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001088
Roland McGrath7ec1d352002-12-17 04:50:44 +00001089#ifndef __WNOTHREAD
1090#define __WNOTHREAD 0x20000000
1091#endif
1092#ifndef __WALL
1093#define __WALL 0x40000000
1094#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001095#ifndef __WCLONE
Roland McGrath7ec1d352002-12-17 04:50:44 +00001096#define __WCLONE 0x80000000
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001097#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001098
Roland McGrathd9f816f2004-09-04 03:39:20 +00001099static const struct xlat wait4_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001100 { WNOHANG, "WNOHANG" },
1101#ifndef WSTOPPED
1102 { WUNTRACED, "WUNTRACED" },
1103#endif
1104#ifdef WEXITED
1105 { WEXITED, "WEXITED" },
1106#endif
1107#ifdef WTRAPPED
1108 { WTRAPPED, "WTRAPPED" },
1109#endif
1110#ifdef WSTOPPED
1111 { WSTOPPED, "WSTOPPED" },
1112#endif
1113#ifdef WCONTINUED
1114 { WCONTINUED, "WCONTINUED" },
1115#endif
1116#ifdef WNOWAIT
1117 { WNOWAIT, "WNOWAIT" },
1118#endif
1119#ifdef __WCLONE
1120 { __WCLONE, "__WCLONE" },
1121#endif
Roland McGrath7ec1d352002-12-17 04:50:44 +00001122#ifdef __WALL
1123 { __WALL, "__WALL" },
1124#endif
1125#ifdef __WNOTHREAD
1126 { __WNOTHREAD, "__WNOTHREAD" },
1127#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001128 { 0, NULL },
1129};
1130
Roland McGrath5e02a572004-10-19 23:33:47 +00001131#if !defined WCOREFLAG && defined WCOREFLG
1132# define WCOREFLAG WCOREFLG
1133#endif
1134#ifndef WCOREFLAG
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001135# define WCOREFLAG 0x80
Roland McGrath5e02a572004-10-19 23:33:47 +00001136#endif
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001137#ifndef WCOREDUMP
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001138# define WCOREDUMP(status) ((status) & 0200)
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001139#endif
Roland McGrath5e02a572004-10-19 23:33:47 +00001140#ifndef W_STOPCODE
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001141# define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
Roland McGrath5e02a572004-10-19 23:33:47 +00001142#endif
1143#ifndef W_EXITCODE
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001144# define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
Roland McGrath5e02a572004-10-19 23:33:47 +00001145#endif
1146
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001147static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001148printstatus(int status)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001149{
1150 int exited = 0;
1151
1152 /*
1153 * Here is a tricky presentation problem. This solution
1154 * is still not entirely satisfactory but since there
1155 * are no wait status constructors it will have to do.
1156 */
Roland McGrath79fbda52004-04-14 02:45:55 +00001157 if (WIFSTOPPED(status)) {
1158 tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001159 signame(WSTOPSIG(status)));
Roland McGrath79fbda52004-04-14 02:45:55 +00001160 status &= ~W_STOPCODE(WSTOPSIG(status));
1161 }
1162 else if (WIFSIGNALED(status)) {
1163 tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001164 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001165 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
Roland McGrath79fbda52004-04-14 02:45:55 +00001166 status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
1167 }
1168 else if (WIFEXITED(status)) {
1169 tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001170 WEXITSTATUS(status));
1171 exited = 1;
Roland McGrath79fbda52004-04-14 02:45:55 +00001172 status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001173 }
Roland McGrath79fbda52004-04-14 02:45:55 +00001174 else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001175 tprintf("[%#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001176 return 0;
1177 }
1178
1179 if (status == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001180 tprints("]");
Roland McGrath79fbda52004-04-14 02:45:55 +00001181 else
Roland McGrathf8cc83c2004-06-04 01:24:07 +00001182 tprintf(" | %#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001183
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001184 return exited;
1185}
1186
1187static int
Denys Vlasenko59432db2009-01-26 19:09:35 +00001188printwaitn(struct tcb *tcp, int n, int bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001189{
1190 int status;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001191
1192 if (entering(tcp)) {
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001193 /* On Linux, kernel-side pid_t is typedef'ed to int
1194 * on all arches. Also, glibc-2.8 truncates wait3 and wait4
Denys Vlasenko59432db2009-01-26 19:09:35 +00001195 * pid argument to int on 64bit arches, producing,
1196 * for example, wait4(4294967295, ...) instead of -1
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001197 * in strace. We have to use int here, not long.
1198 */
1199 int pid = tcp->u_arg[0];
1200 tprintf("%d, ", pid);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001201 } else {
1202 /* status */
1203 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001204 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001205 else if (syserror(tcp) || tcp->u_rval == 0)
1206 tprintf("%#lx", tcp->u_arg[1]);
1207 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001208 tprints("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001209 else
Dmitry V. Levind9a4b0a2011-02-23 00:27:12 +00001210 printstatus(status);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001211 /* options */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001212 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001213 printflags(wait4_options, tcp->u_arg[2], "W???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001214 if (n == 4) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001215 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001216 /* usage */
1217 if (!tcp->u_arg[3])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001218 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001219 else if (tcp->u_rval > 0) {
Denys Vlasenko59432db2009-01-26 19:09:35 +00001220#ifdef ALPHA
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001221 if (bitness)
1222 printrusage32(tcp, tcp->u_arg[3]);
1223 else
1224#endif
1225 printrusage(tcp, tcp->u_arg[3]);
1226 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001227 else
1228 tprintf("%#lx", tcp->u_arg[3]);
1229 }
1230 }
1231 return 0;
1232}
1233
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001234int
Denys Vlasenko12014262011-05-30 14:00:14 +02001235sys_waitpid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001236{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001237 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001238}
1239
1240int
Denys Vlasenko12014262011-05-30 14:00:14 +02001241sys_wait4(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001242{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001243 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001244}
1245
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001246#ifdef ALPHA
1247int
Denys Vlasenko12014262011-05-30 14:00:14 +02001248sys_osf_wait4(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001249{
1250 return printwaitn(tcp, 4, 1);
1251}
1252#endif
1253
Roland McGrathd9f816f2004-09-04 03:39:20 +00001254static const struct xlat waitid_types[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001255 { P_PID, "P_PID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001256#ifdef P_PPID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001257 { P_PPID, "P_PPID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001258#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001259 { P_PGID, "P_PGID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001260#ifdef P_SID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001261 { P_SID, "P_SID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001262#endif
1263#ifdef P_CID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001264 { P_CID, "P_CID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001265#endif
1266#ifdef P_UID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001267 { P_UID, "P_UID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001268#endif
1269#ifdef P_GID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001270 { P_GID, "P_GID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001271#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001272 { P_ALL, "P_ALL" },
1273#ifdef P_LWPID
1274 { P_LWPID, "P_LWPID" },
1275#endif
1276 { 0, NULL },
1277};
1278
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001279int
Dmitry V. Levin3eb94912010-09-09 23:08:59 +00001280sys_waitid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001281{
1282 siginfo_t si;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001283
1284 if (entering(tcp)) {
1285 printxval(waitid_types, tcp->u_arg[0], "P_???");
1286 tprintf(", %ld, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001287 }
1288 else {
1289 /* siginfo */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290 if (!tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001291 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 else if (syserror(tcp))
1293 tprintf("%#lx", tcp->u_arg[2]);
1294 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001295 tprints("{???}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00001297 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298 /* options */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001299 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001300 printflags(wait4_options, tcp->u_arg[3], "W???");
Roland McGrath39426a32004-10-06 22:02:59 +00001301 if (tcp->u_nargs > 4) {
1302 /* usage */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001303 tprints(", ");
Roland McGrath39426a32004-10-06 22:02:59 +00001304 if (!tcp->u_arg[4])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001305 tprints("NULL");
Roland McGrath39426a32004-10-06 22:02:59 +00001306 else if (tcp->u_error)
1307 tprintf("%#lx", tcp->u_arg[4]);
1308 else
1309 printrusage(tcp, tcp->u_arg[4]);
1310 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001311 }
1312 return 0;
1313}
1314
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001315int
Denys Vlasenko12014262011-05-30 14:00:14 +02001316sys_uname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001317{
1318 struct utsname uname;
1319
1320 if (exiting(tcp)) {
1321 if (syserror(tcp) || !verbose(tcp))
1322 tprintf("%#lx", tcp->u_arg[0]);
1323 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001324 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001325 else if (!abbrev(tcp)) {
1326
1327 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1328 uname.sysname, uname.nodename);
1329 tprintf("release=\"%s\", version=\"%s\", ",
1330 uname.release, uname.version);
1331 tprintf("machine=\"%s\"", uname.machine);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001332#ifndef __GLIBC__
1333 tprintf(", domainname=\"%s\"", uname.domainname);
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00001334#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001335 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001336 }
1337 else
1338 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1339 uname.sysname, uname.nodename);
1340 }
1341 return 0;
1342}
1343
Roland McGratheb9e2e82009-06-02 16:49:22 -07001344static const struct xlat ptrace_cmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001345 { PTRACE_TRACEME, "PTRACE_TRACEME" },
Denys Vlasenko61526c62011-08-25 10:21:13 +02001346 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT" },
1347 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA" },
1348 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER" },
1349 { PTRACE_POKETEXT, "PTRACE_POKETEXT" },
1350 { PTRACE_POKEDATA, "PTRACE_POKEDATA" },
1351 { PTRACE_POKEUSER, "PTRACE_POKEUSER" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001352 { PTRACE_CONT, "PTRACE_CONT" },
1353 { PTRACE_KILL, "PTRACE_KILL" },
1354 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1355 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1356 { PTRACE_DETACH, "PTRACE_DETACH" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001357#ifdef PTRACE_GETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001358 { PTRACE_GETREGS, "PTRACE_GETREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001359#endif
1360#ifdef PTRACE_SETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001361 { PTRACE_SETREGS, "PTRACE_SETREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001362#endif
1363#ifdef PTRACE_GETFPREGS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001364 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001365#endif
1366#ifdef PTRACE_SETFPREGS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001367 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001368#endif
1369#ifdef PTRACE_GETFPXREGS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001370 { PTRACE_GETFPXREGS, "PTRACE_GETFPXREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001371#endif
1372#ifdef PTRACE_SETFPXREGS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001373 { PTRACE_SETFPXREGS, "PTRACE_SETFPXREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001374#endif
1375#ifdef PTRACE_GETVRREGS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001376 { PTRACE_GETVRREGS, "PTRACE_GETVRREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001377#endif
1378#ifdef PTRACE_SETVRREGS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001379 { PTRACE_SETVRREGS, "PTRACE_SETVRREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001380#endif
1381#ifdef PTRACE_SETOPTIONS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001382 { PTRACE_SETOPTIONS, "PTRACE_SETOPTIONS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001383#endif
1384#ifdef PTRACE_GETEVENTMSG
Denys Vlasenko61526c62011-08-25 10:21:13 +02001385 { PTRACE_GETEVENTMSG, "PTRACE_GETEVENTMSG" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001386#endif
1387#ifdef PTRACE_GETSIGINFO
Denys Vlasenko61526c62011-08-25 10:21:13 +02001388 { PTRACE_GETSIGINFO, "PTRACE_GETSIGINFO" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001389#endif
1390#ifdef PTRACE_SETSIGINFO
Denys Vlasenko61526c62011-08-25 10:21:13 +02001391 { PTRACE_SETSIGINFO, "PTRACE_SETSIGINFO" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001392#endif
1393#ifdef PTRACE_GETREGSET
Denys Vlasenko61526c62011-08-25 10:21:13 +02001394 { PTRACE_GETREGSET, "PTRACE_GETREGSET" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001395#endif
1396#ifdef PTRACE_SETREGSET
Denys Vlasenko61526c62011-08-25 10:21:13 +02001397 { PTRACE_SETREGSET, "PTRACE_SETREGSET" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001398#endif
1399#ifdef PTRACE_SET_SYSCALL
Denys Vlasenko61526c62011-08-25 10:21:13 +02001400 { PTRACE_SET_SYSCALL, "PTRACE_SET_SYSCALL" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001401#endif
1402#ifdef PTRACE_SEIZE
Denys Vlasenko31fa8a22012-01-29 02:01:44 +01001403 { PTRACE_SEIZE, "PTRACE_SEIZE" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001404#endif
1405#ifdef PTRACE_INTERRUPT
Denys Vlasenko31fa8a22012-01-29 02:01:44 +01001406 { PTRACE_INTERRUPT, "PTRACE_INTERRUPT" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001407#endif
1408#ifdef PTRACE_LISTEN
Denys Vlasenko31fa8a22012-01-29 02:01:44 +01001409 { PTRACE_LISTEN, "PTRACE_LISTEN" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001410#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001411 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
Denys Vlasenkof535b542009-01-13 18:30:55 +00001412
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413 { 0, NULL },
1414};
1415
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001416#ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00001417static const struct xlat ptrace_setoptions_flags[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001418# ifdef PTRACE_O_TRACESYSGOOD
Denys Vlasenkof535b542009-01-13 18:30:55 +00001419 { PTRACE_O_TRACESYSGOOD,"PTRACE_O_TRACESYSGOOD" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001420# endif
1421# ifdef PTRACE_O_TRACEFORK
Denys Vlasenkof535b542009-01-13 18:30:55 +00001422 { PTRACE_O_TRACEFORK, "PTRACE_O_TRACEFORK" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001423# endif
1424# ifdef PTRACE_O_TRACEVFORK
Denys Vlasenkof535b542009-01-13 18:30:55 +00001425 { PTRACE_O_TRACEVFORK, "PTRACE_O_TRACEVFORK" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001426# endif
1427# ifdef PTRACE_O_TRACECLONE
Denys Vlasenkof535b542009-01-13 18:30:55 +00001428 { PTRACE_O_TRACECLONE, "PTRACE_O_TRACECLONE" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001429# endif
1430# ifdef PTRACE_O_TRACEEXEC
Denys Vlasenkof535b542009-01-13 18:30:55 +00001431 { PTRACE_O_TRACEEXEC, "PTRACE_O_TRACEEXEC" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001432# endif
1433# ifdef PTRACE_O_TRACEVFORKDONE
Denys Vlasenkof535b542009-01-13 18:30:55 +00001434 { PTRACE_O_TRACEVFORKDONE,"PTRACE_O_TRACEVFORKDONE"},
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001435# endif
1436# ifdef PTRACE_O_TRACEEXIT
Denys Vlasenkof535b542009-01-13 18:30:55 +00001437 { PTRACE_O_TRACEEXIT, "PTRACE_O_TRACEEXIT" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001438# endif
Denys Vlasenkof535b542009-01-13 18:30:55 +00001439 { 0, NULL },
1440};
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001441#endif /* PTRACE_SETOPTIONS */
Denys Vlasenkof535b542009-01-13 18:30:55 +00001442
Roland McGrathd9f816f2004-09-04 03:39:20 +00001443const struct xlat struct_user_offsets[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001444#if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001445 { PT_PSWMASK, "psw_mask" },
1446 { PT_PSWADDR, "psw_addr" },
1447 { PT_GPR0, "gpr0" },
1448 { PT_GPR1, "gpr1" },
1449 { PT_GPR2, "gpr2" },
1450 { PT_GPR3, "gpr3" },
1451 { PT_GPR4, "gpr4" },
1452 { PT_GPR5, "gpr5" },
1453 { PT_GPR6, "gpr6" },
1454 { PT_GPR7, "gpr7" },
1455 { PT_GPR8, "gpr8" },
1456 { PT_GPR9, "gpr9" },
1457 { PT_GPR10, "gpr10" },
1458 { PT_GPR11, "gpr11" },
1459 { PT_GPR12, "gpr12" },
1460 { PT_GPR13, "gpr13" },
1461 { PT_GPR14, "gpr14" },
1462 { PT_GPR15, "gpr15" },
1463 { PT_ACR0, "acr0" },
1464 { PT_ACR1, "acr1" },
1465 { PT_ACR2, "acr2" },
1466 { PT_ACR3, "acr3" },
1467 { PT_ACR4, "acr4" },
1468 { PT_ACR5, "acr5" },
1469 { PT_ACR6, "acr6" },
1470 { PT_ACR7, "acr7" },
1471 { PT_ACR8, "acr8" },
1472 { PT_ACR9, "acr9" },
1473 { PT_ACR10, "acr10" },
1474 { PT_ACR11, "acr11" },
1475 { PT_ACR12, "acr12" },
1476 { PT_ACR13, "acr13" },
1477 { PT_ACR14, "acr14" },
1478 { PT_ACR15, "acr15" },
1479 { PT_ORIGGPR2, "orig_gpr2" },
1480 { PT_FPC, "fpc" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001481#if defined(S390)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001482 { PT_FPR0_HI, "fpr0.hi" },
1483 { PT_FPR0_LO, "fpr0.lo" },
1484 { PT_FPR1_HI, "fpr1.hi" },
1485 { PT_FPR1_LO, "fpr1.lo" },
1486 { PT_FPR2_HI, "fpr2.hi" },
1487 { PT_FPR2_LO, "fpr2.lo" },
1488 { PT_FPR3_HI, "fpr3.hi" },
1489 { PT_FPR3_LO, "fpr3.lo" },
1490 { PT_FPR4_HI, "fpr4.hi" },
1491 { PT_FPR4_LO, "fpr4.lo" },
1492 { PT_FPR5_HI, "fpr5.hi" },
1493 { PT_FPR5_LO, "fpr5.lo" },
1494 { PT_FPR6_HI, "fpr6.hi" },
1495 { PT_FPR6_LO, "fpr6.lo" },
1496 { PT_FPR7_HI, "fpr7.hi" },
1497 { PT_FPR7_LO, "fpr7.lo" },
1498 { PT_FPR8_HI, "fpr8.hi" },
1499 { PT_FPR8_LO, "fpr8.lo" },
1500 { PT_FPR9_HI, "fpr9.hi" },
1501 { PT_FPR9_LO, "fpr9.lo" },
1502 { PT_FPR10_HI, "fpr10.hi" },
1503 { PT_FPR10_LO, "fpr10.lo" },
1504 { PT_FPR11_HI, "fpr11.hi" },
1505 { PT_FPR11_LO, "fpr11.lo" },
1506 { PT_FPR12_HI, "fpr12.hi" },
1507 { PT_FPR12_LO, "fpr12.lo" },
1508 { PT_FPR13_HI, "fpr13.hi" },
1509 { PT_FPR13_LO, "fpr13.lo" },
1510 { PT_FPR14_HI, "fpr14.hi" },
1511 { PT_FPR14_LO, "fpr14.lo" },
1512 { PT_FPR15_HI, "fpr15.hi" },
1513 { PT_FPR15_LO, "fpr15.lo" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001514#endif
1515#if defined(S390X)
Michal Ludvig10a88d02002-10-07 14:31:00 +00001516 { PT_FPR0, "fpr0" },
1517 { PT_FPR1, "fpr1" },
1518 { PT_FPR2, "fpr2" },
1519 { PT_FPR3, "fpr3" },
1520 { PT_FPR4, "fpr4" },
1521 { PT_FPR5, "fpr5" },
1522 { PT_FPR6, "fpr6" },
1523 { PT_FPR7, "fpr7" },
1524 { PT_FPR8, "fpr8" },
1525 { PT_FPR9, "fpr9" },
1526 { PT_FPR10, "fpr10" },
1527 { PT_FPR11, "fpr11" },
1528 { PT_FPR12, "fpr12" },
1529 { PT_FPR13, "fpr13" },
1530 { PT_FPR14, "fpr14" },
1531 { PT_FPR15, "fpr15" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001532#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001533 { PT_CR_9, "cr9" },
1534 { PT_CR_10, "cr10" },
1535 { PT_CR_11, "cr11" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001536 { PT_IEEE_IP, "ieee_exception_ip" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001537#elif defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001538 /* XXX No support for these offsets yet. */
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001539#elif defined(HPPA)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001540 /* XXX No support for these offsets yet. */
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001541#elif defined(POWERPC)
1542# ifndef PT_ORIG_R3
1543# define PT_ORIG_R3 34
1544# endif
1545# define REGSIZE (sizeof(unsigned long))
Roland McGratheb285352003-01-14 09:59:00 +00001546 { REGSIZE*PT_R0, "r0" },
1547 { REGSIZE*PT_R1, "r1" },
1548 { REGSIZE*PT_R2, "r2" },
1549 { REGSIZE*PT_R3, "r3" },
1550 { REGSIZE*PT_R4, "r4" },
1551 { REGSIZE*PT_R5, "r5" },
1552 { REGSIZE*PT_R6, "r6" },
1553 { REGSIZE*PT_R7, "r7" },
1554 { REGSIZE*PT_R8, "r8" },
1555 { REGSIZE*PT_R9, "r9" },
1556 { REGSIZE*PT_R10, "r10" },
1557 { REGSIZE*PT_R11, "r11" },
1558 { REGSIZE*PT_R12, "r12" },
1559 { REGSIZE*PT_R13, "r13" },
1560 { REGSIZE*PT_R14, "r14" },
1561 { REGSIZE*PT_R15, "r15" },
1562 { REGSIZE*PT_R16, "r16" },
1563 { REGSIZE*PT_R17, "r17" },
1564 { REGSIZE*PT_R18, "r18" },
1565 { REGSIZE*PT_R19, "r19" },
1566 { REGSIZE*PT_R20, "r20" },
1567 { REGSIZE*PT_R21, "r21" },
1568 { REGSIZE*PT_R22, "r22" },
1569 { REGSIZE*PT_R23, "r23" },
1570 { REGSIZE*PT_R24, "r24" },
1571 { REGSIZE*PT_R25, "r25" },
1572 { REGSIZE*PT_R26, "r26" },
1573 { REGSIZE*PT_R27, "r27" },
1574 { REGSIZE*PT_R28, "r28" },
1575 { REGSIZE*PT_R29, "r29" },
1576 { REGSIZE*PT_R30, "r30" },
1577 { REGSIZE*PT_R31, "r31" },
1578 { REGSIZE*PT_NIP, "NIP" },
1579 { REGSIZE*PT_MSR, "MSR" },
1580 { REGSIZE*PT_ORIG_R3, "ORIG_R3" },
1581 { REGSIZE*PT_CTR, "CTR" },
1582 { REGSIZE*PT_LNK, "LNK" },
1583 { REGSIZE*PT_XER, "XER" },
1584 { REGSIZE*PT_CCR, "CCR" },
1585 { REGSIZE*PT_FPR0, "FPR0" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001586# undef REGSIZE
1587#elif defined(ALPHA)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001588 { 0, "r0" },
1589 { 1, "r1" },
1590 { 2, "r2" },
1591 { 3, "r3" },
1592 { 4, "r4" },
1593 { 5, "r5" },
1594 { 6, "r6" },
1595 { 7, "r7" },
1596 { 8, "r8" },
1597 { 9, "r9" },
1598 { 10, "r10" },
1599 { 11, "r11" },
1600 { 12, "r12" },
1601 { 13, "r13" },
1602 { 14, "r14" },
1603 { 15, "r15" },
1604 { 16, "r16" },
1605 { 17, "r17" },
1606 { 18, "r18" },
1607 { 19, "r19" },
1608 { 20, "r20" },
1609 { 21, "r21" },
1610 { 22, "r22" },
1611 { 23, "r23" },
1612 { 24, "r24" },
1613 { 25, "r25" },
1614 { 26, "r26" },
1615 { 27, "r27" },
1616 { 28, "r28" },
1617 { 29, "gp" },
1618 { 30, "fp" },
1619 { 31, "zero" },
1620 { 32, "fp0" },
1621 { 33, "fp" },
1622 { 34, "fp2" },
1623 { 35, "fp3" },
1624 { 36, "fp4" },
1625 { 37, "fp5" },
1626 { 38, "fp6" },
1627 { 39, "fp7" },
1628 { 40, "fp8" },
1629 { 41, "fp9" },
1630 { 42, "fp10" },
1631 { 43, "fp11" },
1632 { 44, "fp12" },
1633 { 45, "fp13" },
1634 { 46, "fp14" },
1635 { 47, "fp15" },
1636 { 48, "fp16" },
1637 { 49, "fp17" },
1638 { 50, "fp18" },
1639 { 51, "fp19" },
1640 { 52, "fp20" },
1641 { 53, "fp21" },
1642 { 54, "fp22" },
1643 { 55, "fp23" },
1644 { 56, "fp24" },
1645 { 57, "fp25" },
1646 { 58, "fp26" },
1647 { 59, "fp27" },
1648 { 60, "fp28" },
1649 { 61, "fp29" },
1650 { 62, "fp30" },
1651 { 63, "fp31" },
1652 { 64, "pc" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001653#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001654 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
1655 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
1656 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
1657 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
1658 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
1659 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
1660 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
1661 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
1662 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
1663 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
1664 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
1665 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
1666 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
1667 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
1668 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
1669 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
1670 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
1671 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
1672 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
1673 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
1674 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
1675 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
1676 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
1677 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
1678 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
1679 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
1680 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
1681 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
1682 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
1683 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
1684 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
1685 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
1686 /* switch stack: */
1687 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
1688 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
1689 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
1690 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
1691 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
1692 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
1693 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
1694 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
1695 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
1696 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001697 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
1698 { PT_B4, "b4" }, { PT_B5, "b5" },
Roland McGrathca4e10c2004-01-13 10:13:20 +00001699 { PT_AR_EC, "ar.ec" }, { PT_AR_LC, "ar.lc" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001700 /* pt_regs */
Roland McGrathca4e10c2004-01-13 10:13:20 +00001701 { PT_CR_IPSR, "psr" }, { PT_CR_IIP, "ip" },
1702 { PT_CFM, "cfm" }, { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001703 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
1704 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
1705 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
1706 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
1707 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
1708 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
1709 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
1710 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
1711 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
1712 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
1713 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
1714 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
1715 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
1716 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
1717 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001718# ifdef PT_AR_CSD
Roland McGrathfb1bc072004-03-01 21:29:24 +00001719 { PT_AR_CSD, "ar.csd" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001720# endif
1721# ifdef PT_AR_SSD
Roland McGrathfb1bc072004-03-01 21:29:24 +00001722 { PT_AR_SSD, "ar.ssd" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001723# endif
Roland McGrathca4e10c2004-01-13 10:13:20 +00001724 { PT_DBR, "dbr" }, { PT_IBR, "ibr" }, { PT_PMD, "pmd" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001725#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001726 { 4*EBX, "4*EBX" },
1727 { 4*ECX, "4*ECX" },
1728 { 4*EDX, "4*EDX" },
1729 { 4*ESI, "4*ESI" },
1730 { 4*EDI, "4*EDI" },
1731 { 4*EBP, "4*EBP" },
1732 { 4*EAX, "4*EAX" },
1733 { 4*DS, "4*DS" },
1734 { 4*ES, "4*ES" },
1735 { 4*FS, "4*FS" },
1736 { 4*GS, "4*GS" },
1737 { 4*ORIG_EAX, "4*ORIG_EAX" },
1738 { 4*EIP, "4*EIP" },
1739 { 4*CS, "4*CS" },
1740 { 4*EFL, "4*EFL" },
1741 { 4*UESP, "4*UESP" },
1742 { 4*SS, "4*SS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001743#elif defined(X86_64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001744 { 8*R15, "8*R15" },
1745 { 8*R14, "8*R14" },
1746 { 8*R13, "8*R13" },
1747 { 8*R12, "8*R12" },
Michal Ludvig0e035502002-09-23 15:41:01 +00001748 { 8*RBP, "8*RBP" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00001749 { 8*RBX, "8*RBX" },
1750 { 8*R11, "8*R11" },
1751 { 8*R10, "8*R10" },
1752 { 8*R9, "8*R9" },
1753 { 8*R8, "8*R8" },
Michal Ludvig0e035502002-09-23 15:41:01 +00001754 { 8*RAX, "8*RAX" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00001755 { 8*RCX, "8*RCX" },
1756 { 8*RDX, "8*RDX" },
1757 { 8*RSI, "8*RSI" },
1758 { 8*RDI, "8*RDI" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00001759 { 8*ORIG_RAX, "8*ORIG_RAX" },
Michal Ludvig0e035502002-09-23 15:41:01 +00001760 { 8*RIP, "8*RIP" },
1761 { 8*CS, "8*CS" },
1762 { 8*EFLAGS, "8*EFL" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00001763 { 8*RSP, "8*RSP" },
Michal Ludvig0e035502002-09-23 15:41:01 +00001764 { 8*SS, "8*SS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001765#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001766 { 4*PT_D1, "4*PT_D1" },
1767 { 4*PT_D2, "4*PT_D2" },
1768 { 4*PT_D3, "4*PT_D3" },
1769 { 4*PT_D4, "4*PT_D4" },
1770 { 4*PT_D5, "4*PT_D5" },
1771 { 4*PT_D6, "4*PT_D6" },
1772 { 4*PT_D7, "4*PT_D7" },
1773 { 4*PT_A0, "4*PT_A0" },
1774 { 4*PT_A1, "4*PT_A1" },
1775 { 4*PT_A2, "4*PT_A2" },
1776 { 4*PT_A3, "4*PT_A3" },
1777 { 4*PT_A4, "4*PT_A4" },
1778 { 4*PT_A5, "4*PT_A5" },
1779 { 4*PT_A6, "4*PT_A6" },
1780 { 4*PT_D0, "4*PT_D0" },
1781 { 4*PT_USP, "4*PT_USP" },
1782 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
1783 { 4*PT_SR, "4*PT_SR" },
1784 { 4*PT_PC, "4*PT_PC" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001785#elif defined(SH)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001786 { 4*REG_REG0, "4*REG_REG0" },
1787 { 4*(REG_REG0+1), "4*REG_REG1" },
1788 { 4*(REG_REG0+2), "4*REG_REG2" },
1789 { 4*(REG_REG0+3), "4*REG_REG3" },
1790 { 4*(REG_REG0+4), "4*REG_REG4" },
1791 { 4*(REG_REG0+5), "4*REG_REG5" },
1792 { 4*(REG_REG0+6), "4*REG_REG6" },
1793 { 4*(REG_REG0+7), "4*REG_REG7" },
1794 { 4*(REG_REG0+8), "4*REG_REG8" },
1795 { 4*(REG_REG0+9), "4*REG_REG9" },
1796 { 4*(REG_REG0+10), "4*REG_REG10" },
1797 { 4*(REG_REG0+11), "4*REG_REG11" },
1798 { 4*(REG_REG0+12), "4*REG_REG12" },
1799 { 4*(REG_REG0+13), "4*REG_REG13" },
1800 { 4*(REG_REG0+14), "4*REG_REG14" },
1801 { 4*REG_REG15, "4*REG_REG15" },
1802 { 4*REG_PC, "4*REG_PC" },
1803 { 4*REG_PR, "4*REG_PR" },
1804 { 4*REG_SR, "4*REG_SR" },
1805 { 4*REG_GBR, "4*REG_GBR" },
1806 { 4*REG_MACH, "4*REG_MACH" },
1807 { 4*REG_MACL, "4*REG_MACL" },
1808 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
1809 { 4*REG_FPUL, "4*REG_FPUL" },
1810 { 4*REG_FPREG0, "4*REG_FPREG0" },
1811 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
1812 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
1813 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
1814 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
1815 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
1816 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
1817 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
1818 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
1819 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
1820 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
1821 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
1822 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
1823 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
1824 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
1825 { 4*REG_FPREG15, "4*REG_FPREG15" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001826# ifdef REG_XDREG0
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001827 { 4*REG_XDREG0, "4*REG_XDREG0" },
1828 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
1829 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
1830 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
1831 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
1832 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
1833 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
1834 { 4*REG_XDREG14, "4*REG_XDREG14" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001835# endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001836 { 4*REG_FPSCR, "4*REG_FPSCR" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001837#elif defined(SH64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001838 { 0, "PC(L)" },
1839 { 4, "PC(U)" },
1840 { 8, "SR(L)" },
1841 { 12, "SR(U)" },
1842 { 16, "syscall no.(L)" },
1843 { 20, "syscall_no.(U)" },
1844 { 24, "R0(L)" },
1845 { 28, "R0(U)" },
1846 { 32, "R1(L)" },
1847 { 36, "R1(U)" },
1848 { 40, "R2(L)" },
1849 { 44, "R2(U)" },
1850 { 48, "R3(L)" },
1851 { 52, "R3(U)" },
1852 { 56, "R4(L)" },
1853 { 60, "R4(U)" },
1854 { 64, "R5(L)" },
1855 { 68, "R5(U)" },
1856 { 72, "R6(L)" },
1857 { 76, "R6(U)" },
1858 { 80, "R7(L)" },
1859 { 84, "R7(U)" },
1860 { 88, "R8(L)" },
1861 { 92, "R8(U)" },
1862 { 96, "R9(L)" },
1863 { 100, "R9(U)" },
1864 { 104, "R10(L)" },
1865 { 108, "R10(U)" },
1866 { 112, "R11(L)" },
1867 { 116, "R11(U)" },
1868 { 120, "R12(L)" },
1869 { 124, "R12(U)" },
1870 { 128, "R13(L)" },
1871 { 132, "R13(U)" },
1872 { 136, "R14(L)" },
1873 { 140, "R14(U)" },
1874 { 144, "R15(L)" },
1875 { 148, "R15(U)" },
1876 { 152, "R16(L)" },
1877 { 156, "R16(U)" },
1878 { 160, "R17(L)" },
1879 { 164, "R17(U)" },
1880 { 168, "R18(L)" },
1881 { 172, "R18(U)" },
1882 { 176, "R19(L)" },
1883 { 180, "R19(U)" },
1884 { 184, "R20(L)" },
1885 { 188, "R20(U)" },
1886 { 192, "R21(L)" },
1887 { 196, "R21(U)" },
1888 { 200, "R22(L)" },
1889 { 204, "R22(U)" },
1890 { 208, "R23(L)" },
1891 { 212, "R23(U)" },
1892 { 216, "R24(L)" },
1893 { 220, "R24(U)" },
1894 { 224, "R25(L)" },
1895 { 228, "R25(U)" },
1896 { 232, "R26(L)" },
1897 { 236, "R26(U)" },
1898 { 240, "R27(L)" },
1899 { 244, "R27(U)" },
1900 { 248, "R28(L)" },
1901 { 252, "R28(U)" },
1902 { 256, "R29(L)" },
1903 { 260, "R29(U)" },
1904 { 264, "R30(L)" },
1905 { 268, "R30(U)" },
1906 { 272, "R31(L)" },
1907 { 276, "R31(U)" },
1908 { 280, "R32(L)" },
1909 { 284, "R32(U)" },
1910 { 288, "R33(L)" },
1911 { 292, "R33(U)" },
1912 { 296, "R34(L)" },
1913 { 300, "R34(U)" },
1914 { 304, "R35(L)" },
1915 { 308, "R35(U)" },
1916 { 312, "R36(L)" },
1917 { 316, "R36(U)" },
1918 { 320, "R37(L)" },
1919 { 324, "R37(U)" },
1920 { 328, "R38(L)" },
1921 { 332, "R38(U)" },
1922 { 336, "R39(L)" },
1923 { 340, "R39(U)" },
1924 { 344, "R40(L)" },
1925 { 348, "R40(U)" },
1926 { 352, "R41(L)" },
1927 { 356, "R41(U)" },
1928 { 360, "R42(L)" },
1929 { 364, "R42(U)" },
1930 { 368, "R43(L)" },
1931 { 372, "R43(U)" },
1932 { 376, "R44(L)" },
1933 { 380, "R44(U)" },
1934 { 384, "R45(L)" },
1935 { 388, "R45(U)" },
1936 { 392, "R46(L)" },
1937 { 396, "R46(U)" },
1938 { 400, "R47(L)" },
1939 { 404, "R47(U)" },
1940 { 408, "R48(L)" },
1941 { 412, "R48(U)" },
1942 { 416, "R49(L)" },
1943 { 420, "R49(U)" },
1944 { 424, "R50(L)" },
1945 { 428, "R50(U)" },
1946 { 432, "R51(L)" },
1947 { 436, "R51(U)" },
1948 { 440, "R52(L)" },
1949 { 444, "R52(U)" },
1950 { 448, "R53(L)" },
1951 { 452, "R53(U)" },
1952 { 456, "R54(L)" },
1953 { 460, "R54(U)" },
1954 { 464, "R55(L)" },
1955 { 468, "R55(U)" },
1956 { 472, "R56(L)" },
1957 { 476, "R56(U)" },
1958 { 480, "R57(L)" },
1959 { 484, "R57(U)" },
1960 { 488, "R58(L)" },
1961 { 492, "R58(U)" },
1962 { 496, "R59(L)" },
1963 { 500, "R59(U)" },
1964 { 504, "R60(L)" },
1965 { 508, "R60(U)" },
1966 { 512, "R61(L)" },
1967 { 516, "R61(U)" },
1968 { 520, "R62(L)" },
1969 { 524, "R62(U)" },
1970 { 528, "TR0(L)" },
1971 { 532, "TR0(U)" },
1972 { 536, "TR1(L)" },
1973 { 540, "TR1(U)" },
1974 { 544, "TR2(L)" },
1975 { 548, "TR2(U)" },
1976 { 552, "TR3(L)" },
1977 { 556, "TR3(U)" },
1978 { 560, "TR4(L)" },
1979 { 564, "TR4(U)" },
1980 { 568, "TR5(L)" },
1981 { 572, "TR5(U)" },
1982 { 576, "TR6(L)" },
1983 { 580, "TR6(U)" },
1984 { 584, "TR7(L)" },
1985 { 588, "TR7(U)" },
Denys Vlasenkoadedb512008-12-30 18:47:55 +00001986 /* This entry is in case pt_regs contains dregs (depends on
1987 the kernel build options). */
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001988 { uoff(regs), "offsetof(struct user, regs)" },
1989 { uoff(fpu), "offsetof(struct user, fpu)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001990#elif defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001991 { uoff(regs.ARM_r0), "r0" },
1992 { uoff(regs.ARM_r1), "r1" },
1993 { uoff(regs.ARM_r2), "r2" },
1994 { uoff(regs.ARM_r3), "r3" },
1995 { uoff(regs.ARM_r4), "r4" },
1996 { uoff(regs.ARM_r5), "r5" },
1997 { uoff(regs.ARM_r6), "r6" },
1998 { uoff(regs.ARM_r7), "r7" },
1999 { uoff(regs.ARM_r8), "r8" },
2000 { uoff(regs.ARM_r9), "r9" },
2001 { uoff(regs.ARM_r10), "r10" },
2002 { uoff(regs.ARM_fp), "fp" },
2003 { uoff(regs.ARM_ip), "ip" },
2004 { uoff(regs.ARM_sp), "sp" },
2005 { uoff(regs.ARM_lr), "lr" },
2006 { uoff(regs.ARM_pc), "pc" },
2007 { uoff(regs.ARM_cpsr), "cpsr" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002008#elif defined(AVR32)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00002009 { uoff(regs.sr), "sr" },
2010 { uoff(regs.pc), "pc" },
2011 { uoff(regs.lr), "lr" },
2012 { uoff(regs.sp), "sp" },
2013 { uoff(regs.r12), "r12" },
2014 { uoff(regs.r11), "r11" },
2015 { uoff(regs.r10), "r10" },
2016 { uoff(regs.r9), "r9" },
2017 { uoff(regs.r8), "r8" },
2018 { uoff(regs.r7), "r7" },
2019 { uoff(regs.r6), "r6" },
2020 { uoff(regs.r5), "r5" },
2021 { uoff(regs.r4), "r4" },
2022 { uoff(regs.r3), "r3" },
2023 { uoff(regs.r2), "r2" },
2024 { uoff(regs.r1), "r1" },
2025 { uoff(regs.r0), "r0" },
2026 { uoff(regs.r12_orig), "orig_r12" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002027#elif defined(MIPS)
Roland McGrath542c2c62008-05-20 01:11:56 +00002028 { 0, "r0" },
2029 { 1, "r1" },
2030 { 2, "r2" },
2031 { 3, "r3" },
2032 { 4, "r4" },
2033 { 5, "r5" },
2034 { 6, "r6" },
2035 { 7, "r7" },
2036 { 8, "r8" },
2037 { 9, "r9" },
2038 { 10, "r10" },
2039 { 11, "r11" },
2040 { 12, "r12" },
2041 { 13, "r13" },
2042 { 14, "r14" },
2043 { 15, "r15" },
2044 { 16, "r16" },
2045 { 17, "r17" },
2046 { 18, "r18" },
2047 { 19, "r19" },
2048 { 20, "r20" },
2049 { 21, "r21" },
2050 { 22, "r22" },
2051 { 23, "r23" },
2052 { 24, "r24" },
2053 { 25, "r25" },
2054 { 26, "r26" },
2055 { 27, "r27" },
2056 { 28, "r28" },
2057 { 29, "r29" },
2058 { 30, "r30" },
2059 { 31, "r31" },
2060 { 32, "f0" },
2061 { 33, "f1" },
2062 { 34, "f2" },
2063 { 35, "f3" },
2064 { 36, "f4" },
2065 { 37, "f5" },
2066 { 38, "f6" },
2067 { 39, "f7" },
2068 { 40, "f8" },
2069 { 41, "f9" },
2070 { 42, "f10" },
2071 { 43, "f11" },
2072 { 44, "f12" },
2073 { 45, "f13" },
2074 { 46, "f14" },
2075 { 47, "f15" },
2076 { 48, "f16" },
2077 { 49, "f17" },
2078 { 50, "f18" },
2079 { 51, "f19" },
2080 { 52, "f20" },
2081 { 53, "f21" },
2082 { 54, "f22" },
2083 { 55, "f23" },
2084 { 56, "f24" },
2085 { 57, "f25" },
2086 { 58, "f26" },
2087 { 59, "f27" },
2088 { 60, "f28" },
2089 { 61, "f29" },
2090 { 62, "f30" },
2091 { 63, "f31" },
2092 { 64, "pc" },
2093 { 65, "cause" },
2094 { 66, "badvaddr" },
2095 { 67, "mmhi" },
2096 { 68, "mmlo" },
2097 { 69, "fpcsr" },
2098 { 70, "fpeir" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002099#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -05002100 { PTREGS_OFFSET_REG(0), "r0" },
2101 { PTREGS_OFFSET_REG(1), "r1" },
2102 { PTREGS_OFFSET_REG(2), "r2" },
2103 { PTREGS_OFFSET_REG(3), "r3" },
2104 { PTREGS_OFFSET_REG(4), "r4" },
2105 { PTREGS_OFFSET_REG(5), "r5" },
2106 { PTREGS_OFFSET_REG(6), "r6" },
2107 { PTREGS_OFFSET_REG(7), "r7" },
2108 { PTREGS_OFFSET_REG(8), "r8" },
2109 { PTREGS_OFFSET_REG(9), "r9" },
2110 { PTREGS_OFFSET_REG(10), "r10" },
2111 { PTREGS_OFFSET_REG(11), "r11" },
2112 { PTREGS_OFFSET_REG(12), "r12" },
2113 { PTREGS_OFFSET_REG(13), "r13" },
2114 { PTREGS_OFFSET_REG(14), "r14" },
2115 { PTREGS_OFFSET_REG(15), "r15" },
2116 { PTREGS_OFFSET_REG(16), "r16" },
2117 { PTREGS_OFFSET_REG(17), "r17" },
2118 { PTREGS_OFFSET_REG(18), "r18" },
2119 { PTREGS_OFFSET_REG(19), "r19" },
2120 { PTREGS_OFFSET_REG(20), "r20" },
2121 { PTREGS_OFFSET_REG(21), "r21" },
2122 { PTREGS_OFFSET_REG(22), "r22" },
2123 { PTREGS_OFFSET_REG(23), "r23" },
2124 { PTREGS_OFFSET_REG(24), "r24" },
2125 { PTREGS_OFFSET_REG(25), "r25" },
2126 { PTREGS_OFFSET_REG(26), "r26" },
2127 { PTREGS_OFFSET_REG(27), "r27" },
2128 { PTREGS_OFFSET_REG(28), "r28" },
2129 { PTREGS_OFFSET_REG(29), "r29" },
2130 { PTREGS_OFFSET_REG(30), "r30" },
2131 { PTREGS_OFFSET_REG(31), "r31" },
2132 { PTREGS_OFFSET_REG(32), "r32" },
2133 { PTREGS_OFFSET_REG(33), "r33" },
2134 { PTREGS_OFFSET_REG(34), "r34" },
2135 { PTREGS_OFFSET_REG(35), "r35" },
2136 { PTREGS_OFFSET_REG(36), "r36" },
2137 { PTREGS_OFFSET_REG(37), "r37" },
2138 { PTREGS_OFFSET_REG(38), "r38" },
2139 { PTREGS_OFFSET_REG(39), "r39" },
2140 { PTREGS_OFFSET_REG(40), "r40" },
2141 { PTREGS_OFFSET_REG(41), "r41" },
2142 { PTREGS_OFFSET_REG(42), "r42" },
2143 { PTREGS_OFFSET_REG(43), "r43" },
2144 { PTREGS_OFFSET_REG(44), "r44" },
2145 { PTREGS_OFFSET_REG(45), "r45" },
2146 { PTREGS_OFFSET_REG(46), "r46" },
2147 { PTREGS_OFFSET_REG(47), "r47" },
2148 { PTREGS_OFFSET_REG(48), "r48" },
2149 { PTREGS_OFFSET_REG(49), "r49" },
2150 { PTREGS_OFFSET_REG(50), "r50" },
2151 { PTREGS_OFFSET_REG(51), "r51" },
2152 { PTREGS_OFFSET_REG(52), "r52" },
2153 { PTREGS_OFFSET_TP, "tp" },
2154 { PTREGS_OFFSET_SP, "sp" },
2155 { PTREGS_OFFSET_LR, "lr" },
2156 { PTREGS_OFFSET_PC, "pc" },
2157 { PTREGS_OFFSET_EX1, "ex1" },
2158 { PTREGS_OFFSET_FAULTNUM, "faultnum" },
2159 { PTREGS_OFFSET_ORIG_R0, "orig_r0" },
2160 { PTREGS_OFFSET_FLAGS, "flags" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002161#endif
2162#ifdef CRISV10
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00002163 { 4*PT_FRAMETYPE, "4*PT_FRAMETYPE" },
2164 { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
2165 { 4*PT_R13, "4*PT_R13" },
2166 { 4*PT_R12, "4*PT_R12" },
2167 { 4*PT_R11, "4*PT_R11" },
2168 { 4*PT_R10, "4*PT_R10" },
2169 { 4*PT_R9, "4*PT_R9" },
2170 { 4*PT_R8, "4*PT_R8" },
2171 { 4*PT_R7, "4*PT_R7" },
2172 { 4*PT_R6, "4*PT_R6" },
2173 { 4*PT_R5, "4*PT_R5" },
2174 { 4*PT_R4, "4*PT_R4" },
2175 { 4*PT_R3, "4*PT_R3" },
2176 { 4*PT_R2, "4*PT_R2" },
2177 { 4*PT_R1, "4*PT_R1" },
2178 { 4*PT_R0, "4*PT_R0" },
2179 { 4*PT_MOF, "4*PT_MOF" },
2180 { 4*PT_DCCR, "4*PT_DCCR" },
2181 { 4*PT_SRP, "4*PT_SRP" },
2182 { 4*PT_IRP, "4*PT_IRP" },
2183 { 4*PT_CSRINSTR, "4*PT_CSRINSTR" },
2184 { 4*PT_CSRADDR, "4*PT_CSRADDR" },
2185 { 4*PT_CSRDATA, "4*PT_CSRDATA" },
2186 { 4*PT_USP, "4*PT_USP" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002187#endif
2188#ifdef CRISV32
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00002189 { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
2190 { 4*PT_R0, "4*PT_R0" },
2191 { 4*PT_R1, "4*PT_R1" },
2192 { 4*PT_R2, "4*PT_R2" },
2193 { 4*PT_R3, "4*PT_R3" },
2194 { 4*PT_R4, "4*PT_R4" },
2195 { 4*PT_R5, "4*PT_R5" },
2196 { 4*PT_R6, "4*PT_R6" },
2197 { 4*PT_R7, "4*PT_R7" },
2198 { 4*PT_R8, "4*PT_R8" },
2199 { 4*PT_R9, "4*PT_R9" },
2200 { 4*PT_R10, "4*PT_R10" },
2201 { 4*PT_R11, "4*PT_R11" },
2202 { 4*PT_R12, "4*PT_R12" },
2203 { 4*PT_R13, "4*PT_R13" },
2204 { 4*PT_ACR, "4*PT_ACR" },
2205 { 4*PT_SRS, "4*PT_SRS" },
2206 { 4*PT_MOF, "4*PT_MOF" },
2207 { 4*PT_SPC, "4*PT_SPC" },
2208 { 4*PT_CCS, "4*PT_CCS" },
2209 { 4*PT_SRP, "4*PT_SRP" },
2210 { 4*PT_ERP, "4*PT_ERP" },
2211 { 4*PT_EXS, "4*PT_EXS" },
2212 { 4*PT_EDA, "4*PT_EDA" },
2213 { 4*PT_USP, "4*PT_USP" },
2214 { 4*PT_PPC, "4*PT_PPC" },
2215 { 4*PT_BP_CTRL, "4*PT_BP_CTRL" },
2216 { 4*PT_BP+4, "4*PT_BP+4" },
2217 { 4*PT_BP+8, "4*PT_BP+8" },
2218 { 4*PT_BP+12, "4*PT_BP+12" },
2219 { 4*PT_BP+16, "4*PT_BP+16" },
2220 { 4*PT_BP+20, "4*PT_BP+20" },
2221 { 4*PT_BP+24, "4*PT_BP+24" },
2222 { 4*PT_BP+28, "4*PT_BP+28" },
2223 { 4*PT_BP+32, "4*PT_BP+32" },
2224 { 4*PT_BP+36, "4*PT_BP+36" },
2225 { 4*PT_BP+40, "4*PT_BP+40" },
2226 { 4*PT_BP+44, "4*PT_BP+44" },
2227 { 4*PT_BP+48, "4*PT_BP+48" },
2228 { 4*PT_BP+52, "4*PT_BP+52" },
2229 { 4*PT_BP+56, "4*PT_BP+56" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002230#endif
2231#ifdef MICROBLAZE
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02002232 { PT_GPR(0), "r0" },
2233 { PT_GPR(1), "r1" },
2234 { PT_GPR(2), "r2" },
2235 { PT_GPR(3), "r3" },
2236 { PT_GPR(4), "r4" },
2237 { PT_GPR(5), "r5" },
2238 { PT_GPR(6), "r6" },
2239 { PT_GPR(7), "r7" },
2240 { PT_GPR(8), "r8" },
2241 { PT_GPR(9), "r9" },
2242 { PT_GPR(10), "r10" },
2243 { PT_GPR(11), "r11" },
2244 { PT_GPR(12), "r12" },
2245 { PT_GPR(13), "r13" },
2246 { PT_GPR(14), "r14" },
2247 { PT_GPR(15), "r15" },
2248 { PT_GPR(16), "r16" },
2249 { PT_GPR(17), "r17" },
2250 { PT_GPR(18), "r18" },
2251 { PT_GPR(19), "r19" },
2252 { PT_GPR(20), "r20" },
2253 { PT_GPR(21), "r21" },
2254 { PT_GPR(22), "r22" },
2255 { PT_GPR(23), "r23" },
2256 { PT_GPR(24), "r24" },
2257 { PT_GPR(25), "r25" },
2258 { PT_GPR(26), "r26" },
2259 { PT_GPR(27), "r27" },
2260 { PT_GPR(28), "r28" },
2261 { PT_GPR(29), "r29" },
2262 { PT_GPR(30), "r30" },
2263 { PT_GPR(31), "r31" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002264 { PT_PC, "rpc", },
2265 { PT_MSR, "rmsr", },
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02002266 { PT_EAR, "rear", },
2267 { PT_ESR, "resr", },
2268 { PT_FSR, "rfsr", },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002269 { PT_KERNEL_MODE, "kernel_mode", },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002270#endif
Roland McGrath542c2c62008-05-20 01:11:56 +00002271
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002272#if !defined(SPARC) && !defined(HPPA) && !defined(POWERPC) \
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00002273 && !defined(ALPHA) && !defined(IA64) \
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02002274 && !defined(CRISV10) && !defined(CRISV32) && !defined(MICROBLAZE)
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002275# if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SPARC64) && !defined(AVR32) && !defined(BFIN) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002276 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002277# endif
2278# if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002279 { uoff(i387), "offsetof(struct user, i387)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002280# endif
2281# if defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002282 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002283# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002284 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2285 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2286 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002287# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002288 { uoff(start_code), "offsetof(struct user, start_code)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002289# endif
2290# if defined(AVR32) || defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +00002291 { uoff(start_data), "offsetof(struct user, start_data)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002292# endif
2293# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002294 { uoff(start_stack), "offsetof(struct user, start_stack)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002295# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002296 { uoff(signal), "offsetof(struct user, signal)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002297# if !defined(AVR32) && !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH) && !defined(SH64) && !defined(SPARC64) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002298 { uoff(reserved), "offsetof(struct user, reserved)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002299# endif
2300# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002301 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002302# endif
2303# if !defined(ARM) && !defined(AVR32) && !defined(MIPS) && !defined(S390) && !defined(S390X) && !defined(SPARC64) && !defined(BFIN) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002304 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002305# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002306 { uoff(magic), "offsetof(struct user, magic)" },
2307 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002308# if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002309 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002310# endif
2311#endif /* !defined(many arches) */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002312
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002313#ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002314 { sizeof(struct user), "sizeof(struct user)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002315#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002316 { 0, NULL },
2317};
2318
2319int
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002320sys_ptrace(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002321{
Roland McGrathd9f816f2004-09-04 03:39:20 +00002322 const struct xlat *x;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002323 long addr;
2324
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002325 if (entering(tcp)) {
Roland McGrathbf621d42003-01-14 09:46:21 +00002326 printxval(ptrace_cmds, tcp->u_arg[0],
Roland McGrathbf621d42003-01-14 09:46:21 +00002327 "PTRACE_???"
Roland McGrathbf621d42003-01-14 09:46:21 +00002328 );
2329 tprintf(", %lu, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002330 addr = tcp->u_arg[2];
2331 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2332 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2333 for (x = struct_user_offsets; x->str; x++) {
2334 if (x->val >= addr)
2335 break;
2336 }
2337 if (!x->str)
2338 tprintf("%#lx, ", addr);
2339 else if (x->val > addr && x != struct_user_offsets) {
2340 x--;
2341 tprintf("%s + %ld, ", x->str, addr - x->val);
2342 }
2343 else
2344 tprintf("%s, ", x->str);
2345 }
2346 else
2347 tprintf("%#lx, ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002348 switch (tcp->u_arg[0]) {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002349#ifndef IA64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002350 case PTRACE_PEEKDATA:
2351 case PTRACE_PEEKTEXT:
2352 case PTRACE_PEEKUSER:
2353 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002354#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002355 case PTRACE_CONT:
2356 case PTRACE_SINGLESTEP:
2357 case PTRACE_SYSCALL:
2358 case PTRACE_DETACH:
2359 printsignal(tcp->u_arg[3]);
2360 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002361#ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00002362 case PTRACE_SETOPTIONS:
2363 printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???");
2364 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002365#endif
2366#ifdef PTRACE_SETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002367 case PTRACE_SETSIGINFO: {
2368 siginfo_t si;
2369 if (!tcp->u_arg[3])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002370 tprints("NULL");
Denys Vlasenkof535b542009-01-13 18:30:55 +00002371 else if (syserror(tcp))
2372 tprintf("%#lx", tcp->u_arg[3]);
2373 else if (umove(tcp, tcp->u_arg[3], &si) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002374 tprints("{???}");
Denys Vlasenkof535b542009-01-13 18:30:55 +00002375 else
2376 printsiginfo(&si, verbose(tcp));
2377 break;
2378 }
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002379#endif
2380#ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002381 case PTRACE_GETSIGINFO:
2382 /* Don't print anything, do it at syscall return. */
2383 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002384#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002385 default:
2386 tprintf("%#lx", tcp->u_arg[3]);
2387 break;
2388 }
2389 } else {
2390 switch (tcp->u_arg[0]) {
2391 case PTRACE_PEEKDATA:
2392 case PTRACE_PEEKTEXT:
2393 case PTRACE_PEEKUSER:
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002394#ifdef IA64
Roland McGrath1e868062007-11-19 22:11:45 +00002395 return RVAL_HEX;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002396#else
Roland McGratheb285352003-01-14 09:59:00 +00002397 printnum(tcp, tcp->u_arg[3], "%#lx");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002398 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002399#endif
2400#ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002401 case PTRACE_GETSIGINFO: {
2402 siginfo_t si;
2403 if (!tcp->u_arg[3])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002404 tprints("NULL");
Denys Vlasenkof535b542009-01-13 18:30:55 +00002405 else if (syserror(tcp))
2406 tprintf("%#lx", tcp->u_arg[3]);
2407 else if (umove(tcp, tcp->u_arg[3], &si) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002408 tprints("{???}");
Denys Vlasenkof535b542009-01-13 18:30:55 +00002409 else
2410 printsiginfo(&si, verbose(tcp));
2411 break;
2412 }
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002413#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002414 }
2415 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002416 return 0;
2417}
2418
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002419#ifndef FUTEX_CMP_REQUEUE
2420# define FUTEX_CMP_REQUEUE 4
2421#endif
2422#ifndef FUTEX_WAKE_OP
2423# define FUTEX_WAKE_OP 5
2424#endif
2425#ifndef FUTEX_LOCK_PI
2426# define FUTEX_LOCK_PI 6
2427# define FUTEX_UNLOCK_PI 7
2428# define FUTEX_TRYLOCK_PI 8
2429#endif
2430#ifndef FUTEX_WAIT_BITSET
2431# define FUTEX_WAIT_BITSET 9
2432#endif
2433#ifndef FUTEX_WAKE_BITSET
2434# define FUTEX_WAKE_BITSET 10
2435#endif
2436#ifndef FUTEX_WAIT_REQUEUE_PI
2437# define FUTEX_WAIT_REQUEUE_PI 11
2438#endif
2439#ifndef FUTEX_CMP_REQUEUE_PI
2440# define FUTEX_CMP_REQUEUE_PI 12
2441#endif
2442#ifndef FUTEX_PRIVATE_FLAG
2443# define FUTEX_PRIVATE_FLAG 128
2444#endif
2445#ifndef FUTEX_CLOCK_REALTIME
2446# define FUTEX_CLOCK_REALTIME 256
2447#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +00002448static const struct xlat futexops[] = {
Roland McGrath51942a92007-07-05 18:59:11 +00002449 { FUTEX_WAIT, "FUTEX_WAIT" },
2450 { FUTEX_WAKE, "FUTEX_WAKE" },
2451 { FUTEX_FD, "FUTEX_FD" },
2452 { FUTEX_REQUEUE, "FUTEX_REQUEUE" },
2453 { FUTEX_CMP_REQUEUE, "FUTEX_CMP_REQUEUE" },
2454 { FUTEX_WAKE_OP, "FUTEX_WAKE_OP" },
2455 { FUTEX_LOCK_PI, "FUTEX_LOCK_PI" },
2456 { FUTEX_UNLOCK_PI, "FUTEX_UNLOCK_PI" },
2457 { FUTEX_TRYLOCK_PI, "FUTEX_TRYLOCK_PI" },
Roland McGrath1aeaf742008-07-18 01:27:39 +00002458 { FUTEX_WAIT_BITSET, "FUTEX_WAIT_BITSET" },
2459 { FUTEX_WAKE_BITSET, "FUTEX_WAKE_BITSET" },
Andreas Schwab85f58322009-08-12 09:54:42 +02002460 { FUTEX_WAIT_REQUEUE_PI, "FUTEX_WAIT_REQUEUE_PI" },
2461 { FUTEX_CMP_REQUEUE_PI, "FUTEX_CMP_REQUEUE_PI" },
Roland McGrath51942a92007-07-05 18:59:11 +00002462 { FUTEX_WAIT|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_PRIVATE" },
2463 { FUTEX_WAKE|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_PRIVATE" },
2464 { FUTEX_FD|FUTEX_PRIVATE_FLAG, "FUTEX_FD_PRIVATE" },
2465 { FUTEX_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_REQUEUE_PRIVATE" },
2466 { FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PRIVATE" },
2467 { FUTEX_WAKE_OP|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_OP_PRIVATE" },
2468 { FUTEX_LOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_LOCK_PI_PRIVATE" },
2469 { FUTEX_UNLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_UNLOCK_PI_PRIVATE" },
2470 { FUTEX_TRYLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_TRYLOCK_PI_PRIVATE" },
Roland McGrath1aeaf742008-07-18 01:27:39 +00002471 { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_BITSET_PRIVATE" },
2472 { FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_BITSET_PRIVATE" },
Andreas Schwab85f58322009-08-12 09:54:42 +02002473 { FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_REQUEUE_PI_PRIVATE" },
2474 { FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PI_PRIVATE" },
2475 { FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME" },
2476 { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME" },
2477 { FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME" },
2478 { FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_REQUEUE_PI_PRIVATE|FUTEX_CLOCK_REALTIME" },
Roland McGrath51942a92007-07-05 18:59:11 +00002479 { 0, NULL }
2480};
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002481#ifndef FUTEX_OP_SET
2482# define FUTEX_OP_SET 0
2483# define FUTEX_OP_ADD 1
2484# define FUTEX_OP_OR 2
2485# define FUTEX_OP_ANDN 3
2486# define FUTEX_OP_XOR 4
2487# define FUTEX_OP_CMP_EQ 0
2488# define FUTEX_OP_CMP_NE 1
2489# define FUTEX_OP_CMP_LT 2
2490# define FUTEX_OP_CMP_LE 3
2491# define FUTEX_OP_CMP_GT 4
2492# define FUTEX_OP_CMP_GE 5
2493#endif
Roland McGrath51942a92007-07-05 18:59:11 +00002494static const struct xlat futexwakeops[] = {
2495 { FUTEX_OP_SET, "FUTEX_OP_SET" },
2496 { FUTEX_OP_ADD, "FUTEX_OP_ADD" },
2497 { FUTEX_OP_OR, "FUTEX_OP_OR" },
2498 { FUTEX_OP_ANDN, "FUTEX_OP_ANDN" },
2499 { FUTEX_OP_XOR, "FUTEX_OP_XOR" },
2500 { 0, NULL }
2501};
2502static const struct xlat futexwakecmps[] = {
2503 { FUTEX_OP_CMP_EQ, "FUTEX_OP_CMP_EQ" },
2504 { FUTEX_OP_CMP_NE, "FUTEX_OP_CMP_NE" },
2505 { FUTEX_OP_CMP_LT, "FUTEX_OP_CMP_LT" },
2506 { FUTEX_OP_CMP_LE, "FUTEX_OP_CMP_LE" },
2507 { FUTEX_OP_CMP_GT, "FUTEX_OP_CMP_GT" },
2508 { FUTEX_OP_CMP_GE, "FUTEX_OP_CMP_GE" },
2509 { 0, NULL }
Roland McGrath5a223472002-12-15 23:58:26 +00002510};
2511
2512int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002513sys_futex(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00002514{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002515 if (entering(tcp)) {
2516 long int cmd = tcp->u_arg[1] & 127;
2517 tprintf("%p, ", (void *) tcp->u_arg[0]);
2518 printxval(futexops, tcp->u_arg[1], "FUTEX_???");
2519 tprintf(", %ld", tcp->u_arg[2]);
2520 if (cmd == FUTEX_WAKE_BITSET)
2521 tprintf(", %lx", tcp->u_arg[5]);
2522 else if (cmd == FUTEX_WAIT) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002523 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002524 printtv(tcp, tcp->u_arg[3]);
2525 } else if (cmd == FUTEX_WAIT_BITSET) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002526 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002527 printtv(tcp, tcp->u_arg[3]);
2528 tprintf(", %lx", tcp->u_arg[5]);
2529 } else if (cmd == FUTEX_REQUEUE)
2530 tprintf(", %ld, %p", tcp->u_arg[3], (void *) tcp->u_arg[4]);
Andreas Schwab85f58322009-08-12 09:54:42 +02002531 else if (cmd == FUTEX_CMP_REQUEUE || cmd == FUTEX_CMP_REQUEUE_PI)
Denys Vlasenko1d632462009-04-14 12:51:00 +00002532 tprintf(", %ld, %p, %ld", tcp->u_arg[3], (void *) tcp->u_arg[4], tcp->u_arg[5]);
2533 else if (cmd == FUTEX_WAKE_OP) {
2534 tprintf(", %ld, %p, {", tcp->u_arg[3], (void *) tcp->u_arg[4]);
2535 if ((tcp->u_arg[5] >> 28) & 8)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002536 tprints("FUTEX_OP_OPARG_SHIFT|");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002537 printxval(futexwakeops, (tcp->u_arg[5] >> 28) & 0x7, "FUTEX_OP_???");
2538 tprintf(", %ld, ", (tcp->u_arg[5] >> 12) & 0xfff);
2539 if ((tcp->u_arg[5] >> 24) & 8)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002540 tprints("FUTEX_OP_OPARG_SHIFT|");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002541 printxval(futexwakecmps, (tcp->u_arg[5] >> 24) & 0x7, "FUTEX_OP_CMP_???");
2542 tprintf(", %ld}", tcp->u_arg[5] & 0xfff);
Andreas Schwab85f58322009-08-12 09:54:42 +02002543 } else if (cmd == FUTEX_WAIT_REQUEUE_PI) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002544 tprints(", ");
Andreas Schwab85f58322009-08-12 09:54:42 +02002545 printtv(tcp, tcp->u_arg[3]);
2546 tprintf(", %p", (void *) tcp->u_arg[4]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002547 }
Roland McGrath51942a92007-07-05 18:59:11 +00002548 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002549 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00002550}
2551
2552static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002553print_affinitylist(struct tcb *tcp, long list, unsigned int len)
Roland McGrath5a223472002-12-15 23:58:26 +00002554{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002555 int first = 1;
Dmitry V. Levin62e05962009-11-03 14:38:44 +00002556 unsigned long w, min_len;
2557
2558 if (abbrev(tcp) && len / sizeof(w) > max_strlen)
2559 min_len = len - max_strlen * sizeof(w);
2560 else
2561 min_len = 0;
2562 for (; len >= sizeof(w) && len > min_len;
2563 len -= sizeof(w), list += sizeof(w)) {
2564 if (umove(tcp, list, &w) < 0)
2565 break;
2566 if (first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002567 tprints("{");
Dmitry V. Levin62e05962009-11-03 14:38:44 +00002568 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002569 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002570 first = 0;
Dmitry V. Levin62e05962009-11-03 14:38:44 +00002571 tprintf("%lx", w);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002572 }
Dmitry V. Levin62e05962009-11-03 14:38:44 +00002573 if (len) {
2574 if (first)
2575 tprintf("%#lx", list);
2576 else
2577 tprintf(", %s}", (len >= sizeof(w) && len > min_len ?
2578 "???" : "..."));
2579 } else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002580 tprints(first ? "{}" : "}");
Dmitry V. Levin62e05962009-11-03 14:38:44 +00002581 }
Roland McGrath5a223472002-12-15 23:58:26 +00002582}
2583
2584int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002585sys_sched_setaffinity(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00002586{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002587 if (entering(tcp)) {
2588 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2589 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2590 }
2591 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00002592}
2593
2594int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002595sys_sched_getaffinity(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00002596{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002597 if (entering(tcp)) {
2598 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2599 } else {
2600 if (tcp->u_rval == -1)
2601 tprintf("%#lx", tcp->u_arg[2]);
2602 else
2603 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_rval);
2604 }
2605 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00002606}
Roland McGrath279d3782004-03-01 20:27:37 +00002607
Dmitry V. Levin1b0bae22012-03-11 22:32:26 +00002608int
2609sys_get_robust_list(struct tcb *tcp)
2610{
2611 if (entering(tcp)) {
2612 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
2613 } else {
2614 void *addr;
2615 size_t len;
2616
2617 if (syserror(tcp) ||
2618 !tcp->u_arg[1] ||
2619 umove(tcp, tcp->u_arg[1], &addr) < 0) {
2620 tprintf("%#lx, ", tcp->u_arg[1]);
2621 } else {
2622 tprintf("[%p], ", addr);
2623 }
2624
2625 if (syserror(tcp) ||
2626 !tcp->u_arg[2] ||
2627 umove(tcp, tcp->u_arg[2], &len) < 0) {
2628 tprintf("%#lx", tcp->u_arg[2]);
2629 } else {
2630 tprintf("[%lu]", (unsigned long) len);
2631 }
2632 }
2633 return 0;
2634}
2635
Roland McGrathd9f816f2004-09-04 03:39:20 +00002636static const struct xlat schedulers[] = {
Roland McGrath279d3782004-03-01 20:27:37 +00002637 { SCHED_OTHER, "SCHED_OTHER" },
2638 { SCHED_RR, "SCHED_RR" },
2639 { SCHED_FIFO, "SCHED_FIFO" },
2640 { 0, NULL }
2641};
2642
2643int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002644sys_sched_getscheduler(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00002645{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002646 if (entering(tcp)) {
2647 tprintf("%d", (int) tcp->u_arg[0]);
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002648 } else if (!syserror(tcp)) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002649 tcp->auxstr = xlookup(schedulers, tcp->u_rval);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002650 if (tcp->auxstr != NULL)
2651 return RVAL_STR;
2652 }
2653 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00002654}
2655
2656int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002657sys_sched_setscheduler(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00002658{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002659 if (entering(tcp)) {
2660 struct sched_param p;
2661 tprintf("%d, ", (int) tcp->u_arg[0]);
2662 printxval(schedulers, tcp->u_arg[1], "SCHED_???");
2663 if (umove(tcp, tcp->u_arg[2], &p) < 0)
2664 tprintf(", %#lx", tcp->u_arg[2]);
2665 else
2666 tprintf(", { %d }", p.__sched_priority);
2667 }
2668 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00002669}
2670
2671int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002672sys_sched_getparam(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00002673{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002674 if (entering(tcp)) {
2675 tprintf("%d, ", (int) tcp->u_arg[0]);
2676 } else {
2677 struct sched_param p;
2678 if (umove(tcp, tcp->u_arg[1], &p) < 0)
2679 tprintf("%#lx", tcp->u_arg[1]);
2680 else
2681 tprintf("{ %d }", p.__sched_priority);
2682 }
2683 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00002684}
2685
2686int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002687sys_sched_setparam(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00002688{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002689 if (entering(tcp)) {
2690 struct sched_param p;
2691 if (umove(tcp, tcp->u_arg[1], &p) < 0)
2692 tprintf("%d, %#lx", (int) tcp->u_arg[0], tcp->u_arg[1]);
2693 else
2694 tprintf("%d, { %d }", (int) tcp->u_arg[0], p.__sched_priority);
2695 }
2696 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00002697}
2698
2699int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002700sys_sched_get_priority_min(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00002701{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002702 if (entering(tcp)) {
2703 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
2704 }
2705 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00002706}
Roland McGrathc2d5eb02005-02-02 04:16:56 +00002707
Dmitry V. Levin1ff463d2012-03-11 23:00:11 +00002708int
2709sys_sched_rr_get_interval(struct tcb *tcp)
2710{
2711 if (entering(tcp)) {
2712 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
2713 } else {
2714 if (syserror(tcp))
2715 tprintf("%#lx", tcp->u_arg[1]);
2716 else
2717 print_timespec(tcp, tcp->u_arg[1]);
2718 }
2719 return 0;
2720}
2721
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002722#ifdef X86_64
2723# include <asm/prctl.h>
Roland McGrathc2d5eb02005-02-02 04:16:56 +00002724
2725static const struct xlat archvals[] = {
2726 { ARCH_SET_GS, "ARCH_SET_GS" },
2727 { ARCH_SET_FS, "ARCH_SET_FS" },
2728 { ARCH_GET_FS, "ARCH_GET_FS" },
2729 { ARCH_GET_GS, "ARCH_GET_GS" },
2730 { 0, NULL },
2731};
2732
2733int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002734sys_arch_prctl(struct tcb *tcp)
Roland McGrathc2d5eb02005-02-02 04:16:56 +00002735{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002736 if (entering(tcp)) {
2737 printxval(archvals, tcp->u_arg[0], "ARCH_???");
2738 if (tcp->u_arg[0] == ARCH_SET_GS
2739 || tcp->u_arg[0] == ARCH_SET_FS
2740 ) {
2741 tprintf(", %#lx", tcp->u_arg[1]);
2742 }
2743 } else {
2744 if (tcp->u_arg[0] == ARCH_GET_GS
2745 || tcp->u_arg[0] == ARCH_GET_FS
2746 ) {
2747 long int v;
2748 if (!syserror(tcp) && umove(tcp, tcp->u_arg[1], &v) != -1)
2749 tprintf(", [%#lx]", v);
2750 else
2751 tprintf(", %#lx", tcp->u_arg[1]);
2752 }
Roland McGrathc2d5eb02005-02-02 04:16:56 +00002753 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002754 return 0;
Roland McGrathc2d5eb02005-02-02 04:16:56 +00002755}
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002756#endif /* X86_64 */
Roland McGrathc2d5eb02005-02-02 04:16:56 +00002757
Roland McGrathdb8319f2007-08-02 01:37:55 +00002758int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002759sys_getcpu(struct tcb *tcp)
Roland McGrathdb8319f2007-08-02 01:37:55 +00002760{
2761 if (exiting(tcp)) {
2762 unsigned u;
2763 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002764 tprints("NULL, ");
Roland McGrathdb8319f2007-08-02 01:37:55 +00002765 else if (umove(tcp, tcp->u_arg[0], &u) < 0)
2766 tprintf("%#lx, ", tcp->u_arg[0]);
2767 else
2768 tprintf("[%u], ", u);
2769 if (tcp->u_arg[1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002770 tprints("NULL, ");
Roland McGrathdb8319f2007-08-02 01:37:55 +00002771 else if (umove(tcp, tcp->u_arg[1], &u) < 0)
2772 tprintf("%#lx, ", tcp->u_arg[1]);
2773 else
2774 tprintf("[%u], ", u);
2775 tprintf("%#lx", tcp->u_arg[2]);
2776 }
2777 return 0;
2778}
2779
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002780int
2781sys_process_vm_readv(struct tcb *tcp)
2782{
2783 if (entering(tcp)) {
2784 /* arg 1: pid */
2785 tprintf("%ld, ", tcp->u_arg[0]);
2786 } else {
Dmitry V. Levin0bfd7442012-03-10 14:03:25 +00002787 /* arg 2: local iov */
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002788 if (syserror(tcp)) {
Dmitry V. Levin0bfd7442012-03-10 14:03:25 +00002789 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002790 } else {
2791 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
2792 }
Dmitry V. Levin0bfd7442012-03-10 14:03:25 +00002793 /* arg 3: local iovcnt */
2794 tprintf(", %lu, ", tcp->u_arg[2]);
2795 /* arg 4: remote iov */
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002796 if (syserror(tcp)) {
Dmitry V. Levin0bfd7442012-03-10 14:03:25 +00002797 tprintf("%#lx", tcp->u_arg[3]);
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002798 } else {
2799 tprint_iov(tcp, tcp->u_arg[4], tcp->u_arg[3], 0);
2800 }
Dmitry V. Levin0bfd7442012-03-10 14:03:25 +00002801 /* arg 5: remote iovcnt */
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002802 /* arg 6: flags */
Dmitry V. Levin0bfd7442012-03-10 14:03:25 +00002803 tprintf(", %lu, %lu", tcp->u_arg[4], tcp->u_arg[5]);
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002804 }
2805 return 0;
2806}
Dmitry V. Levin03952102012-03-10 14:14:49 +00002807
2808int
2809sys_process_vm_writev(struct tcb *tcp)
2810{
2811 if (entering(tcp)) {
2812 /* arg 1: pid */
2813 tprintf("%ld, ", tcp->u_arg[0]);
2814 /* arg 2: local iov */
2815 if (syserror(tcp))
2816 tprintf("%#lx", tcp->u_arg[1]);
2817 else
2818 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
2819 /* arg 3: local iovcnt */
2820 tprintf(", %lu, ", tcp->u_arg[2]);
2821 /* arg 4: remote iov */
2822 if (syserror(tcp))
2823 tprintf("%#lx", tcp->u_arg[3]);
2824 else
2825 tprint_iov(tcp, tcp->u_arg[4], tcp->u_arg[3], 0);
2826 /* arg 5: remote iovcnt */
2827 /* arg 6: flags */
2828 tprintf(", %lu, %lu", tcp->u_arg[4], tcp->u_arg[5]);
2829 }
2830 return 0;
2831}