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>
5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
7 * port by Greg Banks <gbanks@pocketpenguins.com>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
38 #include <linux/mman.h>
42 #if defined(LINUX) && defined(I386)
45 #if defined(LINUX) && defined(SHMEDIA)
46 #include <asm/page.h> /* for PAGE_SHIFT */
49 #ifdef HAVE_LONG_LONG_OFF_T
51 * Ugly hacks for systems that have a long long off_t
53 #define sys_mmap64 sys_mmap
61 tprintf("%#lx", tcp->u_arg[0]);
75 tprintf("%lu", tcp->u_arg[0]);
80 static struct xlat mmap_prot[] = {
81 { PROT_NONE, "PROT_NONE", },
82 { PROT_READ, "PROT_READ" },
83 { PROT_WRITE, "PROT_WRITE" },
84 { PROT_EXEC, "PROT_EXEC" },
88 static struct xlat mmap_flags[] = {
89 { MAP_SHARED, "MAP_SHARED" },
90 { MAP_PRIVATE, "MAP_PRIVATE" },
91 { MAP_FIXED, "MAP_FIXED" },
93 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
96 { MAP_RENAME, "MAP_RENAME" },
99 { MAP_NORESERVE,"MAP_NORESERVE" },
102 { MAP_POPULATE, "MAP_POPULATE" },
105 { MAP_NONBLOCK, "MAP_NONBLOCK" },
108 * XXX - this was introduced in SunOS 4.x to distinguish between
109 * the old pre-4.x "mmap()", which:
111 * only let you map devices with an "mmap" routine (e.g.,
114 * required you to specify the mapping address;
116 * returned 0 on success and -1 on failure;
118 * memory and which, and the 4.x "mmap()" which:
120 * can map plain files;
122 * can be asked to pick where to map the file;
124 * returns the address where it mapped the file on success
127 * It's not actually used in source code that calls "mmap()"; the
128 * "mmap()" routine adds it for you.
130 * It'd be nice to come up with some way of eliminating it from
131 * the flags, e.g. reporting calls *without* it as "old_mmap()"
132 * and calls with it as "mmap()".
135 { _MAP_NEW, "_MAP_NEW" },
138 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
141 { MAP_DENYWRITE,"MAP_DENYWRITE" },
143 #ifdef MAP_EXECUTABLE
144 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
147 { MAP_INHERIT,"MAP_INHERIT" },
150 { MAP_FILE,"MAP_FILE"},
153 { MAP_LOCKED,"MAP_LOCKED"},
157 { MAP_ANON, "MAP_ANON" },
159 #ifdef MAP_HASSEMAPHORE
160 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
163 { MAP_STACK, "MAP_STACK" },
166 { MAP_NOSYNC, "MAP_NOSYNC" },
169 { MAP_NOCORE, "MAP_NOCORE" },
174 #if !HAVE_LONG_LONG_OFF_T
177 print_mmap(tcp,u_arg)
186 tprintf("%#lx, ", u_arg[0]);
188 tprintf("%lu, ", u_arg[1]);
190 printflags(mmap_prot, u_arg[2]);
194 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
195 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
197 printflags(mmap_flags, u_arg[3]);
199 /* fd (is always int, not long) */
200 tprintf(", %d, ", (int)u_arg[4]);
202 tprintf("%#lx", u_arg[5]);
208 int sys_old_mmap(tcp)
216 * IA64 processes never call this routine, they only use the
217 * new `sys_mmap' interface. This code converts the integer
218 * arguments that the IA32 process pushed onto the stack into
221 * Note that addresses with bit 31 set will be sign extended.
222 * Fortunately, those addresses are not currently being generated
223 * for IA32 processes so it's not a problem.
225 for (i = 0; i < 6; i++)
226 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
230 #elif defined(SH) || defined(SHMEDIA)
231 /* SH has always passed the args in registers */
234 u_arg[i] = tcp->u_arg[i];
236 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
238 #endif // defined(IA64)
239 return print_mmap(tcp, u_arg);
248 #if defined(LINUX) && defined(SHMEDIA)
250 * Old mmap differs from new mmap in specifying the
251 * offset in units of bytes rather than pages. We
252 * pretend it's in byte units so the user only ever
253 * sees bytes in the printout.
255 tcp->u_arg[5] <<= PAGE_SHIFT;
257 return print_mmap(tcp, tcp->u_arg);
259 #endif /* !HAVE_LONG_LONG_OFF_T */
261 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
268 long *u_arg = tcp->u_arg;
273 long *u_arg = tcp->u_arg;
279 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
280 (char *) u_arg) == -1)
284 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
287 tprintf("%#lx, ", u_arg[0]);
289 tprintf("%lu, ", u_arg[1]);
291 printflags(mmap_prot, u_arg[2]);
295 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
296 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
298 printflags(mmap_flags, u_arg[3]);
301 tprintf(", %ld, ", u_arg[4]);
303 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
316 tcp->u_arg[0], tcp->u_arg[1]);
326 tprintf("%#lx, %lu, ",
327 tcp->u_arg[0], tcp->u_arg[1]);
328 if (!printflags(mmap_prot, tcp->u_arg[2]))
336 static struct xlat mremap_flags[] = {
337 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
346 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
348 printflags(mremap_flags, tcp->u_arg[3]);
353 static struct xlat madvise_flags[] = {
355 { MADV_NORMAL, "MADV_NORMAL" },
358 { MADV_RANDOM, "MADV_RANDOM" },
360 #ifdef MADV_SEQUENTIAL
361 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
364 { MADV_WILLNEED, "MADV_WILLNEED" },
367 { MADV_DONTNEED, "MADV_DONTNEED" },
378 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
379 printflags(madvise_flags, tcp->u_arg[2]);
385 static struct xlat mlockall_flags[] = {
387 { MCL_CURRENT, "MCL_CURRENT" },
390 { MCL_FUTURE, "MCL_FUTURE" },
400 printflags(mlockall_flags, tcp->u_arg[0]);
410 static struct xlat mctl_sync[] = {
412 { MS_SYNC, "MS_SYNC" },
414 { MS_ASYNC, "MS_ASYNC" },
415 { MS_INVALIDATE,"MS_INVALIDATE" },
425 tprintf("%#lx", tcp->u_arg[0]);
427 tprintf(", %lu, ", tcp->u_arg[1]);
429 if (!printflags(mctl_sync, tcp->u_arg[2]))
435 #endif /* MS_ASYNC */
439 static struct xlat mctl_funcs[] = {
440 { MC_LOCK, "MC_LOCK" },
441 { MC_LOCKAS, "MC_LOCKAS" },
442 { MC_SYNC, "MC_SYNC" },
443 { MC_UNLOCK, "MC_UNLOCK" },
444 { MC_UNLOCKAS, "MC_UNLOCKAS" },
448 static struct xlat mctl_lockas[] = {
449 { MCL_CURRENT, "MCL_CURRENT" },
450 { MCL_FUTURE, "MCL_FUTURE" },
462 tprintf("%#lx", tcp->u_arg[0]);
464 tprintf(", %lu, ", tcp->u_arg[1]);
466 function = tcp->u_arg[2];
467 if (!printflags(mctl_funcs, function))
474 if (!printflags(mctl_sync, arg))
478 if (!printflags(mctl_lockas, arg))
499 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
502 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
503 (vec = malloc((u_int)len)) == NULL ||
504 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
505 tprintf("%#lx", tcp->u_arg[2]);
508 for (i = 0; i < len; i++) {
509 if (abbrev(tcp) && i >= max_strlen) {
513 tprintf((vec[i] & 1) ? "1" : "0");
532 #if defined(LINUX) && defined(__i386__)
534 print_ldt_entry (ldt_entry)
535 struct modify_ldt_ldt_s *ldt_entry;
537 tprintf("base_addr:%#08lx, "
541 "read_exec_only:%d, "
542 "limit_in_pages:%d, "
543 "seg_not_present:%d, "
545 ldt_entry->base_addr,
547 ldt_entry->seg_32bit,
549 ldt_entry->read_exec_only,
550 ldt_entry->limit_in_pages,
551 ldt_entry->seg_not_present,
560 struct modify_ldt_ldt_s copy;
561 tprintf("%ld", tcp->u_arg[0]);
562 if (tcp->u_arg[1] == 0
563 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
564 || umove(tcp, tcp->u_arg[1], ©) == -1)
565 tprintf(", %lx", tcp->u_arg[1]);
567 tprintf(", {entry_number:%d, ", copy.entry_number);
571 print_ldt_entry(©);
574 tprintf(", %lu", tcp->u_arg[2]);
580 sys_set_thread_area(tcp)
583 struct modify_ldt_ldt_s copy;
585 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
586 if (copy.entry_number == -1)
587 tprintf("{entry_number:%d -> ",
590 tprintf("{entry_number:");
593 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
594 tprintf("%d, ", copy.entry_number);
598 print_ldt_entry(©);
601 tprintf("%lx", tcp->u_arg[0]);
609 sys_get_thread_area(tcp)
612 struct modify_ldt_ldt_s copy;
614 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
615 tprintf("{entry_number:%d, ", copy.entry_number);
619 print_ldt_entry(©);
622 tprintf("%lx", tcp->u_arg[0]);
628 #endif /* LINUX && __i386__ */
632 sys_remap_file_pages(tcp)
636 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
637 printflags(mmap_prot, tcp->u_arg[2]);
638 tprintf(", %lu, ", tcp->u_arg[3]);
640 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
641 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
643 printflags(mmap_flags, tcp->u_arg[4]);