blob: 31e51f027ae0900c21c30b542190986d853a3639 [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"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000058#include "xlat/mmap_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059
Dmitry V. Levin31382132011-03-04 05:08:02 +030060static int
Denys Vlasenko923255c2013-02-18 02:36:36 +010061print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000062{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000063 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000064 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +000065 if (!u_arg[0])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020066 tprints("NULL, ");
Wichert Akkerman8829a551999-06-11 13:18:40 +000067 else
68 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000069 /* len */
70 tprintf("%lu, ", u_arg[1]);
71 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +000072 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020073 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000075#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000076 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
77 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000078#else
Roland McGrathb2dee132005-06-01 19:02:36 +000079 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000080#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020081 tprints(", ");
Denys Vlasenko923255c2013-02-18 02:36:36 +010082 /* fd */
Dmitry V. Levin31382132011-03-04 05:08:02 +030083 printfd(tcp, u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084 /* offset */
Dmitry V. Levin31382132011-03-04 05:08:02 +030085 tprintf(", %#llx", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000086 }
87 return RVAL_HEX;
88}
89
Denys Vlasenko1ba85432013-02-19 11:28:20 +010090/* Syscall name<->function correspondence is messed up on many arches.
91 * For example:
92 * i386 has __NR_mmap == 90, and it is "old mmap", and
93 * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
94 * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
95 * Confused? Me too!
96 */
97
98/* Params are pointed to by u_arg[0], offset is in bytes */
99int
100sys_old_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000101{
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100102 long u_arg[6];
Denys Vlasenko72a58482011-08-19 16:01:51 +0200103#if defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000104 /*
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200105 * IA64 processes never call this routine, they only use the
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100106 * new 'sys_mmap' interface. Only IA32 processes come here.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000107 */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200108 int i;
Denys Vlasenko923255c2013-02-18 02:36:36 +0100109 unsigned narrow_arg[6];
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200110 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
111 return 0;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000112 for (i = 0; i < 6; i++)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100113 u_arg[i] = (unsigned long) narrow_arg[i];
Denys Vlasenko923255c2013-02-18 02:36:36 +0100114#elif defined(X86_64)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100115 /* We are here only in personality 1 (i386) */
116 int i;
117 unsigned narrow_arg[6];
118 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
119 return 0;
120 for (i = 0; i < 6; ++i)
121 u_arg[i] = (unsigned long) narrow_arg[i];
Denys Vlasenko923255c2013-02-18 02:36:36 +0100122#else
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200123 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000124 return 0;
Denys Vlasenko923255c2013-02-18 02:36:36 +0100125#endif
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100126 return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000127}
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000128
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100129#if defined(S390)
130/* Params are pointed to by u_arg[0], offset is in pages */
131int
132sys_old_mmap_pgoff(struct tcb *tcp)
133{
134 long u_arg[5];
135 int i;
136 unsigned narrow_arg[6];
137 unsigned long long offset;
138 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
139 return 0;
140 for (i = 0; i < 5; i++)
141 u_arg[i] = (unsigned long) narrow_arg[i];
142 offset = narrow_arg[5];
Dmitry V. Levinc76a3632013-03-05 14:58:24 +0000143 offset *= get_pagesize();
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100144 return print_mmap(tcp, u_arg, offset);
145}
146#endif
147
148/* Params are passed directly, offset is in bytes */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000149int
Denys Vlasenko12014262011-05-30 14:00:14 +0200150sys_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000151{
Denys Vlasenko8dedb0d2013-02-18 03:13:07 +0100152 unsigned long long offset = (unsigned long) tcp->u_arg[5];
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100153#if defined(LINUX_MIPSN32) || defined(X32)
Denys Vlasenko8dedb0d2013-02-18 03:13:07 +0100154 /* Try test/x32_mmap.c */
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000155 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000156#endif
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100157 /* Example of kernel-side handling of this variety of mmap:
158 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
159 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
160 * since the above code converts off to pages.
161 */
162 return print_mmap(tcp, tcp->u_arg, offset);
163}
164
165/* Params are passed directly, offset is in pages */
166int
167sys_mmap_pgoff(struct tcb *tcp)
168{
169 /* Try test/mmap_offset_decode.c */
170 unsigned long long offset;
171 offset = (unsigned long) tcp->u_arg[5];
Dmitry V. Levinc76a3632013-03-05 14:58:24 +0000172 offset *= get_pagesize();
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100173 return print_mmap(tcp, tcp->u_arg, offset);
174}
175
176/* Params are passed directly, offset is in 4k units */
177int
178sys_mmap_4koff(struct tcb *tcp)
179{
180 unsigned long long offset;
181 offset = (unsigned long) tcp->u_arg[5];
182 offset <<= 12;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000183 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000184}
185
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186int
Denys Vlasenko12014262011-05-30 14:00:14 +0200187sys_munmap(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000188{
189 if (entering(tcp)) {
190 tprintf("%#lx, %lu",
191 tcp->u_arg[0], tcp->u_arg[1]);
192 }
193 return 0;
194}
195
196int
Denys Vlasenko12014262011-05-30 14:00:14 +0200197sys_mprotect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000198{
199 if (entering(tcp)) {
200 tprintf("%#lx, %lu, ",
201 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000202 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203 }
204 return 0;
205}
206
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000207#include "xlat/mremap_flags.h"
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000208
209int
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000210sys_mremap(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000211{
212 if (entering(tcp)) {
213 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
214 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000215 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000216#ifdef MREMAP_FIXED
217 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
218 (MREMAP_MAYMOVE | MREMAP_FIXED))
219 tprintf(", %#lx", tcp->u_arg[4]);
220#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000221 }
222 return RVAL_HEX;
223}
224
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000225#include "xlat/madvise_cmds.h"
Wichert Akkermanc7926982000-04-10 22:22:31 +0000226
Wichert Akkermanc7926982000-04-10 22:22:31 +0000227int
Denys Vlasenko12014262011-05-30 14:00:14 +0200228sys_madvise(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000229{
230 if (entering(tcp)) {
231 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000232 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000233 }
234 return 0;
235}
236
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000237#include "xlat/mlockall_flags.h"
Wichert Akkermanc7926982000-04-10 22:22:31 +0000238
239int
Denys Vlasenko12014262011-05-30 14:00:14 +0200240sys_mlockall(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000241{
242 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000243 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000244 }
245 return 0;
246}
247
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000248#ifdef MS_ASYNC
249
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000250#include "xlat/mctl_sync.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000251
252int
Denys Vlasenko12014262011-05-30 14:00:14 +0200253sys_msync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000254{
255 if (entering(tcp)) {
256 /* addr */
257 tprintf("%#lx", tcp->u_arg[0]);
258 /* len */
259 tprintf(", %lu, ", tcp->u_arg[1]);
260 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000261 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000262 }
263 return 0;
264}
265
266#endif /* MS_ASYNC */
267
268#ifdef MC_SYNC
269
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000270#include "xlat/mctl_funcs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000271
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000272#include "xlat/mctl_lockas.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000273
274int
Denys Vlasenko12014262011-05-30 14:00:14 +0200275sys_mctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000276{
277 int arg, function;
278
279 if (entering(tcp)) {
280 /* addr */
281 tprintf("%#lx", tcp->u_arg[0]);
282 /* len */
283 tprintf(", %lu, ", tcp->u_arg[1]);
284 /* function */
285 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000286 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000287 /* arg */
288 arg = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200289 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000290 switch (function) {
291 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000292 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000293 break;
294 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000295 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000296 break;
297 default:
298 tprintf("%#x", arg);
299 break;
300 }
301 }
302 return 0;
303}
304
305#endif /* MC_SYNC */
306
307int
Denys Vlasenko12014262011-05-30 14:00:14 +0200308sys_mincore(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000309{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000310 if (entering(tcp)) {
311 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
312 } else {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200313 unsigned long i, len;
314 char *vec = NULL;
315
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000316 len = tcp->u_arg[1];
317 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000318 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
320 tprintf("%#lx", tcp->u_arg[2]);
321 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200322 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000323 for (i = 0; i < len; i++) {
324 if (abbrev(tcp) && i >= max_strlen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200325 tprints("...");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000326 break;
327 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200328 tprints((vec[i] & 1) ? "1" : "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000329 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200330 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200332 free(vec);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000333 }
334 return 0;
335}
336
Denys Vlasenko84703742012-02-25 02:38:52 +0100337#if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338int
Denys Vlasenko12014262011-05-30 14:00:14 +0200339sys_getpagesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000340{
341 if (exiting(tcp))
342 return RVAL_HEX;
343 return 0;
344}
Denys Vlasenko84703742012-02-25 02:38:52 +0100345#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000346
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000347int
Denys Vlasenko12014262011-05-30 14:00:14 +0200348sys_remap_file_pages(struct tcb *tcp)
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000349{
350 if (entering(tcp)) {
351 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000352 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000353 tprintf(", %lu, ", tcp->u_arg[3]);
354#ifdef MAP_TYPE
355 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
356 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
357#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000358 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000359#endif
360 }
361 return 0;
362}
Roland McGrathb10a3352004-10-07 18:53:12 +0000363
Roland McGrathb10a3352004-10-07 18:53:12 +0000364#define MPOL_DEFAULT 0
365#define MPOL_PREFERRED 1
366#define MPOL_BIND 2
367#define MPOL_INTERLEAVE 3
368
369#define MPOL_F_NODE (1<<0)
370#define MPOL_F_ADDR (1<<1)
371
372#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000373#define MPOL_MF_MOVE (1<<1)
374#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000375
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000376#include "xlat/policies.h"
Roland McGrathb10a3352004-10-07 18:53:12 +0000377
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000378#include "xlat/mbindflags.h"
Roland McGrathb10a3352004-10-07 18:53:12 +0000379
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000380#include "xlat/mempolicyflags.h"
Roland McGrathb10a3352004-10-07 18:53:12 +0000381
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000382#include "xlat/move_pages_flags.h"
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000383
Roland McGrathb10a3352004-10-07 18:53:12 +0000384static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200385get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
Roland McGrathb10a3352004-10-07 18:53:12 +0000386{
Roland McGrathaa524c82005-06-01 19:22:06 +0000387 unsigned long nlongs, size, end;
388
389 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
390 size = nlongs * sizeof(long);
391 end = ptr + size;
392 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
393 && (end > ptr))) {
394 unsigned long n, cur, abbrev_end;
395 int failed = 0;
396
397 if (abbrev(tcp)) {
398 abbrev_end = ptr + max_strlen * sizeof(long);
399 if (abbrev_end < ptr)
400 abbrev_end = end;
401 } else {
402 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000403 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200404 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000405 for (cur = ptr; cur < end; cur += sizeof(long)) {
406 if (cur > ptr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200407 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000408 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200409 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000410 break;
411 }
412 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200413 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000414 failed = 1;
415 break;
416 }
417 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
418 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200419 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000420 if (failed)
421 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000422 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000423 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000424 tprintf(", %lu", maxnodes);
425}
426
427int
Denys Vlasenko12014262011-05-30 14:00:14 +0200428sys_mbind(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000429{
430 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000431 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000432 printxval(policies, tcp->u_arg[2], "MPOL_???");
433 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200434 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000435 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000436 }
437 return 0;
438}
439
440int
Denys Vlasenko12014262011-05-30 14:00:14 +0200441sys_set_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000442{
443 if (entering(tcp)) {
444 printxval(policies, tcp->u_arg[0], "MPOL_???");
445 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
446 }
447 return 0;
448}
449
450int
Denys Vlasenko12014262011-05-30 14:00:14 +0200451sys_get_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000452{
453 if (exiting(tcp)) {
454 int pol;
455 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200456 tprints("NULL");
Roland McGrathb10a3352004-10-07 18:53:12 +0000457 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
458 tprintf("%#lx", tcp->u_arg[0]);
459 else
460 printxval(policies, pol, "MPOL_???");
461 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
462 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000463 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000464 }
465 return 0;
466}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000467
468int
Dmitry V. Levin64d0e712012-03-11 22:44:14 +0000469sys_migrate_pages(struct tcb *tcp)
470{
471 if (entering(tcp)) {
472 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
473 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
474 tprints(", ");
475 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
476 }
477 return 0;
478}
479
480int
Denys Vlasenko12014262011-05-30 14:00:14 +0200481sys_move_pages(struct tcb *tcp)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000482{
483 if (entering(tcp)) {
484 unsigned long npages = tcp->u_arg[1];
485 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
486 if (tcp->u_arg[2] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200487 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000488 else {
489 int i;
490 long puser = tcp->u_arg[2];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200491 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000492 for (i = 0; i < npages; ++i) {
493 void *p;
494 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200495 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000496 if (umove(tcp, puser, &p) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200497 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000498 break;
499 }
500 tprintf("%p", p);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200501 puser += sizeof(void *);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000502 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200503 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000504 }
505 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200506 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000507 else {
508 int i;
509 long nodeuser = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200510 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000511 for (i = 0; i < npages; ++i) {
512 int node;
513 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200514 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000515 if (umove(tcp, nodeuser, &node) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200516 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000517 break;
518 }
519 tprintf("%#x", node);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200520 nodeuser += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000521 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200522 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000523 }
524 }
525 if (exiting(tcp)) {
526 unsigned long npages = tcp->u_arg[1];
527 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200528 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000529 else {
530 int i;
531 long statususer = tcp->u_arg[4];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200532 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000533 for (i = 0; i < npages; ++i) {
534 int status;
535 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200536 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000537 if (umove(tcp, statususer, &status) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200538 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000539 break;
540 }
541 tprintf("%#x", status);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200542 statususer += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000543 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200544 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000545 }
546 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
547 }
548 return 0;
549}
Roland McGrath4a6f6522008-08-25 03:09:16 +0000550
Denys Vlasenko84703742012-02-25 02:38:52 +0100551#if defined(POWERPC)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000552int
Denys Vlasenko12014262011-05-30 14:00:14 +0200553sys_subpage_prot(struct tcb *tcp)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000554{
555 if (entering(tcp)) {
556 unsigned long cur, end, abbrev_end, entries;
557 unsigned int entry;
558
559 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
560 entries = tcp->u_arg[1] >> 16;
561 if (!entries || !tcp->u_arg[2]) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200562 tprints("{}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000563 return 0;
564 }
565 cur = tcp->u_arg[2];
566 end = cur + (sizeof(int) * entries);
567 if (!verbose(tcp) || end < tcp->u_arg[2]) {
568 tprintf("%#lx", tcp->u_arg[2]);
569 return 0;
570 }
571 if (abbrev(tcp)) {
572 abbrev_end = cur + (sizeof(int) * max_strlen);
573 if (abbrev_end > end)
574 abbrev_end = end;
575 }
576 else
577 abbrev_end = end;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200578 tprints("{");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000579 for (; cur < end; cur += sizeof(int)) {
580 if (cur > tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200581 tprints(", ");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000582 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200583 tprints("...");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000584 break;
585 }
586 if (umove(tcp, cur, &entry) < 0) {
587 tprintf("??? [%#lx]", cur);
588 break;
589 }
590 else
591 tprintf("%#08x", entry);
592 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200593 tprints("}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000594 }
595
596 return 0;
597}
598#endif