blob: d4c223a4cee51fc11a9c1da702e30ba7512be7d7 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Roland McGrathe1e584b2003-06-02 19:18:58 +00006 * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
7 * port by Greg Banks <gbanks@pocketpenguins.com>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00008 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * $Id$
33 */
34
35#include "defs.h"
36
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000037#ifdef LINUX
Roland McGrath05cdd3c2004-03-02 06:16:59 +000038#include <asm/mman.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000039#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000040#include <sys/mman.h>
Wichert Akkerman5daa0281999-03-15 19:49:42 +000041
Roland McGrath909875b2002-12-22 03:34:36 +000042#if defined(LINUX) && defined(I386)
Wichert Akkerman8bc6cfd1999-04-21 15:57:38 +000043#include <asm/ldt.h>
Roland McGrath7decfb22004-03-01 22:10:52 +000044# ifdef HAVE_STRUCT_USER_DESC
45# define modify_ldt_ldt_s user_desc
46# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047#endif
Roland McGrathf5a47772003-06-26 22:40:42 +000048#if defined(LINUX) && defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +000049#include <asm/page.h> /* for PAGE_SHIFT */
50#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051
John Hughes70623be2001-03-08 13:59:00 +000052#ifdef HAVE_LONG_LONG_OFF_T
53/*
54 * Ugly hacks for systems that have a long long off_t
55 */
56#define sys_mmap64 sys_mmap
57#endif
58
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059int
60sys_brk(tcp)
61struct tcb *tcp;
62{
63 if (entering(tcp)) {
64 tprintf("%#lx", tcp->u_arg[0]);
65 }
Wichert Akkerman5daa0281999-03-15 19:49:42 +000066#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000067 return RVAL_HEX;
68#else
69 return 0;
70#endif
71}
72
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +000073#if defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074int
75sys_sbrk(tcp)
76struct tcb *tcp;
77{
78 if (entering(tcp)) {
79 tprintf("%lu", tcp->u_arg[0]);
80 }
81 return RVAL_HEX;
82}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +000083#endif /* FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084
Roland McGrathd9f816f2004-09-04 03:39:20 +000085static const struct xlat mmap_prot[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000086 { PROT_NONE, "PROT_NONE", },
87 { PROT_READ, "PROT_READ" },
88 { PROT_WRITE, "PROT_WRITE" },
89 { PROT_EXEC, "PROT_EXEC" },
Roland McGrath47eb0e22003-09-25 23:06:04 +000090#ifdef PROT_SEM
91 { PROT_SEM, "PROT_SEM" },
92#endif
93#ifdef PROT_GROWSDOWN
94 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
95#endif
96#ifdef PROT_GROWSUP
97 { PROT_GROWSUP, "PROT_GROWSUP" },
98#endif
Roland McGrath586d6ab2008-08-25 03:00:47 +000099#ifdef PROT_SAO
100 { PROT_SAO, "PROT_SAO" },
101#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000102 { 0, NULL },
103};
104
Roland McGrathd9f816f2004-09-04 03:39:20 +0000105static const struct xlat mmap_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000106 { MAP_SHARED, "MAP_SHARED" },
107 { MAP_PRIVATE, "MAP_PRIVATE" },
108 { MAP_FIXED, "MAP_FIXED" },
109#ifdef MAP_ANONYMOUS
110 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
111#endif
Dmitry V. Levin71f1a132007-03-29 23:30:09 +0000112#ifdef MAP_32BIT
113 { MAP_32BIT, "MAP_32BIT" },
114#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000115#ifdef MAP_RENAME
116 { MAP_RENAME, "MAP_RENAME" },
117#endif
118#ifdef MAP_NORESERVE
119 { MAP_NORESERVE,"MAP_NORESERVE" },
120#endif
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000121#ifdef MAP_POPULATE
122 { MAP_POPULATE, "MAP_POPULATE" },
123#endif
124#ifdef MAP_NONBLOCK
125 { MAP_NONBLOCK, "MAP_NONBLOCK" },
126#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000127 /*
128 * XXX - this was introduced in SunOS 4.x to distinguish between
129 * the old pre-4.x "mmap()", which:
130 *
131 * only let you map devices with an "mmap" routine (e.g.,
132 * frame buffers) in;
133 *
134 * required you to specify the mapping address;
135 *
136 * returned 0 on success and -1 on failure;
137 *
138 * memory and which, and the 4.x "mmap()" which:
139 *
140 * can map plain files;
141 *
142 * can be asked to pick where to map the file;
143 *
144 * returns the address where it mapped the file on success
145 * and -1 on failure.
146 *
147 * It's not actually used in source code that calls "mmap()"; the
148 * "mmap()" routine adds it for you.
149 *
150 * It'd be nice to come up with some way of eliminating it from
151 * the flags, e.g. reporting calls *without* it as "old_mmap()"
152 * and calls with it as "mmap()".
153 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000154#ifdef _MAP_NEW
155 { _MAP_NEW, "_MAP_NEW" },
156#endif
157#ifdef MAP_GROWSDOWN
158 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
159#endif
160#ifdef MAP_DENYWRITE
161 { MAP_DENYWRITE,"MAP_DENYWRITE" },
162#endif
163#ifdef MAP_EXECUTABLE
164 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
165#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000166#ifdef MAP_INHERIT
167 { MAP_INHERIT,"MAP_INHERIT" },
168#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000169#ifdef MAP_FILE
170 { MAP_FILE,"MAP_FILE"},
171#endif
172#ifdef MAP_LOCKED
173 { MAP_LOCKED,"MAP_LOCKED"},
174#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000175 /* FreeBSD ones */
176#ifdef MAP_ANON
177 { MAP_ANON, "MAP_ANON" },
178#endif
179#ifdef MAP_HASSEMAPHORE
180 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
181#endif
182#ifdef MAP_STACK
183 { MAP_STACK, "MAP_STACK" },
184#endif
185#ifdef MAP_NOSYNC
186 { MAP_NOSYNC, "MAP_NOSYNC" },
187#endif
188#ifdef MAP_NOCORE
189 { MAP_NOCORE, "MAP_NOCORE" },
190#endif
Chris Metcalfc8c66982009-12-28 10:00:15 -0500191#ifdef TILE
192 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
193 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
194 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
195#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000196 { 0, NULL },
197};
198
Chris Metcalfc8c66982009-12-28 10:00:15 -0500199#ifdef TILE
200static
201int
202addtileflags(flags)
203long flags;
204{
205 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
206 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
207
208 if (flags & _MAP_CACHE_INCOHERENT) {
209 flags &= ~_MAP_CACHE_INCOHERENT;
210 if (home == MAP_CACHE_HOME_NONE) {
211 tprintf("|MAP_CACHE_INCOHERENT");
212 return flags;
213 }
214 tprintf("|_MAP_CACHE_INCOHERENT");
215 }
216
217 switch (home) {
218 case 0: break;
219 case MAP_CACHE_HOME_HERE: tprintf("|MAP_CACHE_HOME_HERE"); break;
220 case MAP_CACHE_HOME_NONE: tprintf("|MAP_CACHE_HOME_NONE"); break;
221 case MAP_CACHE_HOME_SINGLE: tprintf("|MAP_CACHE_HOME_SINGLE"); break;
222 case MAP_CACHE_HOME_TASK: tprintf("|MAP_CACHE_HOME_TASK"); break;
223 case MAP_CACHE_HOME_HASH: tprintf("|MAP_CACHE_HOME_HASH"); break;
224 default:
225 tprintf("|MAP_CACHE_HOME(%d)",
226 (home >> _MAP_CACHE_HOME_SHIFT) );
227 break;
228 }
229
230 return flags;
231}
232#endif
233
John Hughes70623be2001-03-08 13:59:00 +0000234#if !HAVE_LONG_LONG_OFF_T
Dmitry V. Levin31382132011-03-04 05:08:02 +0300235static int
236print_mmap(struct tcb *tcp, long *u_arg, long long offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000237{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000238 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000239 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000240 if (!u_arg[0])
241 tprintf("NULL, ");
242 else
243 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000244 /* len */
245 tprintf("%lu, ", u_arg[1]);
246 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000247 printflags(mmap_prot, u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000248 tprintf(", ");
249 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000250#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000251 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500252#ifdef TILE
253 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
254#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Chris Metcalfc8c66982009-12-28 10:00:15 -0500256#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000257#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000258 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000259#endif
Dmitry V. Levin31382132011-03-04 05:08:02 +0300260 /* fd */
261 tprintf(", ");
262 printfd(tcp, u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000263 /* offset */
Dmitry V. Levin31382132011-03-04 05:08:02 +0300264 tprintf(", %#llx", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000265 }
266 return RVAL_HEX;
267}
268
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000269#ifdef LINUX
270int sys_old_mmap(tcp)
271struct tcb *tcp;
272{
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000273 long u_arg[6];
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000274
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000275#if defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000276 int i, v;
277 /*
278 * IA64 processes never call this routine, they only use the
279 * new `sys_mmap' interface. This code converts the integer
280 * arguments that the IA32 process pushed onto the stack into
281 * longs.
282 *
283 * Note that addresses with bit 31 set will be sign extended.
284 * Fortunately, those addresses are not currently being generated
285 * for IA32 processes so it's not a problem.
286 */
287 for (i = 0; i < 6; i++)
288 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
289 return 0;
290 else
291 u_arg[i] = v;
Roland McGrathf5a47772003-06-26 22:40:42 +0000292#elif defined(SH) || defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000293 /* SH has always passed the args in registers */
294 int i;
295 for (i=0; i<6; i++)
296 u_arg[i] = tcp->u_arg[i];
Roland McGrath6b1d43e2003-03-31 01:05:01 +0000297#else
Roland McGrath520e21f2005-07-05 09:50:18 +0000298# if defined(X86_64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000299 if (current_personality == 1) {
300 int i;
301 for (i = 0; i < 6; ++i) {
302 unsigned int val;
303 if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
304 return 0;
305 u_arg[i] = val;
306 }
307 }
308 else
Roland McGrath520e21f2005-07-05 09:50:18 +0000309# endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000310 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
311 return 0;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000312#endif // defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000313 return print_mmap(tcp, u_arg, u_arg[5]);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000314}
315#endif
316
317int
318sys_mmap(tcp)
319struct tcb *tcp;
320{
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000321 long long offset = tcp->u_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000322
Roland McGrathf5a47772003-06-26 22:40:42 +0000323#if defined(LINUX) && defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000324 /*
325 * Old mmap differs from new mmap in specifying the
326 * offset in units of bytes rather than pages. We
327 * pretend it's in byte units so the user only ever
328 * sees bytes in the printout.
329 */
330 offset <<= PAGE_SHIFT;
Roland McGrathe1e584b2003-06-02 19:18:58 +0000331#endif
Roland McGrath542c2c62008-05-20 01:11:56 +0000332#if defined(LINUX_MIPSN32)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000333 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000334#endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000335 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000336}
John Hughes70623be2001-03-08 13:59:00 +0000337#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000338
John Hughes70623be2001-03-08 13:59:00 +0000339#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000340int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300341sys_mmap64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000342{
343#ifdef linux
344#ifdef ALPHA
345 long *u_arg = tcp->u_arg;
346#else /* !ALPHA */
347 long u_arg[7];
348#endif /* !ALPHA */
349#else /* !linux */
350 long *u_arg = tcp->u_arg;
351#endif /* !linux */
352
353 if (entering(tcp)) {
354#ifdef linux
355#ifndef ALPHA
356 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
357 (char *) u_arg) == -1)
358 return 0;
359#endif /* ALPHA */
360#endif /* linux */
361
362 /* addr */
363 tprintf("%#lx, ", u_arg[0]);
364 /* len */
365 tprintf("%lu, ", u_arg[1]);
366 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000367 printflags(mmap_prot, u_arg[2], "PROT_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000368 tprintf(", ");
369 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000370#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000371 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
372 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000373#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000374 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000375#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000376 /* fd */
Dmitry V. Levin31382132011-03-04 05:08:02 +0300377 tprintf(", ");
378 printfd(tcp, tcp->u_arg[4]);
John Hughesbdf48f52001-03-06 15:08:09 +0000379 /* offset */
Dmitry V. Levin31382132011-03-04 05:08:02 +0300380 printllval(tcp, ", %#llx", 5);
John Hughesbdf48f52001-03-06 15:08:09 +0000381 }
382 return RVAL_HEX;
383}
384#endif
385
Roland McGrath909875b2002-12-22 03:34:36 +0000386
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387int
388sys_munmap(tcp)
389struct tcb *tcp;
390{
391 if (entering(tcp)) {
392 tprintf("%#lx, %lu",
393 tcp->u_arg[0], tcp->u_arg[1]);
394 }
395 return 0;
396}
397
398int
399sys_mprotect(tcp)
400struct tcb *tcp;
401{
402 if (entering(tcp)) {
403 tprintf("%#lx, %lu, ",
404 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000405 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406 }
407 return 0;
408}
409
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000410#ifdef LINUX
411
Roland McGrathd9f816f2004-09-04 03:39:20 +0000412static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000413 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
Chris Metcalfff3474a2009-12-24 23:19:19 +0000414#ifdef MREMAP_FIXED
415 { MREMAP_FIXED, "MREMAP_FIXED" },
416#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000417 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000418};
419
420int
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000421sys_mremap(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000422{
423 if (entering(tcp)) {
424 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
425 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000426 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000427#ifdef MREMAP_FIXED
428 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
429 (MREMAP_MAYMOVE | MREMAP_FIXED))
430 tprintf(", %#lx", tcp->u_arg[4]);
431#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000432 }
433 return RVAL_HEX;
434}
435
Roland McGrathf4021b12008-08-25 02:59:36 +0000436static const struct xlat madvise_cmds[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000437#ifdef MADV_NORMAL
438 { MADV_NORMAL, "MADV_NORMAL" },
439#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000440#ifdef MADV_RANDOM
Wichert Akkermanc7926982000-04-10 22:22:31 +0000441 { MADV_RANDOM, "MADV_RANDOM" },
442#endif
443#ifdef MADV_SEQUENTIAL
444 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
445#endif
446#ifdef MADV_WILLNEED
447 { MADV_WILLNEED, "MADV_WILLNEED" },
448#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000449#ifdef MADV_DONTNEED
Wichert Akkermanc7926982000-04-10 22:22:31 +0000450 { MADV_DONTNEED, "MADV_DONTNEED" },
451#endif
452 { 0, NULL },
453};
454
455
456int
457sys_madvise(tcp)
458struct tcb *tcp;
459{
460 if (entering(tcp)) {
461 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000462 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000463 }
464 return 0;
465}
466
467
Roland McGrathd9f816f2004-09-04 03:39:20 +0000468static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000469#ifdef MCL_CURRENT
470 { MCL_CURRENT, "MCL_CURRENT" },
471#endif
472#ifdef MCL_FUTURE
473 { MCL_FUTURE, "MCL_FUTURE" },
474#endif
475 { 0, NULL}
476};
477
478int
479sys_mlockall(tcp)
480struct tcb *tcp;
481{
482 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000483 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000484 }
485 return 0;
486}
487
488
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000489#endif /* LINUX */
490
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491#ifdef MS_ASYNC
492
Roland McGrathd9f816f2004-09-04 03:39:20 +0000493static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000494#ifdef MS_SYNC
495 { MS_SYNC, "MS_SYNC" },
496#endif
John Hughesaca07f32001-10-16 18:12:27 +0000497 { MS_ASYNC, "MS_ASYNC" },
498 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000499 { 0, NULL },
500};
501
502int
503sys_msync(tcp)
504struct tcb *tcp;
505{
506 if (entering(tcp)) {
507 /* addr */
508 tprintf("%#lx", tcp->u_arg[0]);
509 /* len */
510 tprintf(", %lu, ", tcp->u_arg[1]);
511 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000512 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000513 }
514 return 0;
515}
516
517#endif /* MS_ASYNC */
518
519#ifdef MC_SYNC
520
Roland McGrathd9f816f2004-09-04 03:39:20 +0000521static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522 { MC_LOCK, "MC_LOCK" },
523 { MC_LOCKAS, "MC_LOCKAS" },
524 { MC_SYNC, "MC_SYNC" },
525 { MC_UNLOCK, "MC_UNLOCK" },
526 { MC_UNLOCKAS, "MC_UNLOCKAS" },
527 { 0, NULL },
528};
529
Roland McGrathd9f816f2004-09-04 03:39:20 +0000530static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531 { MCL_CURRENT, "MCL_CURRENT" },
532 { MCL_FUTURE, "MCL_FUTURE" },
533 { 0, NULL },
534};
535
536int
537sys_mctl(tcp)
538struct tcb *tcp;
539{
540 int arg, function;
541
542 if (entering(tcp)) {
543 /* addr */
544 tprintf("%#lx", tcp->u_arg[0]);
545 /* len */
546 tprintf(", %lu, ", tcp->u_arg[1]);
547 /* function */
548 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000549 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550 /* arg */
551 arg = tcp->u_arg[3];
552 tprintf(", ");
553 switch (function) {
554 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000555 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000556 break;
557 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000558 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559 break;
560 default:
561 tprintf("%#x", arg);
562 break;
563 }
564 }
565 return 0;
566}
567
568#endif /* MC_SYNC */
569
570int
571sys_mincore(tcp)
572struct tcb *tcp;
573{
Roland McGrath46100d02005-06-01 18:55:42 +0000574 unsigned long i, len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575 char *vec = NULL;
576
577 if (entering(tcp)) {
578 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
579 } else {
580 len = tcp->u_arg[1];
581 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000582 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000583 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
584 tprintf("%#lx", tcp->u_arg[2]);
585 else {
586 tprintf("[");
587 for (i = 0; i < len; i++) {
588 if (abbrev(tcp) && i >= max_strlen) {
589 tprintf("...");
590 break;
591 }
592 tprintf((vec[i] & 1) ? "1" : "0");
593 }
594 tprintf("]");
595 }
596 if (vec)
597 free(vec);
598 }
599 return 0;
600}
601
Roland McGrathda6c92c2007-09-12 01:26:29 +0000602#if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000603int
604sys_getpagesize(tcp)
605struct tcb *tcp;
606{
607 if (exiting(tcp))
608 return RVAL_HEX;
609 return 0;
610}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000611#endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000612
613#if defined(LINUX) && defined(__i386__)
Roland McGrath909875b2002-12-22 03:34:36 +0000614void
Denys Vlasenko1f458252009-01-23 16:10:22 +0000615print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
Roland McGrath34e4a692002-12-15 23:58:17 +0000616{
617 tprintf("base_addr:%#08lx, "
618 "limit:%d, "
619 "seg_32bit:%d, "
620 "contents:%d, "
621 "read_exec_only:%d, "
622 "limit_in_pages:%d, "
623 "seg_not_present:%d, "
624 "useable:%d}",
Denys Vlasenko1f458252009-01-23 16:10:22 +0000625 (long) ldt_entry->base_addr,
Roland McGrath34e4a692002-12-15 23:58:17 +0000626 ldt_entry->limit,
627 ldt_entry->seg_32bit,
628 ldt_entry->contents,
629 ldt_entry->read_exec_only,
630 ldt_entry->limit_in_pages,
631 ldt_entry->seg_not_present,
632 ldt_entry->useable);
633}
634
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000635int
636sys_modify_ldt(tcp)
637struct tcb *tcp;
638{
639 if (entering(tcp)) {
640 struct modify_ldt_ldt_s copy;
641 tprintf("%ld", tcp->u_arg[0]);
642 if (tcp->u_arg[1] == 0
643 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
644 || umove(tcp, tcp->u_arg[1], &copy) == -1)
645 tprintf(", %lx", tcp->u_arg[1]);
646 else {
647 tprintf(", {entry_number:%d, ", copy.entry_number);
648 if (!verbose(tcp))
649 tprintf("...}");
650 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000651 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000652 }
653 }
654 tprintf(", %lu", tcp->u_arg[2]);
655 }
656 return 0;
657}
Roland McGrath34e4a692002-12-15 23:58:17 +0000658
659int
660sys_set_thread_area(tcp)
661struct tcb *tcp;
662{
663 struct modify_ldt_ldt_s copy;
664 if (entering(tcp)) {
665 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
666 if (copy.entry_number == -1)
667 tprintf("{entry_number:%d -> ",
668 copy.entry_number);
669 else
670 tprintf("{entry_number:");
671 }
672 } else {
673 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
674 tprintf("%d, ", copy.entry_number);
675 if (!verbose(tcp))
676 tprintf("...}");
677 else {
678 print_ldt_entry(&copy);
679 }
680 } else {
681 tprintf("%lx", tcp->u_arg[0]);
682 }
683 }
684 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000685
Roland McGrath34e4a692002-12-15 23:58:17 +0000686}
687
688int
689sys_get_thread_area(tcp)
690struct tcb *tcp;
691{
692 struct modify_ldt_ldt_s copy;
693 if (exiting(tcp)) {
694 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
695 tprintf("{entry_number:%d, ", copy.entry_number);
696 if (!verbose(tcp))
697 tprintf("...}");
698 else {
699 print_ldt_entry(&copy);
700 }
701 } else {
702 tprintf("%lx", tcp->u_arg[0]);
703 }
704 }
705 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000706
Roland McGrath34e4a692002-12-15 23:58:17 +0000707}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000708#endif /* LINUX && __i386__ */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000709
Andreas Schwab58743222010-05-28 22:28:51 +0200710#if defined(LINUX) && defined(M68K)
711
712int
713sys_set_thread_area(tcp)
714struct tcb *tcp;
715{
716 if (entering(tcp))
717 tprintf("%#lx", tcp->u_arg[0]);
718 return 0;
719
720}
721
722int
723sys_get_thread_area(tcp)
724struct tcb *tcp;
725{
726 return RVAL_HEX;
727}
728#endif
729
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000730#if defined(LINUX)
731int
732sys_remap_file_pages(tcp)
733struct tcb *tcp;
734{
735 if (entering(tcp)) {
736 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000737 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000738 tprintf(", %lu, ", tcp->u_arg[3]);
739#ifdef MAP_TYPE
740 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
741 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
742#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000743 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000744#endif
745 }
746 return 0;
747}
Roland McGrathb10a3352004-10-07 18:53:12 +0000748
749
750#define MPOL_DEFAULT 0
751#define MPOL_PREFERRED 1
752#define MPOL_BIND 2
753#define MPOL_INTERLEAVE 3
754
755#define MPOL_F_NODE (1<<0)
756#define MPOL_F_ADDR (1<<1)
757
758#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000759#define MPOL_MF_MOVE (1<<1)
760#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000761
762
763static const struct xlat policies[] = {
764 { MPOL_DEFAULT, "MPOL_DEFAULT" },
765 { MPOL_PREFERRED, "MPOL_PREFERRED" },
766 { MPOL_BIND, "MPOL_BIND" },
767 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
768 { 0, NULL }
769};
770
771static const struct xlat mbindflags[] = {
772 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000773 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
774 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
Roland McGrathb10a3352004-10-07 18:53:12 +0000775 { 0, NULL }
776};
777
778static const struct xlat mempolicyflags[] = {
779 { MPOL_F_NODE, "MPOL_F_NODE" },
780 { MPOL_F_ADDR, "MPOL_F_ADDR" },
781 { 0, NULL }
782};
783
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000784static const struct xlat move_pages_flags[] = {
785 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
786 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
787 { 0, NULL }
788};
789
Roland McGrathb10a3352004-10-07 18:53:12 +0000790
791static void
792get_nodes(tcp, ptr, maxnodes, err)
793struct tcb *tcp;
794unsigned long ptr;
795unsigned long maxnodes;
796int err;
797{
Roland McGrathaa524c82005-06-01 19:22:06 +0000798 unsigned long nlongs, size, end;
799
800 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
801 size = nlongs * sizeof(long);
802 end = ptr + size;
803 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
804 && (end > ptr))) {
805 unsigned long n, cur, abbrev_end;
806 int failed = 0;
807
808 if (abbrev(tcp)) {
809 abbrev_end = ptr + max_strlen * sizeof(long);
810 if (abbrev_end < ptr)
811 abbrev_end = end;
812 } else {
813 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000814 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000815 tprintf(", {");
816 for (cur = ptr; cur < end; cur += sizeof(long)) {
817 if (cur > ptr)
818 tprintf(", ");
819 if (cur >= abbrev_end) {
820 tprintf("...");
821 break;
822 }
823 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
824 tprintf("?");
825 failed = 1;
826 break;
827 }
828 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
829 }
830 tprintf("}");
831 if (failed)
832 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000833 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000834 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000835 tprintf(", %lu", maxnodes);
836}
837
838int
839sys_mbind(tcp)
840struct tcb *tcp;
841{
842 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000843 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000844 printxval(policies, tcp->u_arg[2], "MPOL_???");
845 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
846 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000847 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000848 }
849 return 0;
850}
851
852int
853sys_set_mempolicy(tcp)
854struct tcb *tcp;
855{
856 if (entering(tcp)) {
857 printxval(policies, tcp->u_arg[0], "MPOL_???");
858 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
859 }
860 return 0;
861}
862
863int
864sys_get_mempolicy(tcp)
865struct tcb *tcp;
866{
867 if (exiting(tcp)) {
868 int pol;
869 if (tcp->u_arg[0] == 0)
870 tprintf("NULL");
871 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
872 tprintf("%#lx", tcp->u_arg[0]);
873 else
874 printxval(policies, pol, "MPOL_???");
875 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
876 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000877 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000878 }
879 return 0;
880}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000881
882int
883sys_move_pages(tcp)
884struct tcb *tcp;
885{
886 if (entering(tcp)) {
887 unsigned long npages = tcp->u_arg[1];
888 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
889 if (tcp->u_arg[2] == 0)
890 tprintf("NULL, ");
891 else {
892 int i;
893 long puser = tcp->u_arg[2];
894 tprintf("{");
895 for (i = 0; i < npages; ++i) {
896 void *p;
897 if (i > 0)
898 tprintf(", ");
899 if (umove(tcp, puser, &p) < 0) {
900 tprintf("???");
901 break;
902 }
903 tprintf("%p", p);
904 puser += sizeof (void *);
905 }
906 tprintf("}, ");
907 }
908 if (tcp->u_arg[3] == 0)
909 tprintf("NULL, ");
910 else {
911 int i;
912 long nodeuser = tcp->u_arg[3];
913 tprintf("{");
914 for (i = 0; i < npages; ++i) {
915 int node;
916 if (i > 0)
917 tprintf(", ");
918 if (umove(tcp, nodeuser, &node) < 0) {
919 tprintf("???");
920 break;
921 }
922 tprintf("%#x", node);
923 nodeuser += sizeof (int);
924 }
925 tprintf("}, ");
926 }
927 }
928 if (exiting(tcp)) {
929 unsigned long npages = tcp->u_arg[1];
930 if (tcp->u_arg[4] == 0)
931 tprintf("NULL, ");
932 else {
933 int i;
934 long statususer = tcp->u_arg[4];
935 tprintf("{");
936 for (i = 0; i < npages; ++i) {
937 int status;
938 if (i > 0)
939 tprintf(", ");
940 if (umove(tcp, statususer, &status) < 0) {
941 tprintf("???");
942 break;
943 }
944 tprintf("%#x", status);
945 statususer += sizeof (int);
946 }
947 tprintf("}, ");
948 }
949 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
950 }
951 return 0;
952}
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000953#endif
Roland McGrath4a6f6522008-08-25 03:09:16 +0000954
955#if defined(LINUX) && defined(POWERPC)
956int
957sys_subpage_prot(tcp)
958struct tcb *tcp;
959{
960 if (entering(tcp)) {
961 unsigned long cur, end, abbrev_end, entries;
962 unsigned int entry;
963
964 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
965 entries = tcp->u_arg[1] >> 16;
966 if (!entries || !tcp->u_arg[2]) {
967 tprintf("{}");
968 return 0;
969 }
970 cur = tcp->u_arg[2];
971 end = cur + (sizeof(int) * entries);
972 if (!verbose(tcp) || end < tcp->u_arg[2]) {
973 tprintf("%#lx", tcp->u_arg[2]);
974 return 0;
975 }
976 if (abbrev(tcp)) {
977 abbrev_end = cur + (sizeof(int) * max_strlen);
978 if (abbrev_end > end)
979 abbrev_end = end;
980 }
981 else
982 abbrev_end = end;
983 tprintf("{");
984 for (; cur < end; cur += sizeof(int)) {
985 if (cur > tcp->u_arg[2])
986 tprintf(", ");
987 if (cur >= abbrev_end) {
988 tprintf("...");
989 break;
990 }
991 if (umove(tcp, cur, &entry) < 0) {
992 tprintf("??? [%#lx]", cur);
993 break;
994 }
995 else
996 tprintf("%#08x", entry);
997 }
998 tprintf("}");
999 }
1000
1001 return 0;
1002}
1003#endif