blob: d55cd695ca4fe4cad97af9f188a666a5d72b7d7c [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
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000235static
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236int
Roland McGrath542c2c62008-05-20 01:11:56 +0000237print_mmap(tcp,u_arg, offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000238struct tcb *tcp;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000239long *u_arg;
Roland McGrath542c2c62008-05-20 01:11:56 +0000240long long offset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000241{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000242 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000243 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000244 if (!u_arg[0])
245 tprintf("NULL, ");
246 else
247 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000248 /* len */
249 tprintf("%lu, ", u_arg[1]);
250 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000251 printflags(mmap_prot, u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000252 tprintf(", ");
253 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000254#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
Chris Metcalfc8c66982009-12-28 10:00:15 -0500256#ifdef TILE
257 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
258#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000259 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Chris Metcalfc8c66982009-12-28 10:00:15 -0500260#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000261#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000262 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000263#endif
Michal Ludvig0e035502002-09-23 15:41:01 +0000264 /* fd (is always int, not long) */
265 tprintf(", %d, ", (int)u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000266 /* offset */
Roland McGrath542c2c62008-05-20 01:11:56 +0000267 tprintf("%#llx", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000268 }
269 return RVAL_HEX;
270}
271
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000272#ifdef LINUX
273int sys_old_mmap(tcp)
274struct tcb *tcp;
275{
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000276 long u_arg[6];
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000277
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000278#if defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000279 int i, v;
280 /*
281 * IA64 processes never call this routine, they only use the
282 * new `sys_mmap' interface. This code converts the integer
283 * arguments that the IA32 process pushed onto the stack into
284 * longs.
285 *
286 * Note that addresses with bit 31 set will be sign extended.
287 * Fortunately, those addresses are not currently being generated
288 * for IA32 processes so it's not a problem.
289 */
290 for (i = 0; i < 6; i++)
291 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
292 return 0;
293 else
294 u_arg[i] = v;
Roland McGrathf5a47772003-06-26 22:40:42 +0000295#elif defined(SH) || defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000296 /* SH has always passed the args in registers */
297 int i;
298 for (i=0; i<6; i++)
299 u_arg[i] = tcp->u_arg[i];
Roland McGrath6b1d43e2003-03-31 01:05:01 +0000300#else
Roland McGrath520e21f2005-07-05 09:50:18 +0000301# if defined(X86_64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000302 if (current_personality == 1) {
303 int i;
304 for (i = 0; i < 6; ++i) {
305 unsigned int val;
306 if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
307 return 0;
308 u_arg[i] = val;
309 }
310 }
311 else
Roland McGrath520e21f2005-07-05 09:50:18 +0000312# endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000313 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
314 return 0;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000315#endif // defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000316 return print_mmap(tcp, u_arg, u_arg[5]);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000317}
318#endif
319
320int
321sys_mmap(tcp)
322struct tcb *tcp;
323{
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000324 long long offset = tcp->u_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000325
Roland McGrathf5a47772003-06-26 22:40:42 +0000326#if defined(LINUX) && defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000327 /*
328 * Old mmap differs from new mmap in specifying the
329 * offset in units of bytes rather than pages. We
330 * pretend it's in byte units so the user only ever
331 * sees bytes in the printout.
332 */
333 offset <<= PAGE_SHIFT;
Roland McGrathe1e584b2003-06-02 19:18:58 +0000334#endif
Roland McGrath542c2c62008-05-20 01:11:56 +0000335#if defined(LINUX_MIPSN32)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000336 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000337#endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000338 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000339}
John Hughes70623be2001-03-08 13:59:00 +0000340#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000341
John Hughes70623be2001-03-08 13:59:00 +0000342#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000343int
344sys_mmap64(tcp)
345struct tcb *tcp;
346{
347#ifdef linux
348#ifdef ALPHA
349 long *u_arg = tcp->u_arg;
350#else /* !ALPHA */
351 long u_arg[7];
352#endif /* !ALPHA */
353#else /* !linux */
354 long *u_arg = tcp->u_arg;
355#endif /* !linux */
356
357 if (entering(tcp)) {
358#ifdef linux
359#ifndef ALPHA
360 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
361 (char *) u_arg) == -1)
362 return 0;
363#endif /* ALPHA */
364#endif /* linux */
365
366 /* addr */
367 tprintf("%#lx, ", u_arg[0]);
368 /* len */
369 tprintf("%lu, ", u_arg[1]);
370 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000371 printflags(mmap_prot, u_arg[2], "PROT_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000372 tprintf(", ");
373 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000374#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000375 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
376 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000377#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000378 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000379#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000380 /* fd */
381 tprintf(", %ld, ", u_arg[4]);
382 /* offset */
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100383 printllval(tcp, "%#llx", 5);
John Hughesbdf48f52001-03-06 15:08:09 +0000384 }
385 return RVAL_HEX;
386}
387#endif
388
Roland McGrath909875b2002-12-22 03:34:36 +0000389
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000390int
391sys_munmap(tcp)
392struct tcb *tcp;
393{
394 if (entering(tcp)) {
395 tprintf("%#lx, %lu",
396 tcp->u_arg[0], tcp->u_arg[1]);
397 }
398 return 0;
399}
400
401int
402sys_mprotect(tcp)
403struct tcb *tcp;
404{
405 if (entering(tcp)) {
406 tprintf("%#lx, %lu, ",
407 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000408 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000409 }
410 return 0;
411}
412
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000413#ifdef LINUX
414
Roland McGrathd9f816f2004-09-04 03:39:20 +0000415static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000416 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
Chris Metcalfff3474a2009-12-24 23:19:19 +0000417#ifdef MREMAP_FIXED
418 { MREMAP_FIXED, "MREMAP_FIXED" },
419#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000420 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000421};
422
423int
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000424sys_mremap(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000425{
426 if (entering(tcp)) {
427 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
428 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000429 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Dmitry V. Levinfdc45592009-12-24 23:34:58 +0000430#ifdef MREMAP_FIXED
431 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
432 (MREMAP_MAYMOVE | MREMAP_FIXED))
433 tprintf(", %#lx", tcp->u_arg[4]);
434#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000435 }
436 return RVAL_HEX;
437}
438
Roland McGrathf4021b12008-08-25 02:59:36 +0000439static const struct xlat madvise_cmds[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000440#ifdef MADV_NORMAL
441 { MADV_NORMAL, "MADV_NORMAL" },
442#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000443#ifdef MADV_RANDOM
Wichert Akkermanc7926982000-04-10 22:22:31 +0000444 { MADV_RANDOM, "MADV_RANDOM" },
445#endif
446#ifdef MADV_SEQUENTIAL
447 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
448#endif
449#ifdef MADV_WILLNEED
450 { MADV_WILLNEED, "MADV_WILLNEED" },
451#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000452#ifdef MADV_DONTNEED
Wichert Akkermanc7926982000-04-10 22:22:31 +0000453 { MADV_DONTNEED, "MADV_DONTNEED" },
454#endif
455 { 0, NULL },
456};
457
458
459int
460sys_madvise(tcp)
461struct tcb *tcp;
462{
463 if (entering(tcp)) {
464 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000465 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000466 }
467 return 0;
468}
469
470
Roland McGrathd9f816f2004-09-04 03:39:20 +0000471static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000472#ifdef MCL_CURRENT
473 { MCL_CURRENT, "MCL_CURRENT" },
474#endif
475#ifdef MCL_FUTURE
476 { MCL_FUTURE, "MCL_FUTURE" },
477#endif
478 { 0, NULL}
479};
480
481int
482sys_mlockall(tcp)
483struct tcb *tcp;
484{
485 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000486 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000487 }
488 return 0;
489}
490
491
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000492#endif /* LINUX */
493
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000494#ifdef MS_ASYNC
495
Roland McGrathd9f816f2004-09-04 03:39:20 +0000496static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000497#ifdef MS_SYNC
498 { MS_SYNC, "MS_SYNC" },
499#endif
John Hughesaca07f32001-10-16 18:12:27 +0000500 { MS_ASYNC, "MS_ASYNC" },
501 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000502 { 0, NULL },
503};
504
505int
506sys_msync(tcp)
507struct tcb *tcp;
508{
509 if (entering(tcp)) {
510 /* addr */
511 tprintf("%#lx", tcp->u_arg[0]);
512 /* len */
513 tprintf(", %lu, ", tcp->u_arg[1]);
514 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000515 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000516 }
517 return 0;
518}
519
520#endif /* MS_ASYNC */
521
522#ifdef MC_SYNC
523
Roland McGrathd9f816f2004-09-04 03:39:20 +0000524static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525 { MC_LOCK, "MC_LOCK" },
526 { MC_LOCKAS, "MC_LOCKAS" },
527 { MC_SYNC, "MC_SYNC" },
528 { MC_UNLOCK, "MC_UNLOCK" },
529 { MC_UNLOCKAS, "MC_UNLOCKAS" },
530 { 0, NULL },
531};
532
Roland McGrathd9f816f2004-09-04 03:39:20 +0000533static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000534 { MCL_CURRENT, "MCL_CURRENT" },
535 { MCL_FUTURE, "MCL_FUTURE" },
536 { 0, NULL },
537};
538
539int
540sys_mctl(tcp)
541struct tcb *tcp;
542{
543 int arg, function;
544
545 if (entering(tcp)) {
546 /* addr */
547 tprintf("%#lx", tcp->u_arg[0]);
548 /* len */
549 tprintf(", %lu, ", tcp->u_arg[1]);
550 /* function */
551 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000552 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000553 /* arg */
554 arg = tcp->u_arg[3];
555 tprintf(", ");
556 switch (function) {
557 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000558 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559 break;
560 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000561 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562 break;
563 default:
564 tprintf("%#x", arg);
565 break;
566 }
567 }
568 return 0;
569}
570
571#endif /* MC_SYNC */
572
573int
574sys_mincore(tcp)
575struct tcb *tcp;
576{
Roland McGrath46100d02005-06-01 18:55:42 +0000577 unsigned long i, len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578 char *vec = NULL;
579
580 if (entering(tcp)) {
581 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
582 } else {
583 len = tcp->u_arg[1];
584 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000585 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
587 tprintf("%#lx", tcp->u_arg[2]);
588 else {
589 tprintf("[");
590 for (i = 0; i < len; i++) {
591 if (abbrev(tcp) && i >= max_strlen) {
592 tprintf("...");
593 break;
594 }
595 tprintf((vec[i] & 1) ? "1" : "0");
596 }
597 tprintf("]");
598 }
599 if (vec)
600 free(vec);
601 }
602 return 0;
603}
604
Roland McGrathda6c92c2007-09-12 01:26:29 +0000605#if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000606int
607sys_getpagesize(tcp)
608struct tcb *tcp;
609{
610 if (exiting(tcp))
611 return RVAL_HEX;
612 return 0;
613}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000614#endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000615
616#if defined(LINUX) && defined(__i386__)
Roland McGrath909875b2002-12-22 03:34:36 +0000617void
Denys Vlasenko1f458252009-01-23 16:10:22 +0000618print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
Roland McGrath34e4a692002-12-15 23:58:17 +0000619{
620 tprintf("base_addr:%#08lx, "
621 "limit:%d, "
622 "seg_32bit:%d, "
623 "contents:%d, "
624 "read_exec_only:%d, "
625 "limit_in_pages:%d, "
626 "seg_not_present:%d, "
627 "useable:%d}",
Denys Vlasenko1f458252009-01-23 16:10:22 +0000628 (long) ldt_entry->base_addr,
Roland McGrath34e4a692002-12-15 23:58:17 +0000629 ldt_entry->limit,
630 ldt_entry->seg_32bit,
631 ldt_entry->contents,
632 ldt_entry->read_exec_only,
633 ldt_entry->limit_in_pages,
634 ldt_entry->seg_not_present,
635 ldt_entry->useable);
636}
637
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638int
639sys_modify_ldt(tcp)
640struct tcb *tcp;
641{
642 if (entering(tcp)) {
643 struct modify_ldt_ldt_s copy;
644 tprintf("%ld", tcp->u_arg[0]);
645 if (tcp->u_arg[1] == 0
646 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
647 || umove(tcp, tcp->u_arg[1], &copy) == -1)
648 tprintf(", %lx", tcp->u_arg[1]);
649 else {
650 tprintf(", {entry_number:%d, ", copy.entry_number);
651 if (!verbose(tcp))
652 tprintf("...}");
653 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000654 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655 }
656 }
657 tprintf(", %lu", tcp->u_arg[2]);
658 }
659 return 0;
660}
Roland McGrath34e4a692002-12-15 23:58:17 +0000661
662int
663sys_set_thread_area(tcp)
664struct tcb *tcp;
665{
666 struct modify_ldt_ldt_s copy;
667 if (entering(tcp)) {
668 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
669 if (copy.entry_number == -1)
670 tprintf("{entry_number:%d -> ",
671 copy.entry_number);
672 else
673 tprintf("{entry_number:");
674 }
675 } else {
676 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
677 tprintf("%d, ", copy.entry_number);
678 if (!verbose(tcp))
679 tprintf("...}");
680 else {
681 print_ldt_entry(&copy);
682 }
683 } else {
684 tprintf("%lx", tcp->u_arg[0]);
685 }
686 }
687 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000688
Roland McGrath34e4a692002-12-15 23:58:17 +0000689}
690
691int
692sys_get_thread_area(tcp)
693struct tcb *tcp;
694{
695 struct modify_ldt_ldt_s copy;
696 if (exiting(tcp)) {
697 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
698 tprintf("{entry_number:%d, ", copy.entry_number);
699 if (!verbose(tcp))
700 tprintf("...}");
701 else {
702 print_ldt_entry(&copy);
703 }
704 } else {
705 tprintf("%lx", tcp->u_arg[0]);
706 }
707 }
708 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000709
Roland McGrath34e4a692002-12-15 23:58:17 +0000710}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711#endif /* LINUX && __i386__ */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000712
713#if defined(LINUX)
714int
715sys_remap_file_pages(tcp)
716struct tcb *tcp;
717{
718 if (entering(tcp)) {
719 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000720 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000721 tprintf(", %lu, ", tcp->u_arg[3]);
722#ifdef MAP_TYPE
723 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
724 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
725#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000726 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000727#endif
728 }
729 return 0;
730}
Roland McGrathb10a3352004-10-07 18:53:12 +0000731
732
733#define MPOL_DEFAULT 0
734#define MPOL_PREFERRED 1
735#define MPOL_BIND 2
736#define MPOL_INTERLEAVE 3
737
738#define MPOL_F_NODE (1<<0)
739#define MPOL_F_ADDR (1<<1)
740
741#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000742#define MPOL_MF_MOVE (1<<1)
743#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000744
745
746static const struct xlat policies[] = {
747 { MPOL_DEFAULT, "MPOL_DEFAULT" },
748 { MPOL_PREFERRED, "MPOL_PREFERRED" },
749 { MPOL_BIND, "MPOL_BIND" },
750 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
751 { 0, NULL }
752};
753
754static const struct xlat mbindflags[] = {
755 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000756 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
757 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
Roland McGrathb10a3352004-10-07 18:53:12 +0000758 { 0, NULL }
759};
760
761static const struct xlat mempolicyflags[] = {
762 { MPOL_F_NODE, "MPOL_F_NODE" },
763 { MPOL_F_ADDR, "MPOL_F_ADDR" },
764 { 0, NULL }
765};
766
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000767static const struct xlat move_pages_flags[] = {
768 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
769 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
770 { 0, NULL }
771};
772
Roland McGrathb10a3352004-10-07 18:53:12 +0000773
774static void
775get_nodes(tcp, ptr, maxnodes, err)
776struct tcb *tcp;
777unsigned long ptr;
778unsigned long maxnodes;
779int err;
780{
Roland McGrathaa524c82005-06-01 19:22:06 +0000781 unsigned long nlongs, size, end;
782
783 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
784 size = nlongs * sizeof(long);
785 end = ptr + size;
786 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
787 && (end > ptr))) {
788 unsigned long n, cur, abbrev_end;
789 int failed = 0;
790
791 if (abbrev(tcp)) {
792 abbrev_end = ptr + max_strlen * sizeof(long);
793 if (abbrev_end < ptr)
794 abbrev_end = end;
795 } else {
796 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000797 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000798 tprintf(", {");
799 for (cur = ptr; cur < end; cur += sizeof(long)) {
800 if (cur > ptr)
801 tprintf(", ");
802 if (cur >= abbrev_end) {
803 tprintf("...");
804 break;
805 }
806 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
807 tprintf("?");
808 failed = 1;
809 break;
810 }
811 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
812 }
813 tprintf("}");
814 if (failed)
815 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000816 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000817 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000818 tprintf(", %lu", maxnodes);
819}
820
821int
822sys_mbind(tcp)
823struct tcb *tcp;
824{
825 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000826 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000827 printxval(policies, tcp->u_arg[2], "MPOL_???");
828 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
829 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000830 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000831 }
832 return 0;
833}
834
835int
836sys_set_mempolicy(tcp)
837struct tcb *tcp;
838{
839 if (entering(tcp)) {
840 printxval(policies, tcp->u_arg[0], "MPOL_???");
841 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
842 }
843 return 0;
844}
845
846int
847sys_get_mempolicy(tcp)
848struct tcb *tcp;
849{
850 if (exiting(tcp)) {
851 int pol;
852 if (tcp->u_arg[0] == 0)
853 tprintf("NULL");
854 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
855 tprintf("%#lx", tcp->u_arg[0]);
856 else
857 printxval(policies, pol, "MPOL_???");
858 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
859 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000860 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000861 }
862 return 0;
863}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000864
865int
866sys_move_pages(tcp)
867struct tcb *tcp;
868{
869 if (entering(tcp)) {
870 unsigned long npages = tcp->u_arg[1];
871 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
872 if (tcp->u_arg[2] == 0)
873 tprintf("NULL, ");
874 else {
875 int i;
876 long puser = tcp->u_arg[2];
877 tprintf("{");
878 for (i = 0; i < npages; ++i) {
879 void *p;
880 if (i > 0)
881 tprintf(", ");
882 if (umove(tcp, puser, &p) < 0) {
883 tprintf("???");
884 break;
885 }
886 tprintf("%p", p);
887 puser += sizeof (void *);
888 }
889 tprintf("}, ");
890 }
891 if (tcp->u_arg[3] == 0)
892 tprintf("NULL, ");
893 else {
894 int i;
895 long nodeuser = tcp->u_arg[3];
896 tprintf("{");
897 for (i = 0; i < npages; ++i) {
898 int node;
899 if (i > 0)
900 tprintf(", ");
901 if (umove(tcp, nodeuser, &node) < 0) {
902 tprintf("???");
903 break;
904 }
905 tprintf("%#x", node);
906 nodeuser += sizeof (int);
907 }
908 tprintf("}, ");
909 }
910 }
911 if (exiting(tcp)) {
912 unsigned long npages = tcp->u_arg[1];
913 if (tcp->u_arg[4] == 0)
914 tprintf("NULL, ");
915 else {
916 int i;
917 long statususer = tcp->u_arg[4];
918 tprintf("{");
919 for (i = 0; i < npages; ++i) {
920 int status;
921 if (i > 0)
922 tprintf(", ");
923 if (umove(tcp, statususer, &status) < 0) {
924 tprintf("???");
925 break;
926 }
927 tprintf("%#x", status);
928 statususer += sizeof (int);
929 }
930 tprintf("}, ");
931 }
932 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
933 }
934 return 0;
935}
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000936#endif
Roland McGrath4a6f6522008-08-25 03:09:16 +0000937
938#if defined(LINUX) && defined(POWERPC)
939int
940sys_subpage_prot(tcp)
941struct tcb *tcp;
942{
943 if (entering(tcp)) {
944 unsigned long cur, end, abbrev_end, entries;
945 unsigned int entry;
946
947 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
948 entries = tcp->u_arg[1] >> 16;
949 if (!entries || !tcp->u_arg[2]) {
950 tprintf("{}");
951 return 0;
952 }
953 cur = tcp->u_arg[2];
954 end = cur + (sizeof(int) * entries);
955 if (!verbose(tcp) || end < tcp->u_arg[2]) {
956 tprintf("%#lx", tcp->u_arg[2]);
957 return 0;
958 }
959 if (abbrev(tcp)) {
960 abbrev_end = cur + (sizeof(int) * max_strlen);
961 if (abbrev_end > end)
962 abbrev_end = end;
963 }
964 else
965 abbrev_end = end;
966 tprintf("{");
967 for (; cur < end; cur += sizeof(int)) {
968 if (cur > tcp->u_arg[2])
969 tprintf(", ");
970 if (cur >= abbrev_end) {
971 tprintf("...");
972 break;
973 }
974 if (umove(tcp, cur, &entry) < 0) {
975 tprintf("??? [%#lx]", cur);
976 break;
977 }
978 else
979 tprintf("%#08x", entry);
980 }
981 tprintf("}");
982 }
983
984 return 0;
985}
986#endif