blob: 389e098c52fd207304b677a40e81ce9f40595113 [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>
Roland McGrathe1e584b2003-06-02 19:18:58 +00006 * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
7 * port by Greg Banks <gbanks@pocketpenguins.com>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00008 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000031 */
32
33#include "defs.h"
Roland McGrath05cdd3c2004-03-02 06:16:59 +000034#include <asm/mman.h>
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000035#include <sys/mman.h>
Denys Vlasenko84703742012-02-25 02:38:52 +010036#if defined(I386)
Denys Vlasenko72a58482011-08-19 16:01:51 +020037# include <asm/ldt.h>
Roland McGrath7decfb22004-03-01 22:10:52 +000038# ifdef HAVE_STRUCT_USER_DESC
39# define modify_ldt_ldt_s user_desc
40# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041#endif
Denys Vlasenko84703742012-02-25 02:38:52 +010042#if defined(SH64)
Denys Vlasenko72a58482011-08-19 16:01:51 +020043# include <asm/page.h> /* for PAGE_SHIFT */
Roland McGrathe1e584b2003-06-02 19:18:58 +000044#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045
46int
Denys Vlasenko12014262011-05-30 14:00:14 +020047sys_brk(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048{
49 if (entering(tcp)) {
50 tprintf("%#lx", tcp->u_arg[0]);
51 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052 return RVAL_HEX;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053}
54
Roland McGrathd9f816f2004-09-04 03:39:20 +000055static const struct xlat mmap_prot[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000056 { PROT_NONE, "PROT_NONE", },
57 { PROT_READ, "PROT_READ" },
58 { PROT_WRITE, "PROT_WRITE" },
59 { PROT_EXEC, "PROT_EXEC" },
Roland McGrath47eb0e22003-09-25 23:06:04 +000060#ifdef PROT_SEM
61 { PROT_SEM, "PROT_SEM" },
62#endif
63#ifdef PROT_GROWSDOWN
64 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
65#endif
66#ifdef PROT_GROWSUP
67 { PROT_GROWSUP, "PROT_GROWSUP" },
68#endif
Roland McGrath586d6ab2008-08-25 03:00:47 +000069#ifdef PROT_SAO
70 { PROT_SAO, "PROT_SAO" },
71#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000072 { 0, NULL },
73};
74
Roland McGrathd9f816f2004-09-04 03:39:20 +000075static const struct xlat mmap_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000076 { MAP_SHARED, "MAP_SHARED" },
77 { MAP_PRIVATE, "MAP_PRIVATE" },
78 { MAP_FIXED, "MAP_FIXED" },
79#ifdef MAP_ANONYMOUS
80 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
81#endif
Dmitry V. Levin71f1a132007-03-29 23:30:09 +000082#ifdef MAP_32BIT
83 { MAP_32BIT, "MAP_32BIT" },
84#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000085#ifdef MAP_RENAME
86 { MAP_RENAME, "MAP_RENAME" },
87#endif
88#ifdef MAP_NORESERVE
89 { MAP_NORESERVE,"MAP_NORESERVE" },
90#endif
Roland McGrath72c5b7b2003-03-05 04:08:00 +000091#ifdef MAP_POPULATE
92 { MAP_POPULATE, "MAP_POPULATE" },
93#endif
94#ifdef MAP_NONBLOCK
95 { MAP_NONBLOCK, "MAP_NONBLOCK" },
96#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +000097 /*
98 * XXX - this was introduced in SunOS 4.x to distinguish between
99 * the old pre-4.x "mmap()", which:
100 *
101 * only let you map devices with an "mmap" routine (e.g.,
102 * frame buffers) in;
103 *
104 * required you to specify the mapping address;
105 *
106 * returned 0 on success and -1 on failure;
107 *
108 * memory and which, and the 4.x "mmap()" which:
109 *
110 * can map plain files;
111 *
112 * can be asked to pick where to map the file;
113 *
114 * returns the address where it mapped the file on success
115 * and -1 on failure.
116 *
117 * It's not actually used in source code that calls "mmap()"; the
118 * "mmap()" routine adds it for you.
119 *
120 * It'd be nice to come up with some way of eliminating it from
121 * the flags, e.g. reporting calls *without* it as "old_mmap()"
122 * and calls with it as "mmap()".
123 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000124#ifdef _MAP_NEW
125 { _MAP_NEW, "_MAP_NEW" },
126#endif
127#ifdef MAP_GROWSDOWN
128 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
129#endif
130#ifdef MAP_DENYWRITE
131 { MAP_DENYWRITE,"MAP_DENYWRITE" },
132#endif
133#ifdef MAP_EXECUTABLE
134 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
135#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000136#ifdef MAP_INHERIT
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100137 { MAP_INHERIT, "MAP_INHERIT" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000138#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000139#ifdef MAP_FILE
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100140 { MAP_FILE, "MAP_FILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000141#endif
142#ifdef MAP_LOCKED
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100143 { MAP_LOCKED, "MAP_LOCKED" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000144#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000145 /* FreeBSD ones */
Denys Vlasenko2897fb32012-03-17 01:29:40 +0100146#if defined(MAP_ANON) && (!defined(MAP_ANONYMOUS) || MAP_ANON != MAP_ANONYMOUS)
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100147 { MAP_ANON, "MAP_ANON" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000148#endif
149#ifdef MAP_HASSEMAPHORE
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100150 { MAP_HASSEMAPHORE,"MAP_HASSEMAPHORE"},
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000151#endif
152#ifdef MAP_STACK
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100153 { MAP_STACK, "MAP_STACK" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000154#endif
Bernhard Reutner-Fischer21ceeb42013-02-05 19:31:55 +0100155#if defined MAP_UNINITIALIZED && MAP_UNINITIALIZED > 0
156 { MAP_UNINITIALIZED,"MAP_UNINITIALIZED"},
157#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000158#ifdef MAP_NOSYNC
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100159 { MAP_NOSYNC, "MAP_NOSYNC" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000160#endif
161#ifdef MAP_NOCORE
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100162 { MAP_NOCORE, "MAP_NOCORE" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000163#endif
Chris Metcalfc8c66982009-12-28 10:00:15 -0500164#ifdef TILE
165 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
166 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
167 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
168#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000169 { 0, NULL },
170};
171
Chris Metcalfc8c66982009-12-28 10:00:15 -0500172#ifdef TILE
Denys Vlasenko72a58482011-08-19 16:01:51 +0200173static int
174addtileflags(long flags)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500175{
176 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
177 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
178
179 if (flags & _MAP_CACHE_INCOHERENT) {
180 flags &= ~_MAP_CACHE_INCOHERENT;
181 if (home == MAP_CACHE_HOME_NONE) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200182 tprints("|MAP_CACHE_INCOHERENT");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500183 return flags;
184 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200185 tprints("|_MAP_CACHE_INCOHERENT");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500186 }
187
188 switch (home) {
189 case 0: break;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200190 case MAP_CACHE_HOME_HERE: tprints("|MAP_CACHE_HOME_HERE"); break;
191 case MAP_CACHE_HOME_NONE: tprints("|MAP_CACHE_HOME_NONE"); break;
192 case MAP_CACHE_HOME_SINGLE: tprints("|MAP_CACHE_HOME_SINGLE"); break;
193 case MAP_CACHE_HOME_TASK: tprints("|MAP_CACHE_HOME_TASK"); break;
194 case MAP_CACHE_HOME_HASH: tprints("|MAP_CACHE_HOME_HASH"); break;
Chris Metcalfc8c66982009-12-28 10:00:15 -0500195 default:
Chris Metcalf0b99a8a2013-02-05 17:48:33 +0100196 tprintf("|MAP_CACHE_HOME(%ld)",
Chris Metcalfc8c66982009-12-28 10:00:15 -0500197 (home >> _MAP_CACHE_HOME_SHIFT) );
198 break;
199 }
200
201 return flags;
202}
203#endif
204
John Hughes70623be2001-03-08 13:59:00 +0000205#if !HAVE_LONG_LONG_OFF_T
Dmitry V. Levin31382132011-03-04 05:08:02 +0300206static int
Denys Vlasenko923255c2013-02-18 02:36:36 +0100207print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000209 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000210 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000211 if (!u_arg[0])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200212 tprints("NULL, ");
Wichert Akkerman8829a551999-06-11 13:18:40 +0000213 else
214 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000215 /* len */
216 tprintf("%lu, ", u_arg[1]);
217 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000218 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200219 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000220 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000221#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
Denys Vlasenko923255c2013-02-18 02:36:36 +0100223# ifdef TILE
Chris Metcalfc8c66982009-12-28 10:00:15 -0500224 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
Denys Vlasenko923255c2013-02-18 02:36:36 +0100225# else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Denys Vlasenko923255c2013-02-18 02:36:36 +0100227# endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000228#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000229 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000230#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200231 tprints(", ");
Denys Vlasenko923255c2013-02-18 02:36:36 +0100232 /* fd */
Dmitry V. Levin31382132011-03-04 05:08:02 +0300233 printfd(tcp, u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234 /* offset */
Dmitry V. Levin31382132011-03-04 05:08:02 +0300235 tprintf(", %#llx", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236 }
237 return RVAL_HEX;
238}
239
Denys Vlasenko12014262011-05-30 14:00:14 +0200240int sys_old_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000241{
Denys Vlasenko72a58482011-08-19 16:01:51 +0200242#if defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000243 /*
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200244 * IA64 processes never call this routine, they only use the
245 * new `sys_mmap' interface.
246 * For IA32 processes, this code converts the integer arguments
247 * that they pushed onto the stack, into longs.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000248 */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200249 int i;
250 long u_arg[6];
Denys Vlasenko923255c2013-02-18 02:36:36 +0100251 unsigned narrow_arg[6];
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200252 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
253 return 0;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000254 for (i = 0; i < 6; i++)
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200255 u_arg[i] = narrow_arg[i];
Roland McGrathf5a47772003-06-26 22:40:42 +0000256#elif defined(SH) || defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000257 /* SH has always passed the args in registers */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200258 long *u_arg = tcp->u_arg;
Denys Vlasenko923255c2013-02-18 02:36:36 +0100259#elif defined(X86_64)
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200260 long u_arg[6];
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000261 if (current_personality == 1) {
262 int i;
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200263 unsigned narrow_arg[6];
264 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
265 return 0;
266 for (i = 0; i < 6; ++i)
267 u_arg[i] = narrow_arg[i];
Denys Vlasenko923255c2013-02-18 02:36:36 +0100268 } else {
269 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
270 return 0;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000271 }
Denys Vlasenko923255c2013-02-18 02:36:36 +0100272#else
273 long u_arg[6];
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200274 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000275 return 0;
Denys Vlasenko923255c2013-02-18 02:36:36 +0100276#endif
277 return print_mmap(tcp, u_arg, (unsigned long)u_arg[5]);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000278}
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000279
280int
Denys Vlasenko12014262011-05-30 14:00:14 +0200281sys_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000282{
Denys Vlasenko8dedb0d2013-02-18 03:13:07 +0100283 unsigned long long offset = (unsigned long) tcp->u_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000284
Denys Vlasenko84703742012-02-25 02:38:52 +0100285#if defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000286 /*
287 * Old mmap differs from new mmap in specifying the
288 * offset in units of bytes rather than pages. We
289 * pretend it's in byte units so the user only ever
290 * sees bytes in the printout.
291 */
292 offset <<= PAGE_SHIFT;
Denys Vlasenko8dedb0d2013-02-18 03:13:07 +0100293#elif defined(I386)
294 /* Try test/mmap_offset_decode.c */
295 offset <<= 12; /* 4096 byte pages */
296#elif defined(LINUX_MIPSN32) || defined(X32)
297 /* Try test/x32_mmap.c */
298 /* At least for X32 it definitely should not be page-shifted! */
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000299 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000300#endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000301 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000302}
John Hughes70623be2001-03-08 13:59:00 +0000303#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000304
John Hughes70623be2001-03-08 13:59:00 +0000305#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200306/* TODO: comment which arches use this routine.
307 * For one, does ALPHA on Linux use this??
308 * From code it seems that it might use 7 or 8 registers,
309 * which is strange - Linux syscalls can pass maximum of 6 parameters!
310 */
Denys Vlasenko923255c2013-02-18 02:36:36 +0100311# ifdef HAVE_LONG_LONG_OFF_T
312/* For systems that have a long long off_t,
313 * sys_mmap in syscall tables is handled by sys_mmap64:
314 */
315# define sys_mmap64 sys_mmap
316# endif
John Hughesbdf48f52001-03-06 15:08:09 +0000317int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300318sys_mmap64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000319{
John Hughesbdf48f52001-03-06 15:08:09 +0000320 if (entering(tcp)) {
H.J. Lu35be5812012-04-16 13:00:01 +0200321#if defined(ALPHA) || defined(X32)
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200322 long *u_arg = tcp->u_arg;
323#else
324 long u_arg[7];
John Hughesbdf48f52001-03-06 15:08:09 +0000325 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
326 (char *) u_arg) == -1)
327 return 0;
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200328#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000329 /* addr */
H.J. Lud0cd4432012-02-03 10:07:42 -0800330 if (!u_arg[0])
331 tprints("NULL, ");
332 else
333 tprintf("%#lx, ", u_arg[0]);
John Hughesbdf48f52001-03-06 15:08:09 +0000334 /* len */
335 tprintf("%lu, ", u_arg[1]);
336 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000337 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200338 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000339 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000340#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000341 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
342 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000343#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000344 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000345#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000346 /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200347 tprints(", ");
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200348 printfd(tcp, u_arg[4]);
John Hughesbdf48f52001-03-06 15:08:09 +0000349 /* offset */
H.J. Lu35be5812012-04-16 13:00:01 +0200350#if defined(ALPHA) || defined(X32)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300351 printllval(tcp, ", %#llx", 5);
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200352#else
353 /* NOTE: not verified that [5] and [6] should be used.
354 * It's possible that long long is 64-bit aligned in memory
355 * and we need to use [6] and [7] here instead:
356 */
357 tprintf(", %#llx", LONG_LONG(u_arg[5], u_arg[6]));
358#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000359 }
360 return RVAL_HEX;
361}
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200362#endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */
John Hughesbdf48f52001-03-06 15:08:09 +0000363
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000364int
Denys Vlasenko12014262011-05-30 14:00:14 +0200365sys_munmap(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366{
367 if (entering(tcp)) {
368 tprintf("%#lx, %lu",
369 tcp->u_arg[0], tcp->u_arg[1]);
370 }
371 return 0;
372}
373
374int
Denys Vlasenko12014262011-05-30 14:00:14 +0200375sys_mprotect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376{
377 if (entering(tcp)) {
378 tprintf("%#lx, %lu, ",
379 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000380 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381 }
382 return 0;
383}
384
Roland McGrathd9f816f2004-09-04 03:39:20 +0000385static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000386 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
Chris Metcalfff3474a2009-12-24 23:19:19 +0000387#ifdef MREMAP_FIXED
388 { MREMAP_FIXED, "MREMAP_FIXED" },
389#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000390 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000391};
392
393int
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000394sys_mremap(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000395{
396 if (entering(tcp)) {
397 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
398 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000399 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000400#ifdef MREMAP_FIXED
401 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
402 (MREMAP_MAYMOVE | MREMAP_FIXED))
403 tprintf(", %#lx", tcp->u_arg[4]);
404#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000405 }
406 return RVAL_HEX;
407}
408
Roland McGrathf4021b12008-08-25 02:59:36 +0000409static const struct xlat madvise_cmds[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000410#ifdef MADV_NORMAL
411 { MADV_NORMAL, "MADV_NORMAL" },
412#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000413#ifdef MADV_RANDOM
Wichert Akkermanc7926982000-04-10 22:22:31 +0000414 { MADV_RANDOM, "MADV_RANDOM" },
415#endif
416#ifdef MADV_SEQUENTIAL
417 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
418#endif
419#ifdef MADV_WILLNEED
420 { MADV_WILLNEED, "MADV_WILLNEED" },
421#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000422#ifdef MADV_DONTNEED
Wichert Akkermanc7926982000-04-10 22:22:31 +0000423 { MADV_DONTNEED, "MADV_DONTNEED" },
424#endif
425 { 0, NULL },
426};
427
Wichert Akkermanc7926982000-04-10 22:22:31 +0000428int
Denys Vlasenko12014262011-05-30 14:00:14 +0200429sys_madvise(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000430{
431 if (entering(tcp)) {
432 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000433 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000434 }
435 return 0;
436}
437
Roland McGrathd9f816f2004-09-04 03:39:20 +0000438static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000439#ifdef MCL_CURRENT
440 { MCL_CURRENT, "MCL_CURRENT" },
441#endif
442#ifdef MCL_FUTURE
443 { MCL_FUTURE, "MCL_FUTURE" },
444#endif
445 { 0, NULL}
446};
447
448int
Denys Vlasenko12014262011-05-30 14:00:14 +0200449sys_mlockall(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000450{
451 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000452 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000453 }
454 return 0;
455}
456
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000457#ifdef MS_ASYNC
458
Roland McGrathd9f816f2004-09-04 03:39:20 +0000459static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460#ifdef MS_SYNC
461 { MS_SYNC, "MS_SYNC" },
462#endif
John Hughesaca07f32001-10-16 18:12:27 +0000463 { MS_ASYNC, "MS_ASYNC" },
464 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465 { 0, NULL },
466};
467
468int
Denys Vlasenko12014262011-05-30 14:00:14 +0200469sys_msync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000470{
471 if (entering(tcp)) {
472 /* addr */
473 tprintf("%#lx", tcp->u_arg[0]);
474 /* len */
475 tprintf(", %lu, ", tcp->u_arg[1]);
476 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000477 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000478 }
479 return 0;
480}
481
482#endif /* MS_ASYNC */
483
484#ifdef MC_SYNC
485
Roland McGrathd9f816f2004-09-04 03:39:20 +0000486static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000487 { MC_LOCK, "MC_LOCK" },
488 { MC_LOCKAS, "MC_LOCKAS" },
489 { MC_SYNC, "MC_SYNC" },
490 { MC_UNLOCK, "MC_UNLOCK" },
491 { MC_UNLOCKAS, "MC_UNLOCKAS" },
492 { 0, NULL },
493};
494
Roland McGrathd9f816f2004-09-04 03:39:20 +0000495static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496 { MCL_CURRENT, "MCL_CURRENT" },
497 { MCL_FUTURE, "MCL_FUTURE" },
498 { 0, NULL },
499};
500
501int
Denys Vlasenko12014262011-05-30 14:00:14 +0200502sys_mctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000503{
504 int arg, function;
505
506 if (entering(tcp)) {
507 /* addr */
508 tprintf("%#lx", tcp->u_arg[0]);
509 /* len */
510 tprintf(", %lu, ", tcp->u_arg[1]);
511 /* function */
512 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000513 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000514 /* arg */
515 arg = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200516 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517 switch (function) {
518 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000519 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520 break;
521 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000522 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000523 break;
524 default:
525 tprintf("%#x", arg);
526 break;
527 }
528 }
529 return 0;
530}
531
532#endif /* MC_SYNC */
533
534int
Denys Vlasenko12014262011-05-30 14:00:14 +0200535sys_mincore(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537 if (entering(tcp)) {
538 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
539 } else {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200540 unsigned long i, len;
541 char *vec = NULL;
542
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543 len = tcp->u_arg[1];
544 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000545 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
547 tprintf("%#lx", tcp->u_arg[2]);
548 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200549 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550 for (i = 0; i < len; i++) {
551 if (abbrev(tcp) && i >= max_strlen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200552 tprints("...");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000553 break;
554 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200555 tprints((vec[i] & 1) ? "1" : "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000556 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200557 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200559 free(vec);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560 }
561 return 0;
562}
563
Denys Vlasenko84703742012-02-25 02:38:52 +0100564#if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565int
Denys Vlasenko12014262011-05-30 14:00:14 +0200566sys_getpagesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567{
568 if (exiting(tcp))
569 return RVAL_HEX;
570 return 0;
571}
Denys Vlasenko84703742012-02-25 02:38:52 +0100572#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100574#if defined(I386)
Roland McGrath909875b2002-12-22 03:34:36 +0000575void
Denys Vlasenko1f458252009-01-23 16:10:22 +0000576print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
Roland McGrath34e4a692002-12-15 23:58:17 +0000577{
578 tprintf("base_addr:%#08lx, "
579 "limit:%d, "
580 "seg_32bit:%d, "
581 "contents:%d, "
582 "read_exec_only:%d, "
583 "limit_in_pages:%d, "
584 "seg_not_present:%d, "
585 "useable:%d}",
Denys Vlasenko1f458252009-01-23 16:10:22 +0000586 (long) ldt_entry->base_addr,
Roland McGrath34e4a692002-12-15 23:58:17 +0000587 ldt_entry->limit,
588 ldt_entry->seg_32bit,
589 ldt_entry->contents,
590 ldt_entry->read_exec_only,
591 ldt_entry->limit_in_pages,
592 ldt_entry->seg_not_present,
593 ldt_entry->useable);
594}
595
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000596int
Denys Vlasenko12014262011-05-30 14:00:14 +0200597sys_modify_ldt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598{
599 if (entering(tcp)) {
600 struct modify_ldt_ldt_s copy;
601 tprintf("%ld", tcp->u_arg[0]);
602 if (tcp->u_arg[1] == 0
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200603 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604 || umove(tcp, tcp->u_arg[1], &copy) == -1)
605 tprintf(", %lx", tcp->u_arg[1]);
606 else {
607 tprintf(", {entry_number:%d, ", copy.entry_number);
608 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200609 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000610 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000611 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000612 }
613 }
614 tprintf(", %lu", tcp->u_arg[2]);
615 }
616 return 0;
617}
Roland McGrath34e4a692002-12-15 23:58:17 +0000618
619int
Denys Vlasenko12014262011-05-30 14:00:14 +0200620sys_set_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000621{
622 struct modify_ldt_ldt_s copy;
623 if (entering(tcp)) {
624 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
625 if (copy.entry_number == -1)
626 tprintf("{entry_number:%d -> ",
627 copy.entry_number);
628 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200629 tprints("{entry_number:");
Roland McGrath34e4a692002-12-15 23:58:17 +0000630 }
631 } else {
632 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
633 tprintf("%d, ", copy.entry_number);
634 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200635 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000636 else {
637 print_ldt_entry(&copy);
638 }
639 } else {
640 tprintf("%lx", tcp->u_arg[0]);
641 }
642 }
643 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000644
Roland McGrath34e4a692002-12-15 23:58:17 +0000645}
646
647int
Denys Vlasenko12014262011-05-30 14:00:14 +0200648sys_get_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000649{
650 struct modify_ldt_ldt_s copy;
651 if (exiting(tcp)) {
652 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
653 tprintf("{entry_number:%d, ", copy.entry_number);
654 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200655 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000656 else {
657 print_ldt_entry(&copy);
658 }
659 } else {
660 tprintf("%lx", tcp->u_arg[0]);
661 }
662 }
663 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000664
Roland McGrath34e4a692002-12-15 23:58:17 +0000665}
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100666#endif /* I386 */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000667
Denys Vlasenko84703742012-02-25 02:38:52 +0100668#if defined(M68K)
Andreas Schwab58743222010-05-28 22:28:51 +0200669int
Denys Vlasenko12014262011-05-30 14:00:14 +0200670sys_set_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200671{
672 if (entering(tcp))
673 tprintf("%#lx", tcp->u_arg[0]);
674 return 0;
675
676}
677
678int
Denys Vlasenko12014262011-05-30 14:00:14 +0200679sys_get_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200680{
681 return RVAL_HEX;
682}
683#endif
684
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000685int
Denys Vlasenko12014262011-05-30 14:00:14 +0200686sys_remap_file_pages(struct tcb *tcp)
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000687{
688 if (entering(tcp)) {
689 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000690 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000691 tprintf(", %lu, ", tcp->u_arg[3]);
692#ifdef MAP_TYPE
693 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
694 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
695#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000696 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000697#endif
698 }
699 return 0;
700}
Roland McGrathb10a3352004-10-07 18:53:12 +0000701
Roland McGrathb10a3352004-10-07 18:53:12 +0000702#define MPOL_DEFAULT 0
703#define MPOL_PREFERRED 1
704#define MPOL_BIND 2
705#define MPOL_INTERLEAVE 3
706
707#define MPOL_F_NODE (1<<0)
708#define MPOL_F_ADDR (1<<1)
709
710#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000711#define MPOL_MF_MOVE (1<<1)
712#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000713
Roland McGrathb10a3352004-10-07 18:53:12 +0000714static const struct xlat policies[] = {
715 { MPOL_DEFAULT, "MPOL_DEFAULT" },
716 { MPOL_PREFERRED, "MPOL_PREFERRED" },
717 { MPOL_BIND, "MPOL_BIND" },
718 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
719 { 0, NULL }
720};
721
722static const struct xlat mbindflags[] = {
723 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000724 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
725 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
Roland McGrathb10a3352004-10-07 18:53:12 +0000726 { 0, NULL }
727};
728
729static const struct xlat mempolicyflags[] = {
730 { MPOL_F_NODE, "MPOL_F_NODE" },
731 { MPOL_F_ADDR, "MPOL_F_ADDR" },
732 { 0, NULL }
733};
734
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000735static const struct xlat move_pages_flags[] = {
736 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
737 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
738 { 0, NULL }
739};
740
Roland McGrathb10a3352004-10-07 18:53:12 +0000741static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200742get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
Roland McGrathb10a3352004-10-07 18:53:12 +0000743{
Roland McGrathaa524c82005-06-01 19:22:06 +0000744 unsigned long nlongs, size, end;
745
746 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
747 size = nlongs * sizeof(long);
748 end = ptr + size;
749 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
750 && (end > ptr))) {
751 unsigned long n, cur, abbrev_end;
752 int failed = 0;
753
754 if (abbrev(tcp)) {
755 abbrev_end = ptr + max_strlen * sizeof(long);
756 if (abbrev_end < ptr)
757 abbrev_end = end;
758 } else {
759 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000760 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200761 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000762 for (cur = ptr; cur < end; cur += sizeof(long)) {
763 if (cur > ptr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200764 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000765 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200766 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000767 break;
768 }
769 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200770 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000771 failed = 1;
772 break;
773 }
774 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
775 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200776 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000777 if (failed)
778 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000779 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000780 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000781 tprintf(", %lu", maxnodes);
782}
783
784int
Denys Vlasenko12014262011-05-30 14:00:14 +0200785sys_mbind(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000786{
787 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000788 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000789 printxval(policies, tcp->u_arg[2], "MPOL_???");
790 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200791 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000792 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000793 }
794 return 0;
795}
796
797int
Denys Vlasenko12014262011-05-30 14:00:14 +0200798sys_set_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000799{
800 if (entering(tcp)) {
801 printxval(policies, tcp->u_arg[0], "MPOL_???");
802 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
803 }
804 return 0;
805}
806
807int
Denys Vlasenko12014262011-05-30 14:00:14 +0200808sys_get_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000809{
810 if (exiting(tcp)) {
811 int pol;
812 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200813 tprints("NULL");
Roland McGrathb10a3352004-10-07 18:53:12 +0000814 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
815 tprintf("%#lx", tcp->u_arg[0]);
816 else
817 printxval(policies, pol, "MPOL_???");
818 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
819 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000820 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000821 }
822 return 0;
823}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000824
825int
Dmitry V. Levin64d0e712012-03-11 22:44:14 +0000826sys_migrate_pages(struct tcb *tcp)
827{
828 if (entering(tcp)) {
829 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
830 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
831 tprints(", ");
832 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
833 }
834 return 0;
835}
836
837int
Denys Vlasenko12014262011-05-30 14:00:14 +0200838sys_move_pages(struct tcb *tcp)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000839{
840 if (entering(tcp)) {
841 unsigned long npages = tcp->u_arg[1];
842 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
843 if (tcp->u_arg[2] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200844 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000845 else {
846 int i;
847 long puser = tcp->u_arg[2];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200848 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000849 for (i = 0; i < npages; ++i) {
850 void *p;
851 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200852 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000853 if (umove(tcp, puser, &p) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200854 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000855 break;
856 }
857 tprintf("%p", p);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200858 puser += sizeof(void *);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000859 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200860 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000861 }
862 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200863 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000864 else {
865 int i;
866 long nodeuser = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200867 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000868 for (i = 0; i < npages; ++i) {
869 int node;
870 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200871 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000872 if (umove(tcp, nodeuser, &node) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200873 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000874 break;
875 }
876 tprintf("%#x", node);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200877 nodeuser += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000878 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200879 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000880 }
881 }
882 if (exiting(tcp)) {
883 unsigned long npages = tcp->u_arg[1];
884 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200885 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000886 else {
887 int i;
888 long statususer = tcp->u_arg[4];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200889 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000890 for (i = 0; i < npages; ++i) {
891 int status;
892 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200893 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000894 if (umove(tcp, statususer, &status) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200895 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000896 break;
897 }
898 tprintf("%#x", status);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200899 statususer += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000900 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200901 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000902 }
903 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
904 }
905 return 0;
906}
Roland McGrath4a6f6522008-08-25 03:09:16 +0000907
Denys Vlasenko84703742012-02-25 02:38:52 +0100908#if defined(POWERPC)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000909int
Denys Vlasenko12014262011-05-30 14:00:14 +0200910sys_subpage_prot(struct tcb *tcp)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000911{
912 if (entering(tcp)) {
913 unsigned long cur, end, abbrev_end, entries;
914 unsigned int entry;
915
916 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
917 entries = tcp->u_arg[1] >> 16;
918 if (!entries || !tcp->u_arg[2]) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200919 tprints("{}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000920 return 0;
921 }
922 cur = tcp->u_arg[2];
923 end = cur + (sizeof(int) * entries);
924 if (!verbose(tcp) || end < tcp->u_arg[2]) {
925 tprintf("%#lx", tcp->u_arg[2]);
926 return 0;
927 }
928 if (abbrev(tcp)) {
929 abbrev_end = cur + (sizeof(int) * max_strlen);
930 if (abbrev_end > end)
931 abbrev_end = end;
932 }
933 else
934 abbrev_end = end;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200935 tprints("{");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000936 for (; cur < end; cur += sizeof(int)) {
937 if (cur > tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200938 tprints(", ");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000939 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200940 tprints("...");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000941 break;
942 }
943 if (umove(tcp, cur, &entry) < 0) {
944 tprintf("??? [%#lx]", cur);
945 break;
946 }
947 else
948 tprintf("%#08x", entry);
949 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200950 tprints("}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000951 }
952
953 return 0;
954}
955#endif