blob: e8bad07dfd1b957a7c996178c1b00c1116d185a1 [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
Roland McGrath909875b2002-12-22 03:34:36 +000040#if defined(LINUX) && 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
Roland McGrathf5a47772003-06-26 22:40:42 +000046#if defined(LINUX) && 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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000066
Roland McGrathd9f816f2004-09-04 03:39:20 +000067static const struct xlat mmap_prot[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000068 { PROT_NONE, "PROT_NONE", },
69 { PROT_READ, "PROT_READ" },
70 { PROT_WRITE, "PROT_WRITE" },
71 { PROT_EXEC, "PROT_EXEC" },
Roland McGrath47eb0e22003-09-25 23:06:04 +000072#ifdef PROT_SEM
73 { PROT_SEM, "PROT_SEM" },
74#endif
75#ifdef PROT_GROWSDOWN
76 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
77#endif
78#ifdef PROT_GROWSUP
79 { PROT_GROWSUP, "PROT_GROWSUP" },
80#endif
Roland McGrath586d6ab2008-08-25 03:00:47 +000081#ifdef PROT_SAO
82 { PROT_SAO, "PROT_SAO" },
83#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084 { 0, NULL },
85};
86
Roland McGrathd9f816f2004-09-04 03:39:20 +000087static const struct xlat mmap_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000088 { MAP_SHARED, "MAP_SHARED" },
89 { MAP_PRIVATE, "MAP_PRIVATE" },
90 { MAP_FIXED, "MAP_FIXED" },
91#ifdef MAP_ANONYMOUS
92 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
93#endif
Dmitry V. Levin71f1a132007-03-29 23:30:09 +000094#ifdef MAP_32BIT
95 { MAP_32BIT, "MAP_32BIT" },
96#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000097#ifdef MAP_RENAME
98 { MAP_RENAME, "MAP_RENAME" },
99#endif
100#ifdef MAP_NORESERVE
101 { MAP_NORESERVE,"MAP_NORESERVE" },
102#endif
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000103#ifdef MAP_POPULATE
104 { MAP_POPULATE, "MAP_POPULATE" },
105#endif
106#ifdef MAP_NONBLOCK
107 { MAP_NONBLOCK, "MAP_NONBLOCK" },
108#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000109 /*
110 * XXX - this was introduced in SunOS 4.x to distinguish between
111 * the old pre-4.x "mmap()", which:
112 *
113 * only let you map devices with an "mmap" routine (e.g.,
114 * frame buffers) in;
115 *
116 * required you to specify the mapping address;
117 *
118 * returned 0 on success and -1 on failure;
119 *
120 * memory and which, and the 4.x "mmap()" which:
121 *
122 * can map plain files;
123 *
124 * can be asked to pick where to map the file;
125 *
126 * returns the address where it mapped the file on success
127 * and -1 on failure.
128 *
129 * It's not actually used in source code that calls "mmap()"; the
130 * "mmap()" routine adds it for you.
131 *
132 * It'd be nice to come up with some way of eliminating it from
133 * the flags, e.g. reporting calls *without* it as "old_mmap()"
134 * and calls with it as "mmap()".
135 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000136#ifdef _MAP_NEW
137 { _MAP_NEW, "_MAP_NEW" },
138#endif
139#ifdef MAP_GROWSDOWN
140 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
141#endif
142#ifdef MAP_DENYWRITE
143 { MAP_DENYWRITE,"MAP_DENYWRITE" },
144#endif
145#ifdef MAP_EXECUTABLE
146 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
147#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000148#ifdef MAP_INHERIT
149 { MAP_INHERIT,"MAP_INHERIT" },
150#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151#ifdef MAP_FILE
152 { MAP_FILE,"MAP_FILE"},
153#endif
154#ifdef MAP_LOCKED
155 { MAP_LOCKED,"MAP_LOCKED"},
156#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000157 /* FreeBSD ones */
158#ifdef MAP_ANON
159 { MAP_ANON, "MAP_ANON" },
160#endif
161#ifdef MAP_HASSEMAPHORE
162 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
163#endif
164#ifdef MAP_STACK
165 { MAP_STACK, "MAP_STACK" },
166#endif
167#ifdef MAP_NOSYNC
168 { MAP_NOSYNC, "MAP_NOSYNC" },
169#endif
170#ifdef MAP_NOCORE
171 { MAP_NOCORE, "MAP_NOCORE" },
172#endif
Chris Metcalfc8c66982009-12-28 10:00:15 -0500173#ifdef TILE
174 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
175 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
176 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
177#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000178 { 0, NULL },
179};
180
Chris Metcalfc8c66982009-12-28 10:00:15 -0500181#ifdef TILE
Denys Vlasenko72a58482011-08-19 16:01:51 +0200182static int
183addtileflags(long flags)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500184{
185 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
186 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
187
188 if (flags & _MAP_CACHE_INCOHERENT) {
189 flags &= ~_MAP_CACHE_INCOHERENT;
190 if (home == MAP_CACHE_HOME_NONE) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200191 tprints("|MAP_CACHE_INCOHERENT");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500192 return flags;
193 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200194 tprints("|_MAP_CACHE_INCOHERENT");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500195 }
196
197 switch (home) {
198 case 0: break;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200199 case MAP_CACHE_HOME_HERE: tprints("|MAP_CACHE_HOME_HERE"); break;
200 case MAP_CACHE_HOME_NONE: tprints("|MAP_CACHE_HOME_NONE"); break;
201 case MAP_CACHE_HOME_SINGLE: tprints("|MAP_CACHE_HOME_SINGLE"); break;
202 case MAP_CACHE_HOME_TASK: tprints("|MAP_CACHE_HOME_TASK"); break;
203 case MAP_CACHE_HOME_HASH: tprints("|MAP_CACHE_HOME_HASH"); break;
Chris Metcalfc8c66982009-12-28 10:00:15 -0500204 default:
205 tprintf("|MAP_CACHE_HOME(%d)",
206 (home >> _MAP_CACHE_HOME_SHIFT) );
207 break;
208 }
209
210 return flags;
211}
212#endif
213
John Hughes70623be2001-03-08 13:59:00 +0000214#if !HAVE_LONG_LONG_OFF_T
Dmitry V. Levin31382132011-03-04 05:08:02 +0300215static int
216print_mmap(struct tcb *tcp, long *u_arg, long long offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000217{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000219 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000220 if (!u_arg[0])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200221 tprints("NULL, ");
Wichert Akkerman8829a551999-06-11 13:18:40 +0000222 else
223 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224 /* len */
225 tprintf("%lu, ", u_arg[1]);
226 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000227 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200228 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000230#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000231 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500232#ifdef TILE
233 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
234#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000235 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Chris Metcalfc8c66982009-12-28 10:00:15 -0500236#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000237#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000238 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000239#endif
Dmitry V. Levin31382132011-03-04 05:08:02 +0300240 /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200241 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300242 printfd(tcp, u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000243 /* offset */
Dmitry V. Levin31382132011-03-04 05:08:02 +0300244 tprintf(", %#llx", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000245 }
246 return RVAL_HEX;
247}
248
Denys Vlasenko12014262011-05-30 14:00:14 +0200249int sys_old_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000250{
Denys Vlasenko72a58482011-08-19 16:01:51 +0200251#if defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000252 /*
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200253 * IA64 processes never call this routine, they only use the
254 * new `sys_mmap' interface.
255 * For IA32 processes, this code converts the integer arguments
256 * that they pushed onto the stack, into longs.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000257 *
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200258 * Note that addresses with bit 31 set will be sign extended.
259 * Fortunately, those addresses are not currently being generated
260 * for IA32 processes so it's not a problem.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000261 */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200262 int i;
263 long u_arg[6];
264 int narrow_arg[6];
265 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
266 return 0;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000267 for (i = 0; i < 6; i++)
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200268 u_arg[i] = narrow_arg[i];
Roland McGrathf5a47772003-06-26 22:40:42 +0000269#elif defined(SH) || defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000270 /* SH has always passed the args in registers */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200271 long *u_arg = tcp->u_arg;
Roland McGrath6b1d43e2003-03-31 01:05:01 +0000272#else
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200273 long u_arg[6];
Roland McGrath520e21f2005-07-05 09:50:18 +0000274# if defined(X86_64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000275 if (current_personality == 1) {
276 int i;
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200277 unsigned narrow_arg[6];
278 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
279 return 0;
280 for (i = 0; i < 6; ++i)
281 u_arg[i] = narrow_arg[i];
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000282 }
283 else
Roland McGrath520e21f2005-07-05 09:50:18 +0000284# endif
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200285 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000286 return 0;
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200287#endif /* other architectures */
288
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000289 return print_mmap(tcp, u_arg, u_arg[5]);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000290}
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000291
292int
Denys Vlasenko12014262011-05-30 14:00:14 +0200293sys_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000294{
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000295 long long offset = tcp->u_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000296
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200297 /* FIXME: why only SH64? i386 mmap2 syscall ends up
298 * in this function, but does not convert offset
299 * from pages to bytes. See test/mmap_offset_decode.c
300 * Why SH64 and i386 are handled differently?
301 */
Roland McGrathf5a47772003-06-26 22:40:42 +0000302#if defined(LINUX) && defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000303 /*
304 * Old mmap differs from new mmap in specifying the
305 * offset in units of bytes rather than pages. We
306 * pretend it's in byte units so the user only ever
307 * sees bytes in the printout.
308 */
309 offset <<= PAGE_SHIFT;
Roland McGrathe1e584b2003-06-02 19:18:58 +0000310#endif
Roland McGrath542c2c62008-05-20 01:11:56 +0000311#if defined(LINUX_MIPSN32)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000312 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000313#endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000314 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000315}
John Hughes70623be2001-03-08 13:59:00 +0000316#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000317
John Hughes70623be2001-03-08 13:59:00 +0000318#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200319/* TODO: comment which arches use this routine.
320 * For one, does ALPHA on Linux use this??
321 * From code it seems that it might use 7 or 8 registers,
322 * which is strange - Linux syscalls can pass maximum of 6 parameters!
323 */
John Hughesbdf48f52001-03-06 15:08:09 +0000324int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300325sys_mmap64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000326{
John Hughesbdf48f52001-03-06 15:08:09 +0000327 if (entering(tcp)) {
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200328#if !defined(LINUX) || defined(ALPHA)
329 long *u_arg = tcp->u_arg;
330#else
331 long u_arg[7];
John Hughesbdf48f52001-03-06 15:08:09 +0000332 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
333 (char *) u_arg) == -1)
334 return 0;
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200335#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000336 /* addr */
H.J. Lud0cd4432012-02-03 10:07:42 -0800337 if (!u_arg[0])
338 tprints("NULL, ");
339 else
340 tprintf("%#lx, ", u_arg[0]);
John Hughesbdf48f52001-03-06 15:08:09 +0000341 /* len */
342 tprintf("%lu, ", u_arg[1]);
343 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000344 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200345 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000346 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000347#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000348 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
349 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000350#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000351 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000352#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000353 /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200354 tprints(", ");
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200355 printfd(tcp, u_arg[4]);
John Hughesbdf48f52001-03-06 15:08:09 +0000356 /* offset */
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200357#if !defined(LINUX) || defined(ALPHA)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300358 printllval(tcp, ", %#llx", 5);
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200359#else
360 /* NOTE: not verified that [5] and [6] should be used.
361 * It's possible that long long is 64-bit aligned in memory
362 * and we need to use [6] and [7] here instead:
363 */
364 tprintf(", %#llx", LONG_LONG(u_arg[5], u_arg[6]));
365#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000366 }
367 return RVAL_HEX;
368}
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200369#endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */
John Hughesbdf48f52001-03-06 15:08:09 +0000370
Roland McGrath909875b2002-12-22 03:34:36 +0000371
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000372int
Denys Vlasenko12014262011-05-30 14:00:14 +0200373sys_munmap(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000374{
375 if (entering(tcp)) {
376 tprintf("%#lx, %lu",
377 tcp->u_arg[0], tcp->u_arg[1]);
378 }
379 return 0;
380}
381
382int
Denys Vlasenko12014262011-05-30 14:00:14 +0200383sys_mprotect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384{
385 if (entering(tcp)) {
386 tprintf("%#lx, %lu, ",
387 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000388 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000389 }
390 return 0;
391}
392
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000393
Roland McGrathd9f816f2004-09-04 03:39:20 +0000394static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000395 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
Chris Metcalfff3474a2009-12-24 23:19:19 +0000396#ifdef MREMAP_FIXED
397 { MREMAP_FIXED, "MREMAP_FIXED" },
398#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000399 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000400};
401
402int
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000403sys_mremap(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000404{
405 if (entering(tcp)) {
406 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
407 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000408 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000409#ifdef MREMAP_FIXED
410 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
411 (MREMAP_MAYMOVE | MREMAP_FIXED))
412 tprintf(", %#lx", tcp->u_arg[4]);
413#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000414 }
415 return RVAL_HEX;
416}
417
Roland McGrathf4021b12008-08-25 02:59:36 +0000418static const struct xlat madvise_cmds[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000419#ifdef MADV_NORMAL
420 { MADV_NORMAL, "MADV_NORMAL" },
421#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000422#ifdef MADV_RANDOM
Wichert Akkermanc7926982000-04-10 22:22:31 +0000423 { MADV_RANDOM, "MADV_RANDOM" },
424#endif
425#ifdef MADV_SEQUENTIAL
426 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
427#endif
428#ifdef MADV_WILLNEED
429 { MADV_WILLNEED, "MADV_WILLNEED" },
430#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000431#ifdef MADV_DONTNEED
Wichert Akkermanc7926982000-04-10 22:22:31 +0000432 { MADV_DONTNEED, "MADV_DONTNEED" },
433#endif
434 { 0, NULL },
435};
436
437
438int
Denys Vlasenko12014262011-05-30 14:00:14 +0200439sys_madvise(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000440{
441 if (entering(tcp)) {
442 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000443 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000444 }
445 return 0;
446}
447
448
Roland McGrathd9f816f2004-09-04 03:39:20 +0000449static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000450#ifdef MCL_CURRENT
451 { MCL_CURRENT, "MCL_CURRENT" },
452#endif
453#ifdef MCL_FUTURE
454 { MCL_FUTURE, "MCL_FUTURE" },
455#endif
456 { 0, NULL}
457};
458
459int
Denys Vlasenko12014262011-05-30 14:00:14 +0200460sys_mlockall(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000461{
462 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000463 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000464 }
465 return 0;
466}
467
468
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000469
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000470#ifdef MS_ASYNC
471
Roland McGrathd9f816f2004-09-04 03:39:20 +0000472static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000473#ifdef MS_SYNC
474 { MS_SYNC, "MS_SYNC" },
475#endif
John Hughesaca07f32001-10-16 18:12:27 +0000476 { MS_ASYNC, "MS_ASYNC" },
477 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000478 { 0, NULL },
479};
480
481int
Denys Vlasenko12014262011-05-30 14:00:14 +0200482sys_msync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000483{
484 if (entering(tcp)) {
485 /* addr */
486 tprintf("%#lx", tcp->u_arg[0]);
487 /* len */
488 tprintf(", %lu, ", tcp->u_arg[1]);
489 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000490 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491 }
492 return 0;
493}
494
495#endif /* MS_ASYNC */
496
497#ifdef MC_SYNC
498
Roland McGrathd9f816f2004-09-04 03:39:20 +0000499static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000500 { MC_LOCK, "MC_LOCK" },
501 { MC_LOCKAS, "MC_LOCKAS" },
502 { MC_SYNC, "MC_SYNC" },
503 { MC_UNLOCK, "MC_UNLOCK" },
504 { MC_UNLOCKAS, "MC_UNLOCKAS" },
505 { 0, NULL },
506};
507
Roland McGrathd9f816f2004-09-04 03:39:20 +0000508static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509 { MCL_CURRENT, "MCL_CURRENT" },
510 { MCL_FUTURE, "MCL_FUTURE" },
511 { 0, NULL },
512};
513
514int
Denys Vlasenko12014262011-05-30 14:00:14 +0200515sys_mctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000516{
517 int arg, function;
518
519 if (entering(tcp)) {
520 /* addr */
521 tprintf("%#lx", tcp->u_arg[0]);
522 /* len */
523 tprintf(", %lu, ", tcp->u_arg[1]);
524 /* function */
525 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000526 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527 /* arg */
528 arg = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200529 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530 switch (function) {
531 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000532 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533 break;
534 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000535 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536 break;
537 default:
538 tprintf("%#x", arg);
539 break;
540 }
541 }
542 return 0;
543}
544
545#endif /* MC_SYNC */
546
547int
Denys Vlasenko12014262011-05-30 14:00:14 +0200548sys_mincore(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550 if (entering(tcp)) {
551 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
552 } else {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200553 unsigned long i, len;
554 char *vec = NULL;
555
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000556 len = tcp->u_arg[1];
557 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000558 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
560 tprintf("%#lx", tcp->u_arg[2]);
561 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200562 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000563 for (i = 0; i < len; i++) {
564 if (abbrev(tcp) && i >= max_strlen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200565 tprints("...");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566 break;
567 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200568 tprints((vec[i] & 1) ? "1" : "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000569 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200570 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200572 free(vec);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573 }
574 return 0;
575}
576
Roland McGrathda6c92c2007-09-12 01:26:29 +0000577#if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578int
Denys Vlasenko12014262011-05-30 14:00:14 +0200579sys_getpagesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580{
581 if (exiting(tcp))
582 return RVAL_HEX;
583 return 0;
584}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000585#endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586
587#if defined(LINUX) && defined(__i386__)
Roland McGrath909875b2002-12-22 03:34:36 +0000588void
Denys Vlasenko1f458252009-01-23 16:10:22 +0000589print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
Roland McGrath34e4a692002-12-15 23:58:17 +0000590{
591 tprintf("base_addr:%#08lx, "
592 "limit:%d, "
593 "seg_32bit:%d, "
594 "contents:%d, "
595 "read_exec_only:%d, "
596 "limit_in_pages:%d, "
597 "seg_not_present:%d, "
598 "useable:%d}",
Denys Vlasenko1f458252009-01-23 16:10:22 +0000599 (long) ldt_entry->base_addr,
Roland McGrath34e4a692002-12-15 23:58:17 +0000600 ldt_entry->limit,
601 ldt_entry->seg_32bit,
602 ldt_entry->contents,
603 ldt_entry->read_exec_only,
604 ldt_entry->limit_in_pages,
605 ldt_entry->seg_not_present,
606 ldt_entry->useable);
607}
608
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000609int
Denys Vlasenko12014262011-05-30 14:00:14 +0200610sys_modify_ldt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000611{
612 if (entering(tcp)) {
613 struct modify_ldt_ldt_s copy;
614 tprintf("%ld", tcp->u_arg[0]);
615 if (tcp->u_arg[1] == 0
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200616 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000617 || umove(tcp, tcp->u_arg[1], &copy) == -1)
618 tprintf(", %lx", tcp->u_arg[1]);
619 else {
620 tprintf(", {entry_number:%d, ", copy.entry_number);
621 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200622 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000623 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000624 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000625 }
626 }
627 tprintf(", %lu", tcp->u_arg[2]);
628 }
629 return 0;
630}
Roland McGrath34e4a692002-12-15 23:58:17 +0000631
632int
Denys Vlasenko12014262011-05-30 14:00:14 +0200633sys_set_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000634{
635 struct modify_ldt_ldt_s copy;
636 if (entering(tcp)) {
637 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
638 if (copy.entry_number == -1)
639 tprintf("{entry_number:%d -> ",
640 copy.entry_number);
641 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200642 tprints("{entry_number:");
Roland McGrath34e4a692002-12-15 23:58:17 +0000643 }
644 } else {
645 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
646 tprintf("%d, ", copy.entry_number);
647 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200648 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000649 else {
650 print_ldt_entry(&copy);
651 }
652 } else {
653 tprintf("%lx", tcp->u_arg[0]);
654 }
655 }
656 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000657
Roland McGrath34e4a692002-12-15 23:58:17 +0000658}
659
660int
Denys Vlasenko12014262011-05-30 14:00:14 +0200661sys_get_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000662{
663 struct modify_ldt_ldt_s copy;
664 if (exiting(tcp)) {
665 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
666 tprintf("{entry_number:%d, ", copy.entry_number);
667 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200668 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000669 else {
670 print_ldt_entry(&copy);
671 }
672 } else {
673 tprintf("%lx", tcp->u_arg[0]);
674 }
675 }
676 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000677
Roland McGrath34e4a692002-12-15 23:58:17 +0000678}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000679#endif /* LINUX && __i386__ */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000680
Andreas Schwab58743222010-05-28 22:28:51 +0200681#if defined(LINUX) && defined(M68K)
682
683int
Denys Vlasenko12014262011-05-30 14:00:14 +0200684sys_set_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200685{
686 if (entering(tcp))
687 tprintf("%#lx", tcp->u_arg[0]);
688 return 0;
689
690}
691
692int
Denys Vlasenko12014262011-05-30 14:00:14 +0200693sys_get_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200694{
695 return RVAL_HEX;
696}
697#endif
698
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000699int
Denys Vlasenko12014262011-05-30 14:00:14 +0200700sys_remap_file_pages(struct tcb *tcp)
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000701{
702 if (entering(tcp)) {
703 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000704 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000705 tprintf(", %lu, ", tcp->u_arg[3]);
706#ifdef MAP_TYPE
707 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
708 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
709#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000710 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000711#endif
712 }
713 return 0;
714}
Roland McGrathb10a3352004-10-07 18:53:12 +0000715
716
717#define MPOL_DEFAULT 0
718#define MPOL_PREFERRED 1
719#define MPOL_BIND 2
720#define MPOL_INTERLEAVE 3
721
722#define MPOL_F_NODE (1<<0)
723#define MPOL_F_ADDR (1<<1)
724
725#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000726#define MPOL_MF_MOVE (1<<1)
727#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000728
729
730static const struct xlat policies[] = {
731 { MPOL_DEFAULT, "MPOL_DEFAULT" },
732 { MPOL_PREFERRED, "MPOL_PREFERRED" },
733 { MPOL_BIND, "MPOL_BIND" },
734 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
735 { 0, NULL }
736};
737
738static const struct xlat mbindflags[] = {
739 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000740 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
741 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
Roland McGrathb10a3352004-10-07 18:53:12 +0000742 { 0, NULL }
743};
744
745static const struct xlat mempolicyflags[] = {
746 { MPOL_F_NODE, "MPOL_F_NODE" },
747 { MPOL_F_ADDR, "MPOL_F_ADDR" },
748 { 0, NULL }
749};
750
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000751static const struct xlat move_pages_flags[] = {
752 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
753 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
754 { 0, NULL }
755};
756
Roland McGrathb10a3352004-10-07 18:53:12 +0000757
758static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200759get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
Roland McGrathb10a3352004-10-07 18:53:12 +0000760{
Roland McGrathaa524c82005-06-01 19:22:06 +0000761 unsigned long nlongs, size, end;
762
763 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
764 size = nlongs * sizeof(long);
765 end = ptr + size;
766 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
767 && (end > ptr))) {
768 unsigned long n, cur, abbrev_end;
769 int failed = 0;
770
771 if (abbrev(tcp)) {
772 abbrev_end = ptr + max_strlen * sizeof(long);
773 if (abbrev_end < ptr)
774 abbrev_end = end;
775 } else {
776 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000777 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200778 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000779 for (cur = ptr; cur < end; cur += sizeof(long)) {
780 if (cur > ptr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200781 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000782 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200783 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000784 break;
785 }
786 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200787 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000788 failed = 1;
789 break;
790 }
791 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
792 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200793 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000794 if (failed)
795 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000796 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000797 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000798 tprintf(", %lu", maxnodes);
799}
800
801int
Denys Vlasenko12014262011-05-30 14:00:14 +0200802sys_mbind(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000803{
804 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000805 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000806 printxval(policies, tcp->u_arg[2], "MPOL_???");
807 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200808 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000809 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000810 }
811 return 0;
812}
813
814int
Denys Vlasenko12014262011-05-30 14:00:14 +0200815sys_set_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000816{
817 if (entering(tcp)) {
818 printxval(policies, tcp->u_arg[0], "MPOL_???");
819 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
820 }
821 return 0;
822}
823
824int
Denys Vlasenko12014262011-05-30 14:00:14 +0200825sys_get_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000826{
827 if (exiting(tcp)) {
828 int pol;
829 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200830 tprints("NULL");
Roland McGrathb10a3352004-10-07 18:53:12 +0000831 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
832 tprintf("%#lx", tcp->u_arg[0]);
833 else
834 printxval(policies, pol, "MPOL_???");
835 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
836 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000837 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000838 }
839 return 0;
840}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000841
842int
Denys Vlasenko12014262011-05-30 14:00:14 +0200843sys_move_pages(struct tcb *tcp)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000844{
845 if (entering(tcp)) {
846 unsigned long npages = tcp->u_arg[1];
847 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
848 if (tcp->u_arg[2] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200849 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000850 else {
851 int i;
852 long puser = tcp->u_arg[2];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200853 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000854 for (i = 0; i < npages; ++i) {
855 void *p;
856 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200857 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000858 if (umove(tcp, puser, &p) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200859 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000860 break;
861 }
862 tprintf("%p", p);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200863 puser += sizeof(void *);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000864 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200865 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000866 }
867 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200868 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000869 else {
870 int i;
871 long nodeuser = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200872 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000873 for (i = 0; i < npages; ++i) {
874 int node;
875 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200876 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000877 if (umove(tcp, nodeuser, &node) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200878 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000879 break;
880 }
881 tprintf("%#x", node);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200882 nodeuser += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000883 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200884 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000885 }
886 }
887 if (exiting(tcp)) {
888 unsigned long npages = tcp->u_arg[1];
889 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200890 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000891 else {
892 int i;
893 long statususer = tcp->u_arg[4];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200894 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000895 for (i = 0; i < npages; ++i) {
896 int status;
897 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200898 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000899 if (umove(tcp, statususer, &status) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200900 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000901 break;
902 }
903 tprintf("%#x", status);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200904 statususer += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000905 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200906 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000907 }
908 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
909 }
910 return 0;
911}
Roland McGrath4a6f6522008-08-25 03:09:16 +0000912
913#if defined(LINUX) && defined(POWERPC)
914int
Denys Vlasenko12014262011-05-30 14:00:14 +0200915sys_subpage_prot(struct tcb *tcp)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000916{
917 if (entering(tcp)) {
918 unsigned long cur, end, abbrev_end, entries;
919 unsigned int entry;
920
921 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
922 entries = tcp->u_arg[1] >> 16;
923 if (!entries || !tcp->u_arg[2]) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200924 tprints("{}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000925 return 0;
926 }
927 cur = tcp->u_arg[2];
928 end = cur + (sizeof(int) * entries);
929 if (!verbose(tcp) || end < tcp->u_arg[2]) {
930 tprintf("%#lx", tcp->u_arg[2]);
931 return 0;
932 }
933 if (abbrev(tcp)) {
934 abbrev_end = cur + (sizeof(int) * max_strlen);
935 if (abbrev_end > end)
936 abbrev_end = end;
937 }
938 else
939 abbrev_end = end;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200940 tprints("{");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000941 for (; cur < end; cur += sizeof(int)) {
942 if (cur > tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200943 tprints(", ");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000944 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200945 tprints("...");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000946 break;
947 }
948 if (umove(tcp, cur, &entry) < 0) {
949 tprintf("??? [%#lx]", cur);
950 break;
951 }
952 else
953 tprintf("%#08x", entry);
954 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200955 tprints("}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000956 }
957
958 return 0;
959}
960#endif