blob: 4b6bc1848ca584fce9b06ea1dff863f2978d67a4 [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>
Dmitry V. Levinf94e8472014-04-09 12:30:38 +000036#if defined(I386) || defined(X86_64) || defined(X32)
Denys Vlasenko72a58482011-08-19 16:01:51 +020037# include <asm/ldt.h>
Roland McGrath7decfb22004-03-01 22:10:52 +000038# ifdef HAVE_STRUCT_USER_DESC
39# define modify_ldt_ldt_s user_desc
40# endif
Dmitry V. Levinf94e8472014-04-09 12:30:38 +000041#endif /* I386 || X86_64 || X32 */
Denys Vlasenko1ba85432013-02-19 11:28:20 +010042
Dmitry V. Levinc76a3632013-03-05 14:58:24 +000043static unsigned long
44get_pagesize()
45{
46 static unsigned long pagesize;
47
48 if (!pagesize)
49 pagesize = sysconf(_SC_PAGESIZE);
50 return pagesize;
51}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052
53int
Denys Vlasenko12014262011-05-30 14:00:14 +020054sys_brk(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055{
56 if (entering(tcp)) {
57 tprintf("%#lx", tcp->u_arg[0]);
58 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059 return RVAL_HEX;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000060}
61
Roland McGrathd9f816f2004-09-04 03:39:20 +000062static const struct xlat mmap_prot[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000063 XLAT(PROT_NONE),
64 XLAT(PROT_READ),
65 XLAT(PROT_WRITE),
66 XLAT(PROT_EXEC),
Roland McGrath47eb0e22003-09-25 23:06:04 +000067#ifdef PROT_SEM
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000068 XLAT(PROT_SEM),
Roland McGrath47eb0e22003-09-25 23:06:04 +000069#endif
70#ifdef PROT_GROWSDOWN
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000071 XLAT(PROT_GROWSDOWN),
Roland McGrath47eb0e22003-09-25 23:06:04 +000072#endif
73#ifdef PROT_GROWSUP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000074 XLAT(PROT_GROWSUP),
Roland McGrath47eb0e22003-09-25 23:06:04 +000075#endif
Roland McGrath586d6ab2008-08-25 03:00:47 +000076#ifdef PROT_SAO
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000077 XLAT(PROT_SAO),
Roland McGrath586d6ab2008-08-25 03:00:47 +000078#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +000079 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000080};
81
Roland McGrathd9f816f2004-09-04 03:39:20 +000082static const struct xlat mmap_flags[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000083 XLAT(MAP_SHARED),
84 XLAT(MAP_PRIVATE),
85 XLAT(MAP_FIXED),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000086#ifdef MAP_ANONYMOUS
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000087 XLAT(MAP_ANONYMOUS),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000088#endif
Dmitry V. Levin71f1a132007-03-29 23:30:09 +000089#ifdef MAP_32BIT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000090 XLAT(MAP_32BIT),
Dmitry V. Levin71f1a132007-03-29 23:30:09 +000091#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000092#ifdef MAP_RENAME
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000093 XLAT(MAP_RENAME),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000094#endif
95#ifdef MAP_NORESERVE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000096 XLAT(MAP_NORESERVE),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000097#endif
Roland McGrath72c5b7b2003-03-05 04:08:00 +000098#ifdef MAP_POPULATE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000099 XLAT(MAP_POPULATE),
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000100#endif
101#ifdef MAP_NONBLOCK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000102 XLAT(MAP_NONBLOCK),
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000103#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000104 /*
105 * XXX - this was introduced in SunOS 4.x to distinguish between
106 * the old pre-4.x "mmap()", which:
107 *
108 * only let you map devices with an "mmap" routine (e.g.,
109 * frame buffers) in;
110 *
111 * required you to specify the mapping address;
112 *
113 * returned 0 on success and -1 on failure;
114 *
115 * memory and which, and the 4.x "mmap()" which:
116 *
117 * can map plain files;
118 *
119 * can be asked to pick where to map the file;
120 *
121 * returns the address where it mapped the file on success
122 * and -1 on failure.
123 *
124 * It's not actually used in source code that calls "mmap()"; the
125 * "mmap()" routine adds it for you.
126 *
127 * It'd be nice to come up with some way of eliminating it from
128 * the flags, e.g. reporting calls *without* it as "old_mmap()"
129 * and calls with it as "mmap()".
130 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000131#ifdef _MAP_NEW
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000132 XLAT(_MAP_NEW),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133#endif
134#ifdef MAP_GROWSDOWN
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000135 XLAT(MAP_GROWSDOWN),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000136#endif
137#ifdef MAP_DENYWRITE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000138 XLAT(MAP_DENYWRITE),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000139#endif
140#ifdef MAP_EXECUTABLE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000141 XLAT(MAP_EXECUTABLE),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000142#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000143#ifdef MAP_INHERIT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000144 XLAT(MAP_INHERIT),
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000145#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000146#ifdef MAP_FILE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000147 XLAT(MAP_FILE),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148#endif
149#ifdef MAP_LOCKED
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000150 XLAT(MAP_LOCKED),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000152 /* FreeBSD ones */
Denys Vlasenko2897fb32012-03-17 01:29:40 +0100153#if defined(MAP_ANON) && (!defined(MAP_ANONYMOUS) || MAP_ANON != MAP_ANONYMOUS)
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000154 XLAT(MAP_ANON),
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000155#endif
156#ifdef MAP_HASSEMAPHORE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000157 XLAT(MAP_HASSEMAPHORE),
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000158#endif
159#ifdef MAP_STACK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000160 XLAT(MAP_STACK),
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000161#endif
Kirill A. Shutemovb5530a12014-01-02 13:15:32 +0200162#ifdef MAP_HUGETLB
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000163 XLAT(MAP_HUGETLB),
Kirill A. Shutemovb5530a12014-01-02 13:15:32 +0200164#endif
Bernhard Reutner-Fischer21ceeb42013-02-05 19:31:55 +0100165#if defined MAP_UNINITIALIZED && MAP_UNINITIALIZED > 0
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000166 XLAT(MAP_UNINITIALIZED),
Bernhard Reutner-Fischer21ceeb42013-02-05 19:31:55 +0100167#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000168#ifdef MAP_NOSYNC
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000169 XLAT(MAP_NOSYNC),
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000170#endif
171#ifdef MAP_NOCORE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000172 XLAT(MAP_NOCORE),
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000173#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000174 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000175};
176
Dmitry V. Levin31382132011-03-04 05:08:02 +0300177static int
Denys Vlasenko923255c2013-02-18 02:36:36 +0100178print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000180 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000182 if (!u_arg[0])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200183 tprints("NULL, ");
Wichert Akkerman8829a551999-06-11 13:18:40 +0000184 else
185 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186 /* len */
187 tprintf("%lu, ", u_arg[1]);
188 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000189 printflags(mmap_prot, u_arg[2], "PROT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200190 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000192#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000193 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
194 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000195#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000196 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000197#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200198 tprints(", ");
Denys Vlasenko923255c2013-02-18 02:36:36 +0100199 /* fd */
Dmitry V. Levin31382132011-03-04 05:08:02 +0300200 printfd(tcp, u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000201 /* offset */
Dmitry V. Levin31382132011-03-04 05:08:02 +0300202 tprintf(", %#llx", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203 }
204 return RVAL_HEX;
205}
206
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100207/* Syscall name<->function correspondence is messed up on many arches.
208 * For example:
209 * i386 has __NR_mmap == 90, and it is "old mmap", and
210 * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
211 * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
212 * Confused? Me too!
213 */
214
215/* Params are pointed to by u_arg[0], offset is in bytes */
216int
217sys_old_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000218{
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100219 long u_arg[6];
Denys Vlasenko72a58482011-08-19 16:01:51 +0200220#if defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000221 /*
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200222 * IA64 processes never call this routine, they only use the
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100223 * new 'sys_mmap' interface. Only IA32 processes come here.
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000224 */
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200225 int i;
Denys Vlasenko923255c2013-02-18 02:36:36 +0100226 unsigned narrow_arg[6];
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200227 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
228 return 0;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000229 for (i = 0; i < 6; i++)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100230 u_arg[i] = (unsigned long) narrow_arg[i];
Denys Vlasenko923255c2013-02-18 02:36:36 +0100231#elif defined(X86_64)
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100232 /* We are here only in personality 1 (i386) */
233 int i;
234 unsigned narrow_arg[6];
235 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
236 return 0;
237 for (i = 0; i < 6; ++i)
238 u_arg[i] = (unsigned long) narrow_arg[i];
Denys Vlasenko923255c2013-02-18 02:36:36 +0100239#else
Denys Vlasenko9aa97962011-08-19 17:07:38 +0200240 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000241 return 0;
Denys Vlasenko923255c2013-02-18 02:36:36 +0100242#endif
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100243 return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000244}
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000245
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100246#if defined(S390)
247/* Params are pointed to by u_arg[0], offset is in pages */
248int
249sys_old_mmap_pgoff(struct tcb *tcp)
250{
251 long u_arg[5];
252 int i;
253 unsigned narrow_arg[6];
254 unsigned long long offset;
255 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
256 return 0;
257 for (i = 0; i < 5; i++)
258 u_arg[i] = (unsigned long) narrow_arg[i];
259 offset = narrow_arg[5];
Dmitry V. Levinc76a3632013-03-05 14:58:24 +0000260 offset *= get_pagesize();
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100261 return print_mmap(tcp, u_arg, offset);
262}
263#endif
264
265/* Params are passed directly, offset is in bytes */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000266int
Denys Vlasenko12014262011-05-30 14:00:14 +0200267sys_mmap(struct tcb *tcp)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000268{
Denys Vlasenko8dedb0d2013-02-18 03:13:07 +0100269 unsigned long long offset = (unsigned long) tcp->u_arg[5];
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100270#if defined(LINUX_MIPSN32) || defined(X32)
Denys Vlasenko8dedb0d2013-02-18 03:13:07 +0100271 /* Try test/x32_mmap.c */
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000272 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000273#endif
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100274 /* Example of kernel-side handling of this variety of mmap:
275 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
276 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
277 * since the above code converts off to pages.
278 */
279 return print_mmap(tcp, tcp->u_arg, offset);
280}
281
282/* Params are passed directly, offset is in pages */
283int
284sys_mmap_pgoff(struct tcb *tcp)
285{
286 /* Try test/mmap_offset_decode.c */
287 unsigned long long offset;
288 offset = (unsigned long) tcp->u_arg[5];
Dmitry V. Levinc76a3632013-03-05 14:58:24 +0000289 offset *= get_pagesize();
Denys Vlasenko1ba85432013-02-19 11:28:20 +0100290 return print_mmap(tcp, tcp->u_arg, offset);
291}
292
293/* Params are passed directly, offset is in 4k units */
294int
295sys_mmap_4koff(struct tcb *tcp)
296{
297 unsigned long long offset;
298 offset = (unsigned long) tcp->u_arg[5];
299 offset <<= 12;
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000300 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000301}
302
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000303int
Denys Vlasenko12014262011-05-30 14:00:14 +0200304sys_munmap(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000305{
306 if (entering(tcp)) {
307 tprintf("%#lx, %lu",
308 tcp->u_arg[0], tcp->u_arg[1]);
309 }
310 return 0;
311}
312
313int
Denys Vlasenko12014262011-05-30 14:00:14 +0200314sys_mprotect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000315{
316 if (entering(tcp)) {
317 tprintf("%#lx, %lu, ",
318 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000319 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000320 }
321 return 0;
322}
323
Roland McGrathd9f816f2004-09-04 03:39:20 +0000324static const struct xlat mremap_flags[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000325 XLAT(MREMAP_MAYMOVE),
Chris Metcalfff3474a2009-12-24 23:19:19 +0000326#ifdef MREMAP_FIXED
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000327 XLAT(MREMAP_FIXED),
Chris Metcalfff3474a2009-12-24 23:19:19 +0000328#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000329 XLAT_END
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000330};
331
332int
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000333sys_mremap(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000334{
335 if (entering(tcp)) {
336 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
337 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000338 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000339#ifdef MREMAP_FIXED
340 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
341 (MREMAP_MAYMOVE | MREMAP_FIXED))
342 tprintf(", %#lx", tcp->u_arg[4]);
343#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000344 }
345 return RVAL_HEX;
346}
347
Roland McGrathf4021b12008-08-25 02:59:36 +0000348static const struct xlat madvise_cmds[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000349#ifdef MADV_NORMAL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000350 XLAT(MADV_NORMAL),
Wichert Akkermanc7926982000-04-10 22:22:31 +0000351#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000352#ifdef MADV_RANDOM
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000353 XLAT(MADV_RANDOM),
Wichert Akkermanc7926982000-04-10 22:22:31 +0000354#endif
355#ifdef MADV_SEQUENTIAL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000356 XLAT(MADV_SEQUENTIAL),
Wichert Akkermanc7926982000-04-10 22:22:31 +0000357#endif
358#ifdef MADV_WILLNEED
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000359 XLAT(MADV_WILLNEED),
Wichert Akkermanc7926982000-04-10 22:22:31 +0000360#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000361#ifdef MADV_DONTNEED
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000362 XLAT(MADV_DONTNEED),
Wichert Akkermanc7926982000-04-10 22:22:31 +0000363#endif
Dmitry V. Levin3ec134b2013-03-14 18:55:26 +0000364#ifdef MADV_REMOVE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000365 XLAT(MADV_REMOVE),
Dmitry V. Levin3ec134b2013-03-14 18:55:26 +0000366#endif
367#ifdef MADV_DONTFORK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000368 XLAT(MADV_DONTFORK),
Dmitry V. Levin3ec134b2013-03-14 18:55:26 +0000369#endif
370#ifdef MADV_DOFORK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000371 XLAT(MADV_DOFORK),
Dmitry V. Levin3ec134b2013-03-14 18:55:26 +0000372#endif
373#ifdef MADV_HWPOISON
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000374 XLAT(MADV_HWPOISON),
Dmitry V. Levin3ec134b2013-03-14 18:55:26 +0000375#endif
376#ifdef MADV_SOFT_OFFLINE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000377 XLAT(MADV_SOFT_OFFLINE),
Dmitry V. Levin3ec134b2013-03-14 18:55:26 +0000378#endif
379#ifdef MADV_MERGEABLE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000380 XLAT(MADV_MERGEABLE),
Dmitry V. Levin3ec134b2013-03-14 18:55:26 +0000381#endif
382#ifdef MADV_UNMERGEABLE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000383 XLAT(MADV_UNMERGEABLE),
Dmitry V. Levin3ec134b2013-03-14 18:55:26 +0000384#endif
385#ifdef MADV_HUGEPAGE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000386 XLAT(MADV_HUGEPAGE),
Dmitry V. Levin3ec134b2013-03-14 18:55:26 +0000387#endif
388#ifdef MADV_NOHUGEPAGE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000389 XLAT(MADV_NOHUGEPAGE),
Dmitry V. Levin3ec134b2013-03-14 18:55:26 +0000390#endif
391#ifdef MADV_DONTDUMP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000392 XLAT(MADV_DONTDUMP),
Dmitry V. Levin3ec134b2013-03-14 18:55:26 +0000393#endif
394#ifdef MADV_DODUMP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000395 XLAT(MADV_DODUMP),
Dmitry V. Levin3ec134b2013-03-14 18:55:26 +0000396#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000397 XLAT_END
Wichert Akkermanc7926982000-04-10 22:22:31 +0000398};
399
Wichert Akkermanc7926982000-04-10 22:22:31 +0000400int
Denys Vlasenko12014262011-05-30 14:00:14 +0200401sys_madvise(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000402{
403 if (entering(tcp)) {
404 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000405 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000406 }
407 return 0;
408}
409
Roland McGrathd9f816f2004-09-04 03:39:20 +0000410static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000411#ifdef MCL_CURRENT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000412 XLAT(MCL_CURRENT),
Wichert Akkermanc7926982000-04-10 22:22:31 +0000413#endif
414#ifdef MCL_FUTURE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000415 XLAT(MCL_FUTURE),
Wichert Akkermanc7926982000-04-10 22:22:31 +0000416#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000417 XLAT_END
Wichert Akkermanc7926982000-04-10 22:22:31 +0000418};
419
420int
Denys Vlasenko12014262011-05-30 14:00:14 +0200421sys_mlockall(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +0000422{
423 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000424 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000425 }
426 return 0;
427}
428
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000429#ifdef MS_ASYNC
430
Roland McGrathd9f816f2004-09-04 03:39:20 +0000431static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000432#ifdef MS_SYNC
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000433 XLAT(MS_SYNC),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000434#endif
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000435 XLAT(MS_ASYNC),
436 XLAT(MS_INVALIDATE),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000437 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438};
439
440int
Denys Vlasenko12014262011-05-30 14:00:14 +0200441sys_msync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442{
443 if (entering(tcp)) {
444 /* addr */
445 tprintf("%#lx", tcp->u_arg[0]);
446 /* len */
447 tprintf(", %lu, ", tcp->u_arg[1]);
448 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000449 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000450 }
451 return 0;
452}
453
454#endif /* MS_ASYNC */
455
456#ifdef MC_SYNC
457
Roland McGrathd9f816f2004-09-04 03:39:20 +0000458static const struct xlat mctl_funcs[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000459 XLAT(MC_LOCK),
460 XLAT(MC_LOCKAS),
461 XLAT(MC_SYNC),
462 XLAT(MC_UNLOCK),
463 XLAT(MC_UNLOCKAS),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000464 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465};
466
Roland McGrathd9f816f2004-09-04 03:39:20 +0000467static const struct xlat mctl_lockas[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000468 XLAT(MCL_CURRENT),
469 XLAT(MCL_FUTURE),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000470 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000471};
472
473int
Denys Vlasenko12014262011-05-30 14:00:14 +0200474sys_mctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475{
476 int arg, function;
477
478 if (entering(tcp)) {
479 /* addr */
480 tprintf("%#lx", tcp->u_arg[0]);
481 /* len */
482 tprintf(", %lu, ", tcp->u_arg[1]);
483 /* function */
484 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000485 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000486 /* arg */
487 arg = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200488 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489 switch (function) {
490 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000491 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000492 break;
493 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000494 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000495 break;
496 default:
497 tprintf("%#x", arg);
498 break;
499 }
500 }
501 return 0;
502}
503
504#endif /* MC_SYNC */
505
506int
Denys Vlasenko12014262011-05-30 14:00:14 +0200507sys_mincore(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509 if (entering(tcp)) {
510 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
511 } else {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200512 unsigned long i, len;
513 char *vec = NULL;
514
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515 len = tcp->u_arg[1];
516 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000517 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000518 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
519 tprintf("%#lx", tcp->u_arg[2]);
520 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200521 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522 for (i = 0; i < len; i++) {
523 if (abbrev(tcp) && i >= max_strlen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200524 tprints("...");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525 break;
526 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200527 tprints((vec[i] & 1) ? "1" : "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000528 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200529 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200531 free(vec);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532 }
533 return 0;
534}
535
Denys Vlasenko84703742012-02-25 02:38:52 +0100536#if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537int
Denys Vlasenko12014262011-05-30 14:00:14 +0200538sys_getpagesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539{
540 if (exiting(tcp))
541 return RVAL_HEX;
542 return 0;
543}
Denys Vlasenko84703742012-02-25 02:38:52 +0100544#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545
Dmitry V. Levinf94e8472014-04-09 12:30:38 +0000546#if defined(I386) || defined(X86_64) || defined(X32)
Roland McGrath909875b2002-12-22 03:34:36 +0000547void
Denys Vlasenko1f458252009-01-23 16:10:22 +0000548print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
Roland McGrath34e4a692002-12-15 23:58:17 +0000549{
550 tprintf("base_addr:%#08lx, "
551 "limit:%d, "
552 "seg_32bit:%d, "
553 "contents:%d, "
554 "read_exec_only:%d, "
555 "limit_in_pages:%d, "
556 "seg_not_present:%d, "
557 "useable:%d}",
Denys Vlasenko1f458252009-01-23 16:10:22 +0000558 (long) ldt_entry->base_addr,
Roland McGrath34e4a692002-12-15 23:58:17 +0000559 ldt_entry->limit,
560 ldt_entry->seg_32bit,
561 ldt_entry->contents,
562 ldt_entry->read_exec_only,
563 ldt_entry->limit_in_pages,
564 ldt_entry->seg_not_present,
565 ldt_entry->useable);
566}
567
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000568int
Denys Vlasenko12014262011-05-30 14:00:14 +0200569sys_modify_ldt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570{
571 if (entering(tcp)) {
572 struct modify_ldt_ldt_s copy;
573 tprintf("%ld", tcp->u_arg[0]);
574 if (tcp->u_arg[1] == 0
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200575 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000576 || umove(tcp, tcp->u_arg[1], &copy) == -1)
577 tprintf(", %lx", tcp->u_arg[1]);
578 else {
579 tprintf(", {entry_number:%d, ", copy.entry_number);
580 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200581 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000582 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000583 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000584 }
585 }
586 tprintf(", %lu", tcp->u_arg[2]);
587 }
588 return 0;
589}
Roland McGrath34e4a692002-12-15 23:58:17 +0000590
591int
Denys Vlasenko12014262011-05-30 14:00:14 +0200592sys_set_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000593{
594 struct modify_ldt_ldt_s copy;
595 if (entering(tcp)) {
596 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
597 if (copy.entry_number == -1)
598 tprintf("{entry_number:%d -> ",
599 copy.entry_number);
600 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200601 tprints("{entry_number:");
Roland McGrath34e4a692002-12-15 23:58:17 +0000602 }
603 } else {
604 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
605 tprintf("%d, ", copy.entry_number);
606 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200607 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000608 else {
609 print_ldt_entry(&copy);
610 }
611 } else {
612 tprintf("%lx", tcp->u_arg[0]);
613 }
614 }
615 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000616
Roland McGrath34e4a692002-12-15 23:58:17 +0000617}
618
619int
Denys Vlasenko12014262011-05-30 14:00:14 +0200620sys_get_thread_area(struct tcb *tcp)
Roland McGrath34e4a692002-12-15 23:58:17 +0000621{
622 struct modify_ldt_ldt_s copy;
623 if (exiting(tcp)) {
624 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
625 tprintf("{entry_number:%d, ", copy.entry_number);
626 if (!verbose(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200627 tprints("...}");
Roland McGrath34e4a692002-12-15 23:58:17 +0000628 else {
629 print_ldt_entry(&copy);
630 }
631 } else {
632 tprintf("%lx", tcp->u_arg[0]);
633 }
634 }
635 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000636
Roland McGrath34e4a692002-12-15 23:58:17 +0000637}
Dmitry V. Levinf94e8472014-04-09 12:30:38 +0000638#endif /* I386 || X86_64 || X32 */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000639
Dmitry V. Levin15bc2812014-04-09 13:14:44 +0000640#if defined(M68K) || defined(MIPS)
Andreas Schwab58743222010-05-28 22:28:51 +0200641int
Denys Vlasenko12014262011-05-30 14:00:14 +0200642sys_set_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200643{
644 if (entering(tcp))
645 tprintf("%#lx", tcp->u_arg[0]);
646 return 0;
647
648}
Dmitry V. Levin15bc2812014-04-09 13:14:44 +0000649#endif
Andreas Schwab58743222010-05-28 22:28:51 +0200650
Dmitry V. Levin15bc2812014-04-09 13:14:44 +0000651#if defined(M68K)
Andreas Schwab58743222010-05-28 22:28:51 +0200652int
Denys Vlasenko12014262011-05-30 14:00:14 +0200653sys_get_thread_area(struct tcb *tcp)
Andreas Schwab58743222010-05-28 22:28:51 +0200654{
655 return RVAL_HEX;
656}
657#endif
658
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000659int
Denys Vlasenko12014262011-05-30 14:00:14 +0200660sys_remap_file_pages(struct tcb *tcp)
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000661{
662 if (entering(tcp)) {
663 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000664 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000665 tprintf(", %lu, ", tcp->u_arg[3]);
666#ifdef MAP_TYPE
667 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
668 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
669#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000670 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000671#endif
672 }
673 return 0;
674}
Roland McGrathb10a3352004-10-07 18:53:12 +0000675
Roland McGrathb10a3352004-10-07 18:53:12 +0000676#define MPOL_DEFAULT 0
677#define MPOL_PREFERRED 1
678#define MPOL_BIND 2
679#define MPOL_INTERLEAVE 3
680
681#define MPOL_F_NODE (1<<0)
682#define MPOL_F_ADDR (1<<1)
683
684#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000685#define MPOL_MF_MOVE (1<<1)
686#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000687
Roland McGrathb10a3352004-10-07 18:53:12 +0000688static const struct xlat policies[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000689 XLAT(MPOL_DEFAULT),
690 XLAT(MPOL_PREFERRED),
691 XLAT(MPOL_BIND),
692 XLAT(MPOL_INTERLEAVE),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000693 XLAT_END
Roland McGrathb10a3352004-10-07 18:53:12 +0000694};
695
696static const struct xlat mbindflags[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000697 XLAT(MPOL_MF_STRICT),
698 XLAT(MPOL_MF_MOVE),
699 XLAT(MPOL_MF_MOVE_ALL),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000700 XLAT_END
Roland McGrathb10a3352004-10-07 18:53:12 +0000701};
702
703static const struct xlat mempolicyflags[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000704 XLAT(MPOL_F_NODE),
705 XLAT(MPOL_F_ADDR),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000706 XLAT_END
Roland McGrathb10a3352004-10-07 18:53:12 +0000707};
708
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000709static const struct xlat move_pages_flags[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000710 XLAT(MPOL_MF_MOVE),
711 XLAT(MPOL_MF_MOVE_ALL),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000712 XLAT_END
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000713};
714
Roland McGrathb10a3352004-10-07 18:53:12 +0000715static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200716get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
Roland McGrathb10a3352004-10-07 18:53:12 +0000717{
Roland McGrathaa524c82005-06-01 19:22:06 +0000718 unsigned long nlongs, size, end;
719
720 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
721 size = nlongs * sizeof(long);
722 end = ptr + size;
723 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
724 && (end > ptr))) {
725 unsigned long n, cur, abbrev_end;
726 int failed = 0;
727
728 if (abbrev(tcp)) {
729 abbrev_end = ptr + max_strlen * sizeof(long);
730 if (abbrev_end < ptr)
731 abbrev_end = end;
732 } else {
733 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000734 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200735 tprints(", {");
Roland McGrathaa524c82005-06-01 19:22:06 +0000736 for (cur = ptr; cur < end; cur += sizeof(long)) {
737 if (cur > ptr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200738 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000739 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200740 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000741 break;
742 }
743 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200744 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000745 failed = 1;
746 break;
747 }
748 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
749 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200750 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000751 if (failed)
752 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000753 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000754 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000755 tprintf(", %lu", maxnodes);
756}
757
758int
Denys Vlasenko12014262011-05-30 14:00:14 +0200759sys_mbind(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000760{
761 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000762 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000763 printxval(policies, tcp->u_arg[2], "MPOL_???");
764 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200765 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000766 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000767 }
768 return 0;
769}
770
771int
Denys Vlasenko12014262011-05-30 14:00:14 +0200772sys_set_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000773{
774 if (entering(tcp)) {
775 printxval(policies, tcp->u_arg[0], "MPOL_???");
776 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
777 }
778 return 0;
779}
780
781int
Denys Vlasenko12014262011-05-30 14:00:14 +0200782sys_get_mempolicy(struct tcb *tcp)
Roland McGrathb10a3352004-10-07 18:53:12 +0000783{
784 if (exiting(tcp)) {
785 int pol;
786 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200787 tprints("NULL");
Roland McGrathb10a3352004-10-07 18:53:12 +0000788 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
789 tprintf("%#lx", tcp->u_arg[0]);
790 else
791 printxval(policies, pol, "MPOL_???");
792 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
793 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000794 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000795 }
796 return 0;
797}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000798
799int
Dmitry V. Levin64d0e712012-03-11 22:44:14 +0000800sys_migrate_pages(struct tcb *tcp)
801{
802 if (entering(tcp)) {
803 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
804 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
805 tprints(", ");
806 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
807 }
808 return 0;
809}
810
811int
Denys Vlasenko12014262011-05-30 14:00:14 +0200812sys_move_pages(struct tcb *tcp)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000813{
814 if (entering(tcp)) {
815 unsigned long npages = tcp->u_arg[1];
816 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
817 if (tcp->u_arg[2] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200818 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000819 else {
820 int i;
821 long puser = tcp->u_arg[2];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200822 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000823 for (i = 0; i < npages; ++i) {
824 void *p;
825 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200826 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000827 if (umove(tcp, puser, &p) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200828 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000829 break;
830 }
831 tprintf("%p", p);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200832 puser += sizeof(void *);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000833 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200834 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000835 }
836 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200837 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000838 else {
839 int i;
840 long nodeuser = tcp->u_arg[3];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200841 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000842 for (i = 0; i < npages; ++i) {
843 int node;
844 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200845 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000846 if (umove(tcp, nodeuser, &node) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200847 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000848 break;
849 }
850 tprintf("%#x", node);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200851 nodeuser += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000852 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200853 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000854 }
855 }
856 if (exiting(tcp)) {
857 unsigned long npages = tcp->u_arg[1];
858 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200859 tprints("NULL, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000860 else {
861 int i;
862 long statususer = tcp->u_arg[4];
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200863 tprints("{");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000864 for (i = 0; i < npages; ++i) {
865 int status;
866 if (i > 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200867 tprints(", ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000868 if (umove(tcp, statususer, &status) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200869 tprints("???");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000870 break;
871 }
872 tprintf("%#x", status);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200873 statususer += sizeof(int);
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000874 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200875 tprints("}, ");
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000876 }
877 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
878 }
879 return 0;
880}
Roland McGrath4a6f6522008-08-25 03:09:16 +0000881
Denys Vlasenko84703742012-02-25 02:38:52 +0100882#if defined(POWERPC)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000883int
Denys Vlasenko12014262011-05-30 14:00:14 +0200884sys_subpage_prot(struct tcb *tcp)
Roland McGrath4a6f6522008-08-25 03:09:16 +0000885{
886 if (entering(tcp)) {
887 unsigned long cur, end, abbrev_end, entries;
888 unsigned int entry;
889
890 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
891 entries = tcp->u_arg[1] >> 16;
892 if (!entries || !tcp->u_arg[2]) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200893 tprints("{}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000894 return 0;
895 }
896 cur = tcp->u_arg[2];
897 end = cur + (sizeof(int) * entries);
898 if (!verbose(tcp) || end < tcp->u_arg[2]) {
899 tprintf("%#lx", tcp->u_arg[2]);
900 return 0;
901 }
902 if (abbrev(tcp)) {
903 abbrev_end = cur + (sizeof(int) * max_strlen);
904 if (abbrev_end > end)
905 abbrev_end = end;
906 }
907 else
908 abbrev_end = end;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200909 tprints("{");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000910 for (; cur < end; cur += sizeof(int)) {
911 if (cur > tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200912 tprints(", ");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000913 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200914 tprints("...");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000915 break;
916 }
917 if (umove(tcp, cur, &entry) < 0) {
918 tprintf("??? [%#lx]", cur);
919 break;
920 }
921 else
922 tprintf("%#08x", entry);
923 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200924 tprints("}");
Roland McGrath4a6f6522008-08-25 03:09:16 +0000925 }
926
927 return 0;
928}
929#endif