blob: ac184fa7aefe280efd97804a68f3362dc52b7128 [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
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000534internal_fork(struct tcb *tcp)
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000535{
Denys Vlasenkof44cce42011-06-21 14:34:10 +0200536 if ((ptrace_setoptions
Wang Chaoca8ab8d2010-11-12 17:26:08 +0800537 & (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
538 == (PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK))
539 return 0;
540
Denys Vlasenko65d7c4d2011-06-23 21:46:37 +0200541 if (!followfork)
542 return 0;
543
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000544 if (entering(tcp)) {
Wang Chaoe636c852010-09-16 11:20:56 +0800545 /*
Denys Vlasenko833fb132011-08-17 11:30:56 +0200546 * We won't see the new child if clone is called with
547 * CLONE_UNTRACED, so we keep the same logic with that option
548 * and don't trace it.
Wang Chaoe636c852010-09-16 11:20:56 +0800549 */
550 if ((sysent[tcp->scno].sys_func == sys_clone) &&
551 (tcp->u_arg[ARG_FLAGS] & CLONE_UNTRACED))
552 return 0;
Denys Vlasenkoe7c90242011-06-22 00:09:25 +0200553 setbpt(tcp);
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000554 } else {
Denys Vlasenko833fb132011-08-17 11:30:56 +0200555 if (tcp->flags & TCB_BPTSET)
556 clearbpt(tcp);
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000557 }
Wichert Akkerman7a0b6491999-12-23 15:08:17 +0000558 return 0;
559}
Dmitry V. Levin257e1572009-12-26 17:55:24 +0000560
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561int
Denys Vlasenko081533c2012-03-17 02:17:51 +0100562sys_fork(struct tcb *tcp)
563{
564 if (exiting(tcp))
565 return RVAL_UDECIMAL;
566 return 0;
567}
568
569int
Denys Vlasenko12014262011-05-30 14:00:14 +0200570sys_vfork(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571{
572 if (exiting(tcp))
573 return RVAL_UDECIMAL;
574 return 0;
575}
576
Dmitry V. Levin50a218d2011-01-18 17:36:20 +0000577int sys_getuid(struct tcb *tcp)
578{
579 if (exiting(tcp))
580 tcp->u_rval = (uid_t) tcp->u_rval;
581 return RVAL_UDECIMAL;
582}
583
584int sys_setfsuid(struct tcb *tcp)
585{
586 if (entering(tcp))
587 tprintf("%u", (uid_t) tcp->u_arg[0]);
588 else
589 tcp->u_rval = (uid_t) tcp->u_rval;
590 return RVAL_UDECIMAL;
591}
592
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593int
Denys Vlasenko12014262011-05-30 14:00:14 +0200594sys_setuid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000595{
596 if (entering(tcp)) {
597 tprintf("%u", (uid_t) tcp->u_arg[0]);
598 }
599 return 0;
600}
601
602int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000603sys_getresuid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604{
605 if (exiting(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000606 __kernel_uid_t uid;
607 if (syserror(tcp))
608 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
609 tcp->u_arg[1], tcp->u_arg[2]);
610 else {
611 if (umove(tcp, tcp->u_arg[0], &uid) < 0)
612 tprintf("%#lx, ", tcp->u_arg[0]);
613 else
Roland McGrath83bd47a2003-11-13 22:32:26 +0000614 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +0000615 if (umove(tcp, tcp->u_arg[1], &uid) < 0)
616 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000617 else
Roland McGrath83bd47a2003-11-13 22:32:26 +0000618 tprintf("[%lu], ", (unsigned long) uid);
Roland McGrath9bd6b422003-02-24 07:13:51 +0000619 if (umove(tcp, tcp->u_arg[2], &uid) < 0)
620 tprintf("%#lx", tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000621 else
Roland McGrath83bd47a2003-11-13 22:32:26 +0000622 tprintf("[%lu]", (unsigned long) uid);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000623 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000624 }
625 return 0;
626}
627
628int
Denys Vlasenko12014262011-05-30 14:00:14 +0200629sys_setreuid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630{
631 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +0000632 printuid("", tcp->u_arg[0]);
633 printuid(", ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000634 }
635 return 0;
636}
637
638int
Denys Vlasenko12014262011-05-30 14:00:14 +0200639sys_setresuid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640{
641 if (entering(tcp)) {
Roland McGrath83bd47a2003-11-13 22:32:26 +0000642 printuid("", tcp->u_arg[0]);
643 printuid(", ", tcp->u_arg[1]);
644 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000645 }
646 return 0;
647}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000648
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000649int
Denys Vlasenko12014262011-05-30 14:00:14 +0200650sys_setgroups(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000651{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000652 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +0000653 unsigned long len, size, start, cur, end, abbrev_end;
654 GETGROUPS_T gid;
655 int failed = 0;
656
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +0000658 tprintf("%lu, ", len);
659 if (len == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200660 tprints("[]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000661 return 0;
662 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000663 start = tcp->u_arg[1];
664 if (start == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200665 tprints("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +0000666 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000667 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000668 size = len * sizeof(gid);
669 end = start + size;
670 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
671 tprintf("%#lx", start);
672 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000673 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000674 if (abbrev(tcp)) {
675 abbrev_end = start + max_strlen * sizeof(gid);
676 if (abbrev_end < start)
677 abbrev_end = end;
678 } else {
679 abbrev_end = end;
680 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200681 tprints("[");
Roland McGrathaa524c82005-06-01 19:22:06 +0000682 for (cur = start; cur < end; cur += sizeof(gid)) {
683 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200684 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000685 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200686 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000687 break;
688 }
689 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200690 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000691 failed = 1;
692 break;
693 }
694 tprintf("%lu", (unsigned long) gid);
695 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200696 tprints("]");
Roland McGrathaa524c82005-06-01 19:22:06 +0000697 if (failed)
698 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000699 }
700 return 0;
701}
702
703int
Denys Vlasenko12014262011-05-30 14:00:14 +0200704sys_getgroups(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705{
Roland McGrathaa524c82005-06-01 19:22:06 +0000706 unsigned long len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000707
708 if (entering(tcp)) {
709 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +0000710 tprintf("%lu, ", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +0000712 unsigned long size, start, cur, end, abbrev_end;
713 GETGROUPS_T gid;
714 int failed = 0;
715
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000716 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +0000717 if (len == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200718 tprints("[]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000719 return 0;
720 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000721 start = tcp->u_arg[1];
722 if (start == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200723 tprints("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +0000724 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000725 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000726 if (tcp->u_arg[0] == 0) {
727 tprintf("%#lx", start);
728 return 0;
729 }
730 size = len * sizeof(gid);
731 end = start + size;
732 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
733 size / sizeof(gid) != len || end < start) {
734 tprintf("%#lx", start);
735 return 0;
736 }
737 if (abbrev(tcp)) {
738 abbrev_end = start + max_strlen * sizeof(gid);
739 if (abbrev_end < start)
740 abbrev_end = end;
741 } else {
742 abbrev_end = end;
743 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200744 tprints("[");
Roland McGrathaa524c82005-06-01 19:22:06 +0000745 for (cur = start; cur < end; cur += sizeof(gid)) {
746 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200747 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000748 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200749 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000750 break;
751 }
752 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200753 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000754 failed = 1;
755 break;
756 }
757 tprintf("%lu", (unsigned long) gid);
758 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200759 tprints("]");
Roland McGrathaa524c82005-06-01 19:22:06 +0000760 if (failed)
761 tprintf(" %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000762 }
763 return 0;
764}
765
Roland McGrath83bd47a2003-11-13 22:32:26 +0000766int
Denys Vlasenko12014262011-05-30 14:00:14 +0200767sys_setgroups32(struct tcb *tcp)
Roland McGrath83bd47a2003-11-13 22:32:26 +0000768{
Roland McGrath83bd47a2003-11-13 22:32:26 +0000769 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +0000770 unsigned long len, size, start, cur, end, abbrev_end;
771 GETGROUPS32_T gid;
772 int failed = 0;
773
Roland McGrath83bd47a2003-11-13 22:32:26 +0000774 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +0000775 tprintf("%lu, ", len);
776 if (len == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200777 tprints("[]");
Roland McGrath83bd47a2003-11-13 22:32:26 +0000778 return 0;
779 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000780 start = tcp->u_arg[1];
781 if (start == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200782 tprints("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +0000783 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +0000784 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000785 size = len * sizeof(gid);
786 end = start + size;
787 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
788 tprintf("%#lx", start);
789 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +0000790 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000791 if (abbrev(tcp)) {
792 abbrev_end = start + max_strlen * sizeof(gid);
793 if (abbrev_end < start)
794 abbrev_end = end;
795 } else {
796 abbrev_end = end;
797 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200798 tprints("[");
Roland McGrathaa524c82005-06-01 19:22:06 +0000799 for (cur = start; cur < end; cur += sizeof(gid)) {
800 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200801 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000802 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200803 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000804 break;
805 }
806 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200807 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000808 failed = 1;
809 break;
810 }
811 tprintf("%lu", (unsigned long) gid);
812 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200813 tprints("]");
Roland McGrathaa524c82005-06-01 19:22:06 +0000814 if (failed)
815 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +0000816 }
817 return 0;
818}
819
820int
Denys Vlasenko12014262011-05-30 14:00:14 +0200821sys_getgroups32(struct tcb *tcp)
Roland McGrath83bd47a2003-11-13 22:32:26 +0000822{
Roland McGrathaa524c82005-06-01 19:22:06 +0000823 unsigned long len;
Roland McGrath83bd47a2003-11-13 22:32:26 +0000824
825 if (entering(tcp)) {
826 len = tcp->u_arg[0];
Roland McGrathaa524c82005-06-01 19:22:06 +0000827 tprintf("%lu, ", len);
Roland McGrath83bd47a2003-11-13 22:32:26 +0000828 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +0000829 unsigned long size, start, cur, end, abbrev_end;
830 GETGROUPS32_T gid;
831 int failed = 0;
832
Roland McGrath83bd47a2003-11-13 22:32:26 +0000833 len = tcp->u_rval;
Roland McGrathaa524c82005-06-01 19:22:06 +0000834 if (len == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200835 tprints("[]");
Roland McGrath83bd47a2003-11-13 22:32:26 +0000836 return 0;
837 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000838 start = tcp->u_arg[1];
839 if (start == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200840 tprints("NULL");
Roland McGrathaa524c82005-06-01 19:22:06 +0000841 return 0;
Roland McGrath83bd47a2003-11-13 22:32:26 +0000842 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000843 size = len * sizeof(gid);
844 end = start + size;
845 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
846 size / sizeof(gid) != len || end < start) {
847 tprintf("%#lx", start);
848 return 0;
849 }
850 if (abbrev(tcp)) {
851 abbrev_end = start + max_strlen * sizeof(gid);
852 if (abbrev_end < start)
853 abbrev_end = end;
854 } else {
855 abbrev_end = end;
856 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200857 tprints("[");
Roland McGrathaa524c82005-06-01 19:22:06 +0000858 for (cur = start; cur < end; cur += sizeof(gid)) {
859 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200860 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000861 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200862 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000863 break;
864 }
865 if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200866 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000867 failed = 1;
868 break;
869 }
870 tprintf("%lu", (unsigned long) gid);
871 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200872 tprints("]");
Roland McGrathaa524c82005-06-01 19:22:06 +0000873 if (failed)
874 tprintf(" %#lx", tcp->u_arg[1]);
Roland McGrath83bd47a2003-11-13 22:32:26 +0000875 }
876 return 0;
877}
Roland McGrath83bd47a2003-11-13 22:32:26 +0000878
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000879static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000880printargv(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000881{
Roland McGrath85a3bc42007-08-02 02:13:05 +0000882 union {
Andreas Schwab99c85692009-08-28 19:36:20 +0200883 unsigned int p32;
884 unsigned long p64;
Roland McGrath85a3bc42007-08-02 02:13:05 +0000885 char data[sizeof(long)];
886 } cp;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000887 const char *sep;
Roland McGrath85a3bc42007-08-02 02:13:05 +0000888 int n = 0;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100889 unsigned wordsize = personality_wordsize[current_personality];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000890
Roland McGrath85a3bc42007-08-02 02:13:05 +0000891 cp.p64 = 1;
892 for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100893 if (umoven(tcp, addr, wordsize, cp.data) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000894 tprintf("%#lx", addr);
895 return;
896 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100897 if (wordsize == 4)
Roland McGrath85a3bc42007-08-02 02:13:05 +0000898 cp.p64 = cp.p32;
899 if (cp.p64 == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000900 break;
Denys Vlasenko5940e652011-09-01 09:55:05 +0200901 tprints(sep);
Roland McGrath85a3bc42007-08-02 02:13:05 +0000902 printstr(tcp, cp.p64, -1);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100903 addr += wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000904 }
Roland McGrath85a3bc42007-08-02 02:13:05 +0000905 if (cp.p64)
906 tprintf("%s...", sep);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000907}
908
909static void
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000910printargc(const char *fmt, struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000911{
912 int count;
913 char *cp;
914
915 for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
916 addr += sizeof(char *);
917 }
918 tprintf(fmt, count, count == 1 ? "" : "s");
919}
920
Denys Vlasenko84703742012-02-25 02:38:52 +0100921#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000922int
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000923sys_execv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000924{
925 if (entering(tcp)) {
926 printpath(tcp, tcp->u_arg[0]);
927 if (!verbose(tcp))
928 tprintf(", %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000929 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200930 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000931 printargv(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200932 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000933 }
934 }
935 return 0;
936}
Denys Vlasenko84703742012-02-25 02:38:52 +0100937#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000938
939int
Dmitry V. Levine5e60852009-12-31 22:50:49 +0000940sys_execve(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000941{
942 if (entering(tcp)) {
943 printpath(tcp, tcp->u_arg[0]);
944 if (!verbose(tcp))
945 tprintf(", %#lx", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000946 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200947 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000948 printargv(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200949 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000950 }
951 if (!verbose(tcp))
952 tprintf(", %#lx", tcp->u_arg[2]);
953 else if (abbrev(tcp))
954 printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
955 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200956 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000957 printargv(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200958 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000959 }
960 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000961 return 0;
962}
963
Denys Vlasenko84703742012-02-25 02:38:52 +0100964#if defined(TCB_WAITEXECVE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000965int
Denys Vlasenkof8bc0652011-05-24 20:30:24 +0200966internal_exec(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000967{
Roland McGrathfdb097f2004-07-12 07:38:55 +0000968 if (exiting(tcp) && syserror(tcp))
969 tcp->flags &= ~TCB_WAITEXECVE;
Denys Vlasenkof8bc0652011-05-24 20:30:24 +0200970 else {
971 /* Maybe we have post-execve SIGTRAP suppressed? */
Denys Vlasenkof44cce42011-06-21 14:34:10 +0200972 if (!(ptrace_setoptions & PTRACE_O_TRACEEXEC))
Denys Vlasenkof8bc0652011-05-24 20:30:24 +0200973 tcp->flags |= TCB_WAITEXECVE; /* no */
974 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975 return 0;
976}
Denys Vlasenkoa7949742011-08-21 17:26:55 +0200977#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000978
Roland McGrath7ec1d352002-12-17 04:50:44 +0000979#ifndef __WNOTHREAD
980#define __WNOTHREAD 0x20000000
981#endif
982#ifndef __WALL
983#define __WALL 0x40000000
984#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000985#ifndef __WCLONE
Roland McGrath7ec1d352002-12-17 04:50:44 +0000986#define __WCLONE 0x80000000
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000987#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000988
Roland McGrathd9f816f2004-09-04 03:39:20 +0000989static const struct xlat wait4_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990 { WNOHANG, "WNOHANG" },
991#ifndef WSTOPPED
992 { WUNTRACED, "WUNTRACED" },
993#endif
994#ifdef WEXITED
995 { WEXITED, "WEXITED" },
996#endif
997#ifdef WTRAPPED
998 { WTRAPPED, "WTRAPPED" },
999#endif
1000#ifdef WSTOPPED
1001 { WSTOPPED, "WSTOPPED" },
1002#endif
1003#ifdef WCONTINUED
1004 { WCONTINUED, "WCONTINUED" },
1005#endif
1006#ifdef WNOWAIT
1007 { WNOWAIT, "WNOWAIT" },
1008#endif
1009#ifdef __WCLONE
1010 { __WCLONE, "__WCLONE" },
1011#endif
Roland McGrath7ec1d352002-12-17 04:50:44 +00001012#ifdef __WALL
1013 { __WALL, "__WALL" },
1014#endif
1015#ifdef __WNOTHREAD
1016 { __WNOTHREAD, "__WNOTHREAD" },
1017#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018 { 0, NULL },
1019};
1020
Roland McGrath5e02a572004-10-19 23:33:47 +00001021#if !defined WCOREFLAG && defined WCOREFLG
1022# define WCOREFLAG WCOREFLG
1023#endif
1024#ifndef WCOREFLAG
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001025# define WCOREFLAG 0x80
Roland McGrath5e02a572004-10-19 23:33:47 +00001026#endif
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001027#ifndef WCOREDUMP
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001028# define WCOREDUMP(status) ((status) & 0200)
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001029#endif
Roland McGrath5e02a572004-10-19 23:33:47 +00001030#ifndef W_STOPCODE
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001031# define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
Roland McGrath5e02a572004-10-19 23:33:47 +00001032#endif
1033#ifndef W_EXITCODE
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001034# define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
Roland McGrath5e02a572004-10-19 23:33:47 +00001035#endif
1036
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001037static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001038printstatus(int status)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001039{
1040 int exited = 0;
1041
1042 /*
1043 * Here is a tricky presentation problem. This solution
1044 * is still not entirely satisfactory but since there
1045 * are no wait status constructors it will have to do.
1046 */
Roland McGrath79fbda52004-04-14 02:45:55 +00001047 if (WIFSTOPPED(status)) {
1048 tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001049 signame(WSTOPSIG(status)));
Roland McGrath79fbda52004-04-14 02:45:55 +00001050 status &= ~W_STOPCODE(WSTOPSIG(status));
1051 }
1052 else if (WIFSIGNALED(status)) {
1053 tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
Nate Sammonsce780fc1999-03-29 23:23:13 +00001054 signame(WTERMSIG(status)),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001055 WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
Roland McGrath79fbda52004-04-14 02:45:55 +00001056 status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
1057 }
1058 else if (WIFEXITED(status)) {
1059 tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001060 WEXITSTATUS(status));
1061 exited = 1;
Roland McGrath79fbda52004-04-14 02:45:55 +00001062 status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001063 }
Roland McGrath79fbda52004-04-14 02:45:55 +00001064 else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001065 tprintf("[%#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001066 return 0;
1067 }
1068
1069 if (status == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001070 tprints("]");
Roland McGrath79fbda52004-04-14 02:45:55 +00001071 else
Roland McGrathf8cc83c2004-06-04 01:24:07 +00001072 tprintf(" | %#x]", status);
Roland McGrath79fbda52004-04-14 02:45:55 +00001073
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001074 return exited;
1075}
1076
1077static int
Denys Vlasenko59432db2009-01-26 19:09:35 +00001078printwaitn(struct tcb *tcp, int n, int bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001079{
1080 int status;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001081
1082 if (entering(tcp)) {
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001083 /* On Linux, kernel-side pid_t is typedef'ed to int
1084 * on all arches. Also, glibc-2.8 truncates wait3 and wait4
Denys Vlasenko59432db2009-01-26 19:09:35 +00001085 * pid argument to int on 64bit arches, producing,
1086 * for example, wait4(4294967295, ...) instead of -1
Denys Vlasenkoe740fd32009-04-16 12:06:16 +00001087 * in strace. We have to use int here, not long.
1088 */
1089 int pid = tcp->u_arg[0];
1090 tprintf("%d, ", pid);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001091 } else {
1092 /* status */
1093 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001094 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001095 else if (syserror(tcp) || tcp->u_rval == 0)
1096 tprintf("%#lx", tcp->u_arg[1]);
1097 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001098 tprints("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099 else
Dmitry V. Levind9a4b0a2011-02-23 00:27:12 +00001100 printstatus(status);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001101 /* options */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001102 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001103 printflags(wait4_options, tcp->u_arg[2], "W???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001104 if (n == 4) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001105 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001106 /* usage */
1107 if (!tcp->u_arg[3])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001108 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001109 else if (tcp->u_rval > 0) {
Denys Vlasenko59432db2009-01-26 19:09:35 +00001110#ifdef ALPHA
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001111 if (bitness)
1112 printrusage32(tcp, tcp->u_arg[3]);
1113 else
1114#endif
1115 printrusage(tcp, tcp->u_arg[3]);
1116 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001117 else
1118 tprintf("%#lx", tcp->u_arg[3]);
1119 }
1120 }
1121 return 0;
1122}
1123
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001124int
Denys Vlasenko12014262011-05-30 14:00:14 +02001125sys_waitpid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001127 return printwaitn(tcp, 3, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001128}
1129
1130int
Denys Vlasenko12014262011-05-30 14:00:14 +02001131sys_wait4(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001132{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001133 return printwaitn(tcp, 4, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001134}
1135
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001136#ifdef ALPHA
1137int
Denys Vlasenko12014262011-05-30 14:00:14 +02001138sys_osf_wait4(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001139{
1140 return printwaitn(tcp, 4, 1);
1141}
1142#endif
1143
Roland McGrathd9f816f2004-09-04 03:39:20 +00001144static const struct xlat waitid_types[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001145 { P_PID, "P_PID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001146#ifdef P_PPID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001147 { P_PPID, "P_PPID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001148#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001149 { P_PGID, "P_PGID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001150#ifdef P_SID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001151 { P_SID, "P_SID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001152#endif
1153#ifdef P_CID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001154 { P_CID, "P_CID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001155#endif
1156#ifdef P_UID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001157 { P_UID, "P_UID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001158#endif
1159#ifdef P_GID
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001160 { P_GID, "P_GID" },
Roland McGrathc74c0b72004-09-01 19:39:46 +00001161#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001162 { P_ALL, "P_ALL" },
1163#ifdef P_LWPID
1164 { P_LWPID, "P_LWPID" },
1165#endif
1166 { 0, NULL },
1167};
1168
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001169int
Dmitry V. Levin3eb94912010-09-09 23:08:59 +00001170sys_waitid(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001171{
1172 siginfo_t si;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001173
1174 if (entering(tcp)) {
1175 printxval(waitid_types, tcp->u_arg[0], "P_???");
1176 tprintf(", %ld, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001177 }
1178 else {
1179 /* siginfo */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001180 if (!tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001181 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001182 else if (syserror(tcp))
1183 tprintf("%#lx", tcp->u_arg[2]);
1184 else if (umove(tcp, tcp->u_arg[2], &si) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001185 tprints("{???}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001186 else
Denys Vlasenkof535b542009-01-13 18:30:55 +00001187 printsiginfo(&si, verbose(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001188 /* options */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001189 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001190 printflags(wait4_options, tcp->u_arg[3], "W???");
Roland McGrath39426a32004-10-06 22:02:59 +00001191 if (tcp->u_nargs > 4) {
1192 /* usage */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001193 tprints(", ");
Roland McGrath39426a32004-10-06 22:02:59 +00001194 if (!tcp->u_arg[4])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001195 tprints("NULL");
Roland McGrath39426a32004-10-06 22:02:59 +00001196 else if (tcp->u_error)
1197 tprintf("%#lx", tcp->u_arg[4]);
1198 else
1199 printrusage(tcp, tcp->u_arg[4]);
1200 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001201 }
1202 return 0;
1203}
1204
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001205int
Denys Vlasenko12014262011-05-30 14:00:14 +02001206sys_uname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001207{
1208 struct utsname uname;
1209
1210 if (exiting(tcp)) {
1211 if (syserror(tcp) || !verbose(tcp))
1212 tprintf("%#lx", tcp->u_arg[0]);
1213 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001214 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001215 else if (!abbrev(tcp)) {
1216
1217 tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1218 uname.sysname, uname.nodename);
1219 tprintf("release=\"%s\", version=\"%s\", ",
1220 uname.release, uname.version);
1221 tprintf("machine=\"%s\"", uname.machine);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001222#ifndef __GLIBC__
1223 tprintf(", domainname=\"%s\"", uname.domainname);
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00001224#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001225 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001226 }
1227 else
1228 tprintf("{sys=\"%s\", node=\"%s\", ...}",
1229 uname.sysname, uname.nodename);
1230 }
1231 return 0;
1232}
1233
Roland McGratheb9e2e82009-06-02 16:49:22 -07001234static const struct xlat ptrace_cmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001235 { PTRACE_TRACEME, "PTRACE_TRACEME" },
Denys Vlasenko61526c62011-08-25 10:21:13 +02001236 { PTRACE_PEEKTEXT, "PTRACE_PEEKTEXT" },
1237 { PTRACE_PEEKDATA, "PTRACE_PEEKDATA" },
1238 { PTRACE_PEEKUSER, "PTRACE_PEEKUSER" },
1239 { PTRACE_POKETEXT, "PTRACE_POKETEXT" },
1240 { PTRACE_POKEDATA, "PTRACE_POKEDATA" },
1241 { PTRACE_POKEUSER, "PTRACE_POKEUSER" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001242 { PTRACE_CONT, "PTRACE_CONT" },
1243 { PTRACE_KILL, "PTRACE_KILL" },
1244 { PTRACE_SINGLESTEP, "PTRACE_SINGLESTEP" },
1245 { PTRACE_ATTACH, "PTRACE_ATTACH" },
1246 { PTRACE_DETACH, "PTRACE_DETACH" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001247#ifdef PTRACE_GETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001248 { PTRACE_GETREGS, "PTRACE_GETREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001249#endif
1250#ifdef PTRACE_SETREGS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001251 { PTRACE_SETREGS, "PTRACE_SETREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001252#endif
1253#ifdef PTRACE_GETFPREGS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001254 { PTRACE_GETFPREGS, "PTRACE_GETFPREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001255#endif
1256#ifdef PTRACE_SETFPREGS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001257 { PTRACE_SETFPREGS, "PTRACE_SETFPREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001258#endif
1259#ifdef PTRACE_GETFPXREGS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001260 { PTRACE_GETFPXREGS, "PTRACE_GETFPXREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001261#endif
1262#ifdef PTRACE_SETFPXREGS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001263 { PTRACE_SETFPXREGS, "PTRACE_SETFPXREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001264#endif
1265#ifdef PTRACE_GETVRREGS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001266 { PTRACE_GETVRREGS, "PTRACE_GETVRREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001267#endif
1268#ifdef PTRACE_SETVRREGS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001269 { PTRACE_SETVRREGS, "PTRACE_SETVRREGS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001270#endif
1271#ifdef PTRACE_SETOPTIONS
Denys Vlasenko61526c62011-08-25 10:21:13 +02001272 { PTRACE_SETOPTIONS, "PTRACE_SETOPTIONS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001273#endif
1274#ifdef PTRACE_GETEVENTMSG
Denys Vlasenko61526c62011-08-25 10:21:13 +02001275 { PTRACE_GETEVENTMSG, "PTRACE_GETEVENTMSG" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001276#endif
1277#ifdef PTRACE_GETSIGINFO
Denys Vlasenko61526c62011-08-25 10:21:13 +02001278 { PTRACE_GETSIGINFO, "PTRACE_GETSIGINFO" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001279#endif
1280#ifdef PTRACE_SETSIGINFO
Denys Vlasenko61526c62011-08-25 10:21:13 +02001281 { PTRACE_SETSIGINFO, "PTRACE_SETSIGINFO" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001282#endif
1283#ifdef PTRACE_GETREGSET
Denys Vlasenko61526c62011-08-25 10:21:13 +02001284 { PTRACE_GETREGSET, "PTRACE_GETREGSET" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001285#endif
1286#ifdef PTRACE_SETREGSET
Denys Vlasenko61526c62011-08-25 10:21:13 +02001287 { PTRACE_SETREGSET, "PTRACE_SETREGSET" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001288#endif
1289#ifdef PTRACE_SET_SYSCALL
Denys Vlasenko61526c62011-08-25 10:21:13 +02001290 { PTRACE_SET_SYSCALL, "PTRACE_SET_SYSCALL" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001291#endif
1292#ifdef PTRACE_SEIZE
Denys Vlasenko31fa8a22012-01-29 02:01:44 +01001293 { PTRACE_SEIZE, "PTRACE_SEIZE" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001294#endif
1295#ifdef PTRACE_INTERRUPT
Denys Vlasenko31fa8a22012-01-29 02:01:44 +01001296 { PTRACE_INTERRUPT, "PTRACE_INTERRUPT" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001297#endif
1298#ifdef PTRACE_LISTEN
Denys Vlasenko31fa8a22012-01-29 02:01:44 +01001299 { PTRACE_LISTEN, "PTRACE_LISTEN" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001300#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001301 { PTRACE_SYSCALL, "PTRACE_SYSCALL" },
Denys Vlasenkof535b542009-01-13 18:30:55 +00001302
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001303 { 0, NULL },
1304};
1305
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001306#ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00001307static const struct xlat ptrace_setoptions_flags[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001308# ifdef PTRACE_O_TRACESYSGOOD
Denys Vlasenkof535b542009-01-13 18:30:55 +00001309 { PTRACE_O_TRACESYSGOOD,"PTRACE_O_TRACESYSGOOD" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001310# endif
1311# ifdef PTRACE_O_TRACEFORK
Denys Vlasenkof535b542009-01-13 18:30:55 +00001312 { PTRACE_O_TRACEFORK, "PTRACE_O_TRACEFORK" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001313# endif
1314# ifdef PTRACE_O_TRACEVFORK
Denys Vlasenkof535b542009-01-13 18:30:55 +00001315 { PTRACE_O_TRACEVFORK, "PTRACE_O_TRACEVFORK" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001316# endif
1317# ifdef PTRACE_O_TRACECLONE
Denys Vlasenkof535b542009-01-13 18:30:55 +00001318 { PTRACE_O_TRACECLONE, "PTRACE_O_TRACECLONE" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001319# endif
1320# ifdef PTRACE_O_TRACEEXEC
Denys Vlasenkof535b542009-01-13 18:30:55 +00001321 { PTRACE_O_TRACEEXEC, "PTRACE_O_TRACEEXEC" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001322# endif
1323# ifdef PTRACE_O_TRACEVFORKDONE
Denys Vlasenkof535b542009-01-13 18:30:55 +00001324 { PTRACE_O_TRACEVFORKDONE,"PTRACE_O_TRACEVFORKDONE"},
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001325# endif
1326# ifdef PTRACE_O_TRACEEXIT
Denys Vlasenkof535b542009-01-13 18:30:55 +00001327 { PTRACE_O_TRACEEXIT, "PTRACE_O_TRACEEXIT" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001328# endif
Denys Vlasenkof535b542009-01-13 18:30:55 +00001329 { 0, NULL },
1330};
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001331#endif /* PTRACE_SETOPTIONS */
Denys Vlasenkof535b542009-01-13 18:30:55 +00001332
Roland McGrathd9f816f2004-09-04 03:39:20 +00001333const struct xlat struct_user_offsets[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001334#if defined(S390) || defined(S390X)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001335 { PT_PSWMASK, "psw_mask" },
1336 { PT_PSWADDR, "psw_addr" },
1337 { PT_GPR0, "gpr0" },
1338 { PT_GPR1, "gpr1" },
1339 { PT_GPR2, "gpr2" },
1340 { PT_GPR3, "gpr3" },
1341 { PT_GPR4, "gpr4" },
1342 { PT_GPR5, "gpr5" },
1343 { PT_GPR6, "gpr6" },
1344 { PT_GPR7, "gpr7" },
1345 { PT_GPR8, "gpr8" },
1346 { PT_GPR9, "gpr9" },
1347 { PT_GPR10, "gpr10" },
1348 { PT_GPR11, "gpr11" },
1349 { PT_GPR12, "gpr12" },
1350 { PT_GPR13, "gpr13" },
1351 { PT_GPR14, "gpr14" },
1352 { PT_GPR15, "gpr15" },
1353 { PT_ACR0, "acr0" },
1354 { PT_ACR1, "acr1" },
1355 { PT_ACR2, "acr2" },
1356 { PT_ACR3, "acr3" },
1357 { PT_ACR4, "acr4" },
1358 { PT_ACR5, "acr5" },
1359 { PT_ACR6, "acr6" },
1360 { PT_ACR7, "acr7" },
1361 { PT_ACR8, "acr8" },
1362 { PT_ACR9, "acr9" },
1363 { PT_ACR10, "acr10" },
1364 { PT_ACR11, "acr11" },
1365 { PT_ACR12, "acr12" },
1366 { PT_ACR13, "acr13" },
1367 { PT_ACR14, "acr14" },
1368 { PT_ACR15, "acr15" },
1369 { PT_ORIGGPR2, "orig_gpr2" },
1370 { PT_FPC, "fpc" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001371#if defined(S390)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001372 { PT_FPR0_HI, "fpr0.hi" },
1373 { PT_FPR0_LO, "fpr0.lo" },
1374 { PT_FPR1_HI, "fpr1.hi" },
1375 { PT_FPR1_LO, "fpr1.lo" },
1376 { PT_FPR2_HI, "fpr2.hi" },
1377 { PT_FPR2_LO, "fpr2.lo" },
1378 { PT_FPR3_HI, "fpr3.hi" },
1379 { PT_FPR3_LO, "fpr3.lo" },
1380 { PT_FPR4_HI, "fpr4.hi" },
1381 { PT_FPR4_LO, "fpr4.lo" },
1382 { PT_FPR5_HI, "fpr5.hi" },
1383 { PT_FPR5_LO, "fpr5.lo" },
1384 { PT_FPR6_HI, "fpr6.hi" },
1385 { PT_FPR6_LO, "fpr6.lo" },
1386 { PT_FPR7_HI, "fpr7.hi" },
1387 { PT_FPR7_LO, "fpr7.lo" },
1388 { PT_FPR8_HI, "fpr8.hi" },
1389 { PT_FPR8_LO, "fpr8.lo" },
1390 { PT_FPR9_HI, "fpr9.hi" },
1391 { PT_FPR9_LO, "fpr9.lo" },
1392 { PT_FPR10_HI, "fpr10.hi" },
1393 { PT_FPR10_LO, "fpr10.lo" },
1394 { PT_FPR11_HI, "fpr11.hi" },
1395 { PT_FPR11_LO, "fpr11.lo" },
1396 { PT_FPR12_HI, "fpr12.hi" },
1397 { PT_FPR12_LO, "fpr12.lo" },
1398 { PT_FPR13_HI, "fpr13.hi" },
1399 { PT_FPR13_LO, "fpr13.lo" },
1400 { PT_FPR14_HI, "fpr14.hi" },
1401 { PT_FPR14_LO, "fpr14.lo" },
1402 { PT_FPR15_HI, "fpr15.hi" },
1403 { PT_FPR15_LO, "fpr15.lo" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001404#endif
1405#if defined(S390X)
Michal Ludvig10a88d02002-10-07 14:31:00 +00001406 { PT_FPR0, "fpr0" },
1407 { PT_FPR1, "fpr1" },
1408 { PT_FPR2, "fpr2" },
1409 { PT_FPR3, "fpr3" },
1410 { PT_FPR4, "fpr4" },
1411 { PT_FPR5, "fpr5" },
1412 { PT_FPR6, "fpr6" },
1413 { PT_FPR7, "fpr7" },
1414 { PT_FPR8, "fpr8" },
1415 { PT_FPR9, "fpr9" },
1416 { PT_FPR10, "fpr10" },
1417 { PT_FPR11, "fpr11" },
1418 { PT_FPR12, "fpr12" },
1419 { PT_FPR13, "fpr13" },
1420 { PT_FPR14, "fpr14" },
1421 { PT_FPR15, "fpr15" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001422#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001423 { PT_CR_9, "cr9" },
1424 { PT_CR_10, "cr10" },
1425 { PT_CR_11, "cr11" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001426 { PT_IEEE_IP, "ieee_exception_ip" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001427#elif defined(SPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001428 /* XXX No support for these offsets yet. */
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001429#elif defined(HPPA)
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001430 /* XXX No support for these offsets yet. */
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001431#elif defined(POWERPC)
1432# ifndef PT_ORIG_R3
1433# define PT_ORIG_R3 34
1434# endif
1435# define REGSIZE (sizeof(unsigned long))
Roland McGratheb285352003-01-14 09:59:00 +00001436 { REGSIZE*PT_R0, "r0" },
1437 { REGSIZE*PT_R1, "r1" },
1438 { REGSIZE*PT_R2, "r2" },
1439 { REGSIZE*PT_R3, "r3" },
1440 { REGSIZE*PT_R4, "r4" },
1441 { REGSIZE*PT_R5, "r5" },
1442 { REGSIZE*PT_R6, "r6" },
1443 { REGSIZE*PT_R7, "r7" },
1444 { REGSIZE*PT_R8, "r8" },
1445 { REGSIZE*PT_R9, "r9" },
1446 { REGSIZE*PT_R10, "r10" },
1447 { REGSIZE*PT_R11, "r11" },
1448 { REGSIZE*PT_R12, "r12" },
1449 { REGSIZE*PT_R13, "r13" },
1450 { REGSIZE*PT_R14, "r14" },
1451 { REGSIZE*PT_R15, "r15" },
1452 { REGSIZE*PT_R16, "r16" },
1453 { REGSIZE*PT_R17, "r17" },
1454 { REGSIZE*PT_R18, "r18" },
1455 { REGSIZE*PT_R19, "r19" },
1456 { REGSIZE*PT_R20, "r20" },
1457 { REGSIZE*PT_R21, "r21" },
1458 { REGSIZE*PT_R22, "r22" },
1459 { REGSIZE*PT_R23, "r23" },
1460 { REGSIZE*PT_R24, "r24" },
1461 { REGSIZE*PT_R25, "r25" },
1462 { REGSIZE*PT_R26, "r26" },
1463 { REGSIZE*PT_R27, "r27" },
1464 { REGSIZE*PT_R28, "r28" },
1465 { REGSIZE*PT_R29, "r29" },
1466 { REGSIZE*PT_R30, "r30" },
1467 { REGSIZE*PT_R31, "r31" },
1468 { REGSIZE*PT_NIP, "NIP" },
1469 { REGSIZE*PT_MSR, "MSR" },
1470 { REGSIZE*PT_ORIG_R3, "ORIG_R3" },
1471 { REGSIZE*PT_CTR, "CTR" },
1472 { REGSIZE*PT_LNK, "LNK" },
1473 { REGSIZE*PT_XER, "XER" },
1474 { REGSIZE*PT_CCR, "CCR" },
1475 { REGSIZE*PT_FPR0, "FPR0" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001476# undef REGSIZE
1477#elif defined(ALPHA)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001478 { 0, "r0" },
1479 { 1, "r1" },
1480 { 2, "r2" },
1481 { 3, "r3" },
1482 { 4, "r4" },
1483 { 5, "r5" },
1484 { 6, "r6" },
1485 { 7, "r7" },
1486 { 8, "r8" },
1487 { 9, "r9" },
1488 { 10, "r10" },
1489 { 11, "r11" },
1490 { 12, "r12" },
1491 { 13, "r13" },
1492 { 14, "r14" },
1493 { 15, "r15" },
1494 { 16, "r16" },
1495 { 17, "r17" },
1496 { 18, "r18" },
1497 { 19, "r19" },
1498 { 20, "r20" },
1499 { 21, "r21" },
1500 { 22, "r22" },
1501 { 23, "r23" },
1502 { 24, "r24" },
1503 { 25, "r25" },
1504 { 26, "r26" },
1505 { 27, "r27" },
1506 { 28, "r28" },
1507 { 29, "gp" },
1508 { 30, "fp" },
1509 { 31, "zero" },
1510 { 32, "fp0" },
1511 { 33, "fp" },
1512 { 34, "fp2" },
1513 { 35, "fp3" },
1514 { 36, "fp4" },
1515 { 37, "fp5" },
1516 { 38, "fp6" },
1517 { 39, "fp7" },
1518 { 40, "fp8" },
1519 { 41, "fp9" },
1520 { 42, "fp10" },
1521 { 43, "fp11" },
1522 { 44, "fp12" },
1523 { 45, "fp13" },
1524 { 46, "fp14" },
1525 { 47, "fp15" },
1526 { 48, "fp16" },
1527 { 49, "fp17" },
1528 { 50, "fp18" },
1529 { 51, "fp19" },
1530 { 52, "fp20" },
1531 { 53, "fp21" },
1532 { 54, "fp22" },
1533 { 55, "fp23" },
1534 { 56, "fp24" },
1535 { 57, "fp25" },
1536 { 58, "fp26" },
1537 { 59, "fp27" },
1538 { 60, "fp28" },
1539 { 61, "fp29" },
1540 { 62, "fp30" },
1541 { 63, "fp31" },
1542 { 64, "pc" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001543#elif defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001544 { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
1545 { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
1546 { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
1547 { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
1548 { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
1549 { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
1550 { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
1551 { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
1552 { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
1553 { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
1554 { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
1555 { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
1556 { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
1557 { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
1558 { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
1559 { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
1560 { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
1561 { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
1562 { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
1563 { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
1564 { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
1565 { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
1566 { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
1567 { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
1568 { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
1569 { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
1570 { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
1571 { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
1572 { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
1573 { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
1574 { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
1575 { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
1576 /* switch stack: */
1577 { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
1578 { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
1579 { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
1580 { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
1581 { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
1582 { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
1583 { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
1584 { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
1585 { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
1586 { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001587 { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
1588 { PT_B4, "b4" }, { PT_B5, "b5" },
Roland McGrathca4e10c2004-01-13 10:13:20 +00001589 { PT_AR_EC, "ar.ec" }, { PT_AR_LC, "ar.lc" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001590 /* pt_regs */
Roland McGrathca4e10c2004-01-13 10:13:20 +00001591 { PT_CR_IPSR, "psr" }, { PT_CR_IIP, "ip" },
1592 { PT_CFM, "cfm" }, { PT_AR_UNAT, "ar.unat" },
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001593 { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
1594 { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
1595 { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
1596 { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
1597 { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
1598 { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
1599 { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
1600 { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
1601 { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
1602 { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
1603 { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
1604 { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
1605 { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
1606 { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
1607 { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001608# ifdef PT_AR_CSD
Roland McGrathfb1bc072004-03-01 21:29:24 +00001609 { PT_AR_CSD, "ar.csd" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001610# endif
1611# ifdef PT_AR_SSD
Roland McGrathfb1bc072004-03-01 21:29:24 +00001612 { PT_AR_SSD, "ar.ssd" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001613# endif
Roland McGrathca4e10c2004-01-13 10:13:20 +00001614 { PT_DBR, "dbr" }, { PT_IBR, "ibr" }, { PT_PMD, "pmd" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001615#elif defined(I386)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001616 { 4*EBX, "4*EBX" },
1617 { 4*ECX, "4*ECX" },
1618 { 4*EDX, "4*EDX" },
1619 { 4*ESI, "4*ESI" },
1620 { 4*EDI, "4*EDI" },
1621 { 4*EBP, "4*EBP" },
1622 { 4*EAX, "4*EAX" },
1623 { 4*DS, "4*DS" },
1624 { 4*ES, "4*ES" },
1625 { 4*FS, "4*FS" },
1626 { 4*GS, "4*GS" },
1627 { 4*ORIG_EAX, "4*ORIG_EAX" },
1628 { 4*EIP, "4*EIP" },
1629 { 4*CS, "4*CS" },
1630 { 4*EFL, "4*EFL" },
1631 { 4*UESP, "4*UESP" },
1632 { 4*SS, "4*SS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001633#elif defined(X86_64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001634 { 8*R15, "8*R15" },
1635 { 8*R14, "8*R14" },
1636 { 8*R13, "8*R13" },
1637 { 8*R12, "8*R12" },
Michal Ludvig0e035502002-09-23 15:41:01 +00001638 { 8*RBP, "8*RBP" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00001639 { 8*RBX, "8*RBX" },
1640 { 8*R11, "8*R11" },
1641 { 8*R10, "8*R10" },
1642 { 8*R9, "8*R9" },
1643 { 8*R8, "8*R8" },
Michal Ludvig0e035502002-09-23 15:41:01 +00001644 { 8*RAX, "8*RAX" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00001645 { 8*RCX, "8*RCX" },
1646 { 8*RDX, "8*RDX" },
1647 { 8*RSI, "8*RSI" },
1648 { 8*RDI, "8*RDI" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00001649 { 8*ORIG_RAX, "8*ORIG_RAX" },
Michal Ludvig0e035502002-09-23 15:41:01 +00001650 { 8*RIP, "8*RIP" },
1651 { 8*CS, "8*CS" },
1652 { 8*EFLAGS, "8*EFL" },
Roland McGratha4f9f2d2005-06-07 23:21:20 +00001653 { 8*RSP, "8*RSP" },
Michal Ludvig0e035502002-09-23 15:41:01 +00001654 { 8*SS, "8*SS" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001655#elif defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001656 { 4*PT_D1, "4*PT_D1" },
1657 { 4*PT_D2, "4*PT_D2" },
1658 { 4*PT_D3, "4*PT_D3" },
1659 { 4*PT_D4, "4*PT_D4" },
1660 { 4*PT_D5, "4*PT_D5" },
1661 { 4*PT_D6, "4*PT_D6" },
1662 { 4*PT_D7, "4*PT_D7" },
1663 { 4*PT_A0, "4*PT_A0" },
1664 { 4*PT_A1, "4*PT_A1" },
1665 { 4*PT_A2, "4*PT_A2" },
1666 { 4*PT_A3, "4*PT_A3" },
1667 { 4*PT_A4, "4*PT_A4" },
1668 { 4*PT_A5, "4*PT_A5" },
1669 { 4*PT_A6, "4*PT_A6" },
1670 { 4*PT_D0, "4*PT_D0" },
1671 { 4*PT_USP, "4*PT_USP" },
1672 { 4*PT_ORIG_D0, "4*PT_ORIG_D0" },
1673 { 4*PT_SR, "4*PT_SR" },
1674 { 4*PT_PC, "4*PT_PC" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001675#elif defined(SH)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001676 { 4*REG_REG0, "4*REG_REG0" },
1677 { 4*(REG_REG0+1), "4*REG_REG1" },
1678 { 4*(REG_REG0+2), "4*REG_REG2" },
1679 { 4*(REG_REG0+3), "4*REG_REG3" },
1680 { 4*(REG_REG0+4), "4*REG_REG4" },
1681 { 4*(REG_REG0+5), "4*REG_REG5" },
1682 { 4*(REG_REG0+6), "4*REG_REG6" },
1683 { 4*(REG_REG0+7), "4*REG_REG7" },
1684 { 4*(REG_REG0+8), "4*REG_REG8" },
1685 { 4*(REG_REG0+9), "4*REG_REG9" },
1686 { 4*(REG_REG0+10), "4*REG_REG10" },
1687 { 4*(REG_REG0+11), "4*REG_REG11" },
1688 { 4*(REG_REG0+12), "4*REG_REG12" },
1689 { 4*(REG_REG0+13), "4*REG_REG13" },
1690 { 4*(REG_REG0+14), "4*REG_REG14" },
1691 { 4*REG_REG15, "4*REG_REG15" },
1692 { 4*REG_PC, "4*REG_PC" },
1693 { 4*REG_PR, "4*REG_PR" },
1694 { 4*REG_SR, "4*REG_SR" },
1695 { 4*REG_GBR, "4*REG_GBR" },
1696 { 4*REG_MACH, "4*REG_MACH" },
1697 { 4*REG_MACL, "4*REG_MACL" },
1698 { 4*REG_SYSCALL, "4*REG_SYSCALL" },
1699 { 4*REG_FPUL, "4*REG_FPUL" },
1700 { 4*REG_FPREG0, "4*REG_FPREG0" },
1701 { 4*(REG_FPREG0+1), "4*REG_FPREG1" },
1702 { 4*(REG_FPREG0+2), "4*REG_FPREG2" },
1703 { 4*(REG_FPREG0+3), "4*REG_FPREG3" },
1704 { 4*(REG_FPREG0+4), "4*REG_FPREG4" },
1705 { 4*(REG_FPREG0+5), "4*REG_FPREG5" },
1706 { 4*(REG_FPREG0+6), "4*REG_FPREG6" },
1707 { 4*(REG_FPREG0+7), "4*REG_FPREG7" },
1708 { 4*(REG_FPREG0+8), "4*REG_FPREG8" },
1709 { 4*(REG_FPREG0+9), "4*REG_FPREG9" },
1710 { 4*(REG_FPREG0+10), "4*REG_FPREG10" },
1711 { 4*(REG_FPREG0+11), "4*REG_FPREG11" },
1712 { 4*(REG_FPREG0+12), "4*REG_FPREG12" },
1713 { 4*(REG_FPREG0+13), "4*REG_FPREG13" },
1714 { 4*(REG_FPREG0+14), "4*REG_FPREG14" },
1715 { 4*REG_FPREG15, "4*REG_FPREG15" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001716# ifdef REG_XDREG0
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001717 { 4*REG_XDREG0, "4*REG_XDREG0" },
1718 { 4*(REG_XDREG0+2), "4*REG_XDREG2" },
1719 { 4*(REG_XDREG0+4), "4*REG_XDREG4" },
1720 { 4*(REG_XDREG0+6), "4*REG_XDREG6" },
1721 { 4*(REG_XDREG0+8), "4*REG_XDREG8" },
1722 { 4*(REG_XDREG0+10), "4*REG_XDREG10" },
1723 { 4*(REG_XDREG0+12), "4*REG_XDREG12" },
1724 { 4*REG_XDREG14, "4*REG_XDREG14" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001725# endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001726 { 4*REG_FPSCR, "4*REG_FPSCR" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001727#elif defined(SH64)
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001728 { 0, "PC(L)" },
1729 { 4, "PC(U)" },
1730 { 8, "SR(L)" },
1731 { 12, "SR(U)" },
1732 { 16, "syscall no.(L)" },
1733 { 20, "syscall_no.(U)" },
1734 { 24, "R0(L)" },
1735 { 28, "R0(U)" },
1736 { 32, "R1(L)" },
1737 { 36, "R1(U)" },
1738 { 40, "R2(L)" },
1739 { 44, "R2(U)" },
1740 { 48, "R3(L)" },
1741 { 52, "R3(U)" },
1742 { 56, "R4(L)" },
1743 { 60, "R4(U)" },
1744 { 64, "R5(L)" },
1745 { 68, "R5(U)" },
1746 { 72, "R6(L)" },
1747 { 76, "R6(U)" },
1748 { 80, "R7(L)" },
1749 { 84, "R7(U)" },
1750 { 88, "R8(L)" },
1751 { 92, "R8(U)" },
1752 { 96, "R9(L)" },
1753 { 100, "R9(U)" },
1754 { 104, "R10(L)" },
1755 { 108, "R10(U)" },
1756 { 112, "R11(L)" },
1757 { 116, "R11(U)" },
1758 { 120, "R12(L)" },
1759 { 124, "R12(U)" },
1760 { 128, "R13(L)" },
1761 { 132, "R13(U)" },
1762 { 136, "R14(L)" },
1763 { 140, "R14(U)" },
1764 { 144, "R15(L)" },
1765 { 148, "R15(U)" },
1766 { 152, "R16(L)" },
1767 { 156, "R16(U)" },
1768 { 160, "R17(L)" },
1769 { 164, "R17(U)" },
1770 { 168, "R18(L)" },
1771 { 172, "R18(U)" },
1772 { 176, "R19(L)" },
1773 { 180, "R19(U)" },
1774 { 184, "R20(L)" },
1775 { 188, "R20(U)" },
1776 { 192, "R21(L)" },
1777 { 196, "R21(U)" },
1778 { 200, "R22(L)" },
1779 { 204, "R22(U)" },
1780 { 208, "R23(L)" },
1781 { 212, "R23(U)" },
1782 { 216, "R24(L)" },
1783 { 220, "R24(U)" },
1784 { 224, "R25(L)" },
1785 { 228, "R25(U)" },
1786 { 232, "R26(L)" },
1787 { 236, "R26(U)" },
1788 { 240, "R27(L)" },
1789 { 244, "R27(U)" },
1790 { 248, "R28(L)" },
1791 { 252, "R28(U)" },
1792 { 256, "R29(L)" },
1793 { 260, "R29(U)" },
1794 { 264, "R30(L)" },
1795 { 268, "R30(U)" },
1796 { 272, "R31(L)" },
1797 { 276, "R31(U)" },
1798 { 280, "R32(L)" },
1799 { 284, "R32(U)" },
1800 { 288, "R33(L)" },
1801 { 292, "R33(U)" },
1802 { 296, "R34(L)" },
1803 { 300, "R34(U)" },
1804 { 304, "R35(L)" },
1805 { 308, "R35(U)" },
1806 { 312, "R36(L)" },
1807 { 316, "R36(U)" },
1808 { 320, "R37(L)" },
1809 { 324, "R37(U)" },
1810 { 328, "R38(L)" },
1811 { 332, "R38(U)" },
1812 { 336, "R39(L)" },
1813 { 340, "R39(U)" },
1814 { 344, "R40(L)" },
1815 { 348, "R40(U)" },
1816 { 352, "R41(L)" },
1817 { 356, "R41(U)" },
1818 { 360, "R42(L)" },
1819 { 364, "R42(U)" },
1820 { 368, "R43(L)" },
1821 { 372, "R43(U)" },
1822 { 376, "R44(L)" },
1823 { 380, "R44(U)" },
1824 { 384, "R45(L)" },
1825 { 388, "R45(U)" },
1826 { 392, "R46(L)" },
1827 { 396, "R46(U)" },
1828 { 400, "R47(L)" },
1829 { 404, "R47(U)" },
1830 { 408, "R48(L)" },
1831 { 412, "R48(U)" },
1832 { 416, "R49(L)" },
1833 { 420, "R49(U)" },
1834 { 424, "R50(L)" },
1835 { 428, "R50(U)" },
1836 { 432, "R51(L)" },
1837 { 436, "R51(U)" },
1838 { 440, "R52(L)" },
1839 { 444, "R52(U)" },
1840 { 448, "R53(L)" },
1841 { 452, "R53(U)" },
1842 { 456, "R54(L)" },
1843 { 460, "R54(U)" },
1844 { 464, "R55(L)" },
1845 { 468, "R55(U)" },
1846 { 472, "R56(L)" },
1847 { 476, "R56(U)" },
1848 { 480, "R57(L)" },
1849 { 484, "R57(U)" },
1850 { 488, "R58(L)" },
1851 { 492, "R58(U)" },
1852 { 496, "R59(L)" },
1853 { 500, "R59(U)" },
1854 { 504, "R60(L)" },
1855 { 508, "R60(U)" },
1856 { 512, "R61(L)" },
1857 { 516, "R61(U)" },
1858 { 520, "R62(L)" },
1859 { 524, "R62(U)" },
1860 { 528, "TR0(L)" },
1861 { 532, "TR0(U)" },
1862 { 536, "TR1(L)" },
1863 { 540, "TR1(U)" },
1864 { 544, "TR2(L)" },
1865 { 548, "TR2(U)" },
1866 { 552, "TR3(L)" },
1867 { 556, "TR3(U)" },
1868 { 560, "TR4(L)" },
1869 { 564, "TR4(U)" },
1870 { 568, "TR5(L)" },
1871 { 572, "TR5(U)" },
1872 { 576, "TR6(L)" },
1873 { 580, "TR6(U)" },
1874 { 584, "TR7(L)" },
1875 { 588, "TR7(U)" },
Denys Vlasenkoadedb512008-12-30 18:47:55 +00001876 /* This entry is in case pt_regs contains dregs (depends on
1877 the kernel build options). */
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001878 { uoff(regs), "offsetof(struct user, regs)" },
1879 { uoff(fpu), "offsetof(struct user, fpu)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001880#elif defined(ARM)
Roland McGrath0f87c492003-06-03 23:29:04 +00001881 { uoff(regs.ARM_r0), "r0" },
1882 { uoff(regs.ARM_r1), "r1" },
1883 { uoff(regs.ARM_r2), "r2" },
1884 { uoff(regs.ARM_r3), "r3" },
1885 { uoff(regs.ARM_r4), "r4" },
1886 { uoff(regs.ARM_r5), "r5" },
1887 { uoff(regs.ARM_r6), "r6" },
1888 { uoff(regs.ARM_r7), "r7" },
1889 { uoff(regs.ARM_r8), "r8" },
1890 { uoff(regs.ARM_r9), "r9" },
1891 { uoff(regs.ARM_r10), "r10" },
1892 { uoff(regs.ARM_fp), "fp" },
1893 { uoff(regs.ARM_ip), "ip" },
1894 { uoff(regs.ARM_sp), "sp" },
1895 { uoff(regs.ARM_lr), "lr" },
1896 { uoff(regs.ARM_pc), "pc" },
1897 { uoff(regs.ARM_cpsr), "cpsr" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001898#elif defined(AVR32)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001899 { uoff(regs.sr), "sr" },
1900 { uoff(regs.pc), "pc" },
1901 { uoff(regs.lr), "lr" },
1902 { uoff(regs.sp), "sp" },
1903 { uoff(regs.r12), "r12" },
1904 { uoff(regs.r11), "r11" },
1905 { uoff(regs.r10), "r10" },
1906 { uoff(regs.r9), "r9" },
1907 { uoff(regs.r8), "r8" },
1908 { uoff(regs.r7), "r7" },
1909 { uoff(regs.r6), "r6" },
1910 { uoff(regs.r5), "r5" },
1911 { uoff(regs.r4), "r4" },
1912 { uoff(regs.r3), "r3" },
1913 { uoff(regs.r2), "r2" },
1914 { uoff(regs.r1), "r1" },
1915 { uoff(regs.r0), "r0" },
1916 { uoff(regs.r12_orig), "orig_r12" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001917#elif defined(MIPS)
Roland McGrath542c2c62008-05-20 01:11:56 +00001918 { 0, "r0" },
1919 { 1, "r1" },
1920 { 2, "r2" },
1921 { 3, "r3" },
1922 { 4, "r4" },
1923 { 5, "r5" },
1924 { 6, "r6" },
1925 { 7, "r7" },
1926 { 8, "r8" },
1927 { 9, "r9" },
1928 { 10, "r10" },
1929 { 11, "r11" },
1930 { 12, "r12" },
1931 { 13, "r13" },
1932 { 14, "r14" },
1933 { 15, "r15" },
1934 { 16, "r16" },
1935 { 17, "r17" },
1936 { 18, "r18" },
1937 { 19, "r19" },
1938 { 20, "r20" },
1939 { 21, "r21" },
1940 { 22, "r22" },
1941 { 23, "r23" },
1942 { 24, "r24" },
1943 { 25, "r25" },
1944 { 26, "r26" },
1945 { 27, "r27" },
1946 { 28, "r28" },
1947 { 29, "r29" },
1948 { 30, "r30" },
1949 { 31, "r31" },
1950 { 32, "f0" },
1951 { 33, "f1" },
1952 { 34, "f2" },
1953 { 35, "f3" },
1954 { 36, "f4" },
1955 { 37, "f5" },
1956 { 38, "f6" },
1957 { 39, "f7" },
1958 { 40, "f8" },
1959 { 41, "f9" },
1960 { 42, "f10" },
1961 { 43, "f11" },
1962 { 44, "f12" },
1963 { 45, "f13" },
1964 { 46, "f14" },
1965 { 47, "f15" },
1966 { 48, "f16" },
1967 { 49, "f17" },
1968 { 50, "f18" },
1969 { 51, "f19" },
1970 { 52, "f20" },
1971 { 53, "f21" },
1972 { 54, "f22" },
1973 { 55, "f23" },
1974 { 56, "f24" },
1975 { 57, "f25" },
1976 { 58, "f26" },
1977 { 59, "f27" },
1978 { 60, "f28" },
1979 { 61, "f29" },
1980 { 62, "f30" },
1981 { 63, "f31" },
1982 { 64, "pc" },
1983 { 65, "cause" },
1984 { 66, "badvaddr" },
1985 { 67, "mmhi" },
1986 { 68, "mmlo" },
1987 { 69, "fpcsr" },
1988 { 70, "fpeir" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001989#elif defined(TILE)
Chris Metcalfc8c66982009-12-28 10:00:15 -05001990 { PTREGS_OFFSET_REG(0), "r0" },
1991 { PTREGS_OFFSET_REG(1), "r1" },
1992 { PTREGS_OFFSET_REG(2), "r2" },
1993 { PTREGS_OFFSET_REG(3), "r3" },
1994 { PTREGS_OFFSET_REG(4), "r4" },
1995 { PTREGS_OFFSET_REG(5), "r5" },
1996 { PTREGS_OFFSET_REG(6), "r6" },
1997 { PTREGS_OFFSET_REG(7), "r7" },
1998 { PTREGS_OFFSET_REG(8), "r8" },
1999 { PTREGS_OFFSET_REG(9), "r9" },
2000 { PTREGS_OFFSET_REG(10), "r10" },
2001 { PTREGS_OFFSET_REG(11), "r11" },
2002 { PTREGS_OFFSET_REG(12), "r12" },
2003 { PTREGS_OFFSET_REG(13), "r13" },
2004 { PTREGS_OFFSET_REG(14), "r14" },
2005 { PTREGS_OFFSET_REG(15), "r15" },
2006 { PTREGS_OFFSET_REG(16), "r16" },
2007 { PTREGS_OFFSET_REG(17), "r17" },
2008 { PTREGS_OFFSET_REG(18), "r18" },
2009 { PTREGS_OFFSET_REG(19), "r19" },
2010 { PTREGS_OFFSET_REG(20), "r20" },
2011 { PTREGS_OFFSET_REG(21), "r21" },
2012 { PTREGS_OFFSET_REG(22), "r22" },
2013 { PTREGS_OFFSET_REG(23), "r23" },
2014 { PTREGS_OFFSET_REG(24), "r24" },
2015 { PTREGS_OFFSET_REG(25), "r25" },
2016 { PTREGS_OFFSET_REG(26), "r26" },
2017 { PTREGS_OFFSET_REG(27), "r27" },
2018 { PTREGS_OFFSET_REG(28), "r28" },
2019 { PTREGS_OFFSET_REG(29), "r29" },
2020 { PTREGS_OFFSET_REG(30), "r30" },
2021 { PTREGS_OFFSET_REG(31), "r31" },
2022 { PTREGS_OFFSET_REG(32), "r32" },
2023 { PTREGS_OFFSET_REG(33), "r33" },
2024 { PTREGS_OFFSET_REG(34), "r34" },
2025 { PTREGS_OFFSET_REG(35), "r35" },
2026 { PTREGS_OFFSET_REG(36), "r36" },
2027 { PTREGS_OFFSET_REG(37), "r37" },
2028 { PTREGS_OFFSET_REG(38), "r38" },
2029 { PTREGS_OFFSET_REG(39), "r39" },
2030 { PTREGS_OFFSET_REG(40), "r40" },
2031 { PTREGS_OFFSET_REG(41), "r41" },
2032 { PTREGS_OFFSET_REG(42), "r42" },
2033 { PTREGS_OFFSET_REG(43), "r43" },
2034 { PTREGS_OFFSET_REG(44), "r44" },
2035 { PTREGS_OFFSET_REG(45), "r45" },
2036 { PTREGS_OFFSET_REG(46), "r46" },
2037 { PTREGS_OFFSET_REG(47), "r47" },
2038 { PTREGS_OFFSET_REG(48), "r48" },
2039 { PTREGS_OFFSET_REG(49), "r49" },
2040 { PTREGS_OFFSET_REG(50), "r50" },
2041 { PTREGS_OFFSET_REG(51), "r51" },
2042 { PTREGS_OFFSET_REG(52), "r52" },
2043 { PTREGS_OFFSET_TP, "tp" },
2044 { PTREGS_OFFSET_SP, "sp" },
2045 { PTREGS_OFFSET_LR, "lr" },
2046 { PTREGS_OFFSET_PC, "pc" },
2047 { PTREGS_OFFSET_EX1, "ex1" },
2048 { PTREGS_OFFSET_FAULTNUM, "faultnum" },
2049 { PTREGS_OFFSET_ORIG_R0, "orig_r0" },
2050 { PTREGS_OFFSET_FLAGS, "flags" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002051#endif
2052#ifdef CRISV10
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00002053 { 4*PT_FRAMETYPE, "4*PT_FRAMETYPE" },
2054 { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
2055 { 4*PT_R13, "4*PT_R13" },
2056 { 4*PT_R12, "4*PT_R12" },
2057 { 4*PT_R11, "4*PT_R11" },
2058 { 4*PT_R10, "4*PT_R10" },
2059 { 4*PT_R9, "4*PT_R9" },
2060 { 4*PT_R8, "4*PT_R8" },
2061 { 4*PT_R7, "4*PT_R7" },
2062 { 4*PT_R6, "4*PT_R6" },
2063 { 4*PT_R5, "4*PT_R5" },
2064 { 4*PT_R4, "4*PT_R4" },
2065 { 4*PT_R3, "4*PT_R3" },
2066 { 4*PT_R2, "4*PT_R2" },
2067 { 4*PT_R1, "4*PT_R1" },
2068 { 4*PT_R0, "4*PT_R0" },
2069 { 4*PT_MOF, "4*PT_MOF" },
2070 { 4*PT_DCCR, "4*PT_DCCR" },
2071 { 4*PT_SRP, "4*PT_SRP" },
2072 { 4*PT_IRP, "4*PT_IRP" },
2073 { 4*PT_CSRINSTR, "4*PT_CSRINSTR" },
2074 { 4*PT_CSRADDR, "4*PT_CSRADDR" },
2075 { 4*PT_CSRDATA, "4*PT_CSRDATA" },
2076 { 4*PT_USP, "4*PT_USP" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002077#endif
2078#ifdef CRISV32
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00002079 { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
2080 { 4*PT_R0, "4*PT_R0" },
2081 { 4*PT_R1, "4*PT_R1" },
2082 { 4*PT_R2, "4*PT_R2" },
2083 { 4*PT_R3, "4*PT_R3" },
2084 { 4*PT_R4, "4*PT_R4" },
2085 { 4*PT_R5, "4*PT_R5" },
2086 { 4*PT_R6, "4*PT_R6" },
2087 { 4*PT_R7, "4*PT_R7" },
2088 { 4*PT_R8, "4*PT_R8" },
2089 { 4*PT_R9, "4*PT_R9" },
2090 { 4*PT_R10, "4*PT_R10" },
2091 { 4*PT_R11, "4*PT_R11" },
2092 { 4*PT_R12, "4*PT_R12" },
2093 { 4*PT_R13, "4*PT_R13" },
2094 { 4*PT_ACR, "4*PT_ACR" },
2095 { 4*PT_SRS, "4*PT_SRS" },
2096 { 4*PT_MOF, "4*PT_MOF" },
2097 { 4*PT_SPC, "4*PT_SPC" },
2098 { 4*PT_CCS, "4*PT_CCS" },
2099 { 4*PT_SRP, "4*PT_SRP" },
2100 { 4*PT_ERP, "4*PT_ERP" },
2101 { 4*PT_EXS, "4*PT_EXS" },
2102 { 4*PT_EDA, "4*PT_EDA" },
2103 { 4*PT_USP, "4*PT_USP" },
2104 { 4*PT_PPC, "4*PT_PPC" },
2105 { 4*PT_BP_CTRL, "4*PT_BP_CTRL" },
2106 { 4*PT_BP+4, "4*PT_BP+4" },
2107 { 4*PT_BP+8, "4*PT_BP+8" },
2108 { 4*PT_BP+12, "4*PT_BP+12" },
2109 { 4*PT_BP+16, "4*PT_BP+16" },
2110 { 4*PT_BP+20, "4*PT_BP+20" },
2111 { 4*PT_BP+24, "4*PT_BP+24" },
2112 { 4*PT_BP+28, "4*PT_BP+28" },
2113 { 4*PT_BP+32, "4*PT_BP+32" },
2114 { 4*PT_BP+36, "4*PT_BP+36" },
2115 { 4*PT_BP+40, "4*PT_BP+40" },
2116 { 4*PT_BP+44, "4*PT_BP+44" },
2117 { 4*PT_BP+48, "4*PT_BP+48" },
2118 { 4*PT_BP+52, "4*PT_BP+52" },
2119 { 4*PT_BP+56, "4*PT_BP+56" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002120#endif
2121#ifdef MICROBLAZE
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02002122 { PT_GPR(0), "r0" },
2123 { PT_GPR(1), "r1" },
2124 { PT_GPR(2), "r2" },
2125 { PT_GPR(3), "r3" },
2126 { PT_GPR(4), "r4" },
2127 { PT_GPR(5), "r5" },
2128 { PT_GPR(6), "r6" },
2129 { PT_GPR(7), "r7" },
2130 { PT_GPR(8), "r8" },
2131 { PT_GPR(9), "r9" },
2132 { PT_GPR(10), "r10" },
2133 { PT_GPR(11), "r11" },
2134 { PT_GPR(12), "r12" },
2135 { PT_GPR(13), "r13" },
2136 { PT_GPR(14), "r14" },
2137 { PT_GPR(15), "r15" },
2138 { PT_GPR(16), "r16" },
2139 { PT_GPR(17), "r17" },
2140 { PT_GPR(18), "r18" },
2141 { PT_GPR(19), "r19" },
2142 { PT_GPR(20), "r20" },
2143 { PT_GPR(21), "r21" },
2144 { PT_GPR(22), "r22" },
2145 { PT_GPR(23), "r23" },
2146 { PT_GPR(24), "r24" },
2147 { PT_GPR(25), "r25" },
2148 { PT_GPR(26), "r26" },
2149 { PT_GPR(27), "r27" },
2150 { PT_GPR(28), "r28" },
2151 { PT_GPR(29), "r29" },
2152 { PT_GPR(30), "r30" },
2153 { PT_GPR(31), "r31" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002154 { PT_PC, "rpc", },
2155 { PT_MSR, "rmsr", },
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02002156 { PT_EAR, "rear", },
2157 { PT_ESR, "resr", },
2158 { PT_FSR, "rfsr", },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002159 { PT_KERNEL_MODE, "kernel_mode", },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002160#endif
Roland McGrath542c2c62008-05-20 01:11:56 +00002161
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002162#if !defined(SPARC) && !defined(HPPA) && !defined(POWERPC) \
Denys Vlasenkoea0e6e82009-02-25 17:08:40 +00002163 && !defined(ALPHA) && !defined(IA64) \
Edgar E. Iglesias939caba2010-07-06 14:21:07 +02002164 && !defined(CRISV10) && !defined(CRISV32) && !defined(MICROBLAZE)
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002165# if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SPARC64) && !defined(AVR32) && !defined(BFIN) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002166 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002167# endif
2168# if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002169 { uoff(i387), "offsetof(struct user, i387)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002170# endif
2171# if defined(M68K)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002172 { uoff(m68kfp), "offsetof(struct user, m68kfp)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002173# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002174 { uoff(u_tsize), "offsetof(struct user, u_tsize)" },
2175 { uoff(u_dsize), "offsetof(struct user, u_dsize)" },
2176 { uoff(u_ssize), "offsetof(struct user, u_ssize)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002177# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002178 { uoff(start_code), "offsetof(struct user, start_code)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002179# endif
2180# if defined(AVR32) || defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +00002181 { uoff(start_data), "offsetof(struct user, start_data)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002182# endif
2183# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002184 { uoff(start_stack), "offsetof(struct user, start_stack)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002185# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002186 { uoff(signal), "offsetof(struct user, signal)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002187# if !defined(AVR32) && !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SH) && !defined(SH64) && !defined(SPARC64) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002188 { uoff(reserved), "offsetof(struct user, reserved)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002189# endif
2190# if !defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002191 { uoff(u_ar0), "offsetof(struct user, u_ar0)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002192# endif
2193# if !defined(ARM) && !defined(AVR32) && !defined(MIPS) && !defined(S390) && !defined(S390X) && !defined(SPARC64) && !defined(BFIN) && !defined(TILE)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002194 { uoff(u_fpstate), "offsetof(struct user, u_fpstate)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002195# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002196 { uoff(magic), "offsetof(struct user, magic)" },
2197 { uoff(u_comm), "offsetof(struct user, u_comm)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002198# if defined(I386) || defined(X86_64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002199 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002200# endif
2201#endif /* !defined(many arches) */
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002202
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002203#ifndef HPPA
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002204 { sizeof(struct user), "sizeof(struct user)" },
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002205#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002206 { 0, NULL },
2207};
2208
2209int
Denys Vlasenkoc7e83712009-02-24 12:59:47 +00002210sys_ptrace(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002211{
Roland McGrathd9f816f2004-09-04 03:39:20 +00002212 const struct xlat *x;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002213 long addr;
2214
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002215 if (entering(tcp)) {
Roland McGrathbf621d42003-01-14 09:46:21 +00002216 printxval(ptrace_cmds, tcp->u_arg[0],
Roland McGrathbf621d42003-01-14 09:46:21 +00002217 "PTRACE_???"
Roland McGrathbf621d42003-01-14 09:46:21 +00002218 );
2219 tprintf(", %lu, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002220 addr = tcp->u_arg[2];
2221 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2222 || tcp->u_arg[0] == PTRACE_POKEUSER) {
2223 for (x = struct_user_offsets; x->str; x++) {
2224 if (x->val >= addr)
2225 break;
2226 }
2227 if (!x->str)
2228 tprintf("%#lx, ", addr);
2229 else if (x->val > addr && x != struct_user_offsets) {
2230 x--;
2231 tprintf("%s + %ld, ", x->str, addr - x->val);
2232 }
2233 else
2234 tprintf("%s, ", x->str);
2235 }
2236 else
2237 tprintf("%#lx, ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002238 switch (tcp->u_arg[0]) {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002239#ifndef IA64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002240 case PTRACE_PEEKDATA:
2241 case PTRACE_PEEKTEXT:
2242 case PTRACE_PEEKUSER:
2243 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002244#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002245 case PTRACE_CONT:
2246 case PTRACE_SINGLESTEP:
2247 case PTRACE_SYSCALL:
2248 case PTRACE_DETACH:
2249 printsignal(tcp->u_arg[3]);
2250 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002251#ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +00002252 case PTRACE_SETOPTIONS:
2253 printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???");
2254 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002255#endif
2256#ifdef PTRACE_SETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002257 case PTRACE_SETSIGINFO: {
2258 siginfo_t si;
2259 if (!tcp->u_arg[3])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002260 tprints("NULL");
Denys Vlasenkof535b542009-01-13 18:30:55 +00002261 else if (syserror(tcp))
2262 tprintf("%#lx", tcp->u_arg[3]);
2263 else if (umove(tcp, tcp->u_arg[3], &si) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002264 tprints("{???}");
Denys Vlasenkof535b542009-01-13 18:30:55 +00002265 else
2266 printsiginfo(&si, verbose(tcp));
2267 break;
2268 }
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002269#endif
2270#ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002271 case PTRACE_GETSIGINFO:
2272 /* Don't print anything, do it at syscall return. */
2273 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002274#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002275 default:
2276 tprintf("%#lx", tcp->u_arg[3]);
2277 break;
2278 }
2279 } else {
2280 switch (tcp->u_arg[0]) {
2281 case PTRACE_PEEKDATA:
2282 case PTRACE_PEEKTEXT:
2283 case PTRACE_PEEKUSER:
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002284#ifdef IA64
Roland McGrath1e868062007-11-19 22:11:45 +00002285 return RVAL_HEX;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002286#else
Roland McGratheb285352003-01-14 09:59:00 +00002287 printnum(tcp, tcp->u_arg[3], "%#lx");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002288 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002289#endif
2290#ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +00002291 case PTRACE_GETSIGINFO: {
2292 siginfo_t si;
2293 if (!tcp->u_arg[3])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002294 tprints("NULL");
Denys Vlasenkof535b542009-01-13 18:30:55 +00002295 else if (syserror(tcp))
2296 tprintf("%#lx", tcp->u_arg[3]);
2297 else if (umove(tcp, tcp->u_arg[3], &si) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002298 tprints("{???}");
Denys Vlasenkof535b542009-01-13 18:30:55 +00002299 else
2300 printsiginfo(&si, verbose(tcp));
2301 break;
2302 }
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002303#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002304 }
2305 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002306 return 0;
2307}
2308
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002309#ifndef FUTEX_CMP_REQUEUE
2310# define FUTEX_CMP_REQUEUE 4
2311#endif
2312#ifndef FUTEX_WAKE_OP
2313# define FUTEX_WAKE_OP 5
2314#endif
2315#ifndef FUTEX_LOCK_PI
2316# define FUTEX_LOCK_PI 6
2317# define FUTEX_UNLOCK_PI 7
2318# define FUTEX_TRYLOCK_PI 8
2319#endif
2320#ifndef FUTEX_WAIT_BITSET
2321# define FUTEX_WAIT_BITSET 9
2322#endif
2323#ifndef FUTEX_WAKE_BITSET
2324# define FUTEX_WAKE_BITSET 10
2325#endif
2326#ifndef FUTEX_WAIT_REQUEUE_PI
2327# define FUTEX_WAIT_REQUEUE_PI 11
2328#endif
2329#ifndef FUTEX_CMP_REQUEUE_PI
2330# define FUTEX_CMP_REQUEUE_PI 12
2331#endif
2332#ifndef FUTEX_PRIVATE_FLAG
2333# define FUTEX_PRIVATE_FLAG 128
2334#endif
2335#ifndef FUTEX_CLOCK_REALTIME
2336# define FUTEX_CLOCK_REALTIME 256
2337#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +00002338static const struct xlat futexops[] = {
Roland McGrath51942a92007-07-05 18:59:11 +00002339 { FUTEX_WAIT, "FUTEX_WAIT" },
2340 { FUTEX_WAKE, "FUTEX_WAKE" },
2341 { FUTEX_FD, "FUTEX_FD" },
2342 { FUTEX_REQUEUE, "FUTEX_REQUEUE" },
2343 { FUTEX_CMP_REQUEUE, "FUTEX_CMP_REQUEUE" },
2344 { FUTEX_WAKE_OP, "FUTEX_WAKE_OP" },
2345 { FUTEX_LOCK_PI, "FUTEX_LOCK_PI" },
2346 { FUTEX_UNLOCK_PI, "FUTEX_UNLOCK_PI" },
2347 { FUTEX_TRYLOCK_PI, "FUTEX_TRYLOCK_PI" },
Roland McGrath1aeaf742008-07-18 01:27:39 +00002348 { FUTEX_WAIT_BITSET, "FUTEX_WAIT_BITSET" },
2349 { FUTEX_WAKE_BITSET, "FUTEX_WAKE_BITSET" },
Andreas Schwab85f58322009-08-12 09:54:42 +02002350 { FUTEX_WAIT_REQUEUE_PI, "FUTEX_WAIT_REQUEUE_PI" },
2351 { FUTEX_CMP_REQUEUE_PI, "FUTEX_CMP_REQUEUE_PI" },
Roland McGrath51942a92007-07-05 18:59:11 +00002352 { FUTEX_WAIT|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_PRIVATE" },
2353 { FUTEX_WAKE|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_PRIVATE" },
2354 { FUTEX_FD|FUTEX_PRIVATE_FLAG, "FUTEX_FD_PRIVATE" },
2355 { FUTEX_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_REQUEUE_PRIVATE" },
2356 { FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PRIVATE" },
2357 { FUTEX_WAKE_OP|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_OP_PRIVATE" },
2358 { FUTEX_LOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_LOCK_PI_PRIVATE" },
2359 { FUTEX_UNLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_UNLOCK_PI_PRIVATE" },
2360 { FUTEX_TRYLOCK_PI|FUTEX_PRIVATE_FLAG, "FUTEX_TRYLOCK_PI_PRIVATE" },
Roland McGrath1aeaf742008-07-18 01:27:39 +00002361 { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_BITSET_PRIVATE" },
2362 { FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG, "FUTEX_WAKE_BITSET_PRIVATE" },
Andreas Schwab85f58322009-08-12 09:54:42 +02002363 { FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_WAIT_REQUEUE_PI_PRIVATE" },
2364 { FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG, "FUTEX_CMP_REQUEUE_PI_PRIVATE" },
2365 { FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME" },
2366 { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME" },
2367 { FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME, "FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME" },
2368 { 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 +00002369 { 0, NULL }
2370};
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002371#ifndef FUTEX_OP_SET
2372# define FUTEX_OP_SET 0
2373# define FUTEX_OP_ADD 1
2374# define FUTEX_OP_OR 2
2375# define FUTEX_OP_ANDN 3
2376# define FUTEX_OP_XOR 4
2377# define FUTEX_OP_CMP_EQ 0
2378# define FUTEX_OP_CMP_NE 1
2379# define FUTEX_OP_CMP_LT 2
2380# define FUTEX_OP_CMP_LE 3
2381# define FUTEX_OP_CMP_GT 4
2382# define FUTEX_OP_CMP_GE 5
2383#endif
Roland McGrath51942a92007-07-05 18:59:11 +00002384static const struct xlat futexwakeops[] = {
2385 { FUTEX_OP_SET, "FUTEX_OP_SET" },
2386 { FUTEX_OP_ADD, "FUTEX_OP_ADD" },
2387 { FUTEX_OP_OR, "FUTEX_OP_OR" },
2388 { FUTEX_OP_ANDN, "FUTEX_OP_ANDN" },
2389 { FUTEX_OP_XOR, "FUTEX_OP_XOR" },
2390 { 0, NULL }
2391};
2392static const struct xlat futexwakecmps[] = {
2393 { FUTEX_OP_CMP_EQ, "FUTEX_OP_CMP_EQ" },
2394 { FUTEX_OP_CMP_NE, "FUTEX_OP_CMP_NE" },
2395 { FUTEX_OP_CMP_LT, "FUTEX_OP_CMP_LT" },
2396 { FUTEX_OP_CMP_LE, "FUTEX_OP_CMP_LE" },
2397 { FUTEX_OP_CMP_GT, "FUTEX_OP_CMP_GT" },
2398 { FUTEX_OP_CMP_GE, "FUTEX_OP_CMP_GE" },
2399 { 0, NULL }
Roland McGrath5a223472002-12-15 23:58:26 +00002400};
2401
2402int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002403sys_futex(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00002404{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002405 if (entering(tcp)) {
2406 long int cmd = tcp->u_arg[1] & 127;
2407 tprintf("%p, ", (void *) tcp->u_arg[0]);
2408 printxval(futexops, tcp->u_arg[1], "FUTEX_???");
2409 tprintf(", %ld", tcp->u_arg[2]);
2410 if (cmd == FUTEX_WAKE_BITSET)
2411 tprintf(", %lx", tcp->u_arg[5]);
2412 else if (cmd == FUTEX_WAIT) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002413 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002414 printtv(tcp, tcp->u_arg[3]);
2415 } else if (cmd == FUTEX_WAIT_BITSET) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002416 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002417 printtv(tcp, tcp->u_arg[3]);
2418 tprintf(", %lx", tcp->u_arg[5]);
2419 } else if (cmd == FUTEX_REQUEUE)
2420 tprintf(", %ld, %p", tcp->u_arg[3], (void *) tcp->u_arg[4]);
Andreas Schwab85f58322009-08-12 09:54:42 +02002421 else if (cmd == FUTEX_CMP_REQUEUE || cmd == FUTEX_CMP_REQUEUE_PI)
Denys Vlasenko1d632462009-04-14 12:51:00 +00002422 tprintf(", %ld, %p, %ld", tcp->u_arg[3], (void *) tcp->u_arg[4], tcp->u_arg[5]);
2423 else if (cmd == FUTEX_WAKE_OP) {
2424 tprintf(", %ld, %p, {", tcp->u_arg[3], (void *) tcp->u_arg[4]);
2425 if ((tcp->u_arg[5] >> 28) & 8)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002426 tprints("FUTEX_OP_OPARG_SHIFT|");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002427 printxval(futexwakeops, (tcp->u_arg[5] >> 28) & 0x7, "FUTEX_OP_???");
2428 tprintf(", %ld, ", (tcp->u_arg[5] >> 12) & 0xfff);
2429 if ((tcp->u_arg[5] >> 24) & 8)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002430 tprints("FUTEX_OP_OPARG_SHIFT|");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002431 printxval(futexwakecmps, (tcp->u_arg[5] >> 24) & 0x7, "FUTEX_OP_CMP_???");
2432 tprintf(", %ld}", tcp->u_arg[5] & 0xfff);
Andreas Schwab85f58322009-08-12 09:54:42 +02002433 } else if (cmd == FUTEX_WAIT_REQUEUE_PI) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002434 tprints(", ");
Andreas Schwab85f58322009-08-12 09:54:42 +02002435 printtv(tcp, tcp->u_arg[3]);
2436 tprintf(", %p", (void *) tcp->u_arg[4]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002437 }
Roland McGrath51942a92007-07-05 18:59:11 +00002438 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002439 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00002440}
2441
2442static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002443print_affinitylist(struct tcb *tcp, long list, unsigned int len)
Roland McGrath5a223472002-12-15 23:58:26 +00002444{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002445 int first = 1;
Dmitry V. Levin62e05962009-11-03 14:38:44 +00002446 unsigned long w, min_len;
2447
2448 if (abbrev(tcp) && len / sizeof(w) > max_strlen)
2449 min_len = len - max_strlen * sizeof(w);
2450 else
2451 min_len = 0;
2452 for (; len >= sizeof(w) && len > min_len;
2453 len -= sizeof(w), list += sizeof(w)) {
2454 if (umove(tcp, list, &w) < 0)
2455 break;
2456 if (first)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002457 tprints("{");
Dmitry V. Levin62e05962009-11-03 14:38:44 +00002458 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002459 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002460 first = 0;
Dmitry V. Levin62e05962009-11-03 14:38:44 +00002461 tprintf("%lx", w);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002462 }
Dmitry V. Levin62e05962009-11-03 14:38:44 +00002463 if (len) {
2464 if (first)
2465 tprintf("%#lx", list);
2466 else
2467 tprintf(", %s}", (len >= sizeof(w) && len > min_len ?
2468 "???" : "..."));
2469 } else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002470 tprints(first ? "{}" : "}");
Dmitry V. Levin62e05962009-11-03 14:38:44 +00002471 }
Roland McGrath5a223472002-12-15 23:58:26 +00002472}
2473
2474int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002475sys_sched_setaffinity(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00002476{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002477 if (entering(tcp)) {
2478 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2479 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2480 }
2481 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00002482}
2483
2484int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002485sys_sched_getaffinity(struct tcb *tcp)
Roland McGrath5a223472002-12-15 23:58:26 +00002486{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002487 if (entering(tcp)) {
2488 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2489 } else {
2490 if (tcp->u_rval == -1)
2491 tprintf("%#lx", tcp->u_arg[2]);
2492 else
2493 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_rval);
2494 }
2495 return 0;
Roland McGrath5a223472002-12-15 23:58:26 +00002496}
Roland McGrath279d3782004-03-01 20:27:37 +00002497
Dmitry V. Levin1b0bae22012-03-11 22:32:26 +00002498int
2499sys_get_robust_list(struct tcb *tcp)
2500{
2501 if (entering(tcp)) {
2502 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
2503 } else {
2504 void *addr;
2505 size_t len;
2506
2507 if (syserror(tcp) ||
2508 !tcp->u_arg[1] ||
2509 umove(tcp, tcp->u_arg[1], &addr) < 0) {
2510 tprintf("%#lx, ", tcp->u_arg[1]);
2511 } else {
2512 tprintf("[%p], ", addr);
2513 }
2514
2515 if (syserror(tcp) ||
2516 !tcp->u_arg[2] ||
2517 umove(tcp, tcp->u_arg[2], &len) < 0) {
2518 tprintf("%#lx", tcp->u_arg[2]);
2519 } else {
2520 tprintf("[%lu]", (unsigned long) len);
2521 }
2522 }
2523 return 0;
2524}
2525
Roland McGrathd9f816f2004-09-04 03:39:20 +00002526static const struct xlat schedulers[] = {
Roland McGrath279d3782004-03-01 20:27:37 +00002527 { SCHED_OTHER, "SCHED_OTHER" },
2528 { SCHED_RR, "SCHED_RR" },
2529 { SCHED_FIFO, "SCHED_FIFO" },
2530 { 0, NULL }
2531};
2532
2533int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002534sys_sched_getscheduler(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00002535{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002536 if (entering(tcp)) {
2537 tprintf("%d", (int) tcp->u_arg[0]);
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002538 } else if (!syserror(tcp)) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002539 tcp->auxstr = xlookup(schedulers, tcp->u_rval);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002540 if (tcp->auxstr != NULL)
2541 return RVAL_STR;
2542 }
2543 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00002544}
2545
2546int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002547sys_sched_setscheduler(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00002548{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002549 if (entering(tcp)) {
2550 struct sched_param p;
2551 tprintf("%d, ", (int) tcp->u_arg[0]);
2552 printxval(schedulers, tcp->u_arg[1], "SCHED_???");
2553 if (umove(tcp, tcp->u_arg[2], &p) < 0)
2554 tprintf(", %#lx", tcp->u_arg[2]);
2555 else
2556 tprintf(", { %d }", p.__sched_priority);
2557 }
2558 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00002559}
2560
2561int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002562sys_sched_getparam(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00002563{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002564 if (entering(tcp)) {
2565 tprintf("%d, ", (int) tcp->u_arg[0]);
2566 } else {
2567 struct sched_param p;
2568 if (umove(tcp, tcp->u_arg[1], &p) < 0)
2569 tprintf("%#lx", tcp->u_arg[1]);
2570 else
2571 tprintf("{ %d }", p.__sched_priority);
2572 }
2573 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00002574}
2575
2576int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002577sys_sched_setparam(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00002578{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002579 if (entering(tcp)) {
2580 struct sched_param p;
2581 if (umove(tcp, tcp->u_arg[1], &p) < 0)
2582 tprintf("%d, %#lx", (int) tcp->u_arg[0], tcp->u_arg[1]);
2583 else
2584 tprintf("%d, { %d }", (int) tcp->u_arg[0], p.__sched_priority);
2585 }
2586 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00002587}
2588
2589int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002590sys_sched_get_priority_min(struct tcb *tcp)
Roland McGrath279d3782004-03-01 20:27:37 +00002591{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002592 if (entering(tcp)) {
2593 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
2594 }
2595 return 0;
Roland McGrath279d3782004-03-01 20:27:37 +00002596}
Roland McGrathc2d5eb02005-02-02 04:16:56 +00002597
Dmitry V. Levin1ff463d2012-03-11 23:00:11 +00002598int
2599sys_sched_rr_get_interval(struct tcb *tcp)
2600{
2601 if (entering(tcp)) {
2602 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
2603 } else {
2604 if (syserror(tcp))
2605 tprintf("%#lx", tcp->u_arg[1]);
2606 else
2607 print_timespec(tcp, tcp->u_arg[1]);
2608 }
2609 return 0;
2610}
2611
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002612#ifdef X86_64
2613# include <asm/prctl.h>
Roland McGrathc2d5eb02005-02-02 04:16:56 +00002614
2615static const struct xlat archvals[] = {
2616 { ARCH_SET_GS, "ARCH_SET_GS" },
2617 { ARCH_SET_FS, "ARCH_SET_FS" },
2618 { ARCH_GET_FS, "ARCH_GET_FS" },
2619 { ARCH_GET_GS, "ARCH_GET_GS" },
2620 { 0, NULL },
2621};
2622
2623int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002624sys_arch_prctl(struct tcb *tcp)
Roland McGrathc2d5eb02005-02-02 04:16:56 +00002625{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002626 if (entering(tcp)) {
2627 printxval(archvals, tcp->u_arg[0], "ARCH_???");
2628 if (tcp->u_arg[0] == ARCH_SET_GS
2629 || tcp->u_arg[0] == ARCH_SET_FS
2630 ) {
2631 tprintf(", %#lx", tcp->u_arg[1]);
2632 }
2633 } else {
2634 if (tcp->u_arg[0] == ARCH_GET_GS
2635 || tcp->u_arg[0] == ARCH_GET_FS
2636 ) {
2637 long int v;
2638 if (!syserror(tcp) && umove(tcp, tcp->u_arg[1], &v) != -1)
2639 tprintf(", [%#lx]", v);
2640 else
2641 tprintf(", %#lx", tcp->u_arg[1]);
2642 }
Roland McGrathc2d5eb02005-02-02 04:16:56 +00002643 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002644 return 0;
Roland McGrathc2d5eb02005-02-02 04:16:56 +00002645}
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002646#endif /* X86_64 */
Roland McGrathc2d5eb02005-02-02 04:16:56 +00002647
Roland McGrathdb8319f2007-08-02 01:37:55 +00002648int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002649sys_getcpu(struct tcb *tcp)
Roland McGrathdb8319f2007-08-02 01:37:55 +00002650{
2651 if (exiting(tcp)) {
2652 unsigned u;
2653 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002654 tprints("NULL, ");
Roland McGrathdb8319f2007-08-02 01:37:55 +00002655 else if (umove(tcp, tcp->u_arg[0], &u) < 0)
2656 tprintf("%#lx, ", tcp->u_arg[0]);
2657 else
2658 tprintf("[%u], ", u);
2659 if (tcp->u_arg[1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002660 tprints("NULL, ");
Roland McGrathdb8319f2007-08-02 01:37:55 +00002661 else if (umove(tcp, tcp->u_arg[1], &u) < 0)
2662 tprintf("%#lx, ", tcp->u_arg[1]);
2663 else
2664 tprintf("[%u], ", u);
2665 tprintf("%#lx", tcp->u_arg[2]);
2666 }
2667 return 0;
2668}
2669
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002670int
2671sys_process_vm_readv(struct tcb *tcp)
2672{
2673 if (entering(tcp)) {
2674 /* arg 1: pid */
2675 tprintf("%ld, ", tcp->u_arg[0]);
2676 } else {
Dmitry V. Levin0bfd7442012-03-10 14:03:25 +00002677 /* arg 2: local iov */
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002678 if (syserror(tcp)) {
Dmitry V. Levin0bfd7442012-03-10 14:03:25 +00002679 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002680 } else {
2681 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
2682 }
Dmitry V. Levin0bfd7442012-03-10 14:03:25 +00002683 /* arg 3: local iovcnt */
2684 tprintf(", %lu, ", tcp->u_arg[2]);
2685 /* arg 4: remote iov */
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002686 if (syserror(tcp)) {
Dmitry V. Levin0bfd7442012-03-10 14:03:25 +00002687 tprintf("%#lx", tcp->u_arg[3]);
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002688 } else {
2689 tprint_iov(tcp, tcp->u_arg[4], tcp->u_arg[3], 0);
2690 }
Dmitry V. Levin0bfd7442012-03-10 14:03:25 +00002691 /* arg 5: remote iovcnt */
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002692 /* arg 6: flags */
Dmitry V. Levin0bfd7442012-03-10 14:03:25 +00002693 tprintf(", %lu, %lu", tcp->u_arg[4], tcp->u_arg[5]);
Denys Vlasenko3af224c2012-01-28 01:46:33 +01002694 }
2695 return 0;
2696}
Dmitry V. Levin03952102012-03-10 14:14:49 +00002697
2698int
2699sys_process_vm_writev(struct tcb *tcp)
2700{
2701 if (entering(tcp)) {
2702 /* arg 1: pid */
2703 tprintf("%ld, ", tcp->u_arg[0]);
2704 /* arg 2: local iov */
2705 if (syserror(tcp))
2706 tprintf("%#lx", tcp->u_arg[1]);
2707 else
2708 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
2709 /* arg 3: local iovcnt */
2710 tprintf(", %lu, ", tcp->u_arg[2]);
2711 /* arg 4: remote iov */
2712 if (syserror(tcp))
2713 tprintf("%#lx", tcp->u_arg[3]);
2714 else
2715 tprint_iov(tcp, tcp->u_arg[4], tcp->u_arg[3], 0);
2716 /* arg 5: remote iovcnt */
2717 /* arg 6: flags */
2718 tprintf(", %lu, %lu", tcp->u_arg[4], tcp->u_arg[5]);
2719 }
2720 return 0;
2721}