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(SH64)
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" },
86 { PROT_SEM, "PROT_SEM" },
89 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
92 { PROT_GROWSUP, "PROT_GROWSUP" },
97 static struct xlat mmap_flags[] = {
98 { MAP_SHARED, "MAP_SHARED" },
99 { MAP_PRIVATE, "MAP_PRIVATE" },
100 { MAP_FIXED, "MAP_FIXED" },
102 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
105 { MAP_RENAME, "MAP_RENAME" },
108 { MAP_NORESERVE,"MAP_NORESERVE" },
111 { MAP_POPULATE, "MAP_POPULATE" },
114 { MAP_NONBLOCK, "MAP_NONBLOCK" },
117 * XXX - this was introduced in SunOS 4.x to distinguish between
118 * the old pre-4.x "mmap()", which:
120 * only let you map devices with an "mmap" routine (e.g.,
123 * required you to specify the mapping address;
125 * returned 0 on success and -1 on failure;
127 * memory and which, and the 4.x "mmap()" which:
129 * can map plain files;
131 * can be asked to pick where to map the file;
133 * returns the address where it mapped the file on success
136 * It's not actually used in source code that calls "mmap()"; the
137 * "mmap()" routine adds it for you.
139 * It'd be nice to come up with some way of eliminating it from
140 * the flags, e.g. reporting calls *without* it as "old_mmap()"
141 * and calls with it as "mmap()".
144 { _MAP_NEW, "_MAP_NEW" },
147 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
150 { MAP_DENYWRITE,"MAP_DENYWRITE" },
152 #ifdef MAP_EXECUTABLE
153 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
156 { MAP_INHERIT,"MAP_INHERIT" },
159 { MAP_FILE,"MAP_FILE"},
162 { MAP_LOCKED,"MAP_LOCKED"},
166 { MAP_ANON, "MAP_ANON" },
168 #ifdef MAP_HASSEMAPHORE
169 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
172 { MAP_STACK, "MAP_STACK" },
175 { MAP_NOSYNC, "MAP_NOSYNC" },
178 { MAP_NOCORE, "MAP_NOCORE" },
183 #if !HAVE_LONG_LONG_OFF_T
186 print_mmap(tcp,u_arg)
195 tprintf("%#lx, ", u_arg[0]);
197 tprintf("%lu, ", u_arg[1]);
199 printflags(mmap_prot, u_arg[2]);
203 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
204 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
206 printflags(mmap_flags, u_arg[3]);
208 /* fd (is always int, not long) */
209 tprintf(", %d, ", (int)u_arg[4]);
211 tprintf("%#lx", u_arg[5]);
217 int sys_old_mmap(tcp)
225 * IA64 processes never call this routine, they only use the
226 * new `sys_mmap' interface. This code converts the integer
227 * arguments that the IA32 process pushed onto the stack into
230 * Note that addresses with bit 31 set will be sign extended.
231 * Fortunately, those addresses are not currently being generated
232 * for IA32 processes so it's not a problem.
234 for (i = 0; i < 6; i++)
235 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
239 #elif defined(SH) || defined(SH64)
240 /* SH has always passed the args in registers */
243 u_arg[i] = tcp->u_arg[i];
245 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
247 #endif // defined(IA64)
248 return print_mmap(tcp, u_arg);
257 #if defined(LINUX) && defined(SH64)
259 * Old mmap differs from new mmap in specifying the
260 * offset in units of bytes rather than pages. We
261 * pretend it's in byte units so the user only ever
262 * sees bytes in the printout.
264 tcp->u_arg[5] <<= PAGE_SHIFT;
266 return print_mmap(tcp, tcp->u_arg);
268 #endif /* !HAVE_LONG_LONG_OFF_T */
270 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
277 long *u_arg = tcp->u_arg;
282 long *u_arg = tcp->u_arg;
288 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
289 (char *) u_arg) == -1)
293 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
296 tprintf("%#lx, ", u_arg[0]);
298 tprintf("%lu, ", u_arg[1]);
300 printflags(mmap_prot, u_arg[2]);
304 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
305 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
307 printflags(mmap_flags, u_arg[3]);
310 tprintf(", %ld, ", u_arg[4]);
312 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
325 tcp->u_arg[0], tcp->u_arg[1]);
335 tprintf("%#lx, %lu, ",
336 tcp->u_arg[0], tcp->u_arg[1]);
337 if (!printflags(mmap_prot, tcp->u_arg[2]))
345 static struct xlat mremap_flags[] = {
346 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
355 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
357 printflags(mremap_flags, tcp->u_arg[3]);
362 static struct xlat madvise_flags[] = {
364 { MADV_NORMAL, "MADV_NORMAL" },
367 { MADV_RANDOM, "MADV_RANDOM" },
369 #ifdef MADV_SEQUENTIAL
370 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
373 { MADV_WILLNEED, "MADV_WILLNEED" },
376 { MADV_DONTNEED, "MADV_DONTNEED" },
387 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
388 printflags(madvise_flags, tcp->u_arg[2]);
394 static struct xlat mlockall_flags[] = {
396 { MCL_CURRENT, "MCL_CURRENT" },
399 { MCL_FUTURE, "MCL_FUTURE" },
409 printflags(mlockall_flags, tcp->u_arg[0]);
419 static struct xlat mctl_sync[] = {
421 { MS_SYNC, "MS_SYNC" },
423 { MS_ASYNC, "MS_ASYNC" },
424 { MS_INVALIDATE,"MS_INVALIDATE" },
434 tprintf("%#lx", tcp->u_arg[0]);
436 tprintf(", %lu, ", tcp->u_arg[1]);
438 if (!printflags(mctl_sync, tcp->u_arg[2]))
444 #endif /* MS_ASYNC */
448 static struct xlat mctl_funcs[] = {
449 { MC_LOCK, "MC_LOCK" },
450 { MC_LOCKAS, "MC_LOCKAS" },
451 { MC_SYNC, "MC_SYNC" },
452 { MC_UNLOCK, "MC_UNLOCK" },
453 { MC_UNLOCKAS, "MC_UNLOCKAS" },
457 static struct xlat mctl_lockas[] = {
458 { MCL_CURRENT, "MCL_CURRENT" },
459 { MCL_FUTURE, "MCL_FUTURE" },
471 tprintf("%#lx", tcp->u_arg[0]);
473 tprintf(", %lu, ", tcp->u_arg[1]);
475 function = tcp->u_arg[2];
476 if (!printflags(mctl_funcs, function))
483 if (!printflags(mctl_sync, arg))
487 if (!printflags(mctl_lockas, arg))
508 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
511 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
512 (vec = malloc((u_int)len)) == NULL ||
513 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
514 tprintf("%#lx", tcp->u_arg[2]);
517 for (i = 0; i < len; i++) {
518 if (abbrev(tcp) && i >= max_strlen) {
522 tprintf((vec[i] & 1) ? "1" : "0");
541 #if defined(LINUX) && defined(__i386__)
543 print_ldt_entry (ldt_entry)
544 struct modify_ldt_ldt_s *ldt_entry;
546 tprintf("base_addr:%#08lx, "
550 "read_exec_only:%d, "
551 "limit_in_pages:%d, "
552 "seg_not_present:%d, "
554 ldt_entry->base_addr,
556 ldt_entry->seg_32bit,
558 ldt_entry->read_exec_only,
559 ldt_entry->limit_in_pages,
560 ldt_entry->seg_not_present,
569 struct modify_ldt_ldt_s copy;
570 tprintf("%ld", tcp->u_arg[0]);
571 if (tcp->u_arg[1] == 0
572 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
573 || umove(tcp, tcp->u_arg[1], ©) == -1)
574 tprintf(", %lx", tcp->u_arg[1]);
576 tprintf(", {entry_number:%d, ", copy.entry_number);
580 print_ldt_entry(©);
583 tprintf(", %lu", tcp->u_arg[2]);
589 sys_set_thread_area(tcp)
592 struct modify_ldt_ldt_s copy;
594 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
595 if (copy.entry_number == -1)
596 tprintf("{entry_number:%d -> ",
599 tprintf("{entry_number:");
602 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
603 tprintf("%d, ", copy.entry_number);
607 print_ldt_entry(©);
610 tprintf("%lx", tcp->u_arg[0]);
618 sys_get_thread_area(tcp)
621 struct modify_ldt_ldt_s copy;
623 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
624 tprintf("{entry_number:%d, ", copy.entry_number);
628 print_ldt_entry(©);
631 tprintf("%lx", tcp->u_arg[0]);
637 #endif /* LINUX && __i386__ */
641 sys_remap_file_pages(tcp)
645 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
646 printflags(mmap_prot, tcp->u_arg[2]);
647 tprintf(", %lu, ", tcp->u_arg[3]);
649 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
650 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
652 printflags(mmap_flags, tcp->u_arg[4]);