blob: 28498d451df54c5465791c809f91351ad5593fd9 [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. Levinea1fea62015-03-31 19:45:08 +000037unsigned long
38get_pagesize(void)
Dmitry V. Levinc76a3632013-03-05 14:58:24 +000039{
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
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000047SYS_FUNC(brk)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048{
49 if (entering(tcp)) {
Dmitry V. Levin2c389f62015-07-19 23:25:56 +000050 printaddr(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052 return RVAL_HEX;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053}
54
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000055#include "xlat/mmap_prot.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000056#include "xlat/mmap_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057
Dmitry V. Levin31382132011-03-04 05:08:02 +030058static int
Denys Vlasenko923255c2013-02-18 02:36:36 +010059print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000060{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000061 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000062 /* addr */
Dmitry V. Levin2c389f62015-07-19 23:25:56 +000063 printaddr(u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000064 /* len */
Dmitry V. Levin2c389f62015-07-19 23:25:56 +000065 tprintf(", %lu, ", u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000066 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +000067 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020068 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000069 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000070#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
72 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000073#else
Roland McGrathb2dee132005-06-01 19:02:36 +000074 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000075#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020076 tprints(", ");
Denys Vlasenko923255c2013-02-18 02:36:36 +010077 /* fd */
Dmitry V. Levin31382132011-03-04 05:08:02 +030078 printfd(tcp, u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000079 /* offset */
Dmitry V. Levin31382132011-03-04 05:08:02 +030080 tprintf(", %#llx", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000081 }
82 return RVAL_HEX;
83}
84
Denys Vlasenko1ba85432013-02-19 11:28:20 +010085/* Syscall name<->function correspondence is messed up on many arches.
86 * For example:
87 * i386 has __NR_mmap == 90, and it is "old mmap", and
88 * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
89 * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
90 * Confused? Me too!
91 */
92
93/* Params are pointed to by u_arg[0], offset is in bytes */
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000094SYS_FUNC(old_mmap)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +000095{
Denys Vlasenko1ba85432013-02-19 11:28:20 +010096 long u_arg[6];
Denys Vlasenko72a58482011-08-19 16:01:51 +020097#if defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +000098 /*
Denys Vlasenko9aa97962011-08-19 17:07:38 +020099 * IA64 processes never call this routine, they only use the
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100100 * new 'sys_mmap' interface. Only IA32 processes come here.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000101 */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200102 int i;
Denys Vlasenko923255c2013-02-18 02:36:36 +0100103 unsigned narrow_arg[6];
Denys Vlasenko7e69ed92015-03-21 19:50:53 +0100104 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), narrow_arg) == -1)
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200105 return 0;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000106 for (i = 0; i < 6; i++)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100107 u_arg[i] = (unsigned long) narrow_arg[i];
Denys Vlasenko923255c2013-02-18 02:36:36 +0100108#elif defined(X86_64)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100109 /* We are here only in personality 1 (i386) */
110 int i;
111 unsigned narrow_arg[6];
Denys Vlasenko7e69ed92015-03-21 19:50:53 +0100112 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), narrow_arg) == -1)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100113 return 0;
114 for (i = 0; i < 6; ++i)
115 u_arg[i] = (unsigned long) narrow_arg[i];
Denys Vlasenko923255c2013-02-18 02:36:36 +0100116#else
Denys Vlasenko7e69ed92015-03-21 19:50:53 +0100117 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), u_arg) == -1)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000118 return 0;
Denys Vlasenko923255c2013-02-18 02:36:36 +0100119#endif
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100120 return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000121}
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000122
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100123#if defined(S390)
124/* Params are pointed to by u_arg[0], offset is in pages */
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000125SYS_FUNC(old_mmap_pgoff)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100126{
127 long u_arg[5];
128 int i;
129 unsigned narrow_arg[6];
130 unsigned long long offset;
Denys Vlasenko7e69ed92015-03-21 19:50:53 +0100131 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), narrow_arg) == -1)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100132 return 0;
133 for (i = 0; i < 5; i++)
134 u_arg[i] = (unsigned long) narrow_arg[i];
135 offset = narrow_arg[5];
Dmitry V. Levinc76a3632013-03-05 14:58:24 +0000136 offset *= get_pagesize();
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100137 return print_mmap(tcp, u_arg, offset);
138}
139#endif
140
141/* Params are passed directly, offset is in bytes */
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000142SYS_FUNC(mmap)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000143{
Denys Vlasenko8dedb0d2013-02-18 03:13:07 +0100144 unsigned long long offset = (unsigned long) tcp->u_arg[5];
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100145#if defined(LINUX_MIPSN32) || defined(X32)
Denys Vlasenko8dedb0d2013-02-18 03:13:07 +0100146 /* Try test/x32_mmap.c */
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000147 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000148#endif
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100149 /* Example of kernel-side handling of this variety of mmap:
150 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
151 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
152 * since the above code converts off to pages.
153 */
154 return print_mmap(tcp, tcp->u_arg, offset);
155}
156
157/* Params are passed directly, offset is in pages */
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000158SYS_FUNC(mmap_pgoff)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100159{
160 /* Try test/mmap_offset_decode.c */
161 unsigned long long offset;
162 offset = (unsigned long) tcp->u_arg[5];
Dmitry V. Levinc76a3632013-03-05 14:58:24 +0000163 offset *= get_pagesize();
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100164 return print_mmap(tcp, tcp->u_arg, offset);
165}
166
167/* Params are passed directly, offset is in 4k units */
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000168SYS_FUNC(mmap_4koff)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100169{
170 unsigned long long offset;
171 offset = (unsigned long) tcp->u_arg[5];
172 offset <<= 12;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000173 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000174}
175
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000176SYS_FUNC(munmap)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000177{
178 if (entering(tcp)) {
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000179 printaddr(tcp->u_arg[0]);
180 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181 }
182 return 0;
183}
184
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000185SYS_FUNC(mprotect)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186{
187 if (entering(tcp)) {
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000188 printaddr(tcp->u_arg[0]);
189 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000190 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191 }
192 return 0;
193}
194
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000195#include "xlat/mremap_flags.h"
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000196
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000197SYS_FUNC(mremap)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000198{
199 if (entering(tcp)) {
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000200 printaddr(tcp->u_arg[0]);
201 tprintf(", %lu, %lu, ", tcp->u_arg[1], tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000202 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000203#ifdef MREMAP_FIXED
204 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000205 (MREMAP_MAYMOVE | MREMAP_FIXED)) {
206 tprints(", ");
207 printaddr(tcp->u_arg[4]);
208 }
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000209#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000210 }
211 return RVAL_HEX;
212}
213
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000214#include "xlat/madvise_cmds.h"
Wichert Akkermanc7926982000-04-10 22:22:31 +0000215
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000216SYS_FUNC(madvise)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000217{
218 if (entering(tcp)) {
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000219 printaddr(tcp->u_arg[0]);
220 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000221 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000222 }
223 return 0;
224}
225
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000226#include "xlat/mlockall_flags.h"
Wichert Akkermanc7926982000-04-10 22:22:31 +0000227
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000228SYS_FUNC(mlockall)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000229{
230 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000231 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000232 }
233 return 0;
234}
235
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000236#include "xlat/mctl_sync.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000237
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000238SYS_FUNC(msync)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000239{
240 if (entering(tcp)) {
241 /* addr */
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000242 printaddr(tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000243 /* len */
244 tprintf(", %lu, ", tcp->u_arg[1]);
245 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000246 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000247 }
248 return 0;
249}
250
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000251SYS_FUNC(mincore)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000252{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000253 if (entering(tcp)) {
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000254 printaddr(tcp->u_arg[0]);
255 tprintf(", %lu, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000256 } else {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200257 unsigned long i, len;
258 char *vec = NULL;
259
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000260 len = tcp->u_arg[1];
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000261 if (syserror(tcp) || !verbose(tcp) ||
262 !tcp->u_arg[2] || !(vec = malloc(len)) ||
263 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
264 printaddr(tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000265 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200266 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000267 for (i = 0; i < len; i++) {
268 if (abbrev(tcp) && i >= max_strlen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200269 tprints("...");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270 break;
271 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200272 tprints((vec[i] & 1) ? "1" : "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000273 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200274 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200276 free(vec);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277 }
278 return 0;
279}
280
Denys Vlasenko84703742012-02-25 02:38:52 +0100281#if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000282SYS_FUNC(getpagesize)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000283{
284 if (exiting(tcp))
285 return RVAL_HEX;
286 return 0;
287}
Denys Vlasenko84703742012-02-25 02:38:52 +0100288#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000289
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000290SYS_FUNC(remap_file_pages)
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000291{
292 if (entering(tcp)) {
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000293 printaddr(tcp->u_arg[0]);
294 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000295 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000296 tprintf(", %lu, ", tcp->u_arg[3]);
297#ifdef MAP_TYPE
298 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
299 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
300#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000301 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000302#endif
303 }
304 return 0;
305}
Roland McGrathb10a3352004-10-07 18:53:12 +0000306
Roland McGrathb10a3352004-10-07 18:53:12 +0000307#define MPOL_DEFAULT 0
308#define MPOL_PREFERRED 1
309#define MPOL_BIND 2
310#define MPOL_INTERLEAVE 3
311
312#define MPOL_F_NODE (1<<0)
313#define MPOL_F_ADDR (1<<1)
314
315#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000316#define MPOL_MF_MOVE (1<<1)
317#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000318
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000319#include "xlat/policies.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000320#include "xlat/mbindflags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000321#include "xlat/mempolicyflags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000322#include "xlat/move_pages_flags.h"
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000323
Roland McGrathb10a3352004-10-07 18:53:12 +0000324static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200325get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
Roland McGrathb10a3352004-10-07 18:53:12 +0000326{
Roland McGrathaa524c82005-06-01 19:22:06 +0000327 unsigned long nlongs, size, end;
328
329 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
330 size = nlongs * sizeof(long);
331 end = ptr + size;
332 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
333 && (end > ptr))) {
334 unsigned long n, cur, abbrev_end;
335 int failed = 0;
336
337 if (abbrev(tcp)) {
338 abbrev_end = ptr + max_strlen * sizeof(long);
339 if (abbrev_end < ptr)
340 abbrev_end = end;
341 } else {
342 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000343 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200344 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000345 for (cur = ptr; cur < end; cur += sizeof(long)) {
346 if (cur > ptr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200347 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000348 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200349 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000350 break;
351 }
Denys Vlasenko7e69ed92015-03-21 19:50:53 +0100352 if (umoven(tcp, cur, sizeof(n), &n) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200353 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000354 failed = 1;
355 break;
356 }
357 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
358 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200359 tprints("}");
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000360 if (failed) {
361 tprints(" ");
362 printaddr(ptr);
363 }
364 } else {
365 tprints(" ");
366 printaddr(ptr);
367 }
Roland McGrathb10a3352004-10-07 18:53:12 +0000368 tprintf(", %lu", maxnodes);
369}
370
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000371SYS_FUNC(mbind)
Roland McGrathb10a3352004-10-07 18:53:12 +0000372{
373 if (entering(tcp)) {
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000374 printaddr(tcp->u_arg[0]);
375 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000376 printxval(policies, tcp->u_arg[2], "MPOL_???");
377 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200378 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000379 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000380 }
381 return 0;
382}
383
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000384SYS_FUNC(set_mempolicy)
Roland McGrathb10a3352004-10-07 18:53:12 +0000385{
386 if (entering(tcp)) {
387 printxval(policies, tcp->u_arg[0], "MPOL_???");
388 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
389 }
390 return 0;
391}
392
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000393SYS_FUNC(get_mempolicy)
Roland McGrathb10a3352004-10-07 18:53:12 +0000394{
395 if (exiting(tcp)) {
396 int pol;
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000397 if (!umove_or_printaddr(tcp, tcp->u_arg[0], &pol))
Roland McGrathb10a3352004-10-07 18:53:12 +0000398 printxval(policies, pol, "MPOL_???");
399 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000400 tprints(", ");
401 printaddr(tcp->u_arg[3]);
402 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000403 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000404 }
405 return 0;
406}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000407
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000408SYS_FUNC(migrate_pages)
Dmitry V. Levin64d0e712012-03-11 22:44:14 +0000409{
410 if (entering(tcp)) {
411 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
412 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
413 tprints(", ");
414 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
415 }
416 return 0;
417}
418
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000419SYS_FUNC(move_pages)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000420{
421 if (entering(tcp)) {
422 unsigned long npages = tcp->u_arg[1];
423 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
424 if (tcp->u_arg[2] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200425 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000426 else {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000427 unsigned int i;
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000428 long puser = tcp->u_arg[2];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200429 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000430 for (i = 0; i < npages; ++i) {
431 void *p;
432 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200433 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000434 if (umove(tcp, puser, &p) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200435 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000436 break;
437 }
438 tprintf("%p", p);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200439 puser += sizeof(void *);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000440 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200441 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000442 }
443 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200444 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000445 else {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000446 unsigned int i;
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000447 long nodeuser = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200448 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000449 for (i = 0; i < npages; ++i) {
450 int node;
451 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200452 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000453 if (umove(tcp, nodeuser, &node) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200454 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000455 break;
456 }
457 tprintf("%#x", node);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200458 nodeuser += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000459 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200460 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000461 }
462 }
463 if (exiting(tcp)) {
464 unsigned long npages = tcp->u_arg[1];
465 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200466 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000467 else {
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000468 unsigned int i;
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000469 long statususer = tcp->u_arg[4];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200470 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000471 for (i = 0; i < npages; ++i) {
472 int status;
473 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200474 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000475 if (umove(tcp, statususer, &status) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200476 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000477 break;
478 }
479 tprintf("%#x", status);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200480 statususer += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000481 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200482 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000483 }
484 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
485 }
486 return 0;
487}
Roland McGrath4a6f6522008-08-25 03:09:16 +0000488
Denys Vlasenko84703742012-02-25 02:38:52 +0100489#if defined(POWERPC)
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000490SYS_FUNC(subpage_prot)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000491{
492 if (entering(tcp)) {
493 unsigned long cur, end, abbrev_end, entries;
494 unsigned int entry;
495
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000496 printaddr(tcp->u_arg[0]);
497 tprints(", ");
498 printaddr(tcp->u_arg[1]);
499 tprints(", ");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000500 entries = tcp->u_arg[1] >> 16;
501 if (!entries || !tcp->u_arg[2]) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200502 tprints("{}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000503 return 0;
504 }
505 cur = tcp->u_arg[2];
506 end = cur + (sizeof(int) * entries);
Dmitry V. Levin3b64d992015-01-14 07:17:11 +0000507 if (!verbose(tcp) || end < (unsigned long) tcp->u_arg[2]) {
Dmitry V. Levin2c389f62015-07-19 23:25:56 +0000508 printaddr(tcp->u_arg[2]);
Roland McGrath4a6f6522008-08-25 03:09:16 +0000509 return 0;
510 }
511 if (abbrev(tcp)) {
512 abbrev_end = cur + (sizeof(int) * max_strlen);
513 if (abbrev_end > end)
514 abbrev_end = end;
515 }
516 else
517 abbrev_end = end;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200518 tprints("{");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000519 for (; cur < end; cur += sizeof(int)) {
Dmitry V. Levin3b64d992015-01-14 07:17:11 +0000520 if (cur > (unsigned long) tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200521 tprints(", ");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000522 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200523 tprints("...");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000524 break;
525 }
526 if (umove(tcp, cur, &entry) < 0) {
527 tprintf("??? [%#lx]", cur);
528 break;
529 }
530 else
531 tprintf("%#08x", entry);
532 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200533 tprints("}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000534 }
535
536 return 0;
537}
538#endif