blob: 06da6e18a4744b2499f969ec19ef6f0a8277c4cb [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
109#ifdef MAP_RENAME
110 { MAP_RENAME, "MAP_RENAME" },
111#endif
112#ifdef MAP_NORESERVE
113 { MAP_NORESERVE,"MAP_NORESERVE" },
114#endif
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000115#ifdef MAP_POPULATE
116 { MAP_POPULATE, "MAP_POPULATE" },
117#endif
118#ifdef MAP_NONBLOCK
119 { MAP_NONBLOCK, "MAP_NONBLOCK" },
120#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000121 /*
122 * XXX - this was introduced in SunOS 4.x to distinguish between
123 * the old pre-4.x "mmap()", which:
124 *
125 * only let you map devices with an "mmap" routine (e.g.,
126 * frame buffers) in;
127 *
128 * required you to specify the mapping address;
129 *
130 * returned 0 on success and -1 on failure;
131 *
132 * memory and which, and the 4.x "mmap()" which:
133 *
134 * can map plain files;
135 *
136 * can be asked to pick where to map the file;
137 *
138 * returns the address where it mapped the file on success
139 * and -1 on failure.
140 *
141 * It's not actually used in source code that calls "mmap()"; the
142 * "mmap()" routine adds it for you.
143 *
144 * It'd be nice to come up with some way of eliminating it from
145 * the flags, e.g. reporting calls *without* it as "old_mmap()"
146 * and calls with it as "mmap()".
147 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148#ifdef _MAP_NEW
149 { _MAP_NEW, "_MAP_NEW" },
150#endif
151#ifdef MAP_GROWSDOWN
152 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
153#endif
154#ifdef MAP_DENYWRITE
155 { MAP_DENYWRITE,"MAP_DENYWRITE" },
156#endif
157#ifdef MAP_EXECUTABLE
158 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
159#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000160#ifdef MAP_INHERIT
161 { MAP_INHERIT,"MAP_INHERIT" },
162#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163#ifdef MAP_FILE
164 { MAP_FILE,"MAP_FILE"},
165#endif
166#ifdef MAP_LOCKED
167 { MAP_LOCKED,"MAP_LOCKED"},
168#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000169 /* FreeBSD ones */
170#ifdef MAP_ANON
171 { MAP_ANON, "MAP_ANON" },
172#endif
173#ifdef MAP_HASSEMAPHORE
174 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
175#endif
176#ifdef MAP_STACK
177 { MAP_STACK, "MAP_STACK" },
178#endif
179#ifdef MAP_NOSYNC
180 { MAP_NOSYNC, "MAP_NOSYNC" },
181#endif
182#ifdef MAP_NOCORE
183 { MAP_NOCORE, "MAP_NOCORE" },
184#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185 { 0, NULL },
186};
187
John Hughes70623be2001-03-08 13:59:00 +0000188#if !HAVE_LONG_LONG_OFF_T
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000189static
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000190int
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000191print_mmap(tcp,u_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000192struct tcb *tcp;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000193long *u_arg;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000194{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000196 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000197 if (!u_arg[0])
198 tprintf("NULL, ");
199 else
200 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000201 /* len */
202 tprintf("%lu, ", u_arg[1]);
203 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000204 printflags(mmap_prot, u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205 tprintf(", ");
206 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000207#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
209 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000210#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000211 printflags(mmap_flags, u_arg[3], "MAP_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000212#endif
Michal Ludvig0e035502002-09-23 15:41:01 +0000213 /* fd (is always int, not long) */
214 tprintf(", %d, ", (int)u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000215 /* offset */
216 tprintf("%#lx", u_arg[5]);
217 }
218 return RVAL_HEX;
219}
220
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000221#ifdef LINUX
222int sys_old_mmap(tcp)
223struct tcb *tcp;
224{
225 long u_arg[6];
226
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000227#if defined(IA64)
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000228 int i, v;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000229 /*
230 * IA64 processes never call this routine, they only use the
231 * new `sys_mmap' interface. This code converts the integer
232 * arguments that the IA32 process pushed onto the stack into
233 * longs.
234 *
235 * Note that addresses with bit 31 set will be sign extended.
236 * Fortunately, those addresses are not currently being generated
237 * for IA32 processes so it's not a problem.
238 */
239 for (i = 0; i < 6; i++)
240 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
241 return 0;
242 else
243 u_arg[i] = v;
Roland McGrathf5a47772003-06-26 22:40:42 +0000244#elif defined(SH) || defined(SH64)
Roland McGrath6b1d43e2003-03-31 01:05:01 +0000245 /* SH has always passed the args in registers */
246 int i;
247 for (i=0; i<6; i++)
248 u_arg[i] = tcp->u_arg[i];
249#else
Roland McGrath520e21f2005-07-05 09:50:18 +0000250# if defined(X86_64)
251 if (current_personality == 1) {
252 int i;
253 for (i = 0; i < 6; ++i) {
254 unsigned int val;
255 if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
256 return 0;
257 u_arg[i] = val;
258 }
259 }
260 else
261# endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000262 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
263 return 0;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000264#endif // defined(IA64)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000265 return print_mmap(tcp, u_arg);
Roland McGrath909875b2002-12-22 03:34:36 +0000266
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000267}
268#endif
269
270int
271sys_mmap(tcp)
272struct tcb *tcp;
273{
Roland McGrathf5a47772003-06-26 22:40:42 +0000274#if defined(LINUX) && defined(SH64)
Roland McGrathe1e584b2003-06-02 19:18:58 +0000275 /*
276 * Old mmap differs from new mmap in specifying the
277 * offset in units of bytes rather than pages. We
278 * pretend it's in byte units so the user only ever
279 * sees bytes in the printout.
280 */
281 tcp->u_arg[5] <<= PAGE_SHIFT;
282#endif
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000283 return print_mmap(tcp, tcp->u_arg);
284}
John Hughes70623be2001-03-08 13:59:00 +0000285#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000286
John Hughes70623be2001-03-08 13:59:00 +0000287#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000288int
289sys_mmap64(tcp)
290struct tcb *tcp;
291{
292#ifdef linux
293#ifdef ALPHA
294 long *u_arg = tcp->u_arg;
295#else /* !ALPHA */
296 long u_arg[7];
297#endif /* !ALPHA */
298#else /* !linux */
299 long *u_arg = tcp->u_arg;
300#endif /* !linux */
301
302 if (entering(tcp)) {
303#ifdef linux
304#ifndef ALPHA
305 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
306 (char *) u_arg) == -1)
307 return 0;
308#endif /* ALPHA */
309#endif /* linux */
John Hughes5a826b82001-03-07 13:21:24 +0000310 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
John Hughesbdf48f52001-03-06 15:08:09 +0000311
312 /* addr */
313 tprintf("%#lx, ", u_arg[0]);
314 /* len */
315 tprintf("%lu, ", u_arg[1]);
316 /* prot */
Roland McGrathb2dee132005-06-01 19:02:36 +0000317 printflags(mmap_prot, u_arg[2], "PROT_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000318 tprintf(", ");
319 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000320#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000321 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
322 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000323#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000324 printflags(mmap_flags, u_arg[3], "MAP_???");
John Hughes5a826b82001-03-07 13:21:24 +0000325#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000326 /* fd */
327 tprintf(", %ld, ", u_arg[4]);
328 /* offset */
John Hughes0c79e012001-03-08 14:40:06 +0000329 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
John Hughesbdf48f52001-03-06 15:08:09 +0000330 }
331 return RVAL_HEX;
332}
333#endif
334
Roland McGrath909875b2002-12-22 03:34:36 +0000335
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000336int
337sys_munmap(tcp)
338struct tcb *tcp;
339{
340 if (entering(tcp)) {
341 tprintf("%#lx, %lu",
342 tcp->u_arg[0], tcp->u_arg[1]);
343 }
344 return 0;
345}
346
347int
348sys_mprotect(tcp)
349struct tcb *tcp;
350{
351 if (entering(tcp)) {
352 tprintf("%#lx, %lu, ",
353 tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000354 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000355 }
356 return 0;
357}
358
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000359#ifdef LINUX
360
Roland McGrathd9f816f2004-09-04 03:39:20 +0000361static const struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000362 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
363 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000364};
365
366int
367sys_mremap(tcp)
368struct tcb *tcp;
369{
370 if (entering(tcp)) {
371 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
372 tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000373 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000374 }
375 return RVAL_HEX;
376}
377
Roland McGrathd9f816f2004-09-04 03:39:20 +0000378static const struct xlat madvise_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000379#ifdef MADV_NORMAL
380 { MADV_NORMAL, "MADV_NORMAL" },
381#endif
382#ifdef MADZV_RANDOM
383 { MADV_RANDOM, "MADV_RANDOM" },
384#endif
385#ifdef MADV_SEQUENTIAL
386 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
387#endif
388#ifdef MADV_WILLNEED
389 { MADV_WILLNEED, "MADV_WILLNEED" },
390#endif
391#ifdef MADV_DONTNED
392 { MADV_DONTNEED, "MADV_DONTNEED" },
393#endif
394 { 0, NULL },
395};
396
397
398int
399sys_madvise(tcp)
400struct tcb *tcp;
401{
402 if (entering(tcp)) {
403 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000404 printflags(madvise_flags, tcp->u_arg[2], "MADV_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000405 }
406 return 0;
407}
408
409
Roland McGrathd9f816f2004-09-04 03:39:20 +0000410static const struct xlat mlockall_flags[] = {
Wichert Akkermanc7926982000-04-10 22:22:31 +0000411#ifdef MCL_CURRENT
412 { MCL_CURRENT, "MCL_CURRENT" },
413#endif
414#ifdef MCL_FUTURE
415 { MCL_FUTURE, "MCL_FUTURE" },
416#endif
417 { 0, NULL}
418};
419
420int
421sys_mlockall(tcp)
422struct tcb *tcp;
423{
424 if (entering(tcp)) {
Roland McGrathb2dee132005-06-01 19:02:36 +0000425 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000426 }
427 return 0;
428}
429
430
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000431#endif /* LINUX */
432
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433#ifdef MS_ASYNC
434
Roland McGrathd9f816f2004-09-04 03:39:20 +0000435static const struct xlat mctl_sync[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000436#ifdef MS_SYNC
437 { MS_SYNC, "MS_SYNC" },
438#endif
John Hughesaca07f32001-10-16 18:12:27 +0000439 { MS_ASYNC, "MS_ASYNC" },
440 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000441 { 0, NULL },
442};
443
444int
445sys_msync(tcp)
446struct tcb *tcp;
447{
448 if (entering(tcp)) {
449 /* addr */
450 tprintf("%#lx", tcp->u_arg[0]);
451 /* len */
452 tprintf(", %lu, ", tcp->u_arg[1]);
453 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000454 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000455 }
456 return 0;
457}
458
459#endif /* MS_ASYNC */
460
461#ifdef MC_SYNC
462
Roland McGrathd9f816f2004-09-04 03:39:20 +0000463static const struct xlat mctl_funcs[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464 { MC_LOCK, "MC_LOCK" },
465 { MC_LOCKAS, "MC_LOCKAS" },
466 { MC_SYNC, "MC_SYNC" },
467 { MC_UNLOCK, "MC_UNLOCK" },
468 { MC_UNLOCKAS, "MC_UNLOCKAS" },
469 { 0, NULL },
470};
471
Roland McGrathd9f816f2004-09-04 03:39:20 +0000472static const struct xlat mctl_lockas[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000473 { MCL_CURRENT, "MCL_CURRENT" },
474 { MCL_FUTURE, "MCL_FUTURE" },
475 { 0, NULL },
476};
477
478int
479sys_mctl(tcp)
480struct tcb *tcp;
481{
482 int arg, function;
483
484 if (entering(tcp)) {
485 /* addr */
486 tprintf("%#lx", tcp->u_arg[0]);
487 /* len */
488 tprintf(", %lu, ", tcp->u_arg[1]);
489 /* function */
490 function = tcp->u_arg[2];
Roland McGrathb2dee132005-06-01 19:02:36 +0000491 printflags(mctl_funcs, function, "MC_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000492 /* arg */
493 arg = tcp->u_arg[3];
494 tprintf(", ");
495 switch (function) {
496 case MC_SYNC:
Roland McGrathb2dee132005-06-01 19:02:36 +0000497 printflags(mctl_sync, arg, "MS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498 break;
499 case MC_LOCKAS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000500 printflags(mctl_lockas, arg, "MCL_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501 break;
502 default:
503 tprintf("%#x", arg);
504 break;
505 }
506 }
507 return 0;
508}
509
510#endif /* MC_SYNC */
511
512int
513sys_mincore(tcp)
514struct tcb *tcp;
515{
Roland McGrath46100d02005-06-01 18:55:42 +0000516 unsigned long i, len;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517 char *vec = NULL;
518
519 if (entering(tcp)) {
520 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
521 } else {
522 len = tcp->u_arg[1];
523 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
Roland McGrath46100d02005-06-01 18:55:42 +0000524 (vec = malloc(len)) == NULL ||
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
526 tprintf("%#lx", tcp->u_arg[2]);
527 else {
528 tprintf("[");
529 for (i = 0; i < len; i++) {
530 if (abbrev(tcp) && i >= max_strlen) {
531 tprintf("...");
532 break;
533 }
534 tprintf((vec[i] & 1) ? "1" : "0");
535 }
536 tprintf("]");
537 }
538 if (vec)
539 free(vec);
540 }
541 return 0;
542}
543
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000544#if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545int
546sys_getpagesize(tcp)
547struct tcb *tcp;
548{
549 if (exiting(tcp))
550 return RVAL_HEX;
551 return 0;
552}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000553#endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000554
555#if defined(LINUX) && defined(__i386__)
Roland McGrath909875b2002-12-22 03:34:36 +0000556void
Roland McGrath34e4a692002-12-15 23:58:17 +0000557print_ldt_entry (ldt_entry)
558struct modify_ldt_ldt_s *ldt_entry;
559{
560 tprintf("base_addr:%#08lx, "
561 "limit:%d, "
562 "seg_32bit:%d, "
563 "contents:%d, "
564 "read_exec_only:%d, "
565 "limit_in_pages:%d, "
566 "seg_not_present:%d, "
567 "useable:%d}",
568 ldt_entry->base_addr,
569 ldt_entry->limit,
570 ldt_entry->seg_32bit,
571 ldt_entry->contents,
572 ldt_entry->read_exec_only,
573 ldt_entry->limit_in_pages,
574 ldt_entry->seg_not_present,
575 ldt_entry->useable);
576}
577
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578int
579sys_modify_ldt(tcp)
580struct tcb *tcp;
581{
582 if (entering(tcp)) {
583 struct modify_ldt_ldt_s copy;
584 tprintf("%ld", tcp->u_arg[0]);
585 if (tcp->u_arg[1] == 0
586 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
587 || umove(tcp, tcp->u_arg[1], &copy) == -1)
588 tprintf(", %lx", tcp->u_arg[1]);
589 else {
590 tprintf(", {entry_number:%d, ", copy.entry_number);
591 if (!verbose(tcp))
592 tprintf("...}");
593 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000594 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000595 }
596 }
597 tprintf(", %lu", tcp->u_arg[2]);
598 }
599 return 0;
600}
Roland McGrath34e4a692002-12-15 23:58:17 +0000601
602int
603sys_set_thread_area(tcp)
604struct tcb *tcp;
605{
606 struct modify_ldt_ldt_s copy;
607 if (entering(tcp)) {
608 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
609 if (copy.entry_number == -1)
610 tprintf("{entry_number:%d -> ",
611 copy.entry_number);
612 else
613 tprintf("{entry_number:");
614 }
615 } else {
616 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
617 tprintf("%d, ", copy.entry_number);
618 if (!verbose(tcp))
619 tprintf("...}");
620 else {
621 print_ldt_entry(&copy);
622 }
623 } else {
624 tprintf("%lx", tcp->u_arg[0]);
625 }
626 }
627 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000628
Roland McGrath34e4a692002-12-15 23:58:17 +0000629}
630
631int
632sys_get_thread_area(tcp)
633struct tcb *tcp;
634{
635 struct modify_ldt_ldt_s copy;
636 if (exiting(tcp)) {
637 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
638 tprintf("{entry_number:%d, ", copy.entry_number);
639 if (!verbose(tcp))
640 tprintf("...}");
641 else {
642 print_ldt_entry(&copy);
643 }
644 } else {
645 tprintf("%lx", tcp->u_arg[0]);
646 }
647 }
648 return 0;
Roland McGrath909875b2002-12-22 03:34:36 +0000649
Roland McGrath34e4a692002-12-15 23:58:17 +0000650}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000651#endif /* LINUX && __i386__ */
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000652
653#if defined(LINUX)
654int
655sys_remap_file_pages(tcp)
656struct tcb *tcp;
657{
658 if (entering(tcp)) {
659 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000660 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000661 tprintf(", %lu, ", tcp->u_arg[3]);
662#ifdef MAP_TYPE
663 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
664 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
665#else
Roland McGrathb2dee132005-06-01 19:02:36 +0000666 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000667#endif
668 }
669 return 0;
670}
Roland McGrathb10a3352004-10-07 18:53:12 +0000671
672
673#define MPOL_DEFAULT 0
674#define MPOL_PREFERRED 1
675#define MPOL_BIND 2
676#define MPOL_INTERLEAVE 3
677
678#define MPOL_F_NODE (1<<0)
679#define MPOL_F_ADDR (1<<1)
680
681#define MPOL_MF_STRICT (1<<0)
682
683
684static const struct xlat policies[] = {
685 { MPOL_DEFAULT, "MPOL_DEFAULT" },
686 { MPOL_PREFERRED, "MPOL_PREFERRED" },
687 { MPOL_BIND, "MPOL_BIND" },
688 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
689 { 0, NULL }
690};
691
692static const struct xlat mbindflags[] = {
693 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
694 { 0, NULL }
695};
696
697static const struct xlat mempolicyflags[] = {
698 { MPOL_F_NODE, "MPOL_F_NODE" },
699 { MPOL_F_ADDR, "MPOL_F_ADDR" },
700 { 0, NULL }
701};
702
703
704static void
705get_nodes(tcp, ptr, maxnodes, err)
706struct tcb *tcp;
707unsigned long ptr;
708unsigned long maxnodes;
709int err;
710{
Roland McGrathaa524c82005-06-01 19:22:06 +0000711 unsigned long nlongs, size, end;
712
713 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
714 size = nlongs * sizeof(long);
715 end = ptr + size;
716 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
717 && (end > ptr))) {
718 unsigned long n, cur, abbrev_end;
719 int failed = 0;
720
721 if (abbrev(tcp)) {
722 abbrev_end = ptr + max_strlen * sizeof(long);
723 if (abbrev_end < ptr)
724 abbrev_end = end;
725 } else {
726 abbrev_end = end;
Roland McGrathb10a3352004-10-07 18:53:12 +0000727 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000728 tprintf(", {");
729 for (cur = ptr; cur < end; cur += sizeof(long)) {
730 if (cur > ptr)
731 tprintf(", ");
732 if (cur >= abbrev_end) {
733 tprintf("...");
734 break;
735 }
736 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
737 tprintf("?");
738 failed = 1;
739 break;
740 }
741 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
742 }
743 tprintf("}");
744 if (failed)
745 tprintf(" %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000746 } else
Roland McGrathaa524c82005-06-01 19:22:06 +0000747 tprintf(", %#lx", ptr);
Roland McGrathb10a3352004-10-07 18:53:12 +0000748 tprintf(", %lu", maxnodes);
749}
750
751int
752sys_mbind(tcp)
753struct tcb *tcp;
754{
755 if (entering(tcp)) {
756 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
757 printxval(policies, tcp->u_arg[2], "MPOL_???");
758 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
759 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000760 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000761 }
762 return 0;
763}
764
765int
766sys_set_mempolicy(tcp)
767struct tcb *tcp;
768{
769 if (entering(tcp)) {
770 printxval(policies, tcp->u_arg[0], "MPOL_???");
771 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
772 }
773 return 0;
774}
775
776int
777sys_get_mempolicy(tcp)
778struct tcb *tcp;
779{
780 if (exiting(tcp)) {
781 int pol;
782 if (tcp->u_arg[0] == 0)
783 tprintf("NULL");
784 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
785 tprintf("%#lx", tcp->u_arg[0]);
786 else
787 printxval(policies, pol, "MPOL_???");
788 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
789 tprintf(", %#lx, ", tcp->u_arg[3]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000790 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
Roland McGrathb10a3352004-10-07 18:53:12 +0000791 }
792 return 0;
793}
Roland McGrath72c5b7b2003-03-05 04:08:00 +0000794#endif