blob: 6ecd363c82ad8fdc5bdb16371a1aee5b35e944d4 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Roland McGrathe1e584b2003-06-02 19:18:58 +00006 * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
7 * port by Greg Banks <gbanks@pocketpenguins.com>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00008 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000031 */
32
33#include "defs.h"
Roland McGrath05cdd3c2004-03-02 06:16:59 +000034#include <asm/mman.h>
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000035#include <sys/mman.h>
Denys Vlasenko1ba85432013-02-19 11:28:20 +010036
Dmitry V. Levinc76a3632013-03-05 14:58:24 +000037static unsigned long
38get_pagesize()
39{
40 static unsigned long pagesize;
41
42 if (!pagesize)
43 pagesize = sysconf(_SC_PAGESIZE);
44 return pagesize;
45}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046
47int
Denys Vlasenko12014262011-05-30 14:00:14 +020048sys_brk(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000049{
50 if (entering(tcp)) {
51 tprintf("%#lx", tcp->u_arg[0]);
52 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053 return RVAL_HEX;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054}
55
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000056#include "xlat/mmap_prot.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000057#include "xlat/mmap_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058
Dmitry V. Levin31382132011-03-04 05:08:02 +030059static int
Denys Vlasenko923255c2013-02-18 02:36:36 +010060print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000061{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000062 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000063 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +000064 if (!u_arg[0])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020065 tprints("NULL, ");
Wichert Akkerman8829a551999-06-11 13:18:40 +000066 else
67 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000068 /* len */
69 tprintf("%lu, ", u_arg[1]);
70 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +000071 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020072 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000074#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000075 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
76 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000077#else
Roland McGrathb2dee132005-06-01 19:02:36 +000078 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000079#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020080 tprints(", ");
Denys Vlasenko923255c2013-02-18 02:36:36 +010081 /* fd */
Dmitry V. Levin31382132011-03-04 05:08:02 +030082 printfd(tcp, u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000083 /* offset */
Dmitry V. Levin31382132011-03-04 05:08:02 +030084 tprintf(", %#llx", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000085 }
86 return RVAL_HEX;
87}
88
Denys Vlasenko1ba85432013-02-19 11:28:20 +010089/* Syscall name<->function correspondence is messed up on many arches.
90 * For example:
91 * i386 has __NR_mmap == 90, and it is "old mmap", and
92 * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
93 * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
94 * Confused? Me too!
95 */
96
97/* Params are pointed to by u_arg[0], offset is in bytes */
98int
99sys_old_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000100{
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100101 long u_arg[6];
Denys Vlasenko72a58482011-08-19 16:01:51 +0200102#if defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000103 /*
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200104 * IA64 processes never call this routine, they only use the
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100105 * new 'sys_mmap' interface. Only IA32 processes come here.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000106 */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200107 int i;
Denys Vlasenko923255c2013-02-18 02:36:36 +0100108 unsigned narrow_arg[6];
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200109 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
110 return 0;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000111 for (i = 0; i < 6; i++)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100112 u_arg[i] = (unsigned long) narrow_arg[i];
Denys Vlasenko923255c2013-02-18 02:36:36 +0100113#elif defined(X86_64)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100114 /* We are here only in personality 1 (i386) */
115 int i;
116 unsigned narrow_arg[6];
117 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
118 return 0;
119 for (i = 0; i < 6; ++i)
120 u_arg[i] = (unsigned long) narrow_arg[i];
Denys Vlasenko923255c2013-02-18 02:36:36 +0100121#else
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200122 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000123 return 0;
Denys Vlasenko923255c2013-02-18 02:36:36 +0100124#endif
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100125 return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000126}
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000127
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100128#if defined(S390)
129/* Params are pointed to by u_arg[0], offset is in pages */
130int
131sys_old_mmap_pgoff(struct tcb *tcp)
132{
133 long u_arg[5];
134 int i;
135 unsigned narrow_arg[6];
136 unsigned long long offset;
137 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
138 return 0;
139 for (i = 0; i < 5; i++)
140 u_arg[i] = (unsigned long) narrow_arg[i];
141 offset = narrow_arg[5];
Dmitry V. Levinc76a3632013-03-05 14:58:24 +0000142 offset *= get_pagesize();
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100143 return print_mmap(tcp, u_arg, offset);
144}
145#endif
146
147/* Params are passed directly, offset is in bytes */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000148int
Denys Vlasenko12014262011-05-30 14:00:14 +0200149sys_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000150{
Denys Vlasenko8dedb0d2013-02-18 03:13:07 +0100151 unsigned long long offset = (unsigned long) tcp->u_arg[5];
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100152#if defined(LINUX_MIPSN32) || defined(X32)
Denys Vlasenko8dedb0d2013-02-18 03:13:07 +0100153 /* Try test/x32_mmap.c */
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000154 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000155#endif
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100156 /* Example of kernel-side handling of this variety of mmap:
157 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
158 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
159 * since the above code converts off to pages.
160 */
161 return print_mmap(tcp, tcp->u_arg, offset);
162}
163
164/* Params are passed directly, offset is in pages */
165int
166sys_mmap_pgoff(struct tcb *tcp)
167{
168 /* Try test/mmap_offset_decode.c */
169 unsigned long long offset;
170 offset = (unsigned long) tcp->u_arg[5];
Dmitry V. Levinc76a3632013-03-05 14:58:24 +0000171 offset *= get_pagesize();
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100172 return print_mmap(tcp, tcp->u_arg, offset);
173}
174
175/* Params are passed directly, offset is in 4k units */
176int
177sys_mmap_4koff(struct tcb *tcp)
178{
179 unsigned long long offset;
180 offset = (unsigned long) tcp->u_arg[5];
181 offset <<= 12;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000182 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000183}
184
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185int
Denys Vlasenko12014262011-05-30 14:00:14 +0200186sys_munmap(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000187{
188 if (entering(tcp)) {
189 tprintf("%#lx, %lu",
190 tcp->u_arg[0], tcp->u_arg[1]);
191 }
192 return 0;
193}
194
195int
Denys Vlasenko12014262011-05-30 14:00:14 +0200196sys_mprotect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000197{
198 if (entering(tcp)) {
199 tprintf("%#lx, %lu, ",
200 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000201 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000202 }
203 return 0;
204}
205
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000206#include "xlat/mremap_flags.h"
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000207
208int
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000209sys_mremap(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000210{
211 if (entering(tcp)) {
212 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
213 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000214 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000215#ifdef MREMAP_FIXED
216 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
217 (MREMAP_MAYMOVE | MREMAP_FIXED))
218 tprintf(", %#lx", tcp->u_arg[4]);
219#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000220 }
221 return RVAL_HEX;
222}
223
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000224#include "xlat/madvise_cmds.h"
Wichert Akkermanc7926982000-04-10 22:22:31 +0000225
Wichert Akkermanc7926982000-04-10 22:22:31 +0000226int
Denys Vlasenko12014262011-05-30 14:00:14 +0200227sys_madvise(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000228{
229 if (entering(tcp)) {
230 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000231 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000232 }
233 return 0;
234}
235
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000236#include "xlat/mlockall_flags.h"
Wichert Akkermanc7926982000-04-10 22:22:31 +0000237
238int
Denys Vlasenko12014262011-05-30 14:00:14 +0200239sys_mlockall(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000240{
241 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000242 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000243 }
244 return 0;
245}
246
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000247#ifdef MS_ASYNC
248
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000249#include "xlat/mctl_sync.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000250
251int
Denys Vlasenko12014262011-05-30 14:00:14 +0200252sys_msync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000253{
254 if (entering(tcp)) {
255 /* addr */
256 tprintf("%#lx", tcp->u_arg[0]);
257 /* len */
258 tprintf(", %lu, ", tcp->u_arg[1]);
259 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000260 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261 }
262 return 0;
263}
264
265#endif /* MS_ASYNC */
266
267#ifdef MC_SYNC
268
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000269#include "xlat/mctl_funcs.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000270#include "xlat/mctl_lockas.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000271
272int
Denys Vlasenko12014262011-05-30 14:00:14 +0200273sys_mctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274{
275 int arg, function;
276
277 if (entering(tcp)) {
278 /* addr */
279 tprintf("%#lx", tcp->u_arg[0]);
280 /* len */
281 tprintf(", %lu, ", tcp->u_arg[1]);
282 /* function */
283 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000284 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000285 /* arg */
286 arg = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200287 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000288 switch (function) {
289 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000290 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291 break;
292 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000293 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000294 break;
295 default:
296 tprintf("%#x", arg);
297 break;
298 }
299 }
300 return 0;
301}
302
303#endif /* MC_SYNC */
304
305int
Denys Vlasenko12014262011-05-30 14:00:14 +0200306sys_mincore(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000307{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000308 if (entering(tcp)) {
309 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
310 } else {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200311 unsigned long i, len;
312 char *vec = NULL;
313
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000314 len = tcp->u_arg[1];
315 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000316 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
318 tprintf("%#lx", tcp->u_arg[2]);
319 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200320 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321 for (i = 0; i < len; i++) {
322 if (abbrev(tcp) && i >= max_strlen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200323 tprints("...");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324 break;
325 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200326 tprints((vec[i] & 1) ? "1" : "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000327 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200328 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000329 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200330 free(vec);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331 }
332 return 0;
333}
334
Denys Vlasenko84703742012-02-25 02:38:52 +0100335#if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000336int
Denys Vlasenko12014262011-05-30 14:00:14 +0200337sys_getpagesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338{
339 if (exiting(tcp))
340 return RVAL_HEX;
341 return 0;
342}
Denys Vlasenko84703742012-02-25 02:38:52 +0100343#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000345int
Denys Vlasenko12014262011-05-30 14:00:14 +0200346sys_remap_file_pages(struct tcb *tcp)
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000347{
348 if (entering(tcp)) {
349 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000350 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000351 tprintf(", %lu, ", tcp->u_arg[3]);
352#ifdef MAP_TYPE
353 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
354 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
355#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000356 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000357#endif
358 }
359 return 0;
360}
Roland McGrathb10a3352004-10-07 18:53:12 +0000361
Roland McGrathb10a3352004-10-07 18:53:12 +0000362#define MPOL_DEFAULT 0
363#define MPOL_PREFERRED 1
364#define MPOL_BIND 2
365#define MPOL_INTERLEAVE 3
366
367#define MPOL_F_NODE (1<<0)
368#define MPOL_F_ADDR (1<<1)
369
370#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000371#define MPOL_MF_MOVE (1<<1)
372#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000373
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000374#include "xlat/policies.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000375#include "xlat/mbindflags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000376#include "xlat/mempolicyflags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000377#include "xlat/move_pages_flags.h"
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000378
Roland McGrathb10a3352004-10-07 18:53:12 +0000379static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200380get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
Roland McGrathb10a3352004-10-07 18:53:12 +0000381{
Roland McGrathaa524c82005-06-01 19:22:06 +0000382 unsigned long nlongs, size, end;
383
384 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
385 size = nlongs * sizeof(long);
386 end = ptr + size;
387 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
388 && (end > ptr))) {
389 unsigned long n, cur, abbrev_end;
390 int failed = 0;
391
392 if (abbrev(tcp)) {
393 abbrev_end = ptr + max_strlen * sizeof(long);
394 if (abbrev_end < ptr)
395 abbrev_end = end;
396 } else {
397 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000398 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200399 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000400 for (cur = ptr; cur < end; cur += sizeof(long)) {
401 if (cur > ptr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200402 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000403 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200404 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000405 break;
406 }
407 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200408 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000409 failed = 1;
410 break;
411 }
412 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
413 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200414 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000415 if (failed)
416 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000417 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000418 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000419 tprintf(", %lu", maxnodes);
420}
421
422int
Denys Vlasenko12014262011-05-30 14:00:14 +0200423sys_mbind(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000424{
425 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000426 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000427 printxval(policies, tcp->u_arg[2], "MPOL_???");
428 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200429 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000430 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000431 }
432 return 0;
433}
434
435int
Denys Vlasenko12014262011-05-30 14:00:14 +0200436sys_set_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000437{
438 if (entering(tcp)) {
439 printxval(policies, tcp->u_arg[0], "MPOL_???");
440 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
441 }
442 return 0;
443}
444
445int
Denys Vlasenko12014262011-05-30 14:00:14 +0200446sys_get_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000447{
448 if (exiting(tcp)) {
449 int pol;
450 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200451 tprints("NULL");
Roland McGrathb10a3352004-10-07 18:53:12 +0000452 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
453 tprintf("%#lx", tcp->u_arg[0]);
454 else
455 printxval(policies, pol, "MPOL_???");
456 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
457 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000458 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000459 }
460 return 0;
461}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000462
463int
Dmitry V. Levin64d0e712012-03-11 22:44:14 +0000464sys_migrate_pages(struct tcb *tcp)
465{
466 if (entering(tcp)) {
467 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
468 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
469 tprints(", ");
470 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
471 }
472 return 0;
473}
474
475int
Denys Vlasenko12014262011-05-30 14:00:14 +0200476sys_move_pages(struct tcb *tcp)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000477{
478 if (entering(tcp)) {
479 unsigned long npages = tcp->u_arg[1];
480 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
481 if (tcp->u_arg[2] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200482 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000483 else {
484 int i;
485 long puser = tcp->u_arg[2];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200486 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000487 for (i = 0; i < npages; ++i) {
488 void *p;
489 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200490 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000491 if (umove(tcp, puser, &p) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200492 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000493 break;
494 }
495 tprintf("%p", p);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200496 puser += sizeof(void *);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000497 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200498 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000499 }
500 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200501 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000502 else {
503 int i;
504 long nodeuser = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200505 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000506 for (i = 0; i < npages; ++i) {
507 int node;
508 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200509 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000510 if (umove(tcp, nodeuser, &node) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200511 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000512 break;
513 }
514 tprintf("%#x", node);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200515 nodeuser += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000516 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200517 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000518 }
519 }
520 if (exiting(tcp)) {
521 unsigned long npages = tcp->u_arg[1];
522 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200523 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000524 else {
525 int i;
526 long statususer = tcp->u_arg[4];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200527 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000528 for (i = 0; i < npages; ++i) {
529 int status;
530 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200531 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000532 if (umove(tcp, statususer, &status) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200533 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000534 break;
535 }
536 tprintf("%#x", status);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200537 statususer += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000538 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200539 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000540 }
541 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
542 }
543 return 0;
544}
Roland McGrath4a6f6522008-08-25 03:09:16 +0000545
Denys Vlasenko84703742012-02-25 02:38:52 +0100546#if defined(POWERPC)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000547int
Denys Vlasenko12014262011-05-30 14:00:14 +0200548sys_subpage_prot(struct tcb *tcp)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000549{
550 if (entering(tcp)) {
551 unsigned long cur, end, abbrev_end, entries;
552 unsigned int entry;
553
554 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
555 entries = tcp->u_arg[1] >> 16;
556 if (!entries || !tcp->u_arg[2]) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200557 tprints("{}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000558 return 0;
559 }
560 cur = tcp->u_arg[2];
561 end = cur + (sizeof(int) * entries);
562 if (!verbose(tcp) || end < tcp->u_arg[2]) {
563 tprintf("%#lx", tcp->u_arg[2]);
564 return 0;
565 }
566 if (abbrev(tcp)) {
567 abbrev_end = cur + (sizeof(int) * max_strlen);
568 if (abbrev_end > end)
569 abbrev_end = end;
570 }
571 else
572 abbrev_end = end;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200573 tprints("{");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000574 for (; cur < end; cur += sizeof(int)) {
575 if (cur > tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200576 tprints(", ");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000577 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200578 tprints("...");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000579 break;
580 }
581 if (umove(tcp, cur, &entry) < 0) {
582 tprintf("??? [%#lx]", cur);
583 break;
584 }
585 else
586 tprintf("%#08x", entry);
587 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200588 tprints("}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000589 }
590
591 return 0;
592}
593#endif