blob: e440e9ff33546b48a7cc87e60c16b91ea11c657a [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
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000037#ifdef LINUX
Roland McGrath05cdd3c2004-03-02 06:16:59 +000038#include <asm/mman.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000039#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000040#include <sys/mman.h>
Wichert Akkerman5daa0281999-03-15 19:49:42 +000041
Roland McGrath909875b2002-12-22 03:34:36 +000042#if defined(LINUX) && defined(I386)
Denys Vlasenko72a58482011-08-19 16:01:51 +020043# include <asm/ldt.h>
Roland McGrath7decfb22004-03-01 22:10:52 +000044# ifdef HAVE_STRUCT_USER_DESC
45# define modify_ldt_ldt_s user_desc
46# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047#endif
Roland McGrathf5a47772003-06-26 22:40:42 +000048#if defined(LINUX) && defined(SH64)
Denys Vlasenko72a58482011-08-19 16:01:51 +020049# include <asm/page.h> /* for PAGE_SHIFT */
Roland McGrathe1e584b2003-06-02 19:18:58 +000050#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051
John Hughes70623be2001-03-08 13:59:00 +000052#ifdef HAVE_LONG_LONG_OFF_T
53/*
54 * Ugly hacks for systems that have a long long off_t
55 */
56#define sys_mmap64 sys_mmap
57#endif
58
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059int
Denys Vlasenko12014262011-05-30 14:00:14 +020060sys_brk(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000061{
62 if (entering(tcp)) {
63 tprintf("%#lx", tcp->u_arg[0]);
64 }
Wichert Akkerman5daa0281999-03-15 19:49:42 +000065#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000066 return RVAL_HEX;
67#else
68 return 0;
69#endif
70}
71
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +000072#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073int
Denys Vlasenko12014262011-05-30 14:00:14 +020074sys_sbrk(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000075{
76 if (entering(tcp)) {
77 tprintf("%lu", tcp->u_arg[0]);
78 }
79 return RVAL_HEX;
80}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +000081#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000082
Roland McGrathd9f816f2004-09-04 03:39:20 +000083static const struct xlat mmap_prot[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084 { PROT_NONE, "PROT_NONE", },
85 { PROT_READ, "PROT_READ" },
86 { PROT_WRITE, "PROT_WRITE" },
87 { PROT_EXEC, "PROT_EXEC" },
Roland McGrath47eb0e22003-09-25 23:06:04 +000088#ifdef PROT_SEM
89 { PROT_SEM, "PROT_SEM" },
90#endif
91#ifdef PROT_GROWSDOWN
92 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
93#endif
94#ifdef PROT_GROWSUP
95 { PROT_GROWSUP, "PROT_GROWSUP" },
96#endif
Roland McGrath586d6ab2008-08-25 03:00:47 +000097#ifdef PROT_SAO
98 { PROT_SAO, "PROT_SAO" },
99#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000100 { 0, NULL },
101};
102
Roland McGrathd9f816f2004-09-04 03:39:20 +0000103static const struct xlat mmap_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000104 { MAP_SHARED, "MAP_SHARED" },
105 { MAP_PRIVATE, "MAP_PRIVATE" },
106 { MAP_FIXED, "MAP_FIXED" },
107#ifdef MAP_ANONYMOUS
108 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
109#endif
Dmitry V. Levin71f1a132007-03-29 23:30:09 +0000110#ifdef MAP_32BIT
111 { MAP_32BIT, "MAP_32BIT" },
112#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000113#ifdef MAP_RENAME
114 { MAP_RENAME, "MAP_RENAME" },
115#endif
116#ifdef MAP_NORESERVE
117 { MAP_NORESERVE,"MAP_NORESERVE" },
118#endif
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000119#ifdef MAP_POPULATE
120 { MAP_POPULATE, "MAP_POPULATE" },
121#endif
122#ifdef MAP_NONBLOCK
123 { MAP_NONBLOCK, "MAP_NONBLOCK" },
124#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000125 /*
126 * XXX - this was introduced in SunOS 4.x to distinguish between
127 * the old pre-4.x "mmap()", which:
128 *
129 * only let you map devices with an "mmap" routine (e.g.,
130 * frame buffers) in;
131 *
132 * required you to specify the mapping address;
133 *
134 * returned 0 on success and -1 on failure;
135 *
136 * memory and which, and the 4.x "mmap()" which:
137 *
138 * can map plain files;
139 *
140 * can be asked to pick where to map the file;
141 *
142 * returns the address where it mapped the file on success
143 * and -1 on failure.
144 *
145 * It's not actually used in source code that calls "mmap()"; the
146 * "mmap()" routine adds it for you.
147 *
148 * It'd be nice to come up with some way of eliminating it from
149 * the flags, e.g. reporting calls *without* it as "old_mmap()"
150 * and calls with it as "mmap()".
151 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000152#ifdef _MAP_NEW
153 { _MAP_NEW, "_MAP_NEW" },
154#endif
155#ifdef MAP_GROWSDOWN
156 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
157#endif
158#ifdef MAP_DENYWRITE
159 { MAP_DENYWRITE,"MAP_DENYWRITE" },
160#endif
161#ifdef MAP_EXECUTABLE
162 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
163#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000164#ifdef MAP_INHERIT
165 { MAP_INHERIT,"MAP_INHERIT" },
166#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000167#ifdef MAP_FILE
168 { MAP_FILE,"MAP_FILE"},
169#endif
170#ifdef MAP_LOCKED
171 { MAP_LOCKED,"MAP_LOCKED"},
172#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000173 /* FreeBSD ones */
174#ifdef MAP_ANON
175 { MAP_ANON, "MAP_ANON" },
176#endif
177#ifdef MAP_HASSEMAPHORE
178 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
179#endif
180#ifdef MAP_STACK
181 { MAP_STACK, "MAP_STACK" },
182#endif
183#ifdef MAP_NOSYNC
184 { MAP_NOSYNC, "MAP_NOSYNC" },
185#endif
186#ifdef MAP_NOCORE
187 { MAP_NOCORE, "MAP_NOCORE" },
188#endif
Chris Metcalfc8c66982009-12-28 10:00:15 -0500189#ifdef TILE
190 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
191 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
192 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
193#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000194 { 0, NULL },
195};
196
Chris Metcalfc8c66982009-12-28 10:00:15 -0500197#ifdef TILE
Denys Vlasenko72a58482011-08-19 16:01:51 +0200198static int
199addtileflags(long flags)
Chris Metcalfc8c66982009-12-28 10:00:15 -0500200{
201 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
202 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
203
204 if (flags & _MAP_CACHE_INCOHERENT) {
205 flags &= ~_MAP_CACHE_INCOHERENT;
206 if (home == MAP_CACHE_HOME_NONE) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200207 tprints("|MAP_CACHE_INCOHERENT");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500208 return flags;
209 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200210 tprints("|_MAP_CACHE_INCOHERENT");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500211 }
212
213 switch (home) {
214 case 0: break;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200215 case MAP_CACHE_HOME_HERE: tprints("|MAP_CACHE_HOME_HERE"); break;
216 case MAP_CACHE_HOME_NONE: tprints("|MAP_CACHE_HOME_NONE"); break;
217 case MAP_CACHE_HOME_SINGLE: tprints("|MAP_CACHE_HOME_SINGLE"); break;
218 case MAP_CACHE_HOME_TASK: tprints("|MAP_CACHE_HOME_TASK"); break;
219 case MAP_CACHE_HOME_HASH: tprints("|MAP_CACHE_HOME_HASH"); break;
Chris Metcalfc8c66982009-12-28 10:00:15 -0500220 default:
221 tprintf("|MAP_CACHE_HOME(%d)",
222 (home >> _MAP_CACHE_HOME_SHIFT) );
223 break;
224 }
225
226 return flags;
227}
228#endif
229
John Hughes70623be2001-03-08 13:59:00 +0000230#if !HAVE_LONG_LONG_OFF_T
Dmitry V. Levin31382132011-03-04 05:08:02 +0300231static int
232print_mmap(struct tcb *tcp, long *u_arg, long long offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000233{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000235 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000236 if (!u_arg[0])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200237 tprints("NULL, ");
Wichert Akkerman8829a551999-06-11 13:18:40 +0000238 else
239 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000240 /* len */
241 tprintf("%lu, ", u_arg[1]);
242 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000243 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200244 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000245 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000246#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000247 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500248#ifdef TILE
249 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
250#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000251 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Chris Metcalfc8c66982009-12-28 10:00:15 -0500252#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000253#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000254 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000255#endif
Dmitry V. Levin31382132011-03-04 05:08:02 +0300256 /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200257 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300258 printfd(tcp, u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000259 /* offset */
Dmitry V. Levin31382132011-03-04 05:08:02 +0300260 tprintf(", %#llx", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261 }
262 return RVAL_HEX;
263}
264
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000265#ifdef LINUX
Denys Vlasenko12014262011-05-30 14:00:14 +0200266int sys_old_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000267{
Denys Vlasenko72a58482011-08-19 16:01:51 +0200268#if defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000269 /*
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200270 * IA64 processes never call this routine, they only use the
271 * new `sys_mmap' interface.
272 * For IA32 processes, this code converts the integer arguments
273 * that they pushed onto the stack, into longs.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000274 *
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200275 * Note that addresses with bit 31 set will be sign extended.
276 * Fortunately, those addresses are not currently being generated
277 * for IA32 processes so it's not a problem.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000278 */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200279 int i;
280 long u_arg[6];
281 int narrow_arg[6];
282 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
283 return 0;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000284 for (i = 0; i < 6; i++)
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200285 u_arg[i] = narrow_arg[i];
Roland McGrathf5a47772003-06-26 22:40:42 +0000286#elif defined(SH) || defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000287 /* SH has always passed the args in registers */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200288 long *u_arg = tcp->u_arg;
Roland McGrath6b1d43e2003-03-31 01:05:01 +0000289#else
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200290 long u_arg[6];
Roland McGrath520e21f2005-07-05 09:50:18 +0000291# if defined(X86_64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000292 if (current_personality == 1) {
293 int i;
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200294 unsigned narrow_arg[6];
295 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
296 return 0;
297 for (i = 0; i < 6; ++i)
298 u_arg[i] = narrow_arg[i];
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000299 }
300 else
Roland McGrath520e21f2005-07-05 09:50:18 +0000301# endif
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200302 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000303 return 0;
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200304#endif /* other architectures */
305
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000306 return print_mmap(tcp, u_arg, u_arg[5]);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000307}
Denys Vlasenko72a58482011-08-19 16:01:51 +0200308#endif /* LINUX */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000309
310int
Denys Vlasenko12014262011-05-30 14:00:14 +0200311sys_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000312{
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000313 long long offset = tcp->u_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000314
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200315 /* FIXME: why only SH64? i386 mmap2 syscall ends up
316 * in this function, but does not convert offset
317 * from pages to bytes. See test/mmap_offset_decode.c
318 * Why SH64 and i386 are handled differently?
319 */
Roland McGrathf5a47772003-06-26 22:40:42 +0000320#if defined(LINUX) && defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000321 /*
322 * Old mmap differs from new mmap in specifying the
323 * offset in units of bytes rather than pages. We
324 * pretend it's in byte units so the user only ever
325 * sees bytes in the printout.
326 */
327 offset <<= PAGE_SHIFT;
Roland McGrathe1e584b2003-06-02 19:18:58 +0000328#endif
Roland McGrath542c2c62008-05-20 01:11:56 +0000329#if defined(LINUX_MIPSN32)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000330 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000331#endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000332 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000333}
John Hughes70623be2001-03-08 13:59:00 +0000334#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000335
John Hughes70623be2001-03-08 13:59:00 +0000336#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200337/* TODO: comment which arches use this routine.
338 * For one, does ALPHA on Linux use this??
339 * From code it seems that it might use 7 or 8 registers,
340 * which is strange - Linux syscalls can pass maximum of 6 parameters!
341 */
John Hughesbdf48f52001-03-06 15:08:09 +0000342int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300343sys_mmap64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000344{
John Hughesbdf48f52001-03-06 15:08:09 +0000345 if (entering(tcp)) {
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200346#if !defined(LINUX) || defined(ALPHA)
347 long *u_arg = tcp->u_arg;
348#else
349 long u_arg[7];
John Hughesbdf48f52001-03-06 15:08:09 +0000350 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
351 (char *) u_arg) == -1)
352 return 0;
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200353#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000354 /* addr */
355 tprintf("%#lx, ", u_arg[0]);
356 /* len */
357 tprintf("%lu, ", u_arg[1]);
358 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000359 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200360 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000361 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000362#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000363 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
364 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000365#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000366 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000367#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000368 /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200369 tprints(", ");
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200370 printfd(tcp, u_arg[4]);
John Hughesbdf48f52001-03-06 15:08:09 +0000371 /* offset */
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200372#if !defined(LINUX) || defined(ALPHA)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300373 printllval(tcp, ", %#llx", 5);
Denys Vlasenkod5e66c42011-08-23 17:51:58 +0200374#else
375 /* NOTE: not verified that [5] and [6] should be used.
376 * It's possible that long long is 64-bit aligned in memory
377 * and we need to use [6] and [7] here instead:
378 */
379 tprintf(", %#llx", LONG_LONG(u_arg[5], u_arg[6]));
380#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000381 }
382 return RVAL_HEX;
383}
Denys Vlasenko31f9cb62011-08-19 16:11:07 +0200384#endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */
John Hughesbdf48f52001-03-06 15:08:09 +0000385
Roland McGrath909875b2002-12-22 03:34:36 +0000386
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387int
Denys Vlasenko12014262011-05-30 14:00:14 +0200388sys_munmap(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000389{
390 if (entering(tcp)) {
391 tprintf("%#lx, %lu",
392 tcp->u_arg[0], tcp->u_arg[1]);
393 }
394 return 0;
395}
396
397int
Denys Vlasenko12014262011-05-30 14:00:14 +0200398sys_mprotect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399{
400 if (entering(tcp)) {
401 tprintf("%#lx, %lu, ",
402 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000403 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000404 }
405 return 0;
406}
407
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000408#ifdef LINUX
409
Roland McGrathd9f816f2004-09-04 03:39:20 +0000410static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000411 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
Chris Metcalfff3474a2009-12-24 23:19:19 +0000412#ifdef MREMAP_FIXED
413 { MREMAP_FIXED, "MREMAP_FIXED" },
414#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000415 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000416};
417
418int
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000419sys_mremap(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000420{
421 if (entering(tcp)) {
422 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
423 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000424 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000425#ifdef MREMAP_FIXED
426 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
427 (MREMAP_MAYMOVE | MREMAP_FIXED))
428 tprintf(", %#lx", tcp->u_arg[4]);
429#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000430 }
431 return RVAL_HEX;
432}
433
Roland McGrathf4021b12008-08-25 02:59:36 +0000434static const struct xlat madvise_cmds[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000435#ifdef MADV_NORMAL
436 { MADV_NORMAL, "MADV_NORMAL" },
437#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000438#ifdef MADV_RANDOM
Wichert Akkermanc7926982000-04-10 22:22:31 +0000439 { MADV_RANDOM, "MADV_RANDOM" },
440#endif
441#ifdef MADV_SEQUENTIAL
442 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
443#endif
444#ifdef MADV_WILLNEED
445 { MADV_WILLNEED, "MADV_WILLNEED" },
446#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000447#ifdef MADV_DONTNEED
Wichert Akkermanc7926982000-04-10 22:22:31 +0000448 { MADV_DONTNEED, "MADV_DONTNEED" },
449#endif
450 { 0, NULL },
451};
452
453
454int
Denys Vlasenko12014262011-05-30 14:00:14 +0200455sys_madvise(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000456{
457 if (entering(tcp)) {
458 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000459 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000460 }
461 return 0;
462}
463
464
Roland McGrathd9f816f2004-09-04 03:39:20 +0000465static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000466#ifdef MCL_CURRENT
467 { MCL_CURRENT, "MCL_CURRENT" },
468#endif
469#ifdef MCL_FUTURE
470 { MCL_FUTURE, "MCL_FUTURE" },
471#endif
472 { 0, NULL}
473};
474
475int
Denys Vlasenko12014262011-05-30 14:00:14 +0200476sys_mlockall(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000477{
478 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000479 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000480 }
481 return 0;
482}
483
484
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000485#endif /* LINUX */
486
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000487#ifdef MS_ASYNC
488
Roland McGrathd9f816f2004-09-04 03:39:20 +0000489static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000490#ifdef MS_SYNC
491 { MS_SYNC, "MS_SYNC" },
492#endif
John Hughesaca07f32001-10-16 18:12:27 +0000493 { MS_ASYNC, "MS_ASYNC" },
494 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000495 { 0, NULL },
496};
497
498int
Denys Vlasenko12014262011-05-30 14:00:14 +0200499sys_msync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000500{
501 if (entering(tcp)) {
502 /* addr */
503 tprintf("%#lx", tcp->u_arg[0]);
504 /* len */
505 tprintf(", %lu, ", tcp->u_arg[1]);
506 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000507 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508 }
509 return 0;
510}
511
512#endif /* MS_ASYNC */
513
514#ifdef MC_SYNC
515
Roland McGrathd9f816f2004-09-04 03:39:20 +0000516static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517 { MC_LOCK, "MC_LOCK" },
518 { MC_LOCKAS, "MC_LOCKAS" },
519 { MC_SYNC, "MC_SYNC" },
520 { MC_UNLOCK, "MC_UNLOCK" },
521 { MC_UNLOCKAS, "MC_UNLOCKAS" },
522 { 0, NULL },
523};
524
Roland McGrathd9f816f2004-09-04 03:39:20 +0000525static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526 { MCL_CURRENT, "MCL_CURRENT" },
527 { MCL_FUTURE, "MCL_FUTURE" },
528 { 0, NULL },
529};
530
531int
Denys Vlasenko12014262011-05-30 14:00:14 +0200532sys_mctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533{
534 int arg, function;
535
536 if (entering(tcp)) {
537 /* addr */
538 tprintf("%#lx", tcp->u_arg[0]);
539 /* len */
540 tprintf(", %lu, ", tcp->u_arg[1]);
541 /* function */
542 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000543 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544 /* arg */
545 arg = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200546 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547 switch (function) {
548 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000549 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550 break;
551 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000552 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000553 break;
554 default:
555 tprintf("%#x", arg);
556 break;
557 }
558 }
559 return 0;
560}
561
562#endif /* MC_SYNC */
563
564int
Denys Vlasenko12014262011-05-30 14:00:14 +0200565sys_mincore(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567 if (entering(tcp)) {
568 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
569 } else {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200570 unsigned long i, len;
571 char *vec = NULL;
572
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573 len = tcp->u_arg[1];
574 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000575 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000576 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
577 tprintf("%#lx", tcp->u_arg[2]);
578 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200579 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580 for (i = 0; i < len; i++) {
581 if (abbrev(tcp) && i >= max_strlen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200582 tprints("...");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000583 break;
584 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200585 tprints((vec[i] & 1) ? "1" : "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200587 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000588 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200589 free(vec);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590 }
591 return 0;
592}
593
Roland McGrathda6c92c2007-09-12 01:26:29 +0000594#if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000595int
Denys Vlasenko12014262011-05-30 14:00:14 +0200596sys_getpagesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000597{
598 if (exiting(tcp))
599 return RVAL_HEX;
600 return 0;
601}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000602#endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000603
604#if defined(LINUX) && defined(__i386__)
Roland McGrath909875b2002-12-22 03:34:36 +0000605void
Denys Vlasenko1f458252009-01-23 16:10:22 +0000606print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
Roland McGrath34e4a692002-12-15 23:58:17 +0000607{
608 tprintf("base_addr:%#08lx, "
609 "limit:%d, "
610 "seg_32bit:%d, "
611 "contents:%d, "
612 "read_exec_only:%d, "
613 "limit_in_pages:%d, "
614 "seg_not_present:%d, "
615 "useable:%d}",
Denys Vlasenko1f458252009-01-23 16:10:22 +0000616 (long) ldt_entry->base_addr,
Roland McGrath34e4a692002-12-15 23:58:17 +0000617 ldt_entry->limit,
618 ldt_entry->seg_32bit,
619 ldt_entry->contents,
620 ldt_entry->read_exec_only,
621 ldt_entry->limit_in_pages,
622 ldt_entry->seg_not_present,
623 ldt_entry->useable);
624}
625
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626int
Denys Vlasenko12014262011-05-30 14:00:14 +0200627sys_modify_ldt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000628{
629 if (entering(tcp)) {
630 struct modify_ldt_ldt_s copy;
631 tprintf("%ld", tcp->u_arg[0]);
632 if (tcp->u_arg[1] == 0
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200633 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000634 || umove(tcp, tcp->u_arg[1], &copy) == -1)
635 tprintf(", %lx", tcp->u_arg[1]);
636 else {
637 tprintf(", {entry_number:%d, ", copy.entry_number);
638 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200639 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000641 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642 }
643 }
644 tprintf(", %lu", tcp->u_arg[2]);
645 }
646 return 0;
647}
Roland McGrath34e4a692002-12-15 23:58:17 +0000648
649int
Denys Vlasenko12014262011-05-30 14:00:14 +0200650sys_set_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000651{
652 struct modify_ldt_ldt_s copy;
653 if (entering(tcp)) {
654 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
655 if (copy.entry_number == -1)
656 tprintf("{entry_number:%d -> ",
657 copy.entry_number);
658 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200659 tprints("{entry_number:");
Roland McGrath34e4a692002-12-15 23:58:17 +0000660 }
661 } else {
662 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
663 tprintf("%d, ", copy.entry_number);
664 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200665 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000666 else {
667 print_ldt_entry(&copy);
668 }
669 } else {
670 tprintf("%lx", tcp->u_arg[0]);
671 }
672 }
673 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000674
Roland McGrath34e4a692002-12-15 23:58:17 +0000675}
676
677int
Denys Vlasenko12014262011-05-30 14:00:14 +0200678sys_get_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000679{
680 struct modify_ldt_ldt_s copy;
681 if (exiting(tcp)) {
682 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
683 tprintf("{entry_number:%d, ", copy.entry_number);
684 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200685 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000686 else {
687 print_ldt_entry(&copy);
688 }
689 } else {
690 tprintf("%lx", tcp->u_arg[0]);
691 }
692 }
693 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000694
Roland McGrath34e4a692002-12-15 23:58:17 +0000695}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000696#endif /* LINUX && __i386__ */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000697
Andreas Schwab58743222010-05-28 22:28:51 +0200698#if defined(LINUX) && defined(M68K)
699
700int
Denys Vlasenko12014262011-05-30 14:00:14 +0200701sys_set_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200702{
703 if (entering(tcp))
704 tprintf("%#lx", tcp->u_arg[0]);
705 return 0;
706
707}
708
709int
Denys Vlasenko12014262011-05-30 14:00:14 +0200710sys_get_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200711{
712 return RVAL_HEX;
713}
714#endif
715
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000716#if defined(LINUX)
717int
Denys Vlasenko12014262011-05-30 14:00:14 +0200718sys_remap_file_pages(struct tcb *tcp)
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000719{
720 if (entering(tcp)) {
721 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000722 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000723 tprintf(", %lu, ", tcp->u_arg[3]);
724#ifdef MAP_TYPE
725 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
726 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
727#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000728 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000729#endif
730 }
731 return 0;
732}
Roland McGrathb10a3352004-10-07 18:53:12 +0000733
734
735#define MPOL_DEFAULT 0
736#define MPOL_PREFERRED 1
737#define MPOL_BIND 2
738#define MPOL_INTERLEAVE 3
739
740#define MPOL_F_NODE (1<<0)
741#define MPOL_F_ADDR (1<<1)
742
743#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000744#define MPOL_MF_MOVE (1<<1)
745#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000746
747
748static const struct xlat policies[] = {
749 { MPOL_DEFAULT, "MPOL_DEFAULT" },
750 { MPOL_PREFERRED, "MPOL_PREFERRED" },
751 { MPOL_BIND, "MPOL_BIND" },
752 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
753 { 0, NULL }
754};
755
756static const struct xlat mbindflags[] = {
757 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000758 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
759 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
Roland McGrathb10a3352004-10-07 18:53:12 +0000760 { 0, NULL }
761};
762
763static const struct xlat mempolicyflags[] = {
764 { MPOL_F_NODE, "MPOL_F_NODE" },
765 { MPOL_F_ADDR, "MPOL_F_ADDR" },
766 { 0, NULL }
767};
768
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000769static const struct xlat move_pages_flags[] = {
770 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
771 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
772 { 0, NULL }
773};
774
Roland McGrathb10a3352004-10-07 18:53:12 +0000775
776static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200777get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
Roland McGrathb10a3352004-10-07 18:53:12 +0000778{
Roland McGrathaa524c82005-06-01 19:22:06 +0000779 unsigned long nlongs, size, end;
780
781 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
782 size = nlongs * sizeof(long);
783 end = ptr + size;
784 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
785 && (end > ptr))) {
786 unsigned long n, cur, abbrev_end;
787 int failed = 0;
788
789 if (abbrev(tcp)) {
790 abbrev_end = ptr + max_strlen * sizeof(long);
791 if (abbrev_end < ptr)
792 abbrev_end = end;
793 } else {
794 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000795 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200796 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000797 for (cur = ptr; cur < end; cur += sizeof(long)) {
798 if (cur > ptr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200799 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000800 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200801 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000802 break;
803 }
804 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200805 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000806 failed = 1;
807 break;
808 }
809 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
810 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200811 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000812 if (failed)
813 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000814 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000815 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000816 tprintf(", %lu", maxnodes);
817}
818
819int
Denys Vlasenko12014262011-05-30 14:00:14 +0200820sys_mbind(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000821{
822 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000823 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000824 printxval(policies, tcp->u_arg[2], "MPOL_???");
825 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200826 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000827 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000828 }
829 return 0;
830}
831
832int
Denys Vlasenko12014262011-05-30 14:00:14 +0200833sys_set_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000834{
835 if (entering(tcp)) {
836 printxval(policies, tcp->u_arg[0], "MPOL_???");
837 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
838 }
839 return 0;
840}
841
842int
Denys Vlasenko12014262011-05-30 14:00:14 +0200843sys_get_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000844{
845 if (exiting(tcp)) {
846 int pol;
847 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200848 tprints("NULL");
Roland McGrathb10a3352004-10-07 18:53:12 +0000849 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
850 tprintf("%#lx", tcp->u_arg[0]);
851 else
852 printxval(policies, pol, "MPOL_???");
853 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
854 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000855 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000856 }
857 return 0;
858}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000859
860int
Denys Vlasenko12014262011-05-30 14:00:14 +0200861sys_move_pages(struct tcb *tcp)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000862{
863 if (entering(tcp)) {
864 unsigned long npages = tcp->u_arg[1];
865 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
866 if (tcp->u_arg[2] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200867 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000868 else {
869 int i;
870 long puser = tcp->u_arg[2];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200871 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000872 for (i = 0; i < npages; ++i) {
873 void *p;
874 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200875 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000876 if (umove(tcp, puser, &p) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200877 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000878 break;
879 }
880 tprintf("%p", p);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200881 puser += sizeof(void *);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000882 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200883 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000884 }
885 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200886 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000887 else {
888 int i;
889 long nodeuser = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200890 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000891 for (i = 0; i < npages; ++i) {
892 int node;
893 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200894 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000895 if (umove(tcp, nodeuser, &node) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200896 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000897 break;
898 }
899 tprintf("%#x", node);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200900 nodeuser += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000901 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200902 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000903 }
904 }
905 if (exiting(tcp)) {
906 unsigned long npages = tcp->u_arg[1];
907 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200908 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000909 else {
910 int i;
911 long statususer = tcp->u_arg[4];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200912 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000913 for (i = 0; i < npages; ++i) {
914 int status;
915 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200916 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000917 if (umove(tcp, statususer, &status) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200918 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000919 break;
920 }
921 tprintf("%#x", status);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200922 statususer += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000923 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200924 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000925 }
926 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
927 }
928 return 0;
929}
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000930#endif
Roland McGrath4a6f6522008-08-25 03:09:16 +0000931
932#if defined(LINUX) && defined(POWERPC)
933int
Denys Vlasenko12014262011-05-30 14:00:14 +0200934sys_subpage_prot(struct tcb *tcp)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000935{
936 if (entering(tcp)) {
937 unsigned long cur, end, abbrev_end, entries;
938 unsigned int entry;
939
940 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
941 entries = tcp->u_arg[1] >> 16;
942 if (!entries || !tcp->u_arg[2]) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200943 tprints("{}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000944 return 0;
945 }
946 cur = tcp->u_arg[2];
947 end = cur + (sizeof(int) * entries);
948 if (!verbose(tcp) || end < tcp->u_arg[2]) {
949 tprintf("%#lx", tcp->u_arg[2]);
950 return 0;
951 }
952 if (abbrev(tcp)) {
953 abbrev_end = cur + (sizeof(int) * max_strlen);
954 if (abbrev_end > end)
955 abbrev_end = end;
956 }
957 else
958 abbrev_end = end;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200959 tprints("{");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000960 for (; cur < end; cur += sizeof(int)) {
961 if (cur > tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200962 tprints(", ");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000963 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200964 tprints("...");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000965 break;
966 }
967 if (umove(tcp, cur, &entry) < 0) {
968 tprintf("??? [%#lx]", cur);
969 break;
970 }
971 else
972 tprintf("%#08x", entry);
973 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200974 tprints("}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000975 }
976
977 return 0;
978}
979#endif