blob: b3c4edc40b926891e53e9fdae38e2976613a076e [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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191 { 0, NULL },
192};
193
John Hughes70623be2001-03-08 13:59:00 +0000194#if !HAVE_LONG_LONG_OFF_T
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000195static
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000196int
Roland McGrath542c2c62008-05-20 01:11:56 +0000197print_mmap(tcp,u_arg, offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000198struct tcb *tcp;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000199long *u_arg;
Roland McGrath542c2c62008-05-20 01:11:56 +0000200long long offset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000201{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000202 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000204 if (!u_arg[0])
205 tprintf("NULL, ");
206 else
207 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208 /* len */
209 tprintf("%lu, ", u_arg[1]);
210 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000211 printflags(mmap_prot, u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000212 tprintf(", ");
213 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000214#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000215 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
216 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000217#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000218 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000219#endif
Michal Ludvig0e035502002-09-23 15:41:01 +0000220 /* fd (is always int, not long) */
221 tprintf(", %d, ", (int)u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222 /* offset */
Roland McGrath542c2c62008-05-20 01:11:56 +0000223 tprintf("%#llx", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224 }
225 return RVAL_HEX;
226}
227
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000228#ifdef LINUX
229int sys_old_mmap(tcp)
230struct tcb *tcp;
231{
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000232 long u_arg[6];
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000233
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000234#if defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000235 int i, v;
236 /*
237 * IA64 processes never call this routine, they only use the
238 * new `sys_mmap' interface. This code converts the integer
239 * arguments that the IA32 process pushed onto the stack into
240 * longs.
241 *
242 * Note that addresses with bit 31 set will be sign extended.
243 * Fortunately, those addresses are not currently being generated
244 * for IA32 processes so it's not a problem.
245 */
246 for (i = 0; i < 6; i++)
247 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
248 return 0;
249 else
250 u_arg[i] = v;
Roland McGrathf5a47772003-06-26 22:40:42 +0000251#elif defined(SH) || defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000252 /* SH has always passed the args in registers */
253 int i;
254 for (i=0; i<6; i++)
255 u_arg[i] = tcp->u_arg[i];
Roland McGrath6b1d43e2003-03-31 01:05:01 +0000256#else
Roland McGrath520e21f2005-07-05 09:50:18 +0000257# if defined(X86_64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000258 if (current_personality == 1) {
259 int i;
260 for (i = 0; i < 6; ++i) {
261 unsigned int val;
262 if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
263 return 0;
264 u_arg[i] = val;
265 }
266 }
267 else
Roland McGrath520e21f2005-07-05 09:50:18 +0000268# endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000269 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
270 return 0;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000271#endif // defined(IA64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000272 return print_mmap(tcp, u_arg, u_arg[5]);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000273}
274#endif
275
276int
277sys_mmap(tcp)
278struct tcb *tcp;
279{
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000280 long long offset = tcp->u_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000281
Roland McGrathf5a47772003-06-26 22:40:42 +0000282#if defined(LINUX) && defined(SH64)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000283 /*
284 * Old mmap differs from new mmap in specifying the
285 * offset in units of bytes rather than pages. We
286 * pretend it's in byte units so the user only ever
287 * sees bytes in the printout.
288 */
289 offset <<= PAGE_SHIFT;
Roland McGrathe1e584b2003-06-02 19:18:58 +0000290#endif
Roland McGrath542c2c62008-05-20 01:11:56 +0000291#if defined(LINUX_MIPSN32)
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000292 offset = tcp->ext_arg[5];
Roland McGrath542c2c62008-05-20 01:11:56 +0000293#endif
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000294 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000295}
John Hughes70623be2001-03-08 13:59:00 +0000296#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000297
John Hughes70623be2001-03-08 13:59:00 +0000298#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000299int
300sys_mmap64(tcp)
301struct tcb *tcp;
302{
303#ifdef linux
304#ifdef ALPHA
305 long *u_arg = tcp->u_arg;
306#else /* !ALPHA */
307 long u_arg[7];
308#endif /* !ALPHA */
309#else /* !linux */
310 long *u_arg = tcp->u_arg;
311#endif /* !linux */
312
313 if (entering(tcp)) {
314#ifdef linux
315#ifndef ALPHA
316 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
317 (char *) u_arg) == -1)
318 return 0;
319#endif /* ALPHA */
320#endif /* linux */
John Hughes5a826b82001-03-07 13:21:24 +0000321 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
John Hughesbdf48f52001-03-06 15:08:09 +0000322
323 /* addr */
324 tprintf("%#lx, ", u_arg[0]);
325 /* len */
326 tprintf("%lu, ", u_arg[1]);
327 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000328 printflags(mmap_prot, u_arg[2], "PROT_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000329 tprintf(", ");
330 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000331#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000332 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
333 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000334#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000335 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000336#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000337 /* fd */
338 tprintf(", %ld, ", u_arg[4]);
339 /* offset */
John Hughes0c79e012001-03-08 14:40:06 +0000340 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
John Hughesbdf48f52001-03-06 15:08:09 +0000341 }
342 return RVAL_HEX;
343}
344#endif
345
Roland McGrath909875b2002-12-22 03:34:36 +0000346
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000347int
348sys_munmap(tcp)
349struct tcb *tcp;
350{
351 if (entering(tcp)) {
352 tprintf("%#lx, %lu",
353 tcp->u_arg[0], tcp->u_arg[1]);
354 }
355 return 0;
356}
357
358int
359sys_mprotect(tcp)
360struct tcb *tcp;
361{
362 if (entering(tcp)) {
363 tprintf("%#lx, %lu, ",
364 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000365 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366 }
367 return 0;
368}
369
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000370#ifdef LINUX
371
Roland McGrathd9f816f2004-09-04 03:39:20 +0000372static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000373 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
374 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000375};
376
377int
378sys_mremap(tcp)
379struct tcb *tcp;
380{
381 if (entering(tcp)) {
382 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
383 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000384 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000385 }
386 return RVAL_HEX;
387}
388
Roland McGrathf4021b12008-08-25 02:59:36 +0000389static const struct xlat madvise_cmds[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000390#ifdef MADV_NORMAL
391 { MADV_NORMAL, "MADV_NORMAL" },
392#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000393#ifdef MADV_RANDOM
Wichert Akkermanc7926982000-04-10 22:22:31 +0000394 { MADV_RANDOM, "MADV_RANDOM" },
395#endif
396#ifdef MADV_SEQUENTIAL
397 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
398#endif
399#ifdef MADV_WILLNEED
400 { MADV_WILLNEED, "MADV_WILLNEED" },
401#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000402#ifdef MADV_DONTNEED
Wichert Akkermanc7926982000-04-10 22:22:31 +0000403 { MADV_DONTNEED, "MADV_DONTNEED" },
404#endif
405 { 0, NULL },
406};
407
408
409int
410sys_madvise(tcp)
411struct tcb *tcp;
412{
413 if (entering(tcp)) {
414 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000415 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000416 }
417 return 0;
418}
419
420
Roland McGrathd9f816f2004-09-04 03:39:20 +0000421static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000422#ifdef MCL_CURRENT
423 { MCL_CURRENT, "MCL_CURRENT" },
424#endif
425#ifdef MCL_FUTURE
426 { MCL_FUTURE, "MCL_FUTURE" },
427#endif
428 { 0, NULL}
429};
430
431int
432sys_mlockall(tcp)
433struct tcb *tcp;
434{
435 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000436 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000437 }
438 return 0;
439}
440
441
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000442#endif /* LINUX */
443
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444#ifdef MS_ASYNC
445
Roland McGrathd9f816f2004-09-04 03:39:20 +0000446static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447#ifdef MS_SYNC
448 { MS_SYNC, "MS_SYNC" },
449#endif
John Hughesaca07f32001-10-16 18:12:27 +0000450 { MS_ASYNC, "MS_ASYNC" },
451 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452 { 0, NULL },
453};
454
455int
456sys_msync(tcp)
457struct tcb *tcp;
458{
459 if (entering(tcp)) {
460 /* addr */
461 tprintf("%#lx", tcp->u_arg[0]);
462 /* len */
463 tprintf(", %lu, ", tcp->u_arg[1]);
464 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000465 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000466 }
467 return 0;
468}
469
470#endif /* MS_ASYNC */
471
472#ifdef MC_SYNC
473
Roland McGrathd9f816f2004-09-04 03:39:20 +0000474static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475 { MC_LOCK, "MC_LOCK" },
476 { MC_LOCKAS, "MC_LOCKAS" },
477 { MC_SYNC, "MC_SYNC" },
478 { MC_UNLOCK, "MC_UNLOCK" },
479 { MC_UNLOCKAS, "MC_UNLOCKAS" },
480 { 0, NULL },
481};
482
Roland McGrathd9f816f2004-09-04 03:39:20 +0000483static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000484 { MCL_CURRENT, "MCL_CURRENT" },
485 { MCL_FUTURE, "MCL_FUTURE" },
486 { 0, NULL },
487};
488
489int
490sys_mctl(tcp)
491struct tcb *tcp;
492{
493 int arg, function;
494
495 if (entering(tcp)) {
496 /* addr */
497 tprintf("%#lx", tcp->u_arg[0]);
498 /* len */
499 tprintf(", %lu, ", tcp->u_arg[1]);
500 /* function */
501 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000502 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000503 /* arg */
504 arg = tcp->u_arg[3];
505 tprintf(", ");
506 switch (function) {
507 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000508 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509 break;
510 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000511 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000512 break;
513 default:
514 tprintf("%#x", arg);
515 break;
516 }
517 }
518 return 0;
519}
520
521#endif /* MC_SYNC */
522
523int
524sys_mincore(tcp)
525struct tcb *tcp;
526{
Roland McGrath46100d02005-06-01 18:55:42 +0000527 unsigned long i, len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000528 char *vec = NULL;
529
530 if (entering(tcp)) {
531 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
532 } else {
533 len = tcp->u_arg[1];
534 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000535 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
537 tprintf("%#lx", tcp->u_arg[2]);
538 else {
539 tprintf("[");
540 for (i = 0; i < len; i++) {
541 if (abbrev(tcp) && i >= max_strlen) {
542 tprintf("...");
543 break;
544 }
545 tprintf((vec[i] & 1) ? "1" : "0");
546 }
547 tprintf("]");
548 }
549 if (vec)
550 free(vec);
551 }
552 return 0;
553}
554
Roland McGrathda6c92c2007-09-12 01:26:29 +0000555#if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000556int
557sys_getpagesize(tcp)
558struct tcb *tcp;
559{
560 if (exiting(tcp))
561 return RVAL_HEX;
562 return 0;
563}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000564#endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565
566#if defined(LINUX) && defined(__i386__)
Roland McGrath909875b2002-12-22 03:34:36 +0000567void
Roland McGrath34e4a692002-12-15 23:58:17 +0000568print_ldt_entry (ldt_entry)
569struct modify_ldt_ldt_s *ldt_entry;
570{
571 tprintf("base_addr:%#08lx, "
572 "limit:%d, "
573 "seg_32bit:%d, "
574 "contents:%d, "
575 "read_exec_only:%d, "
576 "limit_in_pages:%d, "
577 "seg_not_present:%d, "
578 "useable:%d}",
579 ldt_entry->base_addr,
580 ldt_entry->limit,
581 ldt_entry->seg_32bit,
582 ldt_entry->contents,
583 ldt_entry->read_exec_only,
584 ldt_entry->limit_in_pages,
585 ldt_entry->seg_not_present,
586 ldt_entry->useable);
587}
588
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589int
590sys_modify_ldt(tcp)
591struct tcb *tcp;
592{
593 if (entering(tcp)) {
594 struct modify_ldt_ldt_s copy;
595 tprintf("%ld", tcp->u_arg[0]);
596 if (tcp->u_arg[1] == 0
597 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
598 || umove(tcp, tcp->u_arg[1], &copy) == -1)
599 tprintf(", %lx", tcp->u_arg[1]);
600 else {
601 tprintf(", {entry_number:%d, ", copy.entry_number);
602 if (!verbose(tcp))
603 tprintf("...}");
604 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000605 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000606 }
607 }
608 tprintf(", %lu", tcp->u_arg[2]);
609 }
610 return 0;
611}
Roland McGrath34e4a692002-12-15 23:58:17 +0000612
613int
614sys_set_thread_area(tcp)
615struct tcb *tcp;
616{
617 struct modify_ldt_ldt_s copy;
618 if (entering(tcp)) {
619 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
620 if (copy.entry_number == -1)
621 tprintf("{entry_number:%d -> ",
622 copy.entry_number);
623 else
624 tprintf("{entry_number:");
625 }
626 } else {
627 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
628 tprintf("%d, ", copy.entry_number);
629 if (!verbose(tcp))
630 tprintf("...}");
631 else {
632 print_ldt_entry(&copy);
633 }
634 } else {
635 tprintf("%lx", tcp->u_arg[0]);
636 }
637 }
638 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000639
Roland McGrath34e4a692002-12-15 23:58:17 +0000640}
641
642int
643sys_get_thread_area(tcp)
644struct tcb *tcp;
645{
646 struct modify_ldt_ldt_s copy;
647 if (exiting(tcp)) {
648 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
649 tprintf("{entry_number:%d, ", copy.entry_number);
650 if (!verbose(tcp))
651 tprintf("...}");
652 else {
653 print_ldt_entry(&copy);
654 }
655 } else {
656 tprintf("%lx", tcp->u_arg[0]);
657 }
658 }
659 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000660
Roland McGrath34e4a692002-12-15 23:58:17 +0000661}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000662#endif /* LINUX && __i386__ */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000663
664#if defined(LINUX)
665int
666sys_remap_file_pages(tcp)
667struct tcb *tcp;
668{
669 if (entering(tcp)) {
670 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000671 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000672 tprintf(", %lu, ", tcp->u_arg[3]);
673#ifdef MAP_TYPE
674 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
675 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
676#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000677 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000678#endif
679 }
680 return 0;
681}
Roland McGrathb10a3352004-10-07 18:53:12 +0000682
683
684#define MPOL_DEFAULT 0
685#define MPOL_PREFERRED 1
686#define MPOL_BIND 2
687#define MPOL_INTERLEAVE 3
688
689#define MPOL_F_NODE (1<<0)
690#define MPOL_F_ADDR (1<<1)
691
692#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000693#define MPOL_MF_MOVE (1<<1)
694#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000695
696
697static const struct xlat policies[] = {
698 { MPOL_DEFAULT, "MPOL_DEFAULT" },
699 { MPOL_PREFERRED, "MPOL_PREFERRED" },
700 { MPOL_BIND, "MPOL_BIND" },
701 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
702 { 0, NULL }
703};
704
705static const struct xlat mbindflags[] = {
706 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000707 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
708 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
Roland McGrathb10a3352004-10-07 18:53:12 +0000709 { 0, NULL }
710};
711
712static const struct xlat mempolicyflags[] = {
713 { MPOL_F_NODE, "MPOL_F_NODE" },
714 { MPOL_F_ADDR, "MPOL_F_ADDR" },
715 { 0, NULL }
716};
717
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000718static const struct xlat move_pages_flags[] = {
719 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
720 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
721 { 0, NULL }
722};
723
Roland McGrathb10a3352004-10-07 18:53:12 +0000724
725static void
726get_nodes(tcp, ptr, maxnodes, err)
727struct tcb *tcp;
728unsigned long ptr;
729unsigned long maxnodes;
730int err;
731{
Roland McGrathaa524c82005-06-01 19:22:06 +0000732 unsigned long nlongs, size, end;
733
734 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
735 size = nlongs * sizeof(long);
736 end = ptr + size;
737 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
738 && (end > ptr))) {
739 unsigned long n, cur, abbrev_end;
740 int failed = 0;
741
742 if (abbrev(tcp)) {
743 abbrev_end = ptr + max_strlen * sizeof(long);
744 if (abbrev_end < ptr)
745 abbrev_end = end;
746 } else {
747 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000748 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000749 tprintf(", {");
750 for (cur = ptr; cur < end; cur += sizeof(long)) {
751 if (cur > ptr)
752 tprintf(", ");
753 if (cur >= abbrev_end) {
754 tprintf("...");
755 break;
756 }
757 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
758 tprintf("?");
759 failed = 1;
760 break;
761 }
762 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
763 }
764 tprintf("}");
765 if (failed)
766 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000767 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000768 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000769 tprintf(", %lu", maxnodes);
770}
771
772int
773sys_mbind(tcp)
774struct tcb *tcp;
775{
776 if (entering(tcp)) {
777 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
778 printxval(policies, tcp->u_arg[2], "MPOL_???");
779 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
780 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000781 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000782 }
783 return 0;
784}
785
786int
787sys_set_mempolicy(tcp)
788struct tcb *tcp;
789{
790 if (entering(tcp)) {
791 printxval(policies, tcp->u_arg[0], "MPOL_???");
792 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
793 }
794 return 0;
795}
796
797int
798sys_get_mempolicy(tcp)
799struct tcb *tcp;
800{
801 if (exiting(tcp)) {
802 int pol;
803 if (tcp->u_arg[0] == 0)
804 tprintf("NULL");
805 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
806 tprintf("%#lx", tcp->u_arg[0]);
807 else
808 printxval(policies, pol, "MPOL_???");
809 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
810 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000811 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000812 }
813 return 0;
814}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000815
816int
817sys_move_pages(tcp)
818struct tcb *tcp;
819{
820 if (entering(tcp)) {
821 unsigned long npages = tcp->u_arg[1];
822 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
823 if (tcp->u_arg[2] == 0)
824 tprintf("NULL, ");
825 else {
826 int i;
827 long puser = tcp->u_arg[2];
828 tprintf("{");
829 for (i = 0; i < npages; ++i) {
830 void *p;
831 if (i > 0)
832 tprintf(", ");
833 if (umove(tcp, puser, &p) < 0) {
834 tprintf("???");
835 break;
836 }
837 tprintf("%p", p);
838 puser += sizeof (void *);
839 }
840 tprintf("}, ");
841 }
842 if (tcp->u_arg[3] == 0)
843 tprintf("NULL, ");
844 else {
845 int i;
846 long nodeuser = tcp->u_arg[3];
847 tprintf("{");
848 for (i = 0; i < npages; ++i) {
849 int node;
850 if (i > 0)
851 tprintf(", ");
852 if (umove(tcp, nodeuser, &node) < 0) {
853 tprintf("???");
854 break;
855 }
856 tprintf("%#x", node);
857 nodeuser += sizeof (int);
858 }
859 tprintf("}, ");
860 }
861 }
862 if (exiting(tcp)) {
863 unsigned long npages = tcp->u_arg[1];
864 if (tcp->u_arg[4] == 0)
865 tprintf("NULL, ");
866 else {
867 int i;
868 long statususer = tcp->u_arg[4];
869 tprintf("{");
870 for (i = 0; i < npages; ++i) {
871 int status;
872 if (i > 0)
873 tprintf(", ");
874 if (umove(tcp, statususer, &status) < 0) {
875 tprintf("???");
876 break;
877 }
878 tprintf("%#x", status);
879 statususer += sizeof (int);
880 }
881 tprintf("}, ");
882 }
883 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
884 }
885 return 0;
886}
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000887#endif
Roland McGrath4a6f6522008-08-25 03:09:16 +0000888
889#if defined(LINUX) && defined(POWERPC)
890int
891sys_subpage_prot(tcp)
892struct tcb *tcp;
893{
894 if (entering(tcp)) {
895 unsigned long cur, end, abbrev_end, entries;
896 unsigned int entry;
897
898 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
899 entries = tcp->u_arg[1] >> 16;
900 if (!entries || !tcp->u_arg[2]) {
901 tprintf("{}");
902 return 0;
903 }
904 cur = tcp->u_arg[2];
905 end = cur + (sizeof(int) * entries);
906 if (!verbose(tcp) || end < tcp->u_arg[2]) {
907 tprintf("%#lx", tcp->u_arg[2]);
908 return 0;
909 }
910 if (abbrev(tcp)) {
911 abbrev_end = cur + (sizeof(int) * max_strlen);
912 if (abbrev_end > end)
913 abbrev_end = end;
914 }
915 else
916 abbrev_end = end;
917 tprintf("{");
918 for (; cur < end; cur += sizeof(int)) {
919 if (cur > tcp->u_arg[2])
920 tprintf(", ");
921 if (cur >= abbrev_end) {
922 tprintf("...");
923 break;
924 }
925 if (umove(tcp, cur, &entry) < 0) {
926 tprintf("??? [%#lx]", cur);
927 break;
928 }
929 else
930 tprintf("%#08x", entry);
931 }
932 tprintf("}");
933 }
934
935 return 0;
936}
937#endif