blob: b1447e547754ff36d13f3f80222057e5c538e201 [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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000099 { 0, NULL },
100};
101
Roland McGrathd9f816f2004-09-04 03:39:20 +0000102static const struct xlat mmap_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000103 { MAP_SHARED, "MAP_SHARED" },
104 { MAP_PRIVATE, "MAP_PRIVATE" },
105 { MAP_FIXED, "MAP_FIXED" },
106#ifdef MAP_ANONYMOUS
107 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
108#endif
Dmitry V. Levin71f1a132007-03-29 23:30:09 +0000109#ifdef MAP_32BIT
110 { MAP_32BIT, "MAP_32BIT" },
111#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000112#ifdef MAP_RENAME
113 { MAP_RENAME, "MAP_RENAME" },
114#endif
115#ifdef MAP_NORESERVE
116 { MAP_NORESERVE,"MAP_NORESERVE" },
117#endif
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000118#ifdef MAP_POPULATE
119 { MAP_POPULATE, "MAP_POPULATE" },
120#endif
121#ifdef MAP_NONBLOCK
122 { MAP_NONBLOCK, "MAP_NONBLOCK" },
123#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000124 /*
125 * XXX - this was introduced in SunOS 4.x to distinguish between
126 * the old pre-4.x "mmap()", which:
127 *
128 * only let you map devices with an "mmap" routine (e.g.,
129 * frame buffers) in;
130 *
131 * required you to specify the mapping address;
132 *
133 * returned 0 on success and -1 on failure;
134 *
135 * memory and which, and the 4.x "mmap()" which:
136 *
137 * can map plain files;
138 *
139 * can be asked to pick where to map the file;
140 *
141 * returns the address where it mapped the file on success
142 * and -1 on failure.
143 *
144 * It's not actually used in source code that calls "mmap()"; the
145 * "mmap()" routine adds it for you.
146 *
147 * It'd be nice to come up with some way of eliminating it from
148 * the flags, e.g. reporting calls *without* it as "old_mmap()"
149 * and calls with it as "mmap()".
150 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151#ifdef _MAP_NEW
152 { _MAP_NEW, "_MAP_NEW" },
153#endif
154#ifdef MAP_GROWSDOWN
155 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
156#endif
157#ifdef MAP_DENYWRITE
158 { MAP_DENYWRITE,"MAP_DENYWRITE" },
159#endif
160#ifdef MAP_EXECUTABLE
161 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
162#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000163#ifdef MAP_INHERIT
164 { MAP_INHERIT,"MAP_INHERIT" },
165#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166#ifdef MAP_FILE
167 { MAP_FILE,"MAP_FILE"},
168#endif
169#ifdef MAP_LOCKED
170 { MAP_LOCKED,"MAP_LOCKED"},
171#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000172 /* FreeBSD ones */
173#ifdef MAP_ANON
174 { MAP_ANON, "MAP_ANON" },
175#endif
176#ifdef MAP_HASSEMAPHORE
177 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
178#endif
179#ifdef MAP_STACK
180 { MAP_STACK, "MAP_STACK" },
181#endif
182#ifdef MAP_NOSYNC
183 { MAP_NOSYNC, "MAP_NOSYNC" },
184#endif
185#ifdef MAP_NOCORE
186 { MAP_NOCORE, "MAP_NOCORE" },
187#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000188 { 0, NULL },
189};
190
John Hughes70623be2001-03-08 13:59:00 +0000191#if !HAVE_LONG_LONG_OFF_T
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000192static
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000193int
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000194print_mmap(tcp,u_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195struct tcb *tcp;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000196long *u_arg;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000197{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000198 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000199 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000200 if (!u_arg[0])
201 tprintf("NULL, ");
202 else
203 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204 /* len */
205 tprintf("%lu, ", u_arg[1]);
206 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000207 printflags(mmap_prot, u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208 tprintf(", ");
209 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000210#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000211 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
212 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000213#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000214 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000215#endif
Michal Ludvig0e035502002-09-23 15:41:01 +0000216 /* fd (is always int, not long) */
217 tprintf(", %d, ", (int)u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218 /* offset */
219 tprintf("%#lx", u_arg[5]);
220 }
221 return RVAL_HEX;
222}
223
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000224#ifdef LINUX
225int sys_old_mmap(tcp)
226struct tcb *tcp;
227{
228 long u_arg[6];
229
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000230#if defined(IA64)
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000231 int i, v;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000232 /*
233 * IA64 processes never call this routine, they only use the
234 * new `sys_mmap' interface. This code converts the integer
235 * arguments that the IA32 process pushed onto the stack into
236 * longs.
237 *
238 * Note that addresses with bit 31 set will be sign extended.
239 * Fortunately, those addresses are not currently being generated
240 * for IA32 processes so it's not a problem.
241 */
242 for (i = 0; i < 6; i++)
243 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
244 return 0;
245 else
246 u_arg[i] = v;
Roland McGrathf5a47772003-06-26 22:40:42 +0000247#elif defined(SH) || defined(SH64)
Roland McGrath6b1d43e2003-03-31 01:05:01 +0000248 /* SH has always passed the args in registers */
249 int i;
250 for (i=0; i<6; i++)
251 u_arg[i] = tcp->u_arg[i];
252#else
Roland McGrath520e21f2005-07-05 09:50:18 +0000253# if defined(X86_64)
254 if (current_personality == 1) {
255 int i;
256 for (i = 0; i < 6; ++i) {
257 unsigned int val;
258 if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
259 return 0;
260 u_arg[i] = val;
261 }
262 }
263 else
264# endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000265 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
266 return 0;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000267#endif // defined(IA64)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000268 return print_mmap(tcp, u_arg);
Roland McGrath909875b2002-12-22 03:34:36 +0000269
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000270}
271#endif
272
273int
274sys_mmap(tcp)
275struct tcb *tcp;
276{
Roland McGrathf5a47772003-06-26 22:40:42 +0000277#if defined(LINUX) && defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +0000278 /*
279 * Old mmap differs from new mmap in specifying the
280 * offset in units of bytes rather than pages. We
281 * pretend it's in byte units so the user only ever
282 * sees bytes in the printout.
283 */
284 tcp->u_arg[5] <<= PAGE_SHIFT;
285#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000286 return print_mmap(tcp, tcp->u_arg);
287}
John Hughes70623be2001-03-08 13:59:00 +0000288#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000289
John Hughes70623be2001-03-08 13:59:00 +0000290#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000291int
292sys_mmap64(tcp)
293struct tcb *tcp;
294{
295#ifdef linux
296#ifdef ALPHA
297 long *u_arg = tcp->u_arg;
298#else /* !ALPHA */
299 long u_arg[7];
300#endif /* !ALPHA */
301#else /* !linux */
302 long *u_arg = tcp->u_arg;
303#endif /* !linux */
304
305 if (entering(tcp)) {
306#ifdef linux
307#ifndef ALPHA
308 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
309 (char *) u_arg) == -1)
310 return 0;
311#endif /* ALPHA */
312#endif /* linux */
John Hughes5a826b82001-03-07 13:21:24 +0000313 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
John Hughesbdf48f52001-03-06 15:08:09 +0000314
315 /* addr */
316 tprintf("%#lx, ", u_arg[0]);
317 /* len */
318 tprintf("%lu, ", u_arg[1]);
319 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000320 printflags(mmap_prot, u_arg[2], "PROT_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000321 tprintf(", ");
322 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000323#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000324 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
325 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000326#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000327 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000328#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000329 /* fd */
330 tprintf(", %ld, ", u_arg[4]);
331 /* offset */
John Hughes0c79e012001-03-08 14:40:06 +0000332 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
John Hughesbdf48f52001-03-06 15:08:09 +0000333 }
334 return RVAL_HEX;
335}
336#endif
337
Roland McGrath909875b2002-12-22 03:34:36 +0000338
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000339int
340sys_munmap(tcp)
341struct tcb *tcp;
342{
343 if (entering(tcp)) {
344 tprintf("%#lx, %lu",
345 tcp->u_arg[0], tcp->u_arg[1]);
346 }
347 return 0;
348}
349
350int
351sys_mprotect(tcp)
352struct tcb *tcp;
353{
354 if (entering(tcp)) {
355 tprintf("%#lx, %lu, ",
356 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000357 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358 }
359 return 0;
360}
361
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000362#ifdef LINUX
363
Roland McGrathd9f816f2004-09-04 03:39:20 +0000364static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000365 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
366 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000367};
368
369int
370sys_mremap(tcp)
371struct tcb *tcp;
372{
373 if (entering(tcp)) {
374 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
375 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000376 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000377 }
378 return RVAL_HEX;
379}
380
Roland McGrathd9f816f2004-09-04 03:39:20 +0000381static const struct xlat madvise_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000382#ifdef MADV_NORMAL
383 { MADV_NORMAL, "MADV_NORMAL" },
384#endif
385#ifdef MADZV_RANDOM
386 { MADV_RANDOM, "MADV_RANDOM" },
387#endif
388#ifdef MADV_SEQUENTIAL
389 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
390#endif
391#ifdef MADV_WILLNEED
392 { MADV_WILLNEED, "MADV_WILLNEED" },
393#endif
394#ifdef MADV_DONTNED
395 { MADV_DONTNEED, "MADV_DONTNEED" },
396#endif
397 { 0, NULL },
398};
399
400
401int
402sys_madvise(tcp)
403struct tcb *tcp;
404{
405 if (entering(tcp)) {
406 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000407 printflags(madvise_flags, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000408 }
409 return 0;
410}
411
412
Roland McGrathd9f816f2004-09-04 03:39:20 +0000413static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000414#ifdef MCL_CURRENT
415 { MCL_CURRENT, "MCL_CURRENT" },
416#endif
417#ifdef MCL_FUTURE
418 { MCL_FUTURE, "MCL_FUTURE" },
419#endif
420 { 0, NULL}
421};
422
423int
424sys_mlockall(tcp)
425struct tcb *tcp;
426{
427 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000428 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000429 }
430 return 0;
431}
432
433
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000434#endif /* LINUX */
435
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000436#ifdef MS_ASYNC
437
Roland McGrathd9f816f2004-09-04 03:39:20 +0000438static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000439#ifdef MS_SYNC
440 { MS_SYNC, "MS_SYNC" },
441#endif
John Hughesaca07f32001-10-16 18:12:27 +0000442 { MS_ASYNC, "MS_ASYNC" },
443 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444 { 0, NULL },
445};
446
447int
448sys_msync(tcp)
449struct tcb *tcp;
450{
451 if (entering(tcp)) {
452 /* addr */
453 tprintf("%#lx", tcp->u_arg[0]);
454 /* len */
455 tprintf(", %lu, ", tcp->u_arg[1]);
456 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000457 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000458 }
459 return 0;
460}
461
462#endif /* MS_ASYNC */
463
464#ifdef MC_SYNC
465
Roland McGrathd9f816f2004-09-04 03:39:20 +0000466static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000467 { MC_LOCK, "MC_LOCK" },
468 { MC_LOCKAS, "MC_LOCKAS" },
469 { MC_SYNC, "MC_SYNC" },
470 { MC_UNLOCK, "MC_UNLOCK" },
471 { MC_UNLOCKAS, "MC_UNLOCKAS" },
472 { 0, NULL },
473};
474
Roland McGrathd9f816f2004-09-04 03:39:20 +0000475static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000476 { MCL_CURRENT, "MCL_CURRENT" },
477 { MCL_FUTURE, "MCL_FUTURE" },
478 { 0, NULL },
479};
480
481int
482sys_mctl(tcp)
483struct tcb *tcp;
484{
485 int arg, function;
486
487 if (entering(tcp)) {
488 /* addr */
489 tprintf("%#lx", tcp->u_arg[0]);
490 /* len */
491 tprintf(", %lu, ", tcp->u_arg[1]);
492 /* function */
493 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000494 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000495 /* arg */
496 arg = tcp->u_arg[3];
497 tprintf(", ");
498 switch (function) {
499 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000500 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501 break;
502 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000503 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504 break;
505 default:
506 tprintf("%#x", arg);
507 break;
508 }
509 }
510 return 0;
511}
512
513#endif /* MC_SYNC */
514
515int
516sys_mincore(tcp)
517struct tcb *tcp;
518{
Roland McGrath46100d02005-06-01 18:55:42 +0000519 unsigned long i, len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520 char *vec = NULL;
521
522 if (entering(tcp)) {
523 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
524 } else {
525 len = tcp->u_arg[1];
526 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000527 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000528 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
529 tprintf("%#lx", tcp->u_arg[2]);
530 else {
531 tprintf("[");
532 for (i = 0; i < len; i++) {
533 if (abbrev(tcp) && i >= max_strlen) {
534 tprintf("...");
535 break;
536 }
537 tprintf((vec[i] & 1) ? "1" : "0");
538 }
539 tprintf("]");
540 }
541 if (vec)
542 free(vec);
543 }
544 return 0;
545}
546
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000547#if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548int
549sys_getpagesize(tcp)
550struct tcb *tcp;
551{
552 if (exiting(tcp))
553 return RVAL_HEX;
554 return 0;
555}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000556#endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000557
558#if defined(LINUX) && defined(__i386__)
Roland McGrath909875b2002-12-22 03:34:36 +0000559void
Roland McGrath34e4a692002-12-15 23:58:17 +0000560print_ldt_entry (ldt_entry)
561struct modify_ldt_ldt_s *ldt_entry;
562{
563 tprintf("base_addr:%#08lx, "
564 "limit:%d, "
565 "seg_32bit:%d, "
566 "contents:%d, "
567 "read_exec_only:%d, "
568 "limit_in_pages:%d, "
569 "seg_not_present:%d, "
570 "useable:%d}",
571 ldt_entry->base_addr,
572 ldt_entry->limit,
573 ldt_entry->seg_32bit,
574 ldt_entry->contents,
575 ldt_entry->read_exec_only,
576 ldt_entry->limit_in_pages,
577 ldt_entry->seg_not_present,
578 ldt_entry->useable);
579}
580
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000581int
582sys_modify_ldt(tcp)
583struct tcb *tcp;
584{
585 if (entering(tcp)) {
586 struct modify_ldt_ldt_s copy;
587 tprintf("%ld", tcp->u_arg[0]);
588 if (tcp->u_arg[1] == 0
589 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
590 || umove(tcp, tcp->u_arg[1], &copy) == -1)
591 tprintf(", %lx", tcp->u_arg[1]);
592 else {
593 tprintf(", {entry_number:%d, ", copy.entry_number);
594 if (!verbose(tcp))
595 tprintf("...}");
596 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000597 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598 }
599 }
600 tprintf(", %lu", tcp->u_arg[2]);
601 }
602 return 0;
603}
Roland McGrath34e4a692002-12-15 23:58:17 +0000604
605int
606sys_set_thread_area(tcp)
607struct tcb *tcp;
608{
609 struct modify_ldt_ldt_s copy;
610 if (entering(tcp)) {
611 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
612 if (copy.entry_number == -1)
613 tprintf("{entry_number:%d -> ",
614 copy.entry_number);
615 else
616 tprintf("{entry_number:");
617 }
618 } else {
619 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
620 tprintf("%d, ", copy.entry_number);
621 if (!verbose(tcp))
622 tprintf("...}");
623 else {
624 print_ldt_entry(&copy);
625 }
626 } else {
627 tprintf("%lx", tcp->u_arg[0]);
628 }
629 }
630 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000631
Roland McGrath34e4a692002-12-15 23:58:17 +0000632}
633
634int
635sys_get_thread_area(tcp)
636struct tcb *tcp;
637{
638 struct modify_ldt_ldt_s copy;
639 if (exiting(tcp)) {
640 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
641 tprintf("{entry_number:%d, ", copy.entry_number);
642 if (!verbose(tcp))
643 tprintf("...}");
644 else {
645 print_ldt_entry(&copy);
646 }
647 } else {
648 tprintf("%lx", tcp->u_arg[0]);
649 }
650 }
651 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000652
Roland McGrath34e4a692002-12-15 23:58:17 +0000653}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000654#endif /* LINUX && __i386__ */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000655
656#if defined(LINUX)
657int
658sys_remap_file_pages(tcp)
659struct tcb *tcp;
660{
661 if (entering(tcp)) {
662 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000663 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000664 tprintf(", %lu, ", tcp->u_arg[3]);
665#ifdef MAP_TYPE
666 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
667 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
668#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000669 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000670#endif
671 }
672 return 0;
673}
Roland McGrathb10a3352004-10-07 18:53:12 +0000674
675
676#define MPOL_DEFAULT 0
677#define MPOL_PREFERRED 1
678#define MPOL_BIND 2
679#define MPOL_INTERLEAVE 3
680
681#define MPOL_F_NODE (1<<0)
682#define MPOL_F_ADDR (1<<1)
683
684#define MPOL_MF_STRICT (1<<0)
685
686
687static const struct xlat policies[] = {
688 { MPOL_DEFAULT, "MPOL_DEFAULT" },
689 { MPOL_PREFERRED, "MPOL_PREFERRED" },
690 { MPOL_BIND, "MPOL_BIND" },
691 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
692 { 0, NULL }
693};
694
695static const struct xlat mbindflags[] = {
696 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
697 { 0, NULL }
698};
699
700static const struct xlat mempolicyflags[] = {
701 { MPOL_F_NODE, "MPOL_F_NODE" },
702 { MPOL_F_ADDR, "MPOL_F_ADDR" },
703 { 0, NULL }
704};
705
706
707static void
708get_nodes(tcp, ptr, maxnodes, err)
709struct tcb *tcp;
710unsigned long ptr;
711unsigned long maxnodes;
712int err;
713{
Roland McGrathaa524c82005-06-01 19:22:06 +0000714 unsigned long nlongs, size, end;
715
716 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
717 size = nlongs * sizeof(long);
718 end = ptr + size;
719 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
720 && (end > ptr))) {
721 unsigned long n, cur, abbrev_end;
722 int failed = 0;
723
724 if (abbrev(tcp)) {
725 abbrev_end = ptr + max_strlen * sizeof(long);
726 if (abbrev_end < ptr)
727 abbrev_end = end;
728 } else {
729 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000730 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000731 tprintf(", {");
732 for (cur = ptr; cur < end; cur += sizeof(long)) {
733 if (cur > ptr)
734 tprintf(", ");
735 if (cur >= abbrev_end) {
736 tprintf("...");
737 break;
738 }
739 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
740 tprintf("?");
741 failed = 1;
742 break;
743 }
744 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
745 }
746 tprintf("}");
747 if (failed)
748 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000749 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000750 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000751 tprintf(", %lu", maxnodes);
752}
753
754int
755sys_mbind(tcp)
756struct tcb *tcp;
757{
758 if (entering(tcp)) {
759 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
760 printxval(policies, tcp->u_arg[2], "MPOL_???");
761 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
762 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000763 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000764 }
765 return 0;
766}
767
768int
769sys_set_mempolicy(tcp)
770struct tcb *tcp;
771{
772 if (entering(tcp)) {
773 printxval(policies, tcp->u_arg[0], "MPOL_???");
774 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
775 }
776 return 0;
777}
778
779int
780sys_get_mempolicy(tcp)
781struct tcb *tcp;
782{
783 if (exiting(tcp)) {
784 int pol;
785 if (tcp->u_arg[0] == 0)
786 tprintf("NULL");
787 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
788 tprintf("%#lx", tcp->u_arg[0]);
789 else
790 printxval(policies, pol, "MPOL_???");
791 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
792 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000793 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000794 }
795 return 0;
796}
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000797#endif