blob: 72b30decc2380ffa8dcc54de71af8753e8fbc8be [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
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200314/* TODO: comment which arches use this routine.
315 * For one, does ALPHA on Linux use this??
316 * From code it seems that it might use 7 or 8 registers,
317 * which is strange - Linux syscalls can pass maximum of 6 parameters!
318 */
John Hughesbdf48f52001-03-06 15:08:09 +0000319int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300320sys_mmap64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000321{
John Hughesbdf48f52001-03-06 15:08:09 +0000322 if (entering(tcp)) {
Denys Vlasenko84703742012-02-25 02:38:52 +0100323#if defined(ALPHA)
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200324 long *u_arg = tcp->u_arg;
325#else
326 long u_arg[7];
John Hughesbdf48f52001-03-06 15:08:09 +0000327 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
328 (char *) u_arg) == -1)
329 return 0;
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200330#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000331 /* addr */
H.J. Lud0cd4432012-02-03 10:07:42 -0800332 if (!u_arg[0])
333 tprints("NULL, ");
334 else
335 tprintf("%#lx, ", u_arg[0]);
John Hughesbdf48f52001-03-06 15:08:09 +0000336 /* len */
337 tprintf("%lu, ", u_arg[1]);
338 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000339 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200340 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000341 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000342#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000343 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
344 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000345#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000346 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000347#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000348 /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200349 tprints(", ");
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200350 printfd(tcp, u_arg[4]);
John Hughesbdf48f52001-03-06 15:08:09 +0000351 /* offset */
Denys Vlasenko84703742012-02-25 02:38:52 +0100352#if defined(ALPHA)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300353 printllval(tcp, ", %#llx", 5);
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200354#else
355 /* NOTE: not verified that [5] and [6] should be used.
356 * It's possible that long long is 64-bit aligned in memory
357 * and we need to use [6] and [7] here instead:
358 */
359 tprintf(", %#llx", LONG_LONG(u_arg[5], u_arg[6]));
360#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000361 }
362 return RVAL_HEX;
363}
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200364#endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */
John Hughesbdf48f52001-03-06 15:08:09 +0000365
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366int
Denys Vlasenko12014262011-05-30 14:00:14 +0200367sys_munmap(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000368{
369 if (entering(tcp)) {
370 tprintf("%#lx, %lu",
371 tcp->u_arg[0], tcp->u_arg[1]);
372 }
373 return 0;
374}
375
376int
Denys Vlasenko12014262011-05-30 14:00:14 +0200377sys_mprotect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378{
379 if (entering(tcp)) {
380 tprintf("%#lx, %lu, ",
381 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000382 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383 }
384 return 0;
385}
386
Roland McGrathd9f816f2004-09-04 03:39:20 +0000387static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000388 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
Chris Metcalfff3474a2009-12-24 23:19:19 +0000389#ifdef MREMAP_FIXED
390 { MREMAP_FIXED, "MREMAP_FIXED" },
391#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000392 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000393};
394
395int
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000396sys_mremap(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000397{
398 if (entering(tcp)) {
399 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
400 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000401 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000402#ifdef MREMAP_FIXED
403 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
404 (MREMAP_MAYMOVE | MREMAP_FIXED))
405 tprintf(", %#lx", tcp->u_arg[4]);
406#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000407 }
408 return RVAL_HEX;
409}
410
Roland McGrathf4021b12008-08-25 02:59:36 +0000411static const struct xlat madvise_cmds[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000412#ifdef MADV_NORMAL
413 { MADV_NORMAL, "MADV_NORMAL" },
414#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000415#ifdef MADV_RANDOM
Wichert Akkermanc7926982000-04-10 22:22:31 +0000416 { MADV_RANDOM, "MADV_RANDOM" },
417#endif
418#ifdef MADV_SEQUENTIAL
419 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
420#endif
421#ifdef MADV_WILLNEED
422 { MADV_WILLNEED, "MADV_WILLNEED" },
423#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000424#ifdef MADV_DONTNEED
Wichert Akkermanc7926982000-04-10 22:22:31 +0000425 { MADV_DONTNEED, "MADV_DONTNEED" },
426#endif
427 { 0, NULL },
428};
429
Wichert Akkermanc7926982000-04-10 22:22:31 +0000430int
Denys Vlasenko12014262011-05-30 14:00:14 +0200431sys_madvise(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000432{
433 if (entering(tcp)) {
434 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000435 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000436 }
437 return 0;
438}
439
Roland McGrathd9f816f2004-09-04 03:39:20 +0000440static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000441#ifdef MCL_CURRENT
442 { MCL_CURRENT, "MCL_CURRENT" },
443#endif
444#ifdef MCL_FUTURE
445 { MCL_FUTURE, "MCL_FUTURE" },
446#endif
447 { 0, NULL}
448};
449
450int
Denys Vlasenko12014262011-05-30 14:00:14 +0200451sys_mlockall(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000452{
453 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000454 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000455 }
456 return 0;
457}
458
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000459#ifdef MS_ASYNC
460
Roland McGrathd9f816f2004-09-04 03:39:20 +0000461static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462#ifdef MS_SYNC
463 { MS_SYNC, "MS_SYNC" },
464#endif
John Hughesaca07f32001-10-16 18:12:27 +0000465 { MS_ASYNC, "MS_ASYNC" },
466 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000467 { 0, NULL },
468};
469
470int
Denys Vlasenko12014262011-05-30 14:00:14 +0200471sys_msync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000472{
473 if (entering(tcp)) {
474 /* addr */
475 tprintf("%#lx", tcp->u_arg[0]);
476 /* len */
477 tprintf(", %lu, ", tcp->u_arg[1]);
478 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000479 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000480 }
481 return 0;
482}
483
484#endif /* MS_ASYNC */
485
486#ifdef MC_SYNC
487
Roland McGrathd9f816f2004-09-04 03:39:20 +0000488static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489 { MC_LOCK, "MC_LOCK" },
490 { MC_LOCKAS, "MC_LOCKAS" },
491 { MC_SYNC, "MC_SYNC" },
492 { MC_UNLOCK, "MC_UNLOCK" },
493 { MC_UNLOCKAS, "MC_UNLOCKAS" },
494 { 0, NULL },
495};
496
Roland McGrathd9f816f2004-09-04 03:39:20 +0000497static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498 { MCL_CURRENT, "MCL_CURRENT" },
499 { MCL_FUTURE, "MCL_FUTURE" },
500 { 0, NULL },
501};
502
503int
Denys Vlasenko12014262011-05-30 14:00:14 +0200504sys_mctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000505{
506 int arg, function;
507
508 if (entering(tcp)) {
509 /* addr */
510 tprintf("%#lx", tcp->u_arg[0]);
511 /* len */
512 tprintf(", %lu, ", tcp->u_arg[1]);
513 /* function */
514 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000515 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000516 /* arg */
517 arg = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200518 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000519 switch (function) {
520 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000521 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522 break;
523 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000524 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525 break;
526 default:
527 tprintf("%#x", arg);
528 break;
529 }
530 }
531 return 0;
532}
533
534#endif /* MC_SYNC */
535
536int
Denys Vlasenko12014262011-05-30 14:00:14 +0200537sys_mincore(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539 if (entering(tcp)) {
540 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
541 } else {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200542 unsigned long i, len;
543 char *vec = NULL;
544
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545 len = tcp->u_arg[1];
546 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000547 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
549 tprintf("%#lx", tcp->u_arg[2]);
550 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200551 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552 for (i = 0; i < len; i++) {
553 if (abbrev(tcp) && i >= max_strlen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200554 tprints("...");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555 break;
556 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200557 tprints((vec[i] & 1) ? "1" : "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200559 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200561 free(vec);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562 }
563 return 0;
564}
565
Denys Vlasenko84703742012-02-25 02:38:52 +0100566#if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567int
Denys Vlasenko12014262011-05-30 14:00:14 +0200568sys_getpagesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000569{
570 if (exiting(tcp))
571 return RVAL_HEX;
572 return 0;
573}
Denys Vlasenko84703742012-02-25 02:38:52 +0100574#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100576#if defined(I386)
Roland McGrath909875b2002-12-22 03:34:36 +0000577void
Denys Vlasenko1f458252009-01-23 16:10:22 +0000578print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
Roland McGrath34e4a692002-12-15 23:58:17 +0000579{
580 tprintf("base_addr:%#08lx, "
581 "limit:%d, "
582 "seg_32bit:%d, "
583 "contents:%d, "
584 "read_exec_only:%d, "
585 "limit_in_pages:%d, "
586 "seg_not_present:%d, "
587 "useable:%d}",
Denys Vlasenko1f458252009-01-23 16:10:22 +0000588 (long) ldt_entry->base_addr,
Roland McGrath34e4a692002-12-15 23:58:17 +0000589 ldt_entry->limit,
590 ldt_entry->seg_32bit,
591 ldt_entry->contents,
592 ldt_entry->read_exec_only,
593 ldt_entry->limit_in_pages,
594 ldt_entry->seg_not_present,
595 ldt_entry->useable);
596}
597
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598int
Denys Vlasenko12014262011-05-30 14:00:14 +0200599sys_modify_ldt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600{
601 if (entering(tcp)) {
602 struct modify_ldt_ldt_s copy;
603 tprintf("%ld", tcp->u_arg[0]);
604 if (tcp->u_arg[1] == 0
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200605 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000606 || umove(tcp, tcp->u_arg[1], &copy) == -1)
607 tprintf(", %lx", tcp->u_arg[1]);
608 else {
609 tprintf(", {entry_number:%d, ", copy.entry_number);
610 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200611 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000612 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000613 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614 }
615 }
616 tprintf(", %lu", tcp->u_arg[2]);
617 }
618 return 0;
619}
Roland McGrath34e4a692002-12-15 23:58:17 +0000620
621int
Denys Vlasenko12014262011-05-30 14:00:14 +0200622sys_set_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000623{
624 struct modify_ldt_ldt_s copy;
625 if (entering(tcp)) {
626 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
627 if (copy.entry_number == -1)
628 tprintf("{entry_number:%d -> ",
629 copy.entry_number);
630 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200631 tprints("{entry_number:");
Roland McGrath34e4a692002-12-15 23:58:17 +0000632 }
633 } else {
634 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
635 tprintf("%d, ", copy.entry_number);
636 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200637 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000638 else {
639 print_ldt_entry(&copy);
640 }
641 } else {
642 tprintf("%lx", tcp->u_arg[0]);
643 }
644 }
645 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000646
Roland McGrath34e4a692002-12-15 23:58:17 +0000647}
648
649int
Denys Vlasenko12014262011-05-30 14:00:14 +0200650sys_get_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000651{
652 struct modify_ldt_ldt_s copy;
653 if (exiting(tcp)) {
654 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
655 tprintf("{entry_number:%d, ", copy.entry_number);
656 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200657 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000658 else {
659 print_ldt_entry(&copy);
660 }
661 } else {
662 tprintf("%lx", tcp->u_arg[0]);
663 }
664 }
665 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000666
Roland McGrath34e4a692002-12-15 23:58:17 +0000667}
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100668#endif /* I386 */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000669
Denys Vlasenko84703742012-02-25 02:38:52 +0100670#if defined(M68K)
Andreas Schwab58743222010-05-28 22:28:51 +0200671int
Denys Vlasenko12014262011-05-30 14:00:14 +0200672sys_set_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200673{
674 if (entering(tcp))
675 tprintf("%#lx", tcp->u_arg[0]);
676 return 0;
677
678}
679
680int
Denys Vlasenko12014262011-05-30 14:00:14 +0200681sys_get_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200682{
683 return RVAL_HEX;
684}
685#endif
686
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000687int
Denys Vlasenko12014262011-05-30 14:00:14 +0200688sys_remap_file_pages(struct tcb *tcp)
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000689{
690 if (entering(tcp)) {
691 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000692 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000693 tprintf(", %lu, ", tcp->u_arg[3]);
694#ifdef MAP_TYPE
695 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
696 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
697#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000698 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000699#endif
700 }
701 return 0;
702}
Roland McGrathb10a3352004-10-07 18:53:12 +0000703
Roland McGrathb10a3352004-10-07 18:53:12 +0000704#define MPOL_DEFAULT 0
705#define MPOL_PREFERRED 1
706#define MPOL_BIND 2
707#define MPOL_INTERLEAVE 3
708
709#define MPOL_F_NODE (1<<0)
710#define MPOL_F_ADDR (1<<1)
711
712#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000713#define MPOL_MF_MOVE (1<<1)
714#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000715
Roland McGrathb10a3352004-10-07 18:53:12 +0000716static const struct xlat policies[] = {
717 { MPOL_DEFAULT, "MPOL_DEFAULT" },
718 { MPOL_PREFERRED, "MPOL_PREFERRED" },
719 { MPOL_BIND, "MPOL_BIND" },
720 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
721 { 0, NULL }
722};
723
724static const struct xlat mbindflags[] = {
725 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000726 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
727 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
Roland McGrathb10a3352004-10-07 18:53:12 +0000728 { 0, NULL }
729};
730
731static const struct xlat mempolicyflags[] = {
732 { MPOL_F_NODE, "MPOL_F_NODE" },
733 { MPOL_F_ADDR, "MPOL_F_ADDR" },
734 { 0, NULL }
735};
736
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000737static const struct xlat move_pages_flags[] = {
738 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
739 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
740 { 0, NULL }
741};
742
Roland McGrathb10a3352004-10-07 18:53:12 +0000743static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200744get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
Roland McGrathb10a3352004-10-07 18:53:12 +0000745{
Roland McGrathaa524c82005-06-01 19:22:06 +0000746 unsigned long nlongs, size, end;
747
748 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
749 size = nlongs * sizeof(long);
750 end = ptr + size;
751 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
752 && (end > ptr))) {
753 unsigned long n, cur, abbrev_end;
754 int failed = 0;
755
756 if (abbrev(tcp)) {
757 abbrev_end = ptr + max_strlen * sizeof(long);
758 if (abbrev_end < ptr)
759 abbrev_end = end;
760 } else {
761 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000762 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200763 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000764 for (cur = ptr; cur < end; cur += sizeof(long)) {
765 if (cur > ptr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200766 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000767 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200768 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000769 break;
770 }
771 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200772 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000773 failed = 1;
774 break;
775 }
776 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
777 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200778 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000779 if (failed)
780 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000781 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000782 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000783 tprintf(", %lu", maxnodes);
784}
785
786int
Denys Vlasenko12014262011-05-30 14:00:14 +0200787sys_mbind(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000788{
789 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000790 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000791 printxval(policies, tcp->u_arg[2], "MPOL_???");
792 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200793 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000794 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000795 }
796 return 0;
797}
798
799int
Denys Vlasenko12014262011-05-30 14:00:14 +0200800sys_set_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000801{
802 if (entering(tcp)) {
803 printxval(policies, tcp->u_arg[0], "MPOL_???");
804 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
805 }
806 return 0;
807}
808
809int
Denys Vlasenko12014262011-05-30 14:00:14 +0200810sys_get_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000811{
812 if (exiting(tcp)) {
813 int pol;
814 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200815 tprints("NULL");
Roland McGrathb10a3352004-10-07 18:53:12 +0000816 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
817 tprintf("%#lx", tcp->u_arg[0]);
818 else
819 printxval(policies, pol, "MPOL_???");
820 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
821 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000822 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000823 }
824 return 0;
825}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000826
827int
Dmitry V. Levin64d0e712012-03-11 22:44:14 +0000828sys_migrate_pages(struct tcb *tcp)
829{
830 if (entering(tcp)) {
831 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
832 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
833 tprints(", ");
834 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
835 }
836 return 0;
837}
838
839int
Denys Vlasenko12014262011-05-30 14:00:14 +0200840sys_move_pages(struct tcb *tcp)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000841{
842 if (entering(tcp)) {
843 unsigned long npages = tcp->u_arg[1];
844 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
845 if (tcp->u_arg[2] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200846 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000847 else {
848 int i;
849 long puser = tcp->u_arg[2];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200850 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000851 for (i = 0; i < npages; ++i) {
852 void *p;
853 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200854 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000855 if (umove(tcp, puser, &p) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200856 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000857 break;
858 }
859 tprintf("%p", p);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200860 puser += sizeof(void *);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000861 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200862 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000863 }
864 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200865 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000866 else {
867 int i;
868 long nodeuser = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200869 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000870 for (i = 0; i < npages; ++i) {
871 int node;
872 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200873 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000874 if (umove(tcp, nodeuser, &node) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200875 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000876 break;
877 }
878 tprintf("%#x", node);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200879 nodeuser += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000880 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200881 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000882 }
883 }
884 if (exiting(tcp)) {
885 unsigned long npages = tcp->u_arg[1];
886 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200887 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000888 else {
889 int i;
890 long statususer = tcp->u_arg[4];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200891 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000892 for (i = 0; i < npages; ++i) {
893 int status;
894 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200895 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000896 if (umove(tcp, statususer, &status) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200897 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000898 break;
899 }
900 tprintf("%#x", status);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200901 statususer += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000902 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200903 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000904 }
905 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
906 }
907 return 0;
908}
Roland McGrath4a6f6522008-08-25 03:09:16 +0000909
Denys Vlasenko84703742012-02-25 02:38:52 +0100910#if defined(POWERPC)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000911int
Denys Vlasenko12014262011-05-30 14:00:14 +0200912sys_subpage_prot(struct tcb *tcp)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000913{
914 if (entering(tcp)) {
915 unsigned long cur, end, abbrev_end, entries;
916 unsigned int entry;
917
918 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
919 entries = tcp->u_arg[1] >> 16;
920 if (!entries || !tcp->u_arg[2]) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200921 tprints("{}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000922 return 0;
923 }
924 cur = tcp->u_arg[2];
925 end = cur + (sizeof(int) * entries);
926 if (!verbose(tcp) || end < tcp->u_arg[2]) {
927 tprintf("%#lx", tcp->u_arg[2]);
928 return 0;
929 }
930 if (abbrev(tcp)) {
931 abbrev_end = cur + (sizeof(int) * max_strlen);
932 if (abbrev_end > end)
933 abbrev_end = end;
934 }
935 else
936 abbrev_end = end;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200937 tprints("{");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000938 for (; cur < end; cur += sizeof(int)) {
939 if (cur > tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200940 tprints(", ");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000941 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200942 tprints("...");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000943 break;
944 }
945 if (umove(tcp, cur, &entry) < 0) {
946 tprintf("??? [%#lx]", cur);
947 break;
948 }
949 else
950 tprintf("%#08x", entry);
951 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200952 tprints("}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000953 }
954
955 return 0;
956}
957#endif