blob: 295238dbfca513e7a5f5ba1d6c34311767d07518 [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
Michal Ludvig0e035502002-09-23 15:41:01 +0000188 /* fd (is always int, not long) */
189 tprintf(", %d, ", (int)u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000190 /* 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[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000386#ifdef MS_SYNC
387 { MS_SYNC, "MS_SYNC" },
388#endif
John Hughesaca07f32001-10-16 18:12:27 +0000389 { MS_ASYNC, "MS_ASYNC" },
390 { MS_INVALIDATE,"MS_INVALIDATE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391 { 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__)
Roland McGrath34e4a692002-12-15 23:58:17 +0000508static void
509print_ldt_entry (ldt_entry)
510struct modify_ldt_ldt_s *ldt_entry;
511{
512 tprintf("base_addr:%#08lx, "
513 "limit:%d, "
514 "seg_32bit:%d, "
515 "contents:%d, "
516 "read_exec_only:%d, "
517 "limit_in_pages:%d, "
518 "seg_not_present:%d, "
519 "useable:%d}",
520 ldt_entry->base_addr,
521 ldt_entry->limit,
522 ldt_entry->seg_32bit,
523 ldt_entry->contents,
524 ldt_entry->read_exec_only,
525 ldt_entry->limit_in_pages,
526 ldt_entry->seg_not_present,
527 ldt_entry->useable);
528}
529
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530int
531sys_modify_ldt(tcp)
532struct tcb *tcp;
533{
534 if (entering(tcp)) {
535 struct modify_ldt_ldt_s copy;
536 tprintf("%ld", tcp->u_arg[0]);
537 if (tcp->u_arg[1] == 0
538 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
539 || umove(tcp, tcp->u_arg[1], &copy) == -1)
540 tprintf(", %lx", tcp->u_arg[1]);
541 else {
542 tprintf(", {entry_number:%d, ", copy.entry_number);
543 if (!verbose(tcp))
544 tprintf("...}");
545 else {
Roland McGrath34e4a692002-12-15 23:58:17 +0000546 print_ldt_entry(&copy);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547 }
548 }
549 tprintf(", %lu", tcp->u_arg[2]);
550 }
551 return 0;
552}
Roland McGrath34e4a692002-12-15 23:58:17 +0000553
554int
555sys_set_thread_area(tcp)
556struct tcb *tcp;
557{
558 struct modify_ldt_ldt_s copy;
559 if (entering(tcp)) {
560 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
561 if (copy.entry_number == -1)
562 tprintf("{entry_number:%d -> ",
563 copy.entry_number);
564 else
565 tprintf("{entry_number:");
566 }
567 } else {
568 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
569 tprintf("%d, ", copy.entry_number);
570 if (!verbose(tcp))
571 tprintf("...}");
572 else {
573 print_ldt_entry(&copy);
574 }
575 } else {
576 tprintf("%lx", tcp->u_arg[0]);
577 }
578 }
579 return 0;
580
581}
582
583int
584sys_get_thread_area(tcp)
585struct tcb *tcp;
586{
587 struct modify_ldt_ldt_s copy;
588 if (exiting(tcp)) {
589 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
590 tprintf("{entry_number:%d, ", copy.entry_number);
591 if (!verbose(tcp))
592 tprintf("...}");
593 else {
594 print_ldt_entry(&copy);
595 }
596 } else {
597 tprintf("%lx", tcp->u_arg[0]);
598 }
599 }
600 return 0;
601
602}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000603#endif /* LINUX && __i386__ */
604