blob: 92526cd901d9fd5f9caeb058a9ea3b5ec247e4ae [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>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000035#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036#include <linux/mman.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000037#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000038#include <sys/mman.h>
Wichert Akkerman5daa0281999-03-15 19:49:42 +000039
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040#if defined(LINUX) && defined(__i386__)
Wichert Akkerman8bc6cfd1999-04-21 15:57:38 +000041#include <asm/ldt.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042#endif
43
John Hughes70623be2001-03-08 13:59:00 +000044#ifdef HAVE_LONG_LONG_OFF_T
45/*
46 * Ugly hacks for systems that have a long long off_t
47 */
48#define sys_mmap64 sys_mmap
49#endif
50
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051int
52sys_brk(tcp)
53struct tcb *tcp;
54{
55 if (entering(tcp)) {
56 tprintf("%#lx", tcp->u_arg[0]);
57 }
Wichert Akkerman5daa0281999-03-15 19:49:42 +000058#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059 return RVAL_HEX;
60#else
61 return 0;
62#endif
63}
64
65int
66sys_sbrk(tcp)
67struct tcb *tcp;
68{
69 if (entering(tcp)) {
70 tprintf("%lu", tcp->u_arg[0]);
71 }
72 return RVAL_HEX;
73}
74
75static struct xlat mmap_prot[] = {
76 { PROT_NONE, "PROT_NONE", },
77 { PROT_READ, "PROT_READ" },
78 { PROT_WRITE, "PROT_WRITE" },
79 { PROT_EXEC, "PROT_EXEC" },
80 { 0, NULL },
81};
82
83static struct xlat mmap_flags[] = {
84 { MAP_SHARED, "MAP_SHARED" },
85 { MAP_PRIVATE, "MAP_PRIVATE" },
86 { MAP_FIXED, "MAP_FIXED" },
87#ifdef MAP_ANONYMOUS
88 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
89#endif
90#ifdef MAP_RENAME
91 { MAP_RENAME, "MAP_RENAME" },
92#endif
93#ifdef MAP_NORESERVE
94 { MAP_NORESERVE,"MAP_NORESERVE" },
95#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +000096 /*
97 * XXX - this was introduced in SunOS 4.x to distinguish between
98 * the old pre-4.x "mmap()", which:
99 *
100 * only let you map devices with an "mmap" routine (e.g.,
101 * frame buffers) in;
102 *
103 * required you to specify the mapping address;
104 *
105 * returned 0 on success and -1 on failure;
106 *
107 * memory and which, and the 4.x "mmap()" which:
108 *
109 * can map plain files;
110 *
111 * can be asked to pick where to map the file;
112 *
113 * returns the address where it mapped the file on success
114 * and -1 on failure.
115 *
116 * It's not actually used in source code that calls "mmap()"; the
117 * "mmap()" routine adds it for you.
118 *
119 * It'd be nice to come up with some way of eliminating it from
120 * the flags, e.g. reporting calls *without* it as "old_mmap()"
121 * and calls with it as "mmap()".
122 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000123#ifdef _MAP_NEW
124 { _MAP_NEW, "_MAP_NEW" },
125#endif
126#ifdef MAP_GROWSDOWN
127 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
128#endif
129#ifdef MAP_DENYWRITE
130 { MAP_DENYWRITE,"MAP_DENYWRITE" },
131#endif
132#ifdef MAP_EXECUTABLE
133 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
134#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000135#ifdef MAP_INHERIT
136 { MAP_INHERIT,"MAP_INHERIT" },
137#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000138#ifdef MAP_FILE
139 { MAP_FILE,"MAP_FILE"},
140#endif
141#ifdef MAP_LOCKED
142 { MAP_LOCKED,"MAP_LOCKED"},
143#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000144 /* FreeBSD ones */
145#ifdef MAP_ANON
146 { MAP_ANON, "MAP_ANON" },
147#endif
148#ifdef MAP_HASSEMAPHORE
149 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
150#endif
151#ifdef MAP_STACK
152 { MAP_STACK, "MAP_STACK" },
153#endif
154#ifdef MAP_NOSYNC
155 { MAP_NOSYNC, "MAP_NOSYNC" },
156#endif
157#ifdef MAP_NOCORE
158 { MAP_NOCORE, "MAP_NOCORE" },
159#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160 { 0, NULL },
161};
162
John Hughes70623be2001-03-08 13:59:00 +0000163#if !HAVE_LONG_LONG_OFF_T
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000164static
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000165int
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000166print_mmap(tcp,u_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000167struct tcb *tcp;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000168long *u_arg;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000169{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000170 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000171 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000172 if (!u_arg[0])
173 tprintf("NULL, ");
174 else
175 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176 /* len */
177 tprintf("%lu, ", u_arg[1]);
178 /* prot */
179 printflags(mmap_prot, u_arg[2]);
180 tprintf(", ");
181 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000182#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000183 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
184 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000185#else
186 printflags(mmap_flags, u_arg[3]);
187#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000188 /* fd */
189 tprintf(", %ld, ", u_arg[4]);
190 /* offset */
191 tprintf("%#lx", u_arg[5]);
192 }
193 return RVAL_HEX;
194}
195
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000196#ifdef LINUX
197int sys_old_mmap(tcp)
198struct tcb *tcp;
199{
200 long u_arg[6];
201
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000202#if defined(IA64)
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000203 int i, v;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000204 /*
205 * IA64 processes never call this routine, they only use the
206 * new `sys_mmap' interface. This code converts the integer
207 * arguments that the IA32 process pushed onto the stack into
208 * longs.
209 *
210 * Note that addresses with bit 31 set will be sign extended.
211 * Fortunately, those addresses are not currently being generated
212 * for IA32 processes so it's not a problem.
213 */
214 for (i = 0; i < 6; i++)
215 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
216 return 0;
217 else
218 u_arg[i] = v;
219#else // defined(IA64)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000220 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
221 return 0;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000222#endif // defined(IA64)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000223 return print_mmap(tcp, u_arg);
224
225}
226#endif
227
228int
229sys_mmap(tcp)
230struct tcb *tcp;
231{
232 return print_mmap(tcp, tcp->u_arg);
233}
John Hughes70623be2001-03-08 13:59:00 +0000234#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000235
John Hughes70623be2001-03-08 13:59:00 +0000236#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000237int
238sys_mmap64(tcp)
239struct tcb *tcp;
240{
241#ifdef linux
242#ifdef ALPHA
243 long *u_arg = tcp->u_arg;
244#else /* !ALPHA */
245 long u_arg[7];
246#endif /* !ALPHA */
247#else /* !linux */
248 long *u_arg = tcp->u_arg;
249#endif /* !linux */
250
251 if (entering(tcp)) {
252#ifdef linux
253#ifndef ALPHA
254 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
255 (char *) u_arg) == -1)
256 return 0;
257#endif /* ALPHA */
258#endif /* linux */
John Hughes5a826b82001-03-07 13:21:24 +0000259 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
John Hughesbdf48f52001-03-06 15:08:09 +0000260
261 /* addr */
262 tprintf("%#lx, ", u_arg[0]);
263 /* len */
264 tprintf("%lu, ", u_arg[1]);
265 /* prot */
266 printflags(mmap_prot, u_arg[2]);
267 tprintf(", ");
268 /* flags */
John Hughes5a826b82001-03-07 13:21:24 +0000269#ifdef MAP_TYPE
John Hughesbdf48f52001-03-06 15:08:09 +0000270 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
271 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
John Hughes5a826b82001-03-07 13:21:24 +0000272#else
273 printflags(mmap_flags, u_arg[3]);
274#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000275 /* fd */
276 tprintf(", %ld, ", u_arg[4]);
277 /* offset */
John Hughes0c79e012001-03-08 14:40:06 +0000278 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
John Hughesbdf48f52001-03-06 15:08:09 +0000279 }
280 return RVAL_HEX;
281}
282#endif
283
284
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000285int
286sys_munmap(tcp)
287struct tcb *tcp;
288{
289 if (entering(tcp)) {
290 tprintf("%#lx, %lu",
291 tcp->u_arg[0], tcp->u_arg[1]);
292 }
293 return 0;
294}
295
296int
297sys_mprotect(tcp)
298struct tcb *tcp;
299{
300 if (entering(tcp)) {
301 tprintf("%#lx, %lu, ",
302 tcp->u_arg[0], tcp->u_arg[1]);
303 if (!printflags(mmap_prot, tcp->u_arg[2]))
304 tprintf("PROT_???");
305 }
306 return 0;
307}
308
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000309#ifdef LINUX
310
311static struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000312 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
313 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000314};
315
316int
317sys_mremap(tcp)
318struct tcb *tcp;
319{
320 if (entering(tcp)) {
321 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
322 tcp->u_arg[2]);
323 printflags(mremap_flags, tcp->u_arg[3]);
324 }
325 return RVAL_HEX;
326}
327
Wichert Akkermanc7926982000-04-10 22:22:31 +0000328static struct xlat madvise_flags[] = {
329#ifdef MADV_NORMAL
330 { MADV_NORMAL, "MADV_NORMAL" },
331#endif
332#ifdef MADZV_RANDOM
333 { MADV_RANDOM, "MADV_RANDOM" },
334#endif
335#ifdef MADV_SEQUENTIAL
336 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
337#endif
338#ifdef MADV_WILLNEED
339 { MADV_WILLNEED, "MADV_WILLNEED" },
340#endif
341#ifdef MADV_DONTNED
342 { MADV_DONTNEED, "MADV_DONTNEED" },
343#endif
344 { 0, NULL },
345};
346
347
348int
349sys_madvise(tcp)
350struct tcb *tcp;
351{
352 if (entering(tcp)) {
353 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
354 printflags(madvise_flags, tcp->u_arg[2]);
355 }
356 return 0;
357}
358
359
360static struct xlat mlockall_flags[] = {
361#ifdef MCL_CURRENT
362 { MCL_CURRENT, "MCL_CURRENT" },
363#endif
364#ifdef MCL_FUTURE
365 { MCL_FUTURE, "MCL_FUTURE" },
366#endif
367 { 0, NULL}
368};
369
370int
371sys_mlockall(tcp)
372struct tcb *tcp;
373{
374 if (entering(tcp)) {
375 printflags(mlockall_flags, tcp->u_arg[0]);
376 }
377 return 0;
378}
379
380
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000381#endif /* LINUX */
382
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383#ifdef MS_ASYNC
384
385static struct xlat mctl_sync[] = {
386 { MS_ASYNC, "MS_ASYNC" },
387 { MS_INVALIDATE,"MS_INVALIDATE" },
388#ifdef MS_SYNC
389 { MS_SYNC, "MS_SYNC" },
390#endif
391 { 0, NULL },
392};
393
394int
395sys_msync(tcp)
396struct tcb *tcp;
397{
398 if (entering(tcp)) {
399 /* addr */
400 tprintf("%#lx", tcp->u_arg[0]);
401 /* len */
402 tprintf(", %lu, ", tcp->u_arg[1]);
403 /* flags */
404 if (!printflags(mctl_sync, tcp->u_arg[2]))
405 tprintf("MS_???");
406 }
407 return 0;
408}
409
410#endif /* MS_ASYNC */
411
412#ifdef MC_SYNC
413
414static struct xlat mctl_funcs[] = {
415 { MC_LOCK, "MC_LOCK" },
416 { MC_LOCKAS, "MC_LOCKAS" },
417 { MC_SYNC, "MC_SYNC" },
418 { MC_UNLOCK, "MC_UNLOCK" },
419 { MC_UNLOCKAS, "MC_UNLOCKAS" },
420 { 0, NULL },
421};
422
423static struct xlat mctl_lockas[] = {
424 { MCL_CURRENT, "MCL_CURRENT" },
425 { MCL_FUTURE, "MCL_FUTURE" },
426 { 0, NULL },
427};
428
429int
430sys_mctl(tcp)
431struct tcb *tcp;
432{
433 int arg, function;
434
435 if (entering(tcp)) {
436 /* addr */
437 tprintf("%#lx", tcp->u_arg[0]);
438 /* len */
439 tprintf(", %lu, ", tcp->u_arg[1]);
440 /* function */
441 function = tcp->u_arg[2];
442 if (!printflags(mctl_funcs, function))
443 tprintf("MC_???");
444 /* arg */
445 arg = tcp->u_arg[3];
446 tprintf(", ");
447 switch (function) {
448 case MC_SYNC:
449 if (!printflags(mctl_sync, arg))
450 tprintf("MS_???");
451 break;
452 case MC_LOCKAS:
453 if (!printflags(mctl_lockas, arg))
454 tprintf("MCL_???");
455 break;
456 default:
457 tprintf("%#x", arg);
458 break;
459 }
460 }
461 return 0;
462}
463
464#endif /* MC_SYNC */
465
466int
467sys_mincore(tcp)
468struct tcb *tcp;
469{
470 int i, len;
471 char *vec = NULL;
472
473 if (entering(tcp)) {
474 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
475 } else {
476 len = tcp->u_arg[1];
477 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
478 (vec = malloc((u_int)len)) == NULL ||
479 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
480 tprintf("%#lx", tcp->u_arg[2]);
481 else {
482 tprintf("[");
483 for (i = 0; i < len; i++) {
484 if (abbrev(tcp) && i >= max_strlen) {
485 tprintf("...");
486 break;
487 }
488 tprintf((vec[i] & 1) ? "1" : "0");
489 }
490 tprintf("]");
491 }
492 if (vec)
493 free(vec);
494 }
495 return 0;
496}
497
498int
499sys_getpagesize(tcp)
500struct tcb *tcp;
501{
502 if (exiting(tcp))
503 return RVAL_HEX;
504 return 0;
505}
506
507#if defined(LINUX) && defined(__i386__)
508int
509sys_modify_ldt(tcp)
510struct tcb *tcp;
511{
512 if (entering(tcp)) {
513 struct modify_ldt_ldt_s copy;
514 tprintf("%ld", tcp->u_arg[0]);
515 if (tcp->u_arg[1] == 0
516 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
517 || umove(tcp, tcp->u_arg[1], &copy) == -1)
518 tprintf(", %lx", tcp->u_arg[1]);
519 else {
520 tprintf(", {entry_number:%d, ", copy.entry_number);
521 if (!verbose(tcp))
522 tprintf("...}");
523 else {
524 tprintf("base_addr:%#08lx, "
525 "limit:%d, "
526 "seg_32bit:%d, "
527 "contents:%d, "
528 "read_exec_only:%d, "
529 "limit_in_pages:%d, "
530 "seg_not_present:%d, "
531 "useable:%d}",
532 copy.base_addr,
533 copy.limit,
534 copy.seg_32bit,
535 copy.contents,
536 copy.read_exec_only,
537 copy.limit_in_pages,
538 copy.seg_not_present,
539 copy.useable);
540 }
541 }
542 tprintf(", %lu", tcp->u_arg[2]);
543 }
544 return 0;
545}
546#endif /* LINUX && __i386__ */
547