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.
42 #if defined(LINUX) && defined(I386)
44 # ifdef HAVE_STRUCT_USER_DESC
45 # define modify_ldt_ldt_s user_desc
48 #if defined(LINUX) && defined(SH64)
49 #include <asm/page.h> /* for PAGE_SHIFT */
52 #ifdef HAVE_LONG_LONG_OFF_T
54 * Ugly hacks for systems that have a long long off_t
56 #define sys_mmap64 sys_mmap
64 tprintf("%#lx", tcp->u_arg[0]);
73 #if defined(FREEBSD) || defined(SUNOS4)
79 tprintf("%lu", tcp->u_arg[0]);
83 #endif /* FREEBSD || SUNOS4 */
85 static const struct xlat mmap_prot[] = {
86 { PROT_NONE, "PROT_NONE", },
87 { PROT_READ, "PROT_READ" },
88 { PROT_WRITE, "PROT_WRITE" },
89 { PROT_EXEC, "PROT_EXEC" },
91 { PROT_SEM, "PROT_SEM" },
94 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
97 { PROT_GROWSUP, "PROT_GROWSUP" },
102 static const struct xlat mmap_flags[] = {
103 { MAP_SHARED, "MAP_SHARED" },
104 { MAP_PRIVATE, "MAP_PRIVATE" },
105 { MAP_FIXED, "MAP_FIXED" },
107 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
110 { MAP_32BIT, "MAP_32BIT" },
113 { MAP_RENAME, "MAP_RENAME" },
116 { MAP_NORESERVE,"MAP_NORESERVE" },
119 { MAP_POPULATE, "MAP_POPULATE" },
122 { MAP_NONBLOCK, "MAP_NONBLOCK" },
125 * XXX - this was introduced in SunOS 4.x to distinguish between
126 * the old pre-4.x "mmap()", which:
128 * only let you map devices with an "mmap" routine (e.g.,
131 * required you to specify the mapping address;
133 * returned 0 on success and -1 on failure;
135 * memory and which, and the 4.x "mmap()" which:
137 * can map plain files;
139 * can be asked to pick where to map the file;
141 * returns the address where it mapped the file on success
144 * It's not actually used in source code that calls "mmap()"; the
145 * "mmap()" routine adds it for you.
147 * It'd be nice to come up with some way of eliminating it from
148 * the flags, e.g. reporting calls *without* it as "old_mmap()"
149 * and calls with it as "mmap()".
152 { _MAP_NEW, "_MAP_NEW" },
155 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
158 { MAP_DENYWRITE,"MAP_DENYWRITE" },
160 #ifdef MAP_EXECUTABLE
161 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
164 { MAP_INHERIT,"MAP_INHERIT" },
167 { MAP_FILE,"MAP_FILE"},
170 { MAP_LOCKED,"MAP_LOCKED"},
174 { MAP_ANON, "MAP_ANON" },
176 #ifdef MAP_HASSEMAPHORE
177 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
180 { MAP_STACK, "MAP_STACK" },
183 { MAP_NOSYNC, "MAP_NOSYNC" },
186 { MAP_NOCORE, "MAP_NOCORE" },
191 #if !HAVE_LONG_LONG_OFF_T
194 print_mmap(tcp,u_arg)
203 tprintf("%#lx, ", u_arg[0]);
205 tprintf("%lu, ", u_arg[1]);
207 printflags(mmap_prot, u_arg[2], "PROT_???");
211 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
212 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
214 printflags(mmap_flags, u_arg[3], "MAP_???");
216 /* fd (is always int, not long) */
217 tprintf(", %d, ", (int)u_arg[4]);
219 tprintf("%#lx", u_arg[5]);
225 int sys_old_mmap(tcp)
233 * IA64 processes never call this routine, they only use the
234 * new `sys_mmap' interface. This code converts the integer
235 * arguments that the IA32 process pushed onto the stack into
238 * Note that addresses with bit 31 set will be sign extended.
239 * Fortunately, those addresses are not currently being generated
240 * for IA32 processes so it's not a problem.
242 for (i = 0; i < 6; i++)
243 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
247 #elif defined(SH) || defined(SH64)
248 /* SH has always passed the args in registers */
251 u_arg[i] = tcp->u_arg[i];
254 if (current_personality == 1) {
256 for (i = 0; i < 6; ++i) {
258 if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
265 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
267 #endif // defined(IA64)
268 return print_mmap(tcp, u_arg);
277 #if defined(LINUX) && defined(SH64)
279 * Old mmap differs from new mmap in specifying the
280 * offset in units of bytes rather than pages. We
281 * pretend it's in byte units so the user only ever
282 * sees bytes in the printout.
284 tcp->u_arg[5] <<= PAGE_SHIFT;
286 return print_mmap(tcp, tcp->u_arg);
288 #endif /* !HAVE_LONG_LONG_OFF_T */
290 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
297 long *u_arg = tcp->u_arg;
302 long *u_arg = tcp->u_arg;
308 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
309 (char *) u_arg) == -1)
313 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
316 tprintf("%#lx, ", u_arg[0]);
318 tprintf("%lu, ", u_arg[1]);
320 printflags(mmap_prot, u_arg[2], "PROT_???");
324 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
325 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
327 printflags(mmap_flags, u_arg[3], "MAP_???");
330 tprintf(", %ld, ", u_arg[4]);
332 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
345 tcp->u_arg[0], tcp->u_arg[1]);
355 tprintf("%#lx, %lu, ",
356 tcp->u_arg[0], tcp->u_arg[1]);
357 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
364 static const struct xlat mremap_flags[] = {
365 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
374 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
376 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
381 static const struct xlat madvise_flags[] = {
383 { MADV_NORMAL, "MADV_NORMAL" },
386 { MADV_RANDOM, "MADV_RANDOM" },
388 #ifdef MADV_SEQUENTIAL
389 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
392 { MADV_WILLNEED, "MADV_WILLNEED" },
395 { MADV_DONTNEED, "MADV_DONTNEED" },
406 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
407 printflags(madvise_flags, tcp->u_arg[2], "MADV_???");
413 static const struct xlat mlockall_flags[] = {
415 { MCL_CURRENT, "MCL_CURRENT" },
418 { MCL_FUTURE, "MCL_FUTURE" },
428 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
438 static const struct xlat mctl_sync[] = {
440 { MS_SYNC, "MS_SYNC" },
442 { MS_ASYNC, "MS_ASYNC" },
443 { MS_INVALIDATE,"MS_INVALIDATE" },
453 tprintf("%#lx", tcp->u_arg[0]);
455 tprintf(", %lu, ", tcp->u_arg[1]);
457 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
462 #endif /* MS_ASYNC */
466 static const struct xlat mctl_funcs[] = {
467 { MC_LOCK, "MC_LOCK" },
468 { MC_LOCKAS, "MC_LOCKAS" },
469 { MC_SYNC, "MC_SYNC" },
470 { MC_UNLOCK, "MC_UNLOCK" },
471 { MC_UNLOCKAS, "MC_UNLOCKAS" },
475 static const struct xlat mctl_lockas[] = {
476 { MCL_CURRENT, "MCL_CURRENT" },
477 { MCL_FUTURE, "MCL_FUTURE" },
489 tprintf("%#lx", tcp->u_arg[0]);
491 tprintf(", %lu, ", tcp->u_arg[1]);
493 function = tcp->u_arg[2];
494 printflags(mctl_funcs, function, "MC_???");
500 printflags(mctl_sync, arg, "MS_???");
503 printflags(mctl_lockas, arg, "MCL_???");
519 unsigned long i, len;
523 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
526 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
527 (vec = malloc(len)) == NULL ||
528 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
529 tprintf("%#lx", tcp->u_arg[2]);
532 for (i = 0; i < len; i++) {
533 if (abbrev(tcp) && i >= max_strlen) {
537 tprintf((vec[i] & 1) ? "1" : "0");
547 #if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4)
556 #endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
558 #if defined(LINUX) && defined(__i386__)
560 print_ldt_entry (ldt_entry)
561 struct modify_ldt_ldt_s *ldt_entry;
563 tprintf("base_addr:%#08lx, "
567 "read_exec_only:%d, "
568 "limit_in_pages:%d, "
569 "seg_not_present:%d, "
571 ldt_entry->base_addr,
573 ldt_entry->seg_32bit,
575 ldt_entry->read_exec_only,
576 ldt_entry->limit_in_pages,
577 ldt_entry->seg_not_present,
586 struct modify_ldt_ldt_s copy;
587 tprintf("%ld", tcp->u_arg[0]);
588 if (tcp->u_arg[1] == 0
589 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
590 || umove(tcp, tcp->u_arg[1], ©) == -1)
591 tprintf(", %lx", tcp->u_arg[1]);
593 tprintf(", {entry_number:%d, ", copy.entry_number);
597 print_ldt_entry(©);
600 tprintf(", %lu", tcp->u_arg[2]);
606 sys_set_thread_area(tcp)
609 struct modify_ldt_ldt_s copy;
611 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
612 if (copy.entry_number == -1)
613 tprintf("{entry_number:%d -> ",
616 tprintf("{entry_number:");
619 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
620 tprintf("%d, ", copy.entry_number);
624 print_ldt_entry(©);
627 tprintf("%lx", tcp->u_arg[0]);
635 sys_get_thread_area(tcp)
638 struct modify_ldt_ldt_s copy;
640 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
641 tprintf("{entry_number:%d, ", copy.entry_number);
645 print_ldt_entry(©);
648 tprintf("%lx", tcp->u_arg[0]);
654 #endif /* LINUX && __i386__ */
658 sys_remap_file_pages(tcp)
662 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
663 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
664 tprintf(", %lu, ", tcp->u_arg[3]);
666 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
667 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
669 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
676 #define MPOL_DEFAULT 0
677 #define MPOL_PREFERRED 1
679 #define MPOL_INTERLEAVE 3
681 #define MPOL_F_NODE (1<<0)
682 #define MPOL_F_ADDR (1<<1)
684 #define MPOL_MF_STRICT (1<<0)
687 static const struct xlat policies[] = {
688 { MPOL_DEFAULT, "MPOL_DEFAULT" },
689 { MPOL_PREFERRED, "MPOL_PREFERRED" },
690 { MPOL_BIND, "MPOL_BIND" },
691 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
695 static const struct xlat mbindflags[] = {
696 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
700 static const struct xlat mempolicyflags[] = {
701 { MPOL_F_NODE, "MPOL_F_NODE" },
702 { MPOL_F_ADDR, "MPOL_F_ADDR" },
708 get_nodes(tcp, ptr, maxnodes, err)
711 unsigned long maxnodes;
714 unsigned long nlongs, size, end;
716 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
717 size = nlongs * sizeof(long);
719 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
721 unsigned long n, cur, abbrev_end;
725 abbrev_end = ptr + max_strlen * sizeof(long);
726 if (abbrev_end < ptr)
732 for (cur = ptr; cur < end; cur += sizeof(long)) {
735 if (cur >= abbrev_end) {
739 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
744 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
748 tprintf(" %#lx", ptr);
750 tprintf(", %#lx", ptr);
751 tprintf(", %lu", maxnodes);
759 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
760 printxval(policies, tcp->u_arg[2], "MPOL_???");
761 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
763 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
769 sys_set_mempolicy(tcp)
773 printxval(policies, tcp->u_arg[0], "MPOL_???");
774 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
780 sys_get_mempolicy(tcp)
785 if (tcp->u_arg[0] == 0)
787 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
788 tprintf("%#lx", tcp->u_arg[0]);
790 printxval(policies, pol, "MPOL_???");
791 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
792 tprintf(", %#lx, ", tcp->u_arg[3]);
793 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");