blob: 0fd4a2a32e35aed50245021e461fc0175ad0c76e [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{
232 long u_arg[6];
233
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000234#if defined(IA64)
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000235 int i, v;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000236 /*
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)
Roland McGrath6b1d43e2003-03-31 01:05:01 +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];
256#else
Roland McGrath520e21f2005-07-05 09:50:18 +0000257# if defined(X86_64)
258 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
268# endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +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)
Roland McGrath542c2c62008-05-20 01:11:56 +0000272 return print_mmap(tcp, u_arg, u_arg[5]);
Roland McGrath909875b2002-12-22 03:34:36 +0000273
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000274}
275#endif
276
277int
278sys_mmap(tcp)
279struct tcb *tcp;
280{
Roland McGrath542c2c62008-05-20 01:11:56 +0000281 long long offset = tcp->u_arg[5];
282
Roland McGrathf5a47772003-06-26 22:40:42 +0000283#if defined(LINUX) && defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +0000284 /*
285 * Old mmap differs from new mmap in specifying the
286 * offset in units of bytes rather than pages. We
287 * pretend it's in byte units so the user only ever
288 * sees bytes in the printout.
289 */
Roland McGrath542c2c62008-05-20 01:11:56 +0000290 offset <<= PAGE_SHIFT;
Roland McGrathe1e584b2003-06-02 19:18:58 +0000291#endif
Roland McGrath542c2c62008-05-20 01:11:56 +0000292#if defined(LINUX_MIPSN32)
293 offset = tcp->ext_arg[5];
294#endif
295 return print_mmap(tcp, tcp->u_arg, offset);
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000296}
John Hughes70623be2001-03-08 13:59:00 +0000297#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000298
John Hughes70623be2001-03-08 13:59:00 +0000299#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000300int
301sys_mmap64(tcp)
302struct tcb *tcp;
303{
304#ifdef linux
305#ifdef ALPHA
306 long *u_arg = tcp->u_arg;
307#else /* !ALPHA */
308 long u_arg[7];
309#endif /* !ALPHA */
310#else /* !linux */
311 long *u_arg = tcp->u_arg;
312#endif /* !linux */
313
314 if (entering(tcp)) {
315#ifdef linux
316#ifndef ALPHA
317 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
318 (char *) u_arg) == -1)
319 return 0;
320#endif /* ALPHA */
321#endif /* linux */
John Hughes5a826b82001-03-07 13:21:24 +0000322 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
John Hughesbdf48f52001-03-06 15:08:09 +0000323
324 /* addr */
325 tprintf("%#lx, ", u_arg[0]);
326 /* len */
327 tprintf("%lu, ", u_arg[1]);
328 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000329 printflags(mmap_prot, u_arg[2], "PROT_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000330 tprintf(", ");
331 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000332#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000333 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
334 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000335#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000336 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000337#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000338 /* fd */
339 tprintf(", %ld, ", u_arg[4]);
340 /* offset */
John Hughes0c79e012001-03-08 14:40:06 +0000341 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
John Hughesbdf48f52001-03-06 15:08:09 +0000342 }
343 return RVAL_HEX;
344}
345#endif
346
Roland McGrath909875b2002-12-22 03:34:36 +0000347
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000348int
349sys_munmap(tcp)
350struct tcb *tcp;
351{
352 if (entering(tcp)) {
353 tprintf("%#lx, %lu",
354 tcp->u_arg[0], tcp->u_arg[1]);
355 }
356 return 0;
357}
358
359int
360sys_mprotect(tcp)
361struct tcb *tcp;
362{
363 if (entering(tcp)) {
364 tprintf("%#lx, %lu, ",
365 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000366 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000367 }
368 return 0;
369}
370
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000371#ifdef LINUX
372
Roland McGrathd9f816f2004-09-04 03:39:20 +0000373static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000374 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
375 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000376};
377
378int
379sys_mremap(tcp)
380struct tcb *tcp;
381{
382 if (entering(tcp)) {
383 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
384 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000385 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000386 }
387 return RVAL_HEX;
388}
389
Roland McGrathf4021b12008-08-25 02:59:36 +0000390static const struct xlat madvise_cmds[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000391#ifdef MADV_NORMAL
392 { MADV_NORMAL, "MADV_NORMAL" },
393#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000394#ifdef MADV_RANDOM
Wichert Akkermanc7926982000-04-10 22:22:31 +0000395 { MADV_RANDOM, "MADV_RANDOM" },
396#endif
397#ifdef MADV_SEQUENTIAL
398 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
399#endif
400#ifdef MADV_WILLNEED
401 { MADV_WILLNEED, "MADV_WILLNEED" },
402#endif
Roland McGrathf4021b12008-08-25 02:59:36 +0000403#ifdef MADV_DONTNEED
Wichert Akkermanc7926982000-04-10 22:22:31 +0000404 { MADV_DONTNEED, "MADV_DONTNEED" },
405#endif
406 { 0, NULL },
407};
408
409
410int
411sys_madvise(tcp)
412struct tcb *tcp;
413{
414 if (entering(tcp)) {
415 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathf4021b12008-08-25 02:59:36 +0000416 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000417 }
418 return 0;
419}
420
421
Roland McGrathd9f816f2004-09-04 03:39:20 +0000422static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000423#ifdef MCL_CURRENT
424 { MCL_CURRENT, "MCL_CURRENT" },
425#endif
426#ifdef MCL_FUTURE
427 { MCL_FUTURE, "MCL_FUTURE" },
428#endif
429 { 0, NULL}
430};
431
432int
433sys_mlockall(tcp)
434struct tcb *tcp;
435{
436 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000437 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000438 }
439 return 0;
440}
441
442
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000443#endif /* LINUX */
444
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000445#ifdef MS_ASYNC
446
Roland McGrathd9f816f2004-09-04 03:39:20 +0000447static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000448#ifdef MS_SYNC
449 { MS_SYNC, "MS_SYNC" },
450#endif
John Hughesaca07f32001-10-16 18:12:27 +0000451 { MS_ASYNC, "MS_ASYNC" },
452 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000453 { 0, NULL },
454};
455
456int
457sys_msync(tcp)
458struct tcb *tcp;
459{
460 if (entering(tcp)) {
461 /* addr */
462 tprintf("%#lx", tcp->u_arg[0]);
463 /* len */
464 tprintf(", %lu, ", tcp->u_arg[1]);
465 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000466 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000467 }
468 return 0;
469}
470
471#endif /* MS_ASYNC */
472
473#ifdef MC_SYNC
474
Roland McGrathd9f816f2004-09-04 03:39:20 +0000475static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000476 { MC_LOCK, "MC_LOCK" },
477 { MC_LOCKAS, "MC_LOCKAS" },
478 { MC_SYNC, "MC_SYNC" },
479 { MC_UNLOCK, "MC_UNLOCK" },
480 { MC_UNLOCKAS, "MC_UNLOCKAS" },
481 { 0, NULL },
482};
483
Roland McGrathd9f816f2004-09-04 03:39:20 +0000484static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000485 { MCL_CURRENT, "MCL_CURRENT" },
486 { MCL_FUTURE, "MCL_FUTURE" },
487 { 0, NULL },
488};
489
490int
491sys_mctl(tcp)
492struct tcb *tcp;
493{
494 int arg, function;
495
496 if (entering(tcp)) {
497 /* addr */
498 tprintf("%#lx", tcp->u_arg[0]);
499 /* len */
500 tprintf(", %lu, ", tcp->u_arg[1]);
501 /* function */
502 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000503 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504 /* arg */
505 arg = tcp->u_arg[3];
506 tprintf(", ");
507 switch (function) {
508 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000509 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000510 break;
511 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000512 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000513 break;
514 default:
515 tprintf("%#x", arg);
516 break;
517 }
518 }
519 return 0;
520}
521
522#endif /* MC_SYNC */
523
524int
525sys_mincore(tcp)
526struct tcb *tcp;
527{
Roland McGrath46100d02005-06-01 18:55:42 +0000528 unsigned long i, len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529 char *vec = NULL;
530
531 if (entering(tcp)) {
532 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
533 } else {
534 len = tcp->u_arg[1];
535 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000536 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
538 tprintf("%#lx", tcp->u_arg[2]);
539 else {
540 tprintf("[");
541 for (i = 0; i < len; i++) {
542 if (abbrev(tcp) && i >= max_strlen) {
543 tprintf("...");
544 break;
545 }
546 tprintf((vec[i] & 1) ? "1" : "0");
547 }
548 tprintf("]");
549 }
550 if (vec)
551 free(vec);
552 }
553 return 0;
554}
555
Roland McGrathda6c92c2007-09-12 01:26:29 +0000556#if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000557int
558sys_getpagesize(tcp)
559struct tcb *tcp;
560{
561 if (exiting(tcp))
562 return RVAL_HEX;
563 return 0;
564}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000565#endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566
567#if defined(LINUX) && defined(__i386__)
Roland McGrath909875b2002-12-22 03:34:36 +0000568void
Roland McGrath34e4a692002-12-15 23:58:17 +0000569print_ldt_entry (ldt_entry)
570struct modify_ldt_ldt_s *ldt_entry;
571{
572 tprintf("base_addr:%#08lx, "
573 "limit:%d, "
574 "seg_32bit:%d, "
575 "contents:%d, "
576 "read_exec_only:%d, "
577 "limit_in_pages:%d, "
578 "seg_not_present:%d, "
579 "useable:%d}",
580 ldt_entry->base_addr,
581 ldt_entry->limit,
582 ldt_entry->seg_32bit,
583 ldt_entry->contents,
584 ldt_entry->read_exec_only,
585 ldt_entry->limit_in_pages,
586 ldt_entry->seg_not_present,
587 ldt_entry->useable);
588}
589
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590int
591sys_modify_ldt(tcp)
592struct tcb *tcp;
593{
594 if (entering(tcp)) {
595 struct modify_ldt_ldt_s copy;
596 tprintf("%ld", tcp->u_arg[0]);
597 if (tcp->u_arg[1] == 0
598 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
599 || umove(tcp, tcp->u_arg[1], &copy) == -1)
600 tprintf(", %lx", tcp->u_arg[1]);
601 else {
602 tprintf(", {entry_number:%d, ", copy.entry_number);
603 if (!verbose(tcp))
604 tprintf("...}");
605 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000606 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000607 }
608 }
609 tprintf(", %lu", tcp->u_arg[2]);
610 }
611 return 0;
612}
Roland McGrath34e4a692002-12-15 23:58:17 +0000613
614int
615sys_set_thread_area(tcp)
616struct tcb *tcp;
617{
618 struct modify_ldt_ldt_s copy;
619 if (entering(tcp)) {
620 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
621 if (copy.entry_number == -1)
622 tprintf("{entry_number:%d -> ",
623 copy.entry_number);
624 else
625 tprintf("{entry_number:");
626 }
627 } else {
628 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
629 tprintf("%d, ", copy.entry_number);
630 if (!verbose(tcp))
631 tprintf("...}");
632 else {
633 print_ldt_entry(&copy);
634 }
635 } else {
636 tprintf("%lx", tcp->u_arg[0]);
637 }
638 }
639 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000640
Roland McGrath34e4a692002-12-15 23:58:17 +0000641}
642
643int
644sys_get_thread_area(tcp)
645struct tcb *tcp;
646{
647 struct modify_ldt_ldt_s copy;
648 if (exiting(tcp)) {
649 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
650 tprintf("{entry_number:%d, ", copy.entry_number);
651 if (!verbose(tcp))
652 tprintf("...}");
653 else {
654 print_ldt_entry(&copy);
655 }
656 } else {
657 tprintf("%lx", tcp->u_arg[0]);
658 }
659 }
660 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000661
Roland McGrath34e4a692002-12-15 23:58:17 +0000662}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000663#endif /* LINUX && __i386__ */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000664
665#if defined(LINUX)
666int
667sys_remap_file_pages(tcp)
668struct tcb *tcp;
669{
670 if (entering(tcp)) {
671 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000672 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000673 tprintf(", %lu, ", tcp->u_arg[3]);
674#ifdef MAP_TYPE
675 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
676 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
677#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000678 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000679#endif
680 }
681 return 0;
682}
Roland McGrathb10a3352004-10-07 18:53:12 +0000683
684
685#define MPOL_DEFAULT 0
686#define MPOL_PREFERRED 1
687#define MPOL_BIND 2
688#define MPOL_INTERLEAVE 3
689
690#define MPOL_F_NODE (1<<0)
691#define MPOL_F_ADDR (1<<1)
692
693#define MPOL_MF_STRICT (1<<0)
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000694#define MPOL_MF_MOVE (1<<1)
695#define MPOL_MF_MOVE_ALL (1<<2)
Roland McGrathb10a3352004-10-07 18:53:12 +0000696
697
698static const struct xlat policies[] = {
699 { MPOL_DEFAULT, "MPOL_DEFAULT" },
700 { MPOL_PREFERRED, "MPOL_PREFERRED" },
701 { MPOL_BIND, "MPOL_BIND" },
702 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
703 { 0, NULL }
704};
705
706static const struct xlat mbindflags[] = {
707 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000708 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
709 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
Roland McGrathb10a3352004-10-07 18:53:12 +0000710 { 0, NULL }
711};
712
713static const struct xlat mempolicyflags[] = {
714 { MPOL_F_NODE, "MPOL_F_NODE" },
715 { MPOL_F_ADDR, "MPOL_F_ADDR" },
716 { 0, NULL }
717};
718
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000719static const struct xlat move_pages_flags[] = {
720 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
721 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
722 { 0, NULL }
723};
724
Roland McGrathb10a3352004-10-07 18:53:12 +0000725
726static void
727get_nodes(tcp, ptr, maxnodes, err)
728struct tcb *tcp;
729unsigned long ptr;
730unsigned long maxnodes;
731int err;
732{
Roland McGrathaa524c82005-06-01 19:22:06 +0000733 unsigned long nlongs, size, end;
734
735 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
736 size = nlongs * sizeof(long);
737 end = ptr + size;
738 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
739 && (end > ptr))) {
740 unsigned long n, cur, abbrev_end;
741 int failed = 0;
742
743 if (abbrev(tcp)) {
744 abbrev_end = ptr + max_strlen * sizeof(long);
745 if (abbrev_end < ptr)
746 abbrev_end = end;
747 } else {
748 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000749 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000750 tprintf(", {");
751 for (cur = ptr; cur < end; cur += sizeof(long)) {
752 if (cur > ptr)
753 tprintf(", ");
754 if (cur >= abbrev_end) {
755 tprintf("...");
756 break;
757 }
758 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
759 tprintf("?");
760 failed = 1;
761 break;
762 }
763 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
764 }
765 tprintf("}");
766 if (failed)
767 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000768 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000769 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000770 tprintf(", %lu", maxnodes);
771}
772
773int
774sys_mbind(tcp)
775struct tcb *tcp;
776{
777 if (entering(tcp)) {
778 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
779 printxval(policies, tcp->u_arg[2], "MPOL_???");
780 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
781 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000782 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000783 }
784 return 0;
785}
786
787int
788sys_set_mempolicy(tcp)
789struct tcb *tcp;
790{
791 if (entering(tcp)) {
792 printxval(policies, tcp->u_arg[0], "MPOL_???");
793 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
794 }
795 return 0;
796}
797
798int
799sys_get_mempolicy(tcp)
800struct tcb *tcp;
801{
802 if (exiting(tcp)) {
803 int pol;
804 if (tcp->u_arg[0] == 0)
805 tprintf("NULL");
806 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
807 tprintf("%#lx", tcp->u_arg[0]);
808 else
809 printxval(policies, pol, "MPOL_???");
810 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
811 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000812 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000813 }
814 return 0;
815}
Roland McGrath2c00a4a2007-07-24 01:52:58 +0000816
817int
818sys_move_pages(tcp)
819struct tcb *tcp;
820{
821 if (entering(tcp)) {
822 unsigned long npages = tcp->u_arg[1];
823 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
824 if (tcp->u_arg[2] == 0)
825 tprintf("NULL, ");
826 else {
827 int i;
828 long puser = tcp->u_arg[2];
829 tprintf("{");
830 for (i = 0; i < npages; ++i) {
831 void *p;
832 if (i > 0)
833 tprintf(", ");
834 if (umove(tcp, puser, &p) < 0) {
835 tprintf("???");
836 break;
837 }
838 tprintf("%p", p);
839 puser += sizeof (void *);
840 }
841 tprintf("}, ");
842 }
843 if (tcp->u_arg[3] == 0)
844 tprintf("NULL, ");
845 else {
846 int i;
847 long nodeuser = tcp->u_arg[3];
848 tprintf("{");
849 for (i = 0; i < npages; ++i) {
850 int node;
851 if (i > 0)
852 tprintf(", ");
853 if (umove(tcp, nodeuser, &node) < 0) {
854 tprintf("???");
855 break;
856 }
857 tprintf("%#x", node);
858 nodeuser += sizeof (int);
859 }
860 tprintf("}, ");
861 }
862 }
863 if (exiting(tcp)) {
864 unsigned long npages = tcp->u_arg[1];
865 if (tcp->u_arg[4] == 0)
866 tprintf("NULL, ");
867 else {
868 int i;
869 long statususer = tcp->u_arg[4];
870 tprintf("{");
871 for (i = 0; i < npages; ++i) {
872 int status;
873 if (i > 0)
874 tprintf(", ");
875 if (umove(tcp, statususer, &status) < 0) {
876 tprintf("???");
877 break;
878 }
879 tprintf("%#x", status);
880 statususer += sizeof (int);
881 }
882 tprintf("}, ");
883 }
884 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
885 }
886 return 0;
887}
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000888#endif
Roland McGrath4a6f6522008-08-25 03:09:16 +0000889
890#if defined(LINUX) && defined(POWERPC)
891int
892sys_subpage_prot(tcp)
893struct tcb *tcp;
894{
895 if (entering(tcp)) {
896 unsigned long cur, end, abbrev_end, entries;
897 unsigned int entry;
898
899 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
900 entries = tcp->u_arg[1] >> 16;
901 if (!entries || !tcp->u_arg[2]) {
902 tprintf("{}");
903 return 0;
904 }
905 cur = tcp->u_arg[2];
906 end = cur + (sizeof(int) * entries);
907 if (!verbose(tcp) || end < tcp->u_arg[2]) {
908 tprintf("%#lx", tcp->u_arg[2]);
909 return 0;
910 }
911 if (abbrev(tcp)) {
912 abbrev_end = cur + (sizeof(int) * max_strlen);
913 if (abbrev_end > end)
914 abbrev_end = end;
915 }
916 else
917 abbrev_end = end;
918 tprintf("{");
919 for (; cur < end; cur += sizeof(int)) {
920 if (cur > tcp->u_arg[2])
921 tprintf(", ");
922 if (cur >= abbrev_end) {
923 tprintf("...");
924 break;
925 }
926 if (umove(tcp, cur, &entry) < 0) {
927 tprintf("??? [%#lx]", cur);
928 break;
929 }
930 else
931 tprintf("%#08x", entry);
932 }
933 tprintf("}");
934 }
935
936 return 0;
937}
938#endif