blob: a0cfc523a72d8157609b8c9c8e213c1c919c8fc5 [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 Vlasenkoadedb512008-12-30 18:47:55 +0000283 long long offset = tcp->u_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000284
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200285 /* FIXME: why only SH64? i386 mmap2 syscall ends up
286 * in this function, but does not convert offset
287 * from pages to bytes. See test/mmap_offset_decode.c
288 * Why SH64 and i386 are handled differently?
289 */
Denys Vlasenko84703742012-02-25 02:38:52 +0100290#if defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000291 /*
292 * Old mmap differs from new mmap in specifying the
293 * offset in units of bytes rather than pages. We
294 * pretend it's in byte units so the user only ever
295 * sees bytes in the printout.
296 */
297 offset <<= PAGE_SHIFT;
Roland McGrathe1e584b2003-06-02 19:18:58 +0000298#endif
Roland McGrath542c2c62008-05-20 01:11:56 +0000299#if defined(LINUX_MIPSN32)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000300 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000301#endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000302 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000303}
John Hughes70623be2001-03-08 13:59:00 +0000304#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000305
John Hughes70623be2001-03-08 13:59:00 +0000306#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
H.J. Lu085e4282012-04-17 11:05:04 -0700307# if defined(X32)
308int sys_old_mmap(struct tcb *tcp)
309{
310 long u_arg[6];
311 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
312 return 0;
313 if (entering(tcp)) {
314 /* addr */
315 if (!u_arg[0])
316 tprints("NULL, ");
317 else
318 tprintf("%#lx, ", u_arg[0]);
319 /* len */
320 tprintf("%lu, ", u_arg[1]);
321 /* prot */
322 printflags(mmap_prot, u_arg[2], "PROT_???");
323 tprints(", ");
324 /* flags */
325# ifdef MAP_TYPE
326 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
327 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
328# else
329 printflags(mmap_flags, u_arg[3], "MAP_???");
330# endif
331 /* fd */
332 tprints(", ");
333 printfd(tcp, u_arg[4]);
334 /* offset */
335 tprintf(", %#lx", u_arg[5]);
336 }
337 return RVAL_HEX;
338}
339# endif
340
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200341/* TODO: comment which arches use this routine.
342 * For one, does ALPHA on Linux use this??
343 * From code it seems that it might use 7 or 8 registers,
344 * which is strange - Linux syscalls can pass maximum of 6 parameters!
345 */
Denys Vlasenko923255c2013-02-18 02:36:36 +0100346# ifdef HAVE_LONG_LONG_OFF_T
347/* For systems that have a long long off_t,
348 * sys_mmap in syscall tables is handled by sys_mmap64:
349 */
350# define sys_mmap64 sys_mmap
351# endif
John Hughesbdf48f52001-03-06 15:08:09 +0000352int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300353sys_mmap64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000354{
John Hughesbdf48f52001-03-06 15:08:09 +0000355 if (entering(tcp)) {
H.J. Lu35be5812012-04-16 13:00:01 +0200356#if defined(ALPHA) || defined(X32)
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200357 long *u_arg = tcp->u_arg;
358#else
359 long u_arg[7];
John Hughesbdf48f52001-03-06 15:08:09 +0000360 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
361 (char *) u_arg) == -1)
362 return 0;
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200363#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000364 /* addr */
H.J. Lud0cd4432012-02-03 10:07:42 -0800365 if (!u_arg[0])
366 tprints("NULL, ");
367 else
368 tprintf("%#lx, ", u_arg[0]);
John Hughesbdf48f52001-03-06 15:08:09 +0000369 /* len */
370 tprintf("%lu, ", u_arg[1]);
371 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000372 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200373 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000374 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000375#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000376 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
377 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000378#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000379 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000380#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000381 /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200382 tprints(", ");
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200383 printfd(tcp, u_arg[4]);
John Hughesbdf48f52001-03-06 15:08:09 +0000384 /* offset */
H.J. Lu35be5812012-04-16 13:00:01 +0200385#if defined(ALPHA) || defined(X32)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300386 printllval(tcp, ", %#llx", 5);
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200387#else
388 /* NOTE: not verified that [5] and [6] should be used.
389 * It's possible that long long is 64-bit aligned in memory
390 * and we need to use [6] and [7] here instead:
391 */
392 tprintf(", %#llx", LONG_LONG(u_arg[5], u_arg[6]));
393#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000394 }
395 return RVAL_HEX;
396}
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200397#endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */
John Hughesbdf48f52001-03-06 15:08:09 +0000398
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399int
Denys Vlasenko12014262011-05-30 14:00:14 +0200400sys_munmap(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000401{
402 if (entering(tcp)) {
403 tprintf("%#lx, %lu",
404 tcp->u_arg[0], tcp->u_arg[1]);
405 }
406 return 0;
407}
408
409int
Denys Vlasenko12014262011-05-30 14:00:14 +0200410sys_mprotect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000411{
412 if (entering(tcp)) {
413 tprintf("%#lx, %lu, ",
414 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000415 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000416 }
417 return 0;
418}
419
Roland McGrathd9f816f2004-09-04 03:39:20 +0000420static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000421 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
Chris Metcalfff3474a2009-12-24 23:19:19 +0000422#ifdef MREMAP_FIXED
423 { MREMAP_FIXED, "MREMAP_FIXED" },
424#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000425 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000426};
427
428int
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000429sys_mremap(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000430{
431 if (entering(tcp)) {
432 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
433 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000434 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000435#ifdef MREMAP_FIXED
436 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
437 (MREMAP_MAYMOVE | MREMAP_FIXED))
438 tprintf(", %#lx", tcp->u_arg[4]);
439#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000440 }
441 return RVAL_HEX;
442}
443
Roland McGrathf4021b12008-08-25 02:59:36 +0000444static const struct xlat madvise_cmds[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000445#ifdef MADV_NORMAL
446 { MADV_NORMAL, "MADV_NORMAL" },
447#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000448#ifdef MADV_RANDOM
Wichert Akkermanc7926982000-04-10 22:22:31 +0000449 { MADV_RANDOM, "MADV_RANDOM" },
450#endif
451#ifdef MADV_SEQUENTIAL
452 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
453#endif
454#ifdef MADV_WILLNEED
455 { MADV_WILLNEED, "MADV_WILLNEED" },
456#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000457#ifdef MADV_DONTNEED
Wichert Akkermanc7926982000-04-10 22:22:31 +0000458 { MADV_DONTNEED, "MADV_DONTNEED" },
459#endif
460 { 0, NULL },
461};
462
Wichert Akkermanc7926982000-04-10 22:22:31 +0000463int
Denys Vlasenko12014262011-05-30 14:00:14 +0200464sys_madvise(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000465{
466 if (entering(tcp)) {
467 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000468 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000469 }
470 return 0;
471}
472
Roland McGrathd9f816f2004-09-04 03:39:20 +0000473static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000474#ifdef MCL_CURRENT
475 { MCL_CURRENT, "MCL_CURRENT" },
476#endif
477#ifdef MCL_FUTURE
478 { MCL_FUTURE, "MCL_FUTURE" },
479#endif
480 { 0, NULL}
481};
482
483int
Denys Vlasenko12014262011-05-30 14:00:14 +0200484sys_mlockall(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000485{
486 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000487 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000488 }
489 return 0;
490}
491
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000492#ifdef MS_ASYNC
493
Roland McGrathd9f816f2004-09-04 03:39:20 +0000494static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000495#ifdef MS_SYNC
496 { MS_SYNC, "MS_SYNC" },
497#endif
John Hughesaca07f32001-10-16 18:12:27 +0000498 { MS_ASYNC, "MS_ASYNC" },
499 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000500 { 0, NULL },
501};
502
503int
Denys Vlasenko12014262011-05-30 14:00:14 +0200504sys_msync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000505{
506 if (entering(tcp)) {
507 /* addr */
508 tprintf("%#lx", tcp->u_arg[0]);
509 /* len */
510 tprintf(", %lu, ", tcp->u_arg[1]);
511 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000512 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000513 }
514 return 0;
515}
516
517#endif /* MS_ASYNC */
518
519#ifdef MC_SYNC
520
Roland McGrathd9f816f2004-09-04 03:39:20 +0000521static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522 { MC_LOCK, "MC_LOCK" },
523 { MC_LOCKAS, "MC_LOCKAS" },
524 { MC_SYNC, "MC_SYNC" },
525 { MC_UNLOCK, "MC_UNLOCK" },
526 { MC_UNLOCKAS, "MC_UNLOCKAS" },
527 { 0, NULL },
528};
529
Roland McGrathd9f816f2004-09-04 03:39:20 +0000530static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531 { MCL_CURRENT, "MCL_CURRENT" },
532 { MCL_FUTURE, "MCL_FUTURE" },
533 { 0, NULL },
534};
535
536int
Denys Vlasenko12014262011-05-30 14:00:14 +0200537sys_mctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538{
539 int arg, function;
540
541 if (entering(tcp)) {
542 /* addr */
543 tprintf("%#lx", tcp->u_arg[0]);
544 /* len */
545 tprintf(", %lu, ", tcp->u_arg[1]);
546 /* function */
547 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000548 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549 /* arg */
550 arg = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200551 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552 switch (function) {
553 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000554 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555 break;
556 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000557 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558 break;
559 default:
560 tprintf("%#x", arg);
561 break;
562 }
563 }
564 return 0;
565}
566
567#endif /* MC_SYNC */
568
569int
Denys Vlasenko12014262011-05-30 14:00:14 +0200570sys_mincore(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572 if (entering(tcp)) {
573 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
574 } else {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200575 unsigned long i, len;
576 char *vec = NULL;
577
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578 len = tcp->u_arg[1];
579 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000580 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000581 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
582 tprintf("%#lx", tcp->u_arg[2]);
583 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200584 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000585 for (i = 0; i < len; i++) {
586 if (abbrev(tcp) && i >= max_strlen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200587 tprints("...");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000588 break;
589 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200590 tprints((vec[i] & 1) ? "1" : "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200592 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200594 free(vec);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000595 }
596 return 0;
597}
598
Denys Vlasenko84703742012-02-25 02:38:52 +0100599#if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600int
Denys Vlasenko12014262011-05-30 14:00:14 +0200601sys_getpagesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000602{
603 if (exiting(tcp))
604 return RVAL_HEX;
605 return 0;
606}
Denys Vlasenko84703742012-02-25 02:38:52 +0100607#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000608
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100609#if defined(I386)
Roland McGrath909875b2002-12-22 03:34:36 +0000610void
Denys Vlasenko1f458252009-01-23 16:10:22 +0000611print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
Roland McGrath34e4a692002-12-15 23:58:17 +0000612{
613 tprintf("base_addr:%#08lx, "
614 "limit:%d, "
615 "seg_32bit:%d, "
616 "contents:%d, "
617 "read_exec_only:%d, "
618 "limit_in_pages:%d, "
619 "seg_not_present:%d, "
620 "useable:%d}",
Denys Vlasenko1f458252009-01-23 16:10:22 +0000621 (long) ldt_entry->base_addr,
Roland McGrath34e4a692002-12-15 23:58:17 +0000622 ldt_entry->limit,
623 ldt_entry->seg_32bit,
624 ldt_entry->contents,
625 ldt_entry->read_exec_only,
626 ldt_entry->limit_in_pages,
627 ldt_entry->seg_not_present,
628 ldt_entry->useable);
629}
630
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000631int
Denys Vlasenko12014262011-05-30 14:00:14 +0200632sys_modify_ldt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000633{
634 if (entering(tcp)) {
635 struct modify_ldt_ldt_s copy;
636 tprintf("%ld", tcp->u_arg[0]);
637 if (tcp->u_arg[1] == 0
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200638 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000639 || umove(tcp, tcp->u_arg[1], &copy) == -1)
640 tprintf(", %lx", tcp->u_arg[1]);
641 else {
642 tprintf(", {entry_number:%d, ", copy.entry_number);
643 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200644 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000645 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000646 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647 }
648 }
649 tprintf(", %lu", tcp->u_arg[2]);
650 }
651 return 0;
652}
Roland McGrath34e4a692002-12-15 23:58:17 +0000653
654int
Denys Vlasenko12014262011-05-30 14:00:14 +0200655sys_set_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000656{
657 struct modify_ldt_ldt_s copy;
658 if (entering(tcp)) {
659 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
660 if (copy.entry_number == -1)
661 tprintf("{entry_number:%d -> ",
662 copy.entry_number);
663 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200664 tprints("{entry_number:");
Roland McGrath34e4a692002-12-15 23:58:17 +0000665 }
666 } else {
667 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
668 tprintf("%d, ", copy.entry_number);
669 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200670 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000671 else {
672 print_ldt_entry(&copy);
673 }
674 } else {
675 tprintf("%lx", tcp->u_arg[0]);
676 }
677 }
678 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000679
Roland McGrath34e4a692002-12-15 23:58:17 +0000680}
681
682int
Denys Vlasenko12014262011-05-30 14:00:14 +0200683sys_get_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000684{
685 struct modify_ldt_ldt_s copy;
686 if (exiting(tcp)) {
687 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
688 tprintf("{entry_number:%d, ", copy.entry_number);
689 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200690 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000691 else {
692 print_ldt_entry(&copy);
693 }
694 } else {
695 tprintf("%lx", tcp->u_arg[0]);
696 }
697 }
698 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000699
Roland McGrath34e4a692002-12-15 23:58:17 +0000700}
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100701#endif /* I386 */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000702
Denys Vlasenko84703742012-02-25 02:38:52 +0100703#if defined(M68K)
Andreas Schwab58743222010-05-28 22:28:51 +0200704int
Denys Vlasenko12014262011-05-30 14:00:14 +0200705sys_set_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200706{
707 if (entering(tcp))
708 tprintf("%#lx", tcp->u_arg[0]);
709 return 0;
710
711}
712
713int
Denys Vlasenko12014262011-05-30 14:00:14 +0200714sys_get_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200715{
716 return RVAL_HEX;
717}
718#endif
719
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000720int
Denys Vlasenko12014262011-05-30 14:00:14 +0200721sys_remap_file_pages(struct tcb *tcp)
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000722{
723 if (entering(tcp)) {
724 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000725 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000726 tprintf(", %lu, ", tcp->u_arg[3]);
727#ifdef MAP_TYPE
728 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
729 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
730#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000731 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000732#endif
733 }
734 return 0;
735}
Roland McGrathb10a3352004-10-07 18:53:12 +0000736
Roland McGrathb10a3352004-10-07 18:53:12 +0000737#define MPOL_DEFAULT 0
738#define MPOL_PREFERRED 1
739#define MPOL_BIND 2
740#define MPOL_INTERLEAVE 3
741
742#define MPOL_F_NODE (1<<0)
743#define MPOL_F_ADDR (1<<1)
744
745#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000746#define MPOL_MF_MOVE (1<<1)
747#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000748
Roland McGrathb10a3352004-10-07 18:53:12 +0000749static const struct xlat policies[] = {
750 { MPOL_DEFAULT, "MPOL_DEFAULT" },
751 { MPOL_PREFERRED, "MPOL_PREFERRED" },
752 { MPOL_BIND, "MPOL_BIND" },
753 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
754 { 0, NULL }
755};
756
757static const struct xlat mbindflags[] = {
758 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000759 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
760 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
Roland McGrathb10a3352004-10-07 18:53:12 +0000761 { 0, NULL }
762};
763
764static const struct xlat mempolicyflags[] = {
765 { MPOL_F_NODE, "MPOL_F_NODE" },
766 { MPOL_F_ADDR, "MPOL_F_ADDR" },
767 { 0, NULL }
768};
769
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000770static const struct xlat move_pages_flags[] = {
771 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
772 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
773 { 0, NULL }
774};
775
Roland McGrathb10a3352004-10-07 18:53:12 +0000776static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200777get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
Roland McGrathb10a3352004-10-07 18:53:12 +0000778{
Roland McGrathaa524c82005-06-01 19:22:06 +0000779 unsigned long nlongs, size, end;
780
781 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
782 size = nlongs * sizeof(long);
783 end = ptr + size;
784 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
785 && (end > ptr))) {
786 unsigned long n, cur, abbrev_end;
787 int failed = 0;
788
789 if (abbrev(tcp)) {
790 abbrev_end = ptr + max_strlen * sizeof(long);
791 if (abbrev_end < ptr)
792 abbrev_end = end;
793 } else {
794 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000795 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200796 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000797 for (cur = ptr; cur < end; cur += sizeof(long)) {
798 if (cur > ptr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200799 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000800 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200801 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000802 break;
803 }
804 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200805 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000806 failed = 1;
807 break;
808 }
809 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
810 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200811 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000812 if (failed)
813 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000814 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000815 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000816 tprintf(", %lu", maxnodes);
817}
818
819int
Denys Vlasenko12014262011-05-30 14:00:14 +0200820sys_mbind(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000821{
822 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000823 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000824 printxval(policies, tcp->u_arg[2], "MPOL_???");
825 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200826 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000827 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000828 }
829 return 0;
830}
831
832int
Denys Vlasenko12014262011-05-30 14:00:14 +0200833sys_set_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000834{
835 if (entering(tcp)) {
836 printxval(policies, tcp->u_arg[0], "MPOL_???");
837 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
838 }
839 return 0;
840}
841
842int
Denys Vlasenko12014262011-05-30 14:00:14 +0200843sys_get_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000844{
845 if (exiting(tcp)) {
846 int pol;
847 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200848 tprints("NULL");
Roland McGrathb10a3352004-10-07 18:53:12 +0000849 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
850 tprintf("%#lx", tcp->u_arg[0]);
851 else
852 printxval(policies, pol, "MPOL_???");
853 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
854 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000855 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000856 }
857 return 0;
858}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000859
860int
Dmitry V. Levin64d0e712012-03-11 22:44:14 +0000861sys_migrate_pages(struct tcb *tcp)
862{
863 if (entering(tcp)) {
864 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
865 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
866 tprints(", ");
867 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
868 }
869 return 0;
870}
871
872int
Denys Vlasenko12014262011-05-30 14:00:14 +0200873sys_move_pages(struct tcb *tcp)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000874{
875 if (entering(tcp)) {
876 unsigned long npages = tcp->u_arg[1];
877 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
878 if (tcp->u_arg[2] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200879 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000880 else {
881 int i;
882 long puser = tcp->u_arg[2];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200883 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000884 for (i = 0; i < npages; ++i) {
885 void *p;
886 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200887 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000888 if (umove(tcp, puser, &p) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200889 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000890 break;
891 }
892 tprintf("%p", p);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200893 puser += sizeof(void *);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000894 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200895 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000896 }
897 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200898 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000899 else {
900 int i;
901 long nodeuser = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200902 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000903 for (i = 0; i < npages; ++i) {
904 int node;
905 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200906 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000907 if (umove(tcp, nodeuser, &node) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200908 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000909 break;
910 }
911 tprintf("%#x", node);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200912 nodeuser += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000913 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200914 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000915 }
916 }
917 if (exiting(tcp)) {
918 unsigned long npages = tcp->u_arg[1];
919 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200920 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000921 else {
922 int i;
923 long statususer = tcp->u_arg[4];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200924 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000925 for (i = 0; i < npages; ++i) {
926 int status;
927 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200928 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000929 if (umove(tcp, statususer, &status) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200930 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000931 break;
932 }
933 tprintf("%#x", status);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200934 statususer += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000935 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200936 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000937 }
938 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
939 }
940 return 0;
941}
Roland McGrath4a6f6522008-08-25 03:09:16 +0000942
Denys Vlasenko84703742012-02-25 02:38:52 +0100943#if defined(POWERPC)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000944int
Denys Vlasenko12014262011-05-30 14:00:14 +0200945sys_subpage_prot(struct tcb *tcp)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000946{
947 if (entering(tcp)) {
948 unsigned long cur, end, abbrev_end, entries;
949 unsigned int entry;
950
951 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
952 entries = tcp->u_arg[1] >> 16;
953 if (!entries || !tcp->u_arg[2]) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200954 tprints("{}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000955 return 0;
956 }
957 cur = tcp->u_arg[2];
958 end = cur + (sizeof(int) * entries);
959 if (!verbose(tcp) || end < tcp->u_arg[2]) {
960 tprintf("%#lx", tcp->u_arg[2]);
961 return 0;
962 }
963 if (abbrev(tcp)) {
964 abbrev_end = cur + (sizeof(int) * max_strlen);
965 if (abbrev_end > end)
966 abbrev_end = end;
967 }
968 else
969 abbrev_end = end;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200970 tprints("{");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000971 for (; cur < end; cur += sizeof(int)) {
972 if (cur > tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200973 tprints(", ");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000974 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200975 tprints("...");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000976 break;
977 }
978 if (umove(tcp, cur, &entry) < 0) {
979 tprintf("??? [%#lx]", cur);
980 break;
981 }
982 else
983 tprintf("%#08x", entry);
984 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200985 tprints("}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000986 }
987
988 return 0;
989}
990#endif