blob: 027903051a1d3a35a1b06fdd418b6f2c7491e572 [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
John Hughes70623be2001-03-08 13:59:00 +000046#ifdef HAVE_LONG_LONG_OFF_T
47/*
48 * Ugly hacks for systems that have a long long off_t
49 */
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010050# define sys_mmap64 sys_mmap
John Hughes70623be2001-03-08 13:59:00 +000051#endif
52
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053int
Denys Vlasenko12014262011-05-30 14:00:14 +020054sys_brk(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055{
56 if (entering(tcp)) {
57 tprintf("%#lx", tcp->u_arg[0]);
58 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059 return RVAL_HEX;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000060}
61
Roland McGrathd9f816f2004-09-04 03:39:20 +000062static const struct xlat mmap_prot[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000063 { PROT_NONE, "PROT_NONE", },
64 { PROT_READ, "PROT_READ" },
65 { PROT_WRITE, "PROT_WRITE" },
66 { PROT_EXEC, "PROT_EXEC" },
Roland McGrath47eb0e22003-09-25 23:06:04 +000067#ifdef PROT_SEM
68 { PROT_SEM, "PROT_SEM" },
69#endif
70#ifdef PROT_GROWSDOWN
71 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
72#endif
73#ifdef PROT_GROWSUP
74 { PROT_GROWSUP, "PROT_GROWSUP" },
75#endif
Roland McGrath586d6ab2008-08-25 03:00:47 +000076#ifdef PROT_SAO
77 { PROT_SAO, "PROT_SAO" },
78#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000079 { 0, NULL },
80};
81
Roland McGrathd9f816f2004-09-04 03:39:20 +000082static const struct xlat mmap_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000083 { MAP_SHARED, "MAP_SHARED" },
84 { MAP_PRIVATE, "MAP_PRIVATE" },
85 { MAP_FIXED, "MAP_FIXED" },
86#ifdef MAP_ANONYMOUS
87 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
88#endif
Dmitry V. Levin71f1a132007-03-29 23:30:09 +000089#ifdef MAP_32BIT
90 { MAP_32BIT, "MAP_32BIT" },
91#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000092#ifdef MAP_RENAME
93 { MAP_RENAME, "MAP_RENAME" },
94#endif
95#ifdef MAP_NORESERVE
96 { MAP_NORESERVE,"MAP_NORESERVE" },
97#endif
Roland McGrath72c5b7b2003-03-05 04:08:00 +000098#ifdef MAP_POPULATE
99 { MAP_POPULATE, "MAP_POPULATE" },
100#endif
101#ifdef MAP_NONBLOCK
102 { MAP_NONBLOCK, "MAP_NONBLOCK" },
103#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000104 /*
105 * XXX - this was introduced in SunOS 4.x to distinguish between
106 * the old pre-4.x "mmap()", which:
107 *
108 * only let you map devices with an "mmap" routine (e.g.,
109 * frame buffers) in;
110 *
111 * required you to specify the mapping address;
112 *
113 * returned 0 on success and -1 on failure;
114 *
115 * memory and which, and the 4.x "mmap()" which:
116 *
117 * can map plain files;
118 *
119 * can be asked to pick where to map the file;
120 *
121 * returns the address where it mapped the file on success
122 * and -1 on failure.
123 *
124 * It's not actually used in source code that calls "mmap()"; the
125 * "mmap()" routine adds it for you.
126 *
127 * It'd be nice to come up with some way of eliminating it from
128 * the flags, e.g. reporting calls *without* it as "old_mmap()"
129 * and calls with it as "mmap()".
130 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000131#ifdef _MAP_NEW
132 { _MAP_NEW, "_MAP_NEW" },
133#endif
134#ifdef MAP_GROWSDOWN
135 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
136#endif
137#ifdef MAP_DENYWRITE
138 { MAP_DENYWRITE,"MAP_DENYWRITE" },
139#endif
140#ifdef MAP_EXECUTABLE
141 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
142#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000143#ifdef MAP_INHERIT
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100144 { MAP_INHERIT, "MAP_INHERIT" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000145#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000146#ifdef MAP_FILE
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100147 { MAP_FILE, "MAP_FILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148#endif
149#ifdef MAP_LOCKED
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100150 { MAP_LOCKED, "MAP_LOCKED" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000152 /* FreeBSD ones */
Denys Vlasenko2897fb32012-03-17 01:29:40 +0100153#if defined(MAP_ANON) && (!defined(MAP_ANONYMOUS) || MAP_ANON != MAP_ANONYMOUS)
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100154 { MAP_ANON, "MAP_ANON" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000155#endif
156#ifdef MAP_HASSEMAPHORE
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100157 { MAP_HASSEMAPHORE,"MAP_HASSEMAPHORE"},
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000158#endif
159#ifdef MAP_STACK
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100160 { MAP_STACK, "MAP_STACK" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000161#endif
162#ifdef MAP_NOSYNC
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100163 { MAP_NOSYNC, "MAP_NOSYNC" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000164#endif
165#ifdef MAP_NOCORE
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100166 { MAP_NOCORE, "MAP_NOCORE" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000167#endif
Chris Metcalfc8c66982009-12-28 10:00:15 -0500168#ifdef TILE
169 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
170 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
171 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
172#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000173 { 0, NULL },
174};
175
Chris Metcalfc8c66982009-12-28 10:00:15 -0500176#ifdef TILE
Denys Vlasenko72a58482011-08-19 16:01:51 +0200177static int
178addtileflags(long flags)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500179{
180 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
181 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
182
183 if (flags & _MAP_CACHE_INCOHERENT) {
184 flags &= ~_MAP_CACHE_INCOHERENT;
185 if (home == MAP_CACHE_HOME_NONE) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200186 tprints("|MAP_CACHE_INCOHERENT");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500187 return flags;
188 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200189 tprints("|_MAP_CACHE_INCOHERENT");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500190 }
191
192 switch (home) {
193 case 0: break;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200194 case MAP_CACHE_HOME_HERE: tprints("|MAP_CACHE_HOME_HERE"); break;
195 case MAP_CACHE_HOME_NONE: tprints("|MAP_CACHE_HOME_NONE"); break;
196 case MAP_CACHE_HOME_SINGLE: tprints("|MAP_CACHE_HOME_SINGLE"); break;
197 case MAP_CACHE_HOME_TASK: tprints("|MAP_CACHE_HOME_TASK"); break;
198 case MAP_CACHE_HOME_HASH: tprints("|MAP_CACHE_HOME_HASH"); break;
Chris Metcalfc8c66982009-12-28 10:00:15 -0500199 default:
200 tprintf("|MAP_CACHE_HOME(%d)",
201 (home >> _MAP_CACHE_HOME_SHIFT) );
202 break;
203 }
204
205 return flags;
206}
207#endif
208
John Hughes70623be2001-03-08 13:59:00 +0000209#if !HAVE_LONG_LONG_OFF_T
Dmitry V. Levin31382132011-03-04 05:08:02 +0300210static int
211print_mmap(struct tcb *tcp, long *u_arg, long long offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000212{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000213 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000214 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000215 if (!u_arg[0])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200216 tprints("NULL, ");
Wichert Akkerman8829a551999-06-11 13:18:40 +0000217 else
218 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000219 /* len */
220 tprintf("%lu, ", u_arg[1]);
221 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000222 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200223 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000225#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500227#ifdef TILE
228 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
229#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Chris Metcalfc8c66982009-12-28 10:00:15 -0500231#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000232#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000233 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000234#endif
Dmitry V. Levin31382132011-03-04 05:08:02 +0300235 /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200236 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300237 printfd(tcp, u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000238 /* offset */
Dmitry V. Levin31382132011-03-04 05:08:02 +0300239 tprintf(", %#llx", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000240 }
241 return RVAL_HEX;
242}
243
Denys Vlasenko12014262011-05-30 14:00:14 +0200244int sys_old_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000245{
Denys Vlasenko72a58482011-08-19 16:01:51 +0200246#if defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000247 /*
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200248 * IA64 processes never call this routine, they only use the
249 * new `sys_mmap' interface.
250 * For IA32 processes, this code converts the integer arguments
251 * that they pushed onto the stack, into longs.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000252 *
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200253 * Note that addresses with bit 31 set will be sign extended.
254 * Fortunately, those addresses are not currently being generated
255 * for IA32 processes so it's not a problem.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000256 */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200257 int i;
258 long u_arg[6];
259 int narrow_arg[6];
260 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
261 return 0;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000262 for (i = 0; i < 6; i++)
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200263 u_arg[i] = narrow_arg[i];
Roland McGrathf5a47772003-06-26 22:40:42 +0000264#elif defined(SH) || defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000265 /* SH has always passed the args in registers */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200266 long *u_arg = tcp->u_arg;
Roland McGrath6b1d43e2003-03-31 01:05:01 +0000267#else
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200268 long u_arg[6];
Roland McGrath520e21f2005-07-05 09:50:18 +0000269# if defined(X86_64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000270 if (current_personality == 1) {
271 int i;
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200272 unsigned narrow_arg[6];
273 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
274 return 0;
275 for (i = 0; i < 6; ++i)
276 u_arg[i] = narrow_arg[i];
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000277 }
278 else
Roland McGrath520e21f2005-07-05 09:50:18 +0000279# endif
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200280 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000281 return 0;
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200282#endif /* other architectures */
283
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000284 return print_mmap(tcp, u_arg, u_arg[5]);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000285}
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000286
287int
Denys Vlasenko12014262011-05-30 14:00:14 +0200288sys_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000289{
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000290 long long offset = tcp->u_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000291
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200292 /* FIXME: why only SH64? i386 mmap2 syscall ends up
293 * in this function, but does not convert offset
294 * from pages to bytes. See test/mmap_offset_decode.c
295 * Why SH64 and i386 are handled differently?
296 */
Denys Vlasenko84703742012-02-25 02:38:52 +0100297#if defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000298 /*
299 * Old mmap differs from new mmap in specifying the
300 * offset in units of bytes rather than pages. We
301 * pretend it's in byte units so the user only ever
302 * sees bytes in the printout.
303 */
304 offset <<= PAGE_SHIFT;
Roland McGrathe1e584b2003-06-02 19:18:58 +0000305#endif
Roland McGrath542c2c62008-05-20 01:11:56 +0000306#if defined(LINUX_MIPSN32)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000307 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000308#endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000309 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000310}
John Hughes70623be2001-03-08 13:59:00 +0000311#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000312
John Hughes70623be2001-03-08 13:59:00 +0000313#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
H.J. Lu085e4282012-04-17 11:05:04 -0700314# if defined(X32)
315int sys_old_mmap(struct tcb *tcp)
316{
317 long u_arg[6];
318 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
319 return 0;
320 if (entering(tcp)) {
321 /* addr */
322 if (!u_arg[0])
323 tprints("NULL, ");
324 else
325 tprintf("%#lx, ", u_arg[0]);
326 /* len */
327 tprintf("%lu, ", u_arg[1]);
328 /* prot */
329 printflags(mmap_prot, u_arg[2], "PROT_???");
330 tprints(", ");
331 /* flags */
332# ifdef MAP_TYPE
333 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
334 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
335# else
336 printflags(mmap_flags, u_arg[3], "MAP_???");
337# endif
338 /* fd */
339 tprints(", ");
340 printfd(tcp, u_arg[4]);
341 /* offset */
342 tprintf(", %#lx", u_arg[5]);
343 }
344 return RVAL_HEX;
345}
346# endif
347
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200348/* TODO: comment which arches use this routine.
349 * For one, does ALPHA on Linux use this??
350 * From code it seems that it might use 7 or 8 registers,
351 * which is strange - Linux syscalls can pass maximum of 6 parameters!
352 */
John Hughesbdf48f52001-03-06 15:08:09 +0000353int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300354sys_mmap64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000355{
John Hughesbdf48f52001-03-06 15:08:09 +0000356 if (entering(tcp)) {
H.J. Lu35be5812012-04-16 13:00:01 +0200357#if defined(ALPHA) || defined(X32)
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200358 long *u_arg = tcp->u_arg;
359#else
360 long u_arg[7];
John Hughesbdf48f52001-03-06 15:08:09 +0000361 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
362 (char *) u_arg) == -1)
363 return 0;
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200364#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000365 /* addr */
H.J. Lud0cd4432012-02-03 10:07:42 -0800366 if (!u_arg[0])
367 tprints("NULL, ");
368 else
369 tprintf("%#lx, ", u_arg[0]);
John Hughesbdf48f52001-03-06 15:08:09 +0000370 /* len */
371 tprintf("%lu, ", u_arg[1]);
372 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000373 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200374 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000375 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000376#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000377 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
378 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000379#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000380 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000381#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000382 /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200383 tprints(", ");
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200384 printfd(tcp, u_arg[4]);
John Hughesbdf48f52001-03-06 15:08:09 +0000385 /* offset */
H.J. Lu35be5812012-04-16 13:00:01 +0200386#if defined(ALPHA) || defined(X32)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300387 printllval(tcp, ", %#llx", 5);
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200388#else
389 /* NOTE: not verified that [5] and [6] should be used.
390 * It's possible that long long is 64-bit aligned in memory
391 * and we need to use [6] and [7] here instead:
392 */
393 tprintf(", %#llx", LONG_LONG(u_arg[5], u_arg[6]));
394#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000395 }
396 return RVAL_HEX;
397}
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200398#endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */
John Hughesbdf48f52001-03-06 15:08:09 +0000399
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400int
Denys Vlasenko12014262011-05-30 14:00:14 +0200401sys_munmap(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402{
403 if (entering(tcp)) {
404 tprintf("%#lx, %lu",
405 tcp->u_arg[0], tcp->u_arg[1]);
406 }
407 return 0;
408}
409
410int
Denys Vlasenko12014262011-05-30 14:00:14 +0200411sys_mprotect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000412{
413 if (entering(tcp)) {
414 tprintf("%#lx, %lu, ",
415 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000416 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417 }
418 return 0;
419}
420
Roland McGrathd9f816f2004-09-04 03:39:20 +0000421static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000422 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
Chris Metcalfff3474a2009-12-24 23:19:19 +0000423#ifdef MREMAP_FIXED
424 { MREMAP_FIXED, "MREMAP_FIXED" },
425#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000426 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000427};
428
429int
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000430sys_mremap(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000431{
432 if (entering(tcp)) {
433 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
434 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000435 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000436#ifdef MREMAP_FIXED
437 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
438 (MREMAP_MAYMOVE | MREMAP_FIXED))
439 tprintf(", %#lx", tcp->u_arg[4]);
440#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000441 }
442 return RVAL_HEX;
443}
444
Roland McGrathf4021b12008-08-25 02:59:36 +0000445static const struct xlat madvise_cmds[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000446#ifdef MADV_NORMAL
447 { MADV_NORMAL, "MADV_NORMAL" },
448#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000449#ifdef MADV_RANDOM
Wichert Akkermanc7926982000-04-10 22:22:31 +0000450 { MADV_RANDOM, "MADV_RANDOM" },
451#endif
452#ifdef MADV_SEQUENTIAL
453 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
454#endif
455#ifdef MADV_WILLNEED
456 { MADV_WILLNEED, "MADV_WILLNEED" },
457#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000458#ifdef MADV_DONTNEED
Wichert Akkermanc7926982000-04-10 22:22:31 +0000459 { MADV_DONTNEED, "MADV_DONTNEED" },
460#endif
461 { 0, NULL },
462};
463
Wichert Akkermanc7926982000-04-10 22:22:31 +0000464int
Denys Vlasenko12014262011-05-30 14:00:14 +0200465sys_madvise(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000466{
467 if (entering(tcp)) {
468 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000469 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000470 }
471 return 0;
472}
473
Roland McGrathd9f816f2004-09-04 03:39:20 +0000474static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000475#ifdef MCL_CURRENT
476 { MCL_CURRENT, "MCL_CURRENT" },
477#endif
478#ifdef MCL_FUTURE
479 { MCL_FUTURE, "MCL_FUTURE" },
480#endif
481 { 0, NULL}
482};
483
484int
Denys Vlasenko12014262011-05-30 14:00:14 +0200485sys_mlockall(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000486{
487 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000488 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000489 }
490 return 0;
491}
492
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000493#ifdef MS_ASYNC
494
Roland McGrathd9f816f2004-09-04 03:39:20 +0000495static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496#ifdef MS_SYNC
497 { MS_SYNC, "MS_SYNC" },
498#endif
John Hughesaca07f32001-10-16 18:12:27 +0000499 { MS_ASYNC, "MS_ASYNC" },
500 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501 { 0, NULL },
502};
503
504int
Denys Vlasenko12014262011-05-30 14:00:14 +0200505sys_msync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000506{
507 if (entering(tcp)) {
508 /* addr */
509 tprintf("%#lx", tcp->u_arg[0]);
510 /* len */
511 tprintf(", %lu, ", tcp->u_arg[1]);
512 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000513 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000514 }
515 return 0;
516}
517
518#endif /* MS_ASYNC */
519
520#ifdef MC_SYNC
521
Roland McGrathd9f816f2004-09-04 03:39:20 +0000522static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000523 { MC_LOCK, "MC_LOCK" },
524 { MC_LOCKAS, "MC_LOCKAS" },
525 { MC_SYNC, "MC_SYNC" },
526 { MC_UNLOCK, "MC_UNLOCK" },
527 { MC_UNLOCKAS, "MC_UNLOCKAS" },
528 { 0, NULL },
529};
530
Roland McGrathd9f816f2004-09-04 03:39:20 +0000531static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532 { MCL_CURRENT, "MCL_CURRENT" },
533 { MCL_FUTURE, "MCL_FUTURE" },
534 { 0, NULL },
535};
536
537int
Denys Vlasenko12014262011-05-30 14:00:14 +0200538sys_mctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539{
540 int arg, function;
541
542 if (entering(tcp)) {
543 /* addr */
544 tprintf("%#lx", tcp->u_arg[0]);
545 /* len */
546 tprintf(", %lu, ", tcp->u_arg[1]);
547 /* function */
548 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000549 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550 /* arg */
551 arg = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200552 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000553 switch (function) {
554 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000555 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000556 break;
557 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000558 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559 break;
560 default:
561 tprintf("%#x", arg);
562 break;
563 }
564 }
565 return 0;
566}
567
568#endif /* MC_SYNC */
569
570int
Denys Vlasenko12014262011-05-30 14:00:14 +0200571sys_mincore(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573 if (entering(tcp)) {
574 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
575 } else {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200576 unsigned long i, len;
577 char *vec = NULL;
578
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000579 len = tcp->u_arg[1];
580 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000581 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000582 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
583 tprintf("%#lx", tcp->u_arg[2]);
584 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200585 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586 for (i = 0; i < len; i++) {
587 if (abbrev(tcp) && i >= max_strlen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200588 tprints("...");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589 break;
590 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200591 tprints((vec[i] & 1) ? "1" : "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200593 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000594 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200595 free(vec);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000596 }
597 return 0;
598}
599
Denys Vlasenko84703742012-02-25 02:38:52 +0100600#if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000601int
Denys Vlasenko12014262011-05-30 14:00:14 +0200602sys_getpagesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000603{
604 if (exiting(tcp))
605 return RVAL_HEX;
606 return 0;
607}
Denys Vlasenko84703742012-02-25 02:38:52 +0100608#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000609
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100610#if defined(I386)
Roland McGrath909875b2002-12-22 03:34:36 +0000611void
Denys Vlasenko1f458252009-01-23 16:10:22 +0000612print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
Roland McGrath34e4a692002-12-15 23:58:17 +0000613{
614 tprintf("base_addr:%#08lx, "
615 "limit:%d, "
616 "seg_32bit:%d, "
617 "contents:%d, "
618 "read_exec_only:%d, "
619 "limit_in_pages:%d, "
620 "seg_not_present:%d, "
621 "useable:%d}",
Denys Vlasenko1f458252009-01-23 16:10:22 +0000622 (long) ldt_entry->base_addr,
Roland McGrath34e4a692002-12-15 23:58:17 +0000623 ldt_entry->limit,
624 ldt_entry->seg_32bit,
625 ldt_entry->contents,
626 ldt_entry->read_exec_only,
627 ldt_entry->limit_in_pages,
628 ldt_entry->seg_not_present,
629 ldt_entry->useable);
630}
631
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000632int
Denys Vlasenko12014262011-05-30 14:00:14 +0200633sys_modify_ldt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000634{
635 if (entering(tcp)) {
636 struct modify_ldt_ldt_s copy;
637 tprintf("%ld", tcp->u_arg[0]);
638 if (tcp->u_arg[1] == 0
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200639 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640 || umove(tcp, tcp->u_arg[1], &copy) == -1)
641 tprintf(", %lx", tcp->u_arg[1]);
642 else {
643 tprintf(", {entry_number:%d, ", copy.entry_number);
644 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200645 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000646 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000647 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000648 }
649 }
650 tprintf(", %lu", tcp->u_arg[2]);
651 }
652 return 0;
653}
Roland McGrath34e4a692002-12-15 23:58:17 +0000654
655int
Denys Vlasenko12014262011-05-30 14:00:14 +0200656sys_set_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000657{
658 struct modify_ldt_ldt_s copy;
659 if (entering(tcp)) {
660 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
661 if (copy.entry_number == -1)
662 tprintf("{entry_number:%d -> ",
663 copy.entry_number);
664 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200665 tprints("{entry_number:");
Roland McGrath34e4a692002-12-15 23:58:17 +0000666 }
667 } else {
668 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
669 tprintf("%d, ", copy.entry_number);
670 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200671 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000672 else {
673 print_ldt_entry(&copy);
674 }
675 } else {
676 tprintf("%lx", tcp->u_arg[0]);
677 }
678 }
679 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000680
Roland McGrath34e4a692002-12-15 23:58:17 +0000681}
682
683int
Denys Vlasenko12014262011-05-30 14:00:14 +0200684sys_get_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000685{
686 struct modify_ldt_ldt_s copy;
687 if (exiting(tcp)) {
688 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
689 tprintf("{entry_number:%d, ", copy.entry_number);
690 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200691 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000692 else {
693 print_ldt_entry(&copy);
694 }
695 } else {
696 tprintf("%lx", tcp->u_arg[0]);
697 }
698 }
699 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000700
Roland McGrath34e4a692002-12-15 23:58:17 +0000701}
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100702#endif /* I386 */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000703
Denys Vlasenko84703742012-02-25 02:38:52 +0100704#if defined(M68K)
Andreas Schwab58743222010-05-28 22:28:51 +0200705int
Denys Vlasenko12014262011-05-30 14:00:14 +0200706sys_set_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200707{
708 if (entering(tcp))
709 tprintf("%#lx", tcp->u_arg[0]);
710 return 0;
711
712}
713
714int
Denys Vlasenko12014262011-05-30 14:00:14 +0200715sys_get_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200716{
717 return RVAL_HEX;
718}
719#endif
720
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000721int
Denys Vlasenko12014262011-05-30 14:00:14 +0200722sys_remap_file_pages(struct tcb *tcp)
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000723{
724 if (entering(tcp)) {
725 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000726 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000727 tprintf(", %lu, ", tcp->u_arg[3]);
728#ifdef MAP_TYPE
729 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
730 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
731#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000732 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000733#endif
734 }
735 return 0;
736}
Roland McGrathb10a3352004-10-07 18:53:12 +0000737
Roland McGrathb10a3352004-10-07 18:53:12 +0000738#define MPOL_DEFAULT 0
739#define MPOL_PREFERRED 1
740#define MPOL_BIND 2
741#define MPOL_INTERLEAVE 3
742
743#define MPOL_F_NODE (1<<0)
744#define MPOL_F_ADDR (1<<1)
745
746#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000747#define MPOL_MF_MOVE (1<<1)
748#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000749
Roland McGrathb10a3352004-10-07 18:53:12 +0000750static const struct xlat policies[] = {
751 { MPOL_DEFAULT, "MPOL_DEFAULT" },
752 { MPOL_PREFERRED, "MPOL_PREFERRED" },
753 { MPOL_BIND, "MPOL_BIND" },
754 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
755 { 0, NULL }
756};
757
758static const struct xlat mbindflags[] = {
759 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000760 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
761 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
Roland McGrathb10a3352004-10-07 18:53:12 +0000762 { 0, NULL }
763};
764
765static const struct xlat mempolicyflags[] = {
766 { MPOL_F_NODE, "MPOL_F_NODE" },
767 { MPOL_F_ADDR, "MPOL_F_ADDR" },
768 { 0, NULL }
769};
770
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000771static const struct xlat move_pages_flags[] = {
772 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
773 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
774 { 0, NULL }
775};
776
Roland McGrathb10a3352004-10-07 18:53:12 +0000777static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200778get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
Roland McGrathb10a3352004-10-07 18:53:12 +0000779{
Roland McGrathaa524c82005-06-01 19:22:06 +0000780 unsigned long nlongs, size, end;
781
782 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
783 size = nlongs * sizeof(long);
784 end = ptr + size;
785 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
786 && (end > ptr))) {
787 unsigned long n, cur, abbrev_end;
788 int failed = 0;
789
790 if (abbrev(tcp)) {
791 abbrev_end = ptr + max_strlen * sizeof(long);
792 if (abbrev_end < ptr)
793 abbrev_end = end;
794 } else {
795 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000796 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200797 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000798 for (cur = ptr; cur < end; cur += sizeof(long)) {
799 if (cur > ptr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200800 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000801 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200802 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000803 break;
804 }
805 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200806 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000807 failed = 1;
808 break;
809 }
810 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
811 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200812 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000813 if (failed)
814 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000815 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000816 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000817 tprintf(", %lu", maxnodes);
818}
819
820int
Denys Vlasenko12014262011-05-30 14:00:14 +0200821sys_mbind(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000822{
823 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000824 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000825 printxval(policies, tcp->u_arg[2], "MPOL_???");
826 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200827 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000828 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000829 }
830 return 0;
831}
832
833int
Denys Vlasenko12014262011-05-30 14:00:14 +0200834sys_set_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000835{
836 if (entering(tcp)) {
837 printxval(policies, tcp->u_arg[0], "MPOL_???");
838 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
839 }
840 return 0;
841}
842
843int
Denys Vlasenko12014262011-05-30 14:00:14 +0200844sys_get_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000845{
846 if (exiting(tcp)) {
847 int pol;
848 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200849 tprints("NULL");
Roland McGrathb10a3352004-10-07 18:53:12 +0000850 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
851 tprintf("%#lx", tcp->u_arg[0]);
852 else
853 printxval(policies, pol, "MPOL_???");
854 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
855 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000856 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000857 }
858 return 0;
859}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000860
861int
Dmitry V. Levin64d0e712012-03-11 22:44:14 +0000862sys_migrate_pages(struct tcb *tcp)
863{
864 if (entering(tcp)) {
865 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
866 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
867 tprints(", ");
868 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
869 }
870 return 0;
871}
872
873int
Denys Vlasenko12014262011-05-30 14:00:14 +0200874sys_move_pages(struct tcb *tcp)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000875{
876 if (entering(tcp)) {
877 unsigned long npages = tcp->u_arg[1];
878 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
879 if (tcp->u_arg[2] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200880 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000881 else {
882 int i;
883 long puser = tcp->u_arg[2];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200884 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000885 for (i = 0; i < npages; ++i) {
886 void *p;
887 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200888 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000889 if (umove(tcp, puser, &p) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200890 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000891 break;
892 }
893 tprintf("%p", p);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200894 puser += sizeof(void *);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000895 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200896 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000897 }
898 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200899 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000900 else {
901 int i;
902 long nodeuser = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200903 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000904 for (i = 0; i < npages; ++i) {
905 int node;
906 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200907 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000908 if (umove(tcp, nodeuser, &node) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200909 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000910 break;
911 }
912 tprintf("%#x", node);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200913 nodeuser += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000914 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200915 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000916 }
917 }
918 if (exiting(tcp)) {
919 unsigned long npages = tcp->u_arg[1];
920 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200921 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000922 else {
923 int i;
924 long statususer = tcp->u_arg[4];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200925 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000926 for (i = 0; i < npages; ++i) {
927 int status;
928 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200929 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000930 if (umove(tcp, statususer, &status) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200931 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000932 break;
933 }
934 tprintf("%#x", status);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200935 statususer += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000936 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200937 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000938 }
939 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
940 }
941 return 0;
942}
Roland McGrath4a6f6522008-08-25 03:09:16 +0000943
Denys Vlasenko84703742012-02-25 02:38:52 +0100944#if defined(POWERPC)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000945int
Denys Vlasenko12014262011-05-30 14:00:14 +0200946sys_subpage_prot(struct tcb *tcp)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000947{
948 if (entering(tcp)) {
949 unsigned long cur, end, abbrev_end, entries;
950 unsigned int entry;
951
952 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
953 entries = tcp->u_arg[1] >> 16;
954 if (!entries || !tcp->u_arg[2]) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200955 tprints("{}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000956 return 0;
957 }
958 cur = tcp->u_arg[2];
959 end = cur + (sizeof(int) * entries);
960 if (!verbose(tcp) || end < tcp->u_arg[2]) {
961 tprintf("%#lx", tcp->u_arg[2]);
962 return 0;
963 }
964 if (abbrev(tcp)) {
965 abbrev_end = cur + (sizeof(int) * max_strlen);
966 if (abbrev_end > end)
967 abbrev_end = end;
968 }
969 else
970 abbrev_end = end;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200971 tprints("{");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000972 for (; cur < end; cur += sizeof(int)) {
973 if (cur > tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200974 tprints(", ");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000975 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200976 tprints("...");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000977 break;
978 }
979 if (umove(tcp, cur, &entry) < 0) {
980 tprintf("??? [%#lx]", cur);
981 break;
982 }
983 else
984 tprintf("%#08x", entry);
985 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200986 tprints("}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000987 }
988
989 return 0;
990}
991#endif