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]);
78 tprintf("%lu", tcp->u_arg[0]);
83 static const struct xlat mmap_prot[] = {
84 { PROT_NONE, "PROT_NONE", },
85 { PROT_READ, "PROT_READ" },
86 { PROT_WRITE, "PROT_WRITE" },
87 { PROT_EXEC, "PROT_EXEC" },
89 { PROT_SEM, "PROT_SEM" },
92 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
95 { PROT_GROWSUP, "PROT_GROWSUP" },
100 static const struct xlat mmap_flags[] = {
101 { MAP_SHARED, "MAP_SHARED" },
102 { MAP_PRIVATE, "MAP_PRIVATE" },
103 { MAP_FIXED, "MAP_FIXED" },
105 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
108 { MAP_RENAME, "MAP_RENAME" },
111 { MAP_NORESERVE,"MAP_NORESERVE" },
114 { MAP_POPULATE, "MAP_POPULATE" },
117 { MAP_NONBLOCK, "MAP_NONBLOCK" },
120 * XXX - this was introduced in SunOS 4.x to distinguish between
121 * the old pre-4.x "mmap()", which:
123 * only let you map devices with an "mmap" routine (e.g.,
126 * required you to specify the mapping address;
128 * returned 0 on success and -1 on failure;
130 * memory and which, and the 4.x "mmap()" which:
132 * can map plain files;
134 * can be asked to pick where to map the file;
136 * returns the address where it mapped the file on success
139 * It's not actually used in source code that calls "mmap()"; the
140 * "mmap()" routine adds it for you.
142 * It'd be nice to come up with some way of eliminating it from
143 * the flags, e.g. reporting calls *without* it as "old_mmap()"
144 * and calls with it as "mmap()".
147 { _MAP_NEW, "_MAP_NEW" },
150 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
153 { MAP_DENYWRITE,"MAP_DENYWRITE" },
155 #ifdef MAP_EXECUTABLE
156 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
159 { MAP_INHERIT,"MAP_INHERIT" },
162 { MAP_FILE,"MAP_FILE"},
165 { MAP_LOCKED,"MAP_LOCKED"},
169 { MAP_ANON, "MAP_ANON" },
171 #ifdef MAP_HASSEMAPHORE
172 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
175 { MAP_STACK, "MAP_STACK" },
178 { MAP_NOSYNC, "MAP_NOSYNC" },
181 { MAP_NOCORE, "MAP_NOCORE" },
186 #if !HAVE_LONG_LONG_OFF_T
189 print_mmap(tcp,u_arg)
198 tprintf("%#lx, ", u_arg[0]);
200 tprintf("%lu, ", u_arg[1]);
202 printflags(mmap_prot, u_arg[2], "PROT_???");
206 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
207 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
209 printflags(mmap_flags, u_arg[3], "MAP_???");
211 /* fd (is always int, not long) */
212 tprintf(", %d, ", (int)u_arg[4]);
214 tprintf("%#lx", u_arg[5]);
220 int sys_old_mmap(tcp)
228 * IA64 processes never call this routine, they only use the
229 * new `sys_mmap' interface. This code converts the integer
230 * arguments that the IA32 process pushed onto the stack into
233 * Note that addresses with bit 31 set will be sign extended.
234 * Fortunately, those addresses are not currently being generated
235 * for IA32 processes so it's not a problem.
237 for (i = 0; i < 6; i++)
238 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
242 #elif defined(SH) || defined(SH64)
243 /* SH has always passed the args in registers */
246 u_arg[i] = tcp->u_arg[i];
249 if (current_personality == 1) {
251 for (i = 0; i < 6; ++i) {
253 if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
260 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
262 #endif // defined(IA64)
263 return print_mmap(tcp, u_arg);
272 #if defined(LINUX) && defined(SH64)
274 * Old mmap differs from new mmap in specifying the
275 * offset in units of bytes rather than pages. We
276 * pretend it's in byte units so the user only ever
277 * sees bytes in the printout.
279 tcp->u_arg[5] <<= PAGE_SHIFT;
281 return print_mmap(tcp, tcp->u_arg);
283 #endif /* !HAVE_LONG_LONG_OFF_T */
285 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
292 long *u_arg = tcp->u_arg;
297 long *u_arg = tcp->u_arg;
303 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
304 (char *) u_arg) == -1)
308 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
311 tprintf("%#lx, ", u_arg[0]);
313 tprintf("%lu, ", u_arg[1]);
315 printflags(mmap_prot, u_arg[2], "PROT_???");
319 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
320 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
322 printflags(mmap_flags, u_arg[3], "MAP_???");
325 tprintf(", %ld, ", u_arg[4]);
327 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
340 tcp->u_arg[0], tcp->u_arg[1]);
350 tprintf("%#lx, %lu, ",
351 tcp->u_arg[0], tcp->u_arg[1]);
352 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
359 static const struct xlat mremap_flags[] = {
360 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
369 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
371 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
376 static const struct xlat madvise_flags[] = {
378 { MADV_NORMAL, "MADV_NORMAL" },
381 { MADV_RANDOM, "MADV_RANDOM" },
383 #ifdef MADV_SEQUENTIAL
384 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
387 { MADV_WILLNEED, "MADV_WILLNEED" },
390 { MADV_DONTNEED, "MADV_DONTNEED" },
401 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
402 printflags(madvise_flags, tcp->u_arg[2], "MADV_???");
408 static const struct xlat mlockall_flags[] = {
410 { MCL_CURRENT, "MCL_CURRENT" },
413 { MCL_FUTURE, "MCL_FUTURE" },
423 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
433 static const struct xlat mctl_sync[] = {
435 { MS_SYNC, "MS_SYNC" },
437 { MS_ASYNC, "MS_ASYNC" },
438 { MS_INVALIDATE,"MS_INVALIDATE" },
448 tprintf("%#lx", tcp->u_arg[0]);
450 tprintf(", %lu, ", tcp->u_arg[1]);
452 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
457 #endif /* MS_ASYNC */
461 static const struct xlat mctl_funcs[] = {
462 { MC_LOCK, "MC_LOCK" },
463 { MC_LOCKAS, "MC_LOCKAS" },
464 { MC_SYNC, "MC_SYNC" },
465 { MC_UNLOCK, "MC_UNLOCK" },
466 { MC_UNLOCKAS, "MC_UNLOCKAS" },
470 static const struct xlat mctl_lockas[] = {
471 { MCL_CURRENT, "MCL_CURRENT" },
472 { MCL_FUTURE, "MCL_FUTURE" },
484 tprintf("%#lx", tcp->u_arg[0]);
486 tprintf(", %lu, ", tcp->u_arg[1]);
488 function = tcp->u_arg[2];
489 printflags(mctl_funcs, function, "MC_???");
495 printflags(mctl_sync, arg, "MS_???");
498 printflags(mctl_lockas, arg, "MCL_???");
514 unsigned long i, len;
518 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
521 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
522 (vec = malloc(len)) == NULL ||
523 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
524 tprintf("%#lx", tcp->u_arg[2]);
527 for (i = 0; i < len; i++) {
528 if (abbrev(tcp) && i >= max_strlen) {
532 tprintf((vec[i] & 1) ? "1" : "0");
551 #if defined(LINUX) && defined(__i386__)
553 print_ldt_entry (ldt_entry)
554 struct modify_ldt_ldt_s *ldt_entry;
556 tprintf("base_addr:%#08lx, "
560 "read_exec_only:%d, "
561 "limit_in_pages:%d, "
562 "seg_not_present:%d, "
564 ldt_entry->base_addr,
566 ldt_entry->seg_32bit,
568 ldt_entry->read_exec_only,
569 ldt_entry->limit_in_pages,
570 ldt_entry->seg_not_present,
579 struct modify_ldt_ldt_s copy;
580 tprintf("%ld", tcp->u_arg[0]);
581 if (tcp->u_arg[1] == 0
582 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
583 || umove(tcp, tcp->u_arg[1], ©) == -1)
584 tprintf(", %lx", tcp->u_arg[1]);
586 tprintf(", {entry_number:%d, ", copy.entry_number);
590 print_ldt_entry(©);
593 tprintf(", %lu", tcp->u_arg[2]);
599 sys_set_thread_area(tcp)
602 struct modify_ldt_ldt_s copy;
604 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
605 if (copy.entry_number == -1)
606 tprintf("{entry_number:%d -> ",
609 tprintf("{entry_number:");
612 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
613 tprintf("%d, ", copy.entry_number);
617 print_ldt_entry(©);
620 tprintf("%lx", tcp->u_arg[0]);
628 sys_get_thread_area(tcp)
631 struct modify_ldt_ldt_s copy;
633 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
634 tprintf("{entry_number:%d, ", copy.entry_number);
638 print_ldt_entry(©);
641 tprintf("%lx", tcp->u_arg[0]);
647 #endif /* LINUX && __i386__ */
651 sys_remap_file_pages(tcp)
655 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
656 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
657 tprintf(", %lu, ", tcp->u_arg[3]);
659 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
660 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
662 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
669 #define MPOL_DEFAULT 0
670 #define MPOL_PREFERRED 1
672 #define MPOL_INTERLEAVE 3
674 #define MPOL_F_NODE (1<<0)
675 #define MPOL_F_ADDR (1<<1)
677 #define MPOL_MF_STRICT (1<<0)
680 static const struct xlat policies[] = {
681 { MPOL_DEFAULT, "MPOL_DEFAULT" },
682 { MPOL_PREFERRED, "MPOL_PREFERRED" },
683 { MPOL_BIND, "MPOL_BIND" },
684 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
688 static const struct xlat mbindflags[] = {
689 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
693 static const struct xlat mempolicyflags[] = {
694 { MPOL_F_NODE, "MPOL_F_NODE" },
695 { MPOL_F_ADDR, "MPOL_F_ADDR" },
701 get_nodes(tcp, ptr, maxnodes, err)
704 unsigned long maxnodes;
707 unsigned long nlongs, size, end;
709 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
710 size = nlongs * sizeof(long);
712 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
714 unsigned long n, cur, abbrev_end;
718 abbrev_end = ptr + max_strlen * sizeof(long);
719 if (abbrev_end < ptr)
725 for (cur = ptr; cur < end; cur += sizeof(long)) {
728 if (cur >= abbrev_end) {
732 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
737 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
741 tprintf(" %#lx", ptr);
743 tprintf(", %#lx", ptr);
744 tprintf(", %lu", maxnodes);
752 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
753 printxval(policies, tcp->u_arg[2], "MPOL_???");
754 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
756 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
762 sys_set_mempolicy(tcp)
766 printxval(policies, tcp->u_arg[0], "MPOL_???");
767 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
773 sys_get_mempolicy(tcp)
778 if (tcp->u_arg[0] == 0)
780 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
781 tprintf("%#lx", tcp->u_arg[0]);
783 printxval(policies, pol, "MPOL_???");
784 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
785 tprintf(", %#lx, ", tcp->u_arg[3]);
786 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");