blob: 88b3a2b477d660897f2a0ce0f2b365e0c7e9cf4a [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.
31 *
32 * $Id$
33 */
34
35#include "defs.h"
36
Roland McGrath05cdd3c2004-03-02 06:16:59 +000037#include <asm/mman.h>
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000038#include <sys/mman.h>
Wichert Akkerman5daa0281999-03-15 19:49:42 +000039
Denys Vlasenko84703742012-02-25 02:38:52 +010040#if defined(I386)
Denys Vlasenko72a58482011-08-19 16:01:51 +020041# include <asm/ldt.h>
Roland McGrath7decfb22004-03-01 22:10:52 +000042# ifdef HAVE_STRUCT_USER_DESC
43# define modify_ldt_ldt_s user_desc
44# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045#endif
Denys Vlasenko84703742012-02-25 02:38:52 +010046#if defined(SH64)
Denys Vlasenko72a58482011-08-19 16:01:51 +020047# include <asm/page.h> /* for PAGE_SHIFT */
Roland McGrathe1e584b2003-06-02 19:18:58 +000048#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000049
John Hughes70623be2001-03-08 13:59:00 +000050#ifdef HAVE_LONG_LONG_OFF_T
51/*
52 * Ugly hacks for systems that have a long long off_t
53 */
54#define sys_mmap64 sys_mmap
55#endif
56
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057int
Denys Vlasenko12014262011-05-30 14:00:14 +020058sys_brk(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059{
60 if (entering(tcp)) {
61 tprintf("%#lx", tcp->u_arg[0]);
62 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000063 return RVAL_HEX;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000064}
65
Roland McGrathd9f816f2004-09-04 03:39:20 +000066static const struct xlat mmap_prot[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000067 { PROT_NONE, "PROT_NONE", },
68 { PROT_READ, "PROT_READ" },
69 { PROT_WRITE, "PROT_WRITE" },
70 { PROT_EXEC, "PROT_EXEC" },
Roland McGrath47eb0e22003-09-25 23:06:04 +000071#ifdef PROT_SEM
72 { PROT_SEM, "PROT_SEM" },
73#endif
74#ifdef PROT_GROWSDOWN
75 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
76#endif
77#ifdef PROT_GROWSUP
78 { PROT_GROWSUP, "PROT_GROWSUP" },
79#endif
Roland McGrath586d6ab2008-08-25 03:00:47 +000080#ifdef PROT_SAO
81 { PROT_SAO, "PROT_SAO" },
82#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000083 { 0, NULL },
84};
85
Roland McGrathd9f816f2004-09-04 03:39:20 +000086static const struct xlat mmap_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000087 { MAP_SHARED, "MAP_SHARED" },
88 { MAP_PRIVATE, "MAP_PRIVATE" },
89 { MAP_FIXED, "MAP_FIXED" },
90#ifdef MAP_ANONYMOUS
91 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
92#endif
Dmitry V. Levin71f1a132007-03-29 23:30:09 +000093#ifdef MAP_32BIT
94 { MAP_32BIT, "MAP_32BIT" },
95#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000096#ifdef MAP_RENAME
97 { MAP_RENAME, "MAP_RENAME" },
98#endif
99#ifdef MAP_NORESERVE
100 { MAP_NORESERVE,"MAP_NORESERVE" },
101#endif
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000102#ifdef MAP_POPULATE
103 { MAP_POPULATE, "MAP_POPULATE" },
104#endif
105#ifdef MAP_NONBLOCK
106 { MAP_NONBLOCK, "MAP_NONBLOCK" },
107#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000108 /*
109 * XXX - this was introduced in SunOS 4.x to distinguish between
110 * the old pre-4.x "mmap()", which:
111 *
112 * only let you map devices with an "mmap" routine (e.g.,
113 * frame buffers) in;
114 *
115 * required you to specify the mapping address;
116 *
117 * returned 0 on success and -1 on failure;
118 *
119 * memory and which, and the 4.x "mmap()" which:
120 *
121 * can map plain files;
122 *
123 * can be asked to pick where to map the file;
124 *
125 * returns the address where it mapped the file on success
126 * and -1 on failure.
127 *
128 * It's not actually used in source code that calls "mmap()"; the
129 * "mmap()" routine adds it for you.
130 *
131 * It'd be nice to come up with some way of eliminating it from
132 * the flags, e.g. reporting calls *without* it as "old_mmap()"
133 * and calls with it as "mmap()".
134 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000135#ifdef _MAP_NEW
136 { _MAP_NEW, "_MAP_NEW" },
137#endif
138#ifdef MAP_GROWSDOWN
139 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
140#endif
141#ifdef MAP_DENYWRITE
142 { MAP_DENYWRITE,"MAP_DENYWRITE" },
143#endif
144#ifdef MAP_EXECUTABLE
145 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
146#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000147#ifdef MAP_INHERIT
148 { MAP_INHERIT,"MAP_INHERIT" },
149#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150#ifdef MAP_FILE
151 { MAP_FILE,"MAP_FILE"},
152#endif
153#ifdef MAP_LOCKED
154 { MAP_LOCKED,"MAP_LOCKED"},
155#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000156 /* FreeBSD ones */
157#ifdef MAP_ANON
158 { MAP_ANON, "MAP_ANON" },
159#endif
160#ifdef MAP_HASSEMAPHORE
161 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
162#endif
163#ifdef MAP_STACK
164 { MAP_STACK, "MAP_STACK" },
165#endif
166#ifdef MAP_NOSYNC
167 { MAP_NOSYNC, "MAP_NOSYNC" },
168#endif
169#ifdef MAP_NOCORE
170 { MAP_NOCORE, "MAP_NOCORE" },
171#endif
Chris Metcalfc8c66982009-12-28 10:00:15 -0500172#ifdef TILE
173 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
174 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
175 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
176#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000177 { 0, NULL },
178};
179
Chris Metcalfc8c66982009-12-28 10:00:15 -0500180#ifdef TILE
Denys Vlasenko72a58482011-08-19 16:01:51 +0200181static int
182addtileflags(long flags)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500183{
184 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
185 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
186
187 if (flags & _MAP_CACHE_INCOHERENT) {
188 flags &= ~_MAP_CACHE_INCOHERENT;
189 if (home == MAP_CACHE_HOME_NONE) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200190 tprints("|MAP_CACHE_INCOHERENT");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500191 return flags;
192 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200193 tprints("|_MAP_CACHE_INCOHERENT");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500194 }
195
196 switch (home) {
197 case 0: break;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200198 case MAP_CACHE_HOME_HERE: tprints("|MAP_CACHE_HOME_HERE"); break;
199 case MAP_CACHE_HOME_NONE: tprints("|MAP_CACHE_HOME_NONE"); break;
200 case MAP_CACHE_HOME_SINGLE: tprints("|MAP_CACHE_HOME_SINGLE"); break;
201 case MAP_CACHE_HOME_TASK: tprints("|MAP_CACHE_HOME_TASK"); break;
202 case MAP_CACHE_HOME_HASH: tprints("|MAP_CACHE_HOME_HASH"); break;
Chris Metcalfc8c66982009-12-28 10:00:15 -0500203 default:
204 tprintf("|MAP_CACHE_HOME(%d)",
205 (home >> _MAP_CACHE_HOME_SHIFT) );
206 break;
207 }
208
209 return flags;
210}
211#endif
212
John Hughes70623be2001-03-08 13:59:00 +0000213#if !HAVE_LONG_LONG_OFF_T
Dmitry V. Levin31382132011-03-04 05:08:02 +0300214static int
215print_mmap(struct tcb *tcp, long *u_arg, long long offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000216{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000217 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000219 if (!u_arg[0])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200220 tprints("NULL, ");
Wichert Akkerman8829a551999-06-11 13:18:40 +0000221 else
222 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000223 /* len */
224 tprintf("%lu, ", u_arg[1]);
225 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000226 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200227 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000228 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000229#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500231#ifdef TILE
232 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
233#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Chris Metcalfc8c66982009-12-28 10:00:15 -0500235#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000236#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000237 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000238#endif
Dmitry V. Levin31382132011-03-04 05:08:02 +0300239 /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200240 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300241 printfd(tcp, u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000242 /* offset */
Dmitry V. Levin31382132011-03-04 05:08:02 +0300243 tprintf(", %#llx", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000244 }
245 return RVAL_HEX;
246}
247
Denys Vlasenko12014262011-05-30 14:00:14 +0200248int sys_old_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000249{
Denys Vlasenko72a58482011-08-19 16:01:51 +0200250#if defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000251 /*
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200252 * IA64 processes never call this routine, they only use the
253 * new `sys_mmap' interface.
254 * For IA32 processes, this code converts the integer arguments
255 * that they pushed onto the stack, into longs.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000256 *
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200257 * Note that addresses with bit 31 set will be sign extended.
258 * Fortunately, those addresses are not currently being generated
259 * for IA32 processes so it's not a problem.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000260 */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200261 int i;
262 long u_arg[6];
263 int narrow_arg[6];
264 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
265 return 0;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000266 for (i = 0; i < 6; i++)
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200267 u_arg[i] = narrow_arg[i];
Roland McGrathf5a47772003-06-26 22:40:42 +0000268#elif defined(SH) || defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000269 /* SH has always passed the args in registers */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200270 long *u_arg = tcp->u_arg;
Roland McGrath6b1d43e2003-03-31 01:05:01 +0000271#else
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200272 long u_arg[6];
Roland McGrath520e21f2005-07-05 09:50:18 +0000273# if defined(X86_64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000274 if (current_personality == 1) {
275 int i;
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200276 unsigned narrow_arg[6];
277 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
278 return 0;
279 for (i = 0; i < 6; ++i)
280 u_arg[i] = narrow_arg[i];
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000281 }
282 else
Roland McGrath520e21f2005-07-05 09:50:18 +0000283# endif
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200284 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000285 return 0;
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200286#endif /* other architectures */
287
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000288 return print_mmap(tcp, u_arg, u_arg[5]);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000289}
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000290
291int
Denys Vlasenko12014262011-05-30 14:00:14 +0200292sys_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000293{
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000294 long long offset = tcp->u_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000295
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200296 /* FIXME: why only SH64? i386 mmap2 syscall ends up
297 * in this function, but does not convert offset
298 * from pages to bytes. See test/mmap_offset_decode.c
299 * Why SH64 and i386 are handled differently?
300 */
Denys Vlasenko84703742012-02-25 02:38:52 +0100301#if defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000302 /*
303 * Old mmap differs from new mmap in specifying the
304 * offset in units of bytes rather than pages. We
305 * pretend it's in byte units so the user only ever
306 * sees bytes in the printout.
307 */
308 offset <<= PAGE_SHIFT;
Roland McGrathe1e584b2003-06-02 19:18:58 +0000309#endif
Roland McGrath542c2c62008-05-20 01:11:56 +0000310#if defined(LINUX_MIPSN32)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000311 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000312#endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000313 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000314}
John Hughes70623be2001-03-08 13:59:00 +0000315#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000316
John Hughes70623be2001-03-08 13:59:00 +0000317#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200318/* TODO: comment which arches use this routine.
319 * For one, does ALPHA on Linux use this??
320 * From code it seems that it might use 7 or 8 registers,
321 * which is strange - Linux syscalls can pass maximum of 6 parameters!
322 */
John Hughesbdf48f52001-03-06 15:08:09 +0000323int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300324sys_mmap64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000325{
John Hughesbdf48f52001-03-06 15:08:09 +0000326 if (entering(tcp)) {
Denys Vlasenko84703742012-02-25 02:38:52 +0100327#if defined(ALPHA)
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200328 long *u_arg = tcp->u_arg;
329#else
330 long u_arg[7];
John Hughesbdf48f52001-03-06 15:08:09 +0000331 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
332 (char *) u_arg) == -1)
333 return 0;
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200334#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000335 /* addr */
H.J. Lud0cd4432012-02-03 10:07:42 -0800336 if (!u_arg[0])
337 tprints("NULL, ");
338 else
339 tprintf("%#lx, ", u_arg[0]);
John Hughesbdf48f52001-03-06 15:08:09 +0000340 /* len */
341 tprintf("%lu, ", u_arg[1]);
342 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000343 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200344 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000345 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000346#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000347 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
348 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000349#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000350 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000351#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000352 /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200353 tprints(", ");
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200354 printfd(tcp, u_arg[4]);
John Hughesbdf48f52001-03-06 15:08:09 +0000355 /* offset */
Denys Vlasenko84703742012-02-25 02:38:52 +0100356#if defined(ALPHA)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300357 printllval(tcp, ", %#llx", 5);
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200358#else
359 /* NOTE: not verified that [5] and [6] should be used.
360 * It's possible that long long is 64-bit aligned in memory
361 * and we need to use [6] and [7] here instead:
362 */
363 tprintf(", %#llx", LONG_LONG(u_arg[5], u_arg[6]));
364#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000365 }
366 return RVAL_HEX;
367}
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200368#endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */
John Hughesbdf48f52001-03-06 15:08:09 +0000369
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000370int
Denys Vlasenko12014262011-05-30 14:00:14 +0200371sys_munmap(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000372{
373 if (entering(tcp)) {
374 tprintf("%#lx, %lu",
375 tcp->u_arg[0], tcp->u_arg[1]);
376 }
377 return 0;
378}
379
380int
Denys Vlasenko12014262011-05-30 14:00:14 +0200381sys_mprotect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000382{
383 if (entering(tcp)) {
384 tprintf("%#lx, %lu, ",
385 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000386 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387 }
388 return 0;
389}
390
Roland McGrathd9f816f2004-09-04 03:39:20 +0000391static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000392 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
Chris Metcalfff3474a2009-12-24 23:19:19 +0000393#ifdef MREMAP_FIXED
394 { MREMAP_FIXED, "MREMAP_FIXED" },
395#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000396 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000397};
398
399int
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000400sys_mremap(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000401{
402 if (entering(tcp)) {
403 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
404 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000405 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000406#ifdef MREMAP_FIXED
407 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
408 (MREMAP_MAYMOVE | MREMAP_FIXED))
409 tprintf(", %#lx", tcp->u_arg[4]);
410#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000411 }
412 return RVAL_HEX;
413}
414
Roland McGrathf4021b12008-08-25 02:59:36 +0000415static const struct xlat madvise_cmds[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000416#ifdef MADV_NORMAL
417 { MADV_NORMAL, "MADV_NORMAL" },
418#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000419#ifdef MADV_RANDOM
Wichert Akkermanc7926982000-04-10 22:22:31 +0000420 { MADV_RANDOM, "MADV_RANDOM" },
421#endif
422#ifdef MADV_SEQUENTIAL
423 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
424#endif
425#ifdef MADV_WILLNEED
426 { MADV_WILLNEED, "MADV_WILLNEED" },
427#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000428#ifdef MADV_DONTNEED
Wichert Akkermanc7926982000-04-10 22:22:31 +0000429 { MADV_DONTNEED, "MADV_DONTNEED" },
430#endif
431 { 0, NULL },
432};
433
Wichert Akkermanc7926982000-04-10 22:22:31 +0000434int
Denys Vlasenko12014262011-05-30 14:00:14 +0200435sys_madvise(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000436{
437 if (entering(tcp)) {
438 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000439 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000440 }
441 return 0;
442}
443
Roland McGrathd9f816f2004-09-04 03:39:20 +0000444static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000445#ifdef MCL_CURRENT
446 { MCL_CURRENT, "MCL_CURRENT" },
447#endif
448#ifdef MCL_FUTURE
449 { MCL_FUTURE, "MCL_FUTURE" },
450#endif
451 { 0, NULL}
452};
453
454int
Denys Vlasenko12014262011-05-30 14:00:14 +0200455sys_mlockall(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000456{
457 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000458 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000459 }
460 return 0;
461}
462
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463#ifdef MS_ASYNC
464
Roland McGrathd9f816f2004-09-04 03:39:20 +0000465static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000466#ifdef MS_SYNC
467 { MS_SYNC, "MS_SYNC" },
468#endif
John Hughesaca07f32001-10-16 18:12:27 +0000469 { MS_ASYNC, "MS_ASYNC" },
470 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000471 { 0, NULL },
472};
473
474int
Denys Vlasenko12014262011-05-30 14:00:14 +0200475sys_msync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000476{
477 if (entering(tcp)) {
478 /* addr */
479 tprintf("%#lx", tcp->u_arg[0]);
480 /* len */
481 tprintf(", %lu, ", tcp->u_arg[1]);
482 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000483 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000484 }
485 return 0;
486}
487
488#endif /* MS_ASYNC */
489
490#ifdef MC_SYNC
491
Roland McGrathd9f816f2004-09-04 03:39:20 +0000492static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000493 { MC_LOCK, "MC_LOCK" },
494 { MC_LOCKAS, "MC_LOCKAS" },
495 { MC_SYNC, "MC_SYNC" },
496 { MC_UNLOCK, "MC_UNLOCK" },
497 { MC_UNLOCKAS, "MC_UNLOCKAS" },
498 { 0, NULL },
499};
500
Roland McGrathd9f816f2004-09-04 03:39:20 +0000501static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000502 { MCL_CURRENT, "MCL_CURRENT" },
503 { MCL_FUTURE, "MCL_FUTURE" },
504 { 0, NULL },
505};
506
507int
Denys Vlasenko12014262011-05-30 14:00:14 +0200508sys_mctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509{
510 int arg, function;
511
512 if (entering(tcp)) {
513 /* addr */
514 tprintf("%#lx", tcp->u_arg[0]);
515 /* len */
516 tprintf(", %lu, ", tcp->u_arg[1]);
517 /* function */
518 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000519 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520 /* arg */
521 arg = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200522 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000523 switch (function) {
524 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000525 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526 break;
527 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000528 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529 break;
530 default:
531 tprintf("%#x", arg);
532 break;
533 }
534 }
535 return 0;
536}
537
538#endif /* MC_SYNC */
539
540int
Denys Vlasenko12014262011-05-30 14:00:14 +0200541sys_mincore(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543 if (entering(tcp)) {
544 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
545 } else {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200546 unsigned long i, len;
547 char *vec = NULL;
548
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549 len = tcp->u_arg[1];
550 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000551 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
553 tprintf("%#lx", tcp->u_arg[2]);
554 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200555 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000556 for (i = 0; i < len; i++) {
557 if (abbrev(tcp) && i >= max_strlen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200558 tprints("...");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559 break;
560 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200561 tprints((vec[i] & 1) ? "1" : "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200563 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200565 free(vec);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566 }
567 return 0;
568}
569
Denys Vlasenko84703742012-02-25 02:38:52 +0100570#if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571int
Denys Vlasenko12014262011-05-30 14:00:14 +0200572sys_getpagesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573{
574 if (exiting(tcp))
575 return RVAL_HEX;
576 return 0;
577}
Denys Vlasenko84703742012-02-25 02:38:52 +0100578#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000579
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100580#if defined(I386)
Roland McGrath909875b2002-12-22 03:34:36 +0000581void
Denys Vlasenko1f458252009-01-23 16:10:22 +0000582print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
Roland McGrath34e4a692002-12-15 23:58:17 +0000583{
584 tprintf("base_addr:%#08lx, "
585 "limit:%d, "
586 "seg_32bit:%d, "
587 "contents:%d, "
588 "read_exec_only:%d, "
589 "limit_in_pages:%d, "
590 "seg_not_present:%d, "
591 "useable:%d}",
Denys Vlasenko1f458252009-01-23 16:10:22 +0000592 (long) ldt_entry->base_addr,
Roland McGrath34e4a692002-12-15 23:58:17 +0000593 ldt_entry->limit,
594 ldt_entry->seg_32bit,
595 ldt_entry->contents,
596 ldt_entry->read_exec_only,
597 ldt_entry->limit_in_pages,
598 ldt_entry->seg_not_present,
599 ldt_entry->useable);
600}
601
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000602int
Denys Vlasenko12014262011-05-30 14:00:14 +0200603sys_modify_ldt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604{
605 if (entering(tcp)) {
606 struct modify_ldt_ldt_s copy;
607 tprintf("%ld", tcp->u_arg[0]);
608 if (tcp->u_arg[1] == 0
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200609 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000610 || umove(tcp, tcp->u_arg[1], &copy) == -1)
611 tprintf(", %lx", tcp->u_arg[1]);
612 else {
613 tprintf(", {entry_number:%d, ", copy.entry_number);
614 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200615 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000616 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000617 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000618 }
619 }
620 tprintf(", %lu", tcp->u_arg[2]);
621 }
622 return 0;
623}
Roland McGrath34e4a692002-12-15 23:58:17 +0000624
625int
Denys Vlasenko12014262011-05-30 14:00:14 +0200626sys_set_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000627{
628 struct modify_ldt_ldt_s copy;
629 if (entering(tcp)) {
630 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
631 if (copy.entry_number == -1)
632 tprintf("{entry_number:%d -> ",
633 copy.entry_number);
634 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200635 tprints("{entry_number:");
Roland McGrath34e4a692002-12-15 23:58:17 +0000636 }
637 } else {
638 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
639 tprintf("%d, ", copy.entry_number);
640 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200641 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000642 else {
643 print_ldt_entry(&copy);
644 }
645 } else {
646 tprintf("%lx", tcp->u_arg[0]);
647 }
648 }
649 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000650
Roland McGrath34e4a692002-12-15 23:58:17 +0000651}
652
653int
Denys Vlasenko12014262011-05-30 14:00:14 +0200654sys_get_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000655{
656 struct modify_ldt_ldt_s copy;
657 if (exiting(tcp)) {
658 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
659 tprintf("{entry_number:%d, ", copy.entry_number);
660 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200661 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000662 else {
663 print_ldt_entry(&copy);
664 }
665 } else {
666 tprintf("%lx", tcp->u_arg[0]);
667 }
668 }
669 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000670
Roland McGrath34e4a692002-12-15 23:58:17 +0000671}
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100672#endif /* I386 */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000673
Denys Vlasenko84703742012-02-25 02:38:52 +0100674#if defined(M68K)
Andreas Schwab58743222010-05-28 22:28:51 +0200675int
Denys Vlasenko12014262011-05-30 14:00:14 +0200676sys_set_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200677{
678 if (entering(tcp))
679 tprintf("%#lx", tcp->u_arg[0]);
680 return 0;
681
682}
683
684int
Denys Vlasenko12014262011-05-30 14:00:14 +0200685sys_get_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200686{
687 return RVAL_HEX;
688}
689#endif
690
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000691int
Denys Vlasenko12014262011-05-30 14:00:14 +0200692sys_remap_file_pages(struct tcb *tcp)
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000693{
694 if (entering(tcp)) {
695 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000696 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000697 tprintf(", %lu, ", tcp->u_arg[3]);
698#ifdef MAP_TYPE
699 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
700 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
701#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000702 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000703#endif
704 }
705 return 0;
706}
Roland McGrathb10a3352004-10-07 18:53:12 +0000707
Roland McGrathb10a3352004-10-07 18:53:12 +0000708#define MPOL_DEFAULT 0
709#define MPOL_PREFERRED 1
710#define MPOL_BIND 2
711#define MPOL_INTERLEAVE 3
712
713#define MPOL_F_NODE (1<<0)
714#define MPOL_F_ADDR (1<<1)
715
716#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000717#define MPOL_MF_MOVE (1<<1)
718#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000719
Roland McGrathb10a3352004-10-07 18:53:12 +0000720static const struct xlat policies[] = {
721 { MPOL_DEFAULT, "MPOL_DEFAULT" },
722 { MPOL_PREFERRED, "MPOL_PREFERRED" },
723 { MPOL_BIND, "MPOL_BIND" },
724 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
725 { 0, NULL }
726};
727
728static const struct xlat mbindflags[] = {
729 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000730 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
731 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
Roland McGrathb10a3352004-10-07 18:53:12 +0000732 { 0, NULL }
733};
734
735static const struct xlat mempolicyflags[] = {
736 { MPOL_F_NODE, "MPOL_F_NODE" },
737 { MPOL_F_ADDR, "MPOL_F_ADDR" },
738 { 0, NULL }
739};
740
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000741static const struct xlat move_pages_flags[] = {
742 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
743 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
744 { 0, NULL }
745};
746
Roland McGrathb10a3352004-10-07 18:53:12 +0000747static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200748get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
Roland McGrathb10a3352004-10-07 18:53:12 +0000749{
Roland McGrathaa524c82005-06-01 19:22:06 +0000750 unsigned long nlongs, size, end;
751
752 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
753 size = nlongs * sizeof(long);
754 end = ptr + size;
755 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
756 && (end > ptr))) {
757 unsigned long n, cur, abbrev_end;
758 int failed = 0;
759
760 if (abbrev(tcp)) {
761 abbrev_end = ptr + max_strlen * sizeof(long);
762 if (abbrev_end < ptr)
763 abbrev_end = end;
764 } else {
765 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000766 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200767 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000768 for (cur = ptr; cur < end; cur += sizeof(long)) {
769 if (cur > ptr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200770 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000771 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200772 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000773 break;
774 }
775 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200776 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000777 failed = 1;
778 break;
779 }
780 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
781 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200782 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000783 if (failed)
784 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000785 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000786 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000787 tprintf(", %lu", maxnodes);
788}
789
790int
Denys Vlasenko12014262011-05-30 14:00:14 +0200791sys_mbind(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000792{
793 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000794 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000795 printxval(policies, tcp->u_arg[2], "MPOL_???");
796 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200797 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000798 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000799 }
800 return 0;
801}
802
803int
Denys Vlasenko12014262011-05-30 14:00:14 +0200804sys_set_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000805{
806 if (entering(tcp)) {
807 printxval(policies, tcp->u_arg[0], "MPOL_???");
808 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
809 }
810 return 0;
811}
812
813int
Denys Vlasenko12014262011-05-30 14:00:14 +0200814sys_get_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000815{
816 if (exiting(tcp)) {
817 int pol;
818 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200819 tprints("NULL");
Roland McGrathb10a3352004-10-07 18:53:12 +0000820 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
821 tprintf("%#lx", tcp->u_arg[0]);
822 else
823 printxval(policies, pol, "MPOL_???");
824 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
825 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000826 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000827 }
828 return 0;
829}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000830
831int
Dmitry V. Levin64d0e712012-03-11 22:44:14 +0000832sys_migrate_pages(struct tcb *tcp)
833{
834 if (entering(tcp)) {
835 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
836 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
837 tprints(", ");
838 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
839 }
840 return 0;
841}
842
843int
Denys Vlasenko12014262011-05-30 14:00:14 +0200844sys_move_pages(struct tcb *tcp)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000845{
846 if (entering(tcp)) {
847 unsigned long npages = tcp->u_arg[1];
848 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
849 if (tcp->u_arg[2] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200850 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000851 else {
852 int i;
853 long puser = tcp->u_arg[2];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200854 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000855 for (i = 0; i < npages; ++i) {
856 void *p;
857 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200858 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000859 if (umove(tcp, puser, &p) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200860 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000861 break;
862 }
863 tprintf("%p", p);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200864 puser += sizeof(void *);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000865 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200866 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000867 }
868 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200869 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000870 else {
871 int i;
872 long nodeuser = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200873 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000874 for (i = 0; i < npages; ++i) {
875 int node;
876 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200877 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000878 if (umove(tcp, nodeuser, &node) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200879 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000880 break;
881 }
882 tprintf("%#x", node);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200883 nodeuser += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000884 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200885 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000886 }
887 }
888 if (exiting(tcp)) {
889 unsigned long npages = tcp->u_arg[1];
890 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200891 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000892 else {
893 int i;
894 long statususer = tcp->u_arg[4];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200895 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000896 for (i = 0; i < npages; ++i) {
897 int status;
898 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200899 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000900 if (umove(tcp, statususer, &status) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200901 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000902 break;
903 }
904 tprintf("%#x", status);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200905 statususer += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000906 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200907 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000908 }
909 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
910 }
911 return 0;
912}
Roland McGrath4a6f6522008-08-25 03:09:16 +0000913
Denys Vlasenko84703742012-02-25 02:38:52 +0100914#if defined(POWERPC)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000915int
Denys Vlasenko12014262011-05-30 14:00:14 +0200916sys_subpage_prot(struct tcb *tcp)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000917{
918 if (entering(tcp)) {
919 unsigned long cur, end, abbrev_end, entries;
920 unsigned int entry;
921
922 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
923 entries = tcp->u_arg[1] >> 16;
924 if (!entries || !tcp->u_arg[2]) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200925 tprints("{}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000926 return 0;
927 }
928 cur = tcp->u_arg[2];
929 end = cur + (sizeof(int) * entries);
930 if (!verbose(tcp) || end < tcp->u_arg[2]) {
931 tprintf("%#lx", tcp->u_arg[2]);
932 return 0;
933 }
934 if (abbrev(tcp)) {
935 abbrev_end = cur + (sizeof(int) * max_strlen);
936 if (abbrev_end > end)
937 abbrev_end = end;
938 }
939 else
940 abbrev_end = end;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200941 tprints("{");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000942 for (; cur < end; cur += sizeof(int)) {
943 if (cur > tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200944 tprints(", ");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000945 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200946 tprints("...");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000947 break;
948 }
949 if (umove(tcp, cur, &entry) < 0) {
950 tprintf("??? [%#lx]", cur);
951 break;
952 }
953 else
954 tprintf("%#08x", entry);
955 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200956 tprints("}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000957 }
958
959 return 0;
960}
961#endif