blob: ec5707a347ac420cef2a9cf755ca5d9973a463e3 [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
Andreas Schwab58743222010-05-28 22:28:51 +0200713#if defined(LINUX) && defined(M68K)
714
715int
716sys_set_thread_area(tcp)
717struct tcb *tcp;
718{
719 if (entering(tcp))
720 tprintf("%#lx", tcp->u_arg[0]);
721 return 0;
722
723}
724
725int
726sys_get_thread_area(tcp)
727struct tcb *tcp;
728{
729 return RVAL_HEX;
730}
731#endif
732
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000733#if defined(LINUX)
734int
735sys_remap_file_pages(tcp)
736struct tcb *tcp;
737{
738 if (entering(tcp)) {
739 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000740 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000741 tprintf(", %lu, ", tcp->u_arg[3]);
742#ifdef MAP_TYPE
743 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
744 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
745#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000746 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000747#endif
748 }
749 return 0;
750}
Roland McGrathb10a3352004-10-07 18:53:12 +0000751
752
753#define MPOL_DEFAULT 0
754#define MPOL_PREFERRED 1
755#define MPOL_BIND 2
756#define MPOL_INTERLEAVE 3
757
758#define MPOL_F_NODE (1<<0)
759#define MPOL_F_ADDR (1<<1)
760
761#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000762#define MPOL_MF_MOVE (1<<1)
763#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000764
765
766static const struct xlat policies[] = {
767 { MPOL_DEFAULT, "MPOL_DEFAULT" },
768 { MPOL_PREFERRED, "MPOL_PREFERRED" },
769 { MPOL_BIND, "MPOL_BIND" },
770 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
771 { 0, NULL }
772};
773
774static const struct xlat mbindflags[] = {
775 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000776 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
777 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
Roland McGrathb10a3352004-10-07 18:53:12 +0000778 { 0, NULL }
779};
780
781static const struct xlat mempolicyflags[] = {
782 { MPOL_F_NODE, "MPOL_F_NODE" },
783 { MPOL_F_ADDR, "MPOL_F_ADDR" },
784 { 0, NULL }
785};
786
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000787static const struct xlat move_pages_flags[] = {
788 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
789 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
790 { 0, NULL }
791};
792
Roland McGrathb10a3352004-10-07 18:53:12 +0000793
794static void
795get_nodes(tcp, ptr, maxnodes, err)
796struct tcb *tcp;
797unsigned long ptr;
798unsigned long maxnodes;
799int err;
800{
Roland McGrathaa524c82005-06-01 19:22:06 +0000801 unsigned long nlongs, size, end;
802
803 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
804 size = nlongs * sizeof(long);
805 end = ptr + size;
806 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
807 && (end > ptr))) {
808 unsigned long n, cur, abbrev_end;
809 int failed = 0;
810
811 if (abbrev(tcp)) {
812 abbrev_end = ptr + max_strlen * sizeof(long);
813 if (abbrev_end < ptr)
814 abbrev_end = end;
815 } else {
816 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000817 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000818 tprintf(", {");
819 for (cur = ptr; cur < end; cur += sizeof(long)) {
820 if (cur > ptr)
821 tprintf(", ");
822 if (cur >= abbrev_end) {
823 tprintf("...");
824 break;
825 }
826 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
827 tprintf("?");
828 failed = 1;
829 break;
830 }
831 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
832 }
833 tprintf("}");
834 if (failed)
835 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000836 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000837 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000838 tprintf(", %lu", maxnodes);
839}
840
841int
842sys_mbind(tcp)
843struct tcb *tcp;
844{
845 if (entering(tcp)) {
Chris Metcalfc5fd1d92009-12-24 23:19:35 +0000846 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb10a3352004-10-07 18:53:12 +0000847 printxval(policies, tcp->u_arg[2], "MPOL_???");
848 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
849 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000850 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000851 }
852 return 0;
853}
854
855int
856sys_set_mempolicy(tcp)
857struct tcb *tcp;
858{
859 if (entering(tcp)) {
860 printxval(policies, tcp->u_arg[0], "MPOL_???");
861 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
862 }
863 return 0;
864}
865
866int
867sys_get_mempolicy(tcp)
868struct tcb *tcp;
869{
870 if (exiting(tcp)) {
871 int pol;
872 if (tcp->u_arg[0] == 0)
873 tprintf("NULL");
874 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
875 tprintf("%#lx", tcp->u_arg[0]);
876 else
877 printxval(policies, pol, "MPOL_???");
878 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
879 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000880 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000881 }
882 return 0;
883}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000884
885int
886sys_move_pages(tcp)
887struct tcb *tcp;
888{
889 if (entering(tcp)) {
890 unsigned long npages = tcp->u_arg[1];
891 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
892 if (tcp->u_arg[2] == 0)
893 tprintf("NULL, ");
894 else {
895 int i;
896 long puser = tcp->u_arg[2];
897 tprintf("{");
898 for (i = 0; i < npages; ++i) {
899 void *p;
900 if (i > 0)
901 tprintf(", ");
902 if (umove(tcp, puser, &p) < 0) {
903 tprintf("???");
904 break;
905 }
906 tprintf("%p", p);
907 puser += sizeof (void *);
908 }
909 tprintf("}, ");
910 }
911 if (tcp->u_arg[3] == 0)
912 tprintf("NULL, ");
913 else {
914 int i;
915 long nodeuser = tcp->u_arg[3];
916 tprintf("{");
917 for (i = 0; i < npages; ++i) {
918 int node;
919 if (i > 0)
920 tprintf(", ");
921 if (umove(tcp, nodeuser, &node) < 0) {
922 tprintf("???");
923 break;
924 }
925 tprintf("%#x", node);
926 nodeuser += sizeof (int);
927 }
928 tprintf("}, ");
929 }
930 }
931 if (exiting(tcp)) {
932 unsigned long npages = tcp->u_arg[1];
933 if (tcp->u_arg[4] == 0)
934 tprintf("NULL, ");
935 else {
936 int i;
937 long statususer = tcp->u_arg[4];
938 tprintf("{");
939 for (i = 0; i < npages; ++i) {
940 int status;
941 if (i > 0)
942 tprintf(", ");
943 if (umove(tcp, statususer, &status) < 0) {
944 tprintf("???");
945 break;
946 }
947 tprintf("%#x", status);
948 statususer += sizeof (int);
949 }
950 tprintf("}, ");
951 }
952 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
953 }
954 return 0;
955}
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000956#endif
Roland McGrath4a6f6522008-08-25 03:09:16 +0000957
958#if defined(LINUX) && defined(POWERPC)
959int
960sys_subpage_prot(tcp)
961struct tcb *tcp;
962{
963 if (entering(tcp)) {
964 unsigned long cur, end, abbrev_end, entries;
965 unsigned int entry;
966
967 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
968 entries = tcp->u_arg[1] >> 16;
969 if (!entries || !tcp->u_arg[2]) {
970 tprintf("{}");
971 return 0;
972 }
973 cur = tcp->u_arg[2];
974 end = cur + (sizeof(int) * entries);
975 if (!verbose(tcp) || end < tcp->u_arg[2]) {
976 tprintf("%#lx", tcp->u_arg[2]);
977 return 0;
978 }
979 if (abbrev(tcp)) {
980 abbrev_end = cur + (sizeof(int) * max_strlen);
981 if (abbrev_end > end)
982 abbrev_end = end;
983 }
984 else
985 abbrev_end = end;
986 tprintf("{");
987 for (; cur < end; cur += sizeof(int)) {
988 if (cur > tcp->u_arg[2])
989 tprintf(", ");
990 if (cur >= abbrev_end) {
991 tprintf("...");
992 break;
993 }
994 if (umove(tcp, cur, &entry) < 0) {
995 tprintf("??? [%#lx]", cur);
996 break;
997 }
998 else
999 tprintf("%#08x", entry);
1000 }
1001 tprintf("}");
1002 }
1003
1004 return 0;
1005}
1006#endif